File tree 2 files changed +29
-7
lines changed
packages/bazel/src/schematics/ng-add
2 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -154,15 +154,18 @@ function updateAngularJsonToUseBazelBuilder(options: Schema): Rule {
154
154
} ,
155
155
} ,
156
156
indent ) ;
157
- replacePropertyInAstObject (
158
- recorder , architect , 'test' , {
159
- builder : '@angular/bazel:build' ,
160
- options : { 'bazelCommand' : 'test' , 'targetLabel' : '//src/...' } ,
161
- } ,
162
- indent ) ;
157
+
158
+ if ( findPropertyInAstObject ( architect , 'test' ) ) {
159
+ replacePropertyInAstObject (
160
+ recorder , architect , 'test' , {
161
+ builder : '@angular/bazel:build' ,
162
+ options : { 'bazelCommand' : 'test' , 'targetLabel' : '//src/...' } ,
163
+ } ,
164
+ indent ) ;
165
+ }
163
166
164
167
const e2eArchitect = findE2eArchitect ( workspaceJsonAst , name ) ;
165
- if ( e2eArchitect ) {
168
+ if ( e2eArchitect && findPropertyInAstObject ( e2eArchitect , 'e2e' ) ) {
166
169
replacePropertyInAstObject (
167
170
recorder , e2eArchitect , 'e2e' , {
168
171
builder : '@angular/bazel:build' ,
Original file line number Diff line number Diff line change @@ -246,4 +246,23 @@ describe('ng-add schematic', () => {
246
246
const json = JSON . parse ( content ) ;
247
247
expect ( json . scripts . postinstall ) . toBe ( 'ngc -p ./angular-metadata.tsconfig.json' ) ;
248
248
} ) ;
249
+
250
+ it ( 'should work when run on a minimal project (without test and e2e targets)' , ( ) => {
251
+ host . overwrite ( 'angular.json' , JSON . stringify ( {
252
+ projects : {
253
+ 'demo' : {
254
+ architect : {
255
+ build : { } ,
256
+ serve : { } ,
257
+ 'extract-i18n' : {
258
+ builder : '@angular-devkit/build-angular:extract-i18n' ,
259
+ } ,
260
+ } ,
261
+ } ,
262
+ } ,
263
+ } ) ) ;
264
+
265
+ expect ( ( ) => schematicRunner . runSchematic ( 'ng-add' , defaultOptions , host ) ) . not . toThrowError ( ) ;
266
+ } ) ;
267
+
249
268
} ) ;
You can’t perform that action at this time.
0 commit comments