Skip to content

Commit

Permalink
fix(bazel): support running ng-add on minimal applications (#29681)
Browse files Browse the repository at this point in the history
Minimal applications don't have `test` and `e2e` targets but we are not currently checking if they exists.

Fixes #29680

PR Close #29681
  • Loading branch information
alan-agius4 authored and jasonaden committed Apr 3, 2019
1 parent 8e83b3b commit 9810c6c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/bazel/src/schematics/ng-add/index.ts
Expand Up @@ -154,15 +154,18 @@ function updateAngularJsonToUseBazelBuilder(options: Schema): Rule {
},
},
indent);
replacePropertyInAstObject(
recorder, architect, 'test', {
builder: '@angular/bazel:build',
options: {'bazelCommand': 'test', 'targetLabel': '//src/...'},
},
indent);

if (findPropertyInAstObject(architect, 'test')) {
replacePropertyInAstObject(
recorder, architect, 'test', {
builder: '@angular/bazel:build',
options: {'bazelCommand': 'test', 'targetLabel': '//src/...'},
},
indent);
}

const e2eArchitect = findE2eArchitect(workspaceJsonAst, name);
if (e2eArchitect) {
if (e2eArchitect && findPropertyInAstObject(e2eArchitect, 'e2e')) {
replacePropertyInAstObject(
recorder, e2eArchitect, 'e2e', {
builder: '@angular/bazel:build',
Expand Down
19 changes: 19 additions & 0 deletions packages/bazel/src/schematics/ng-add/index_spec.ts
Expand Up @@ -246,4 +246,23 @@ describe('ng-add schematic', () => {
const json = JSON.parse(content);
expect(json.scripts.postinstall).toBe('ngc -p ./angular-metadata.tsconfig.json');
});

it('should work when run on a minimal project (without test and e2e targets)', () => {
host.overwrite('angular.json', JSON.stringify({
projects: {
'demo': {
architect: {
build: {},
serve: {},
'extract-i18n': {
builder: '@angular-devkit/build-angular:extract-i18n',
},
},
},
},
}));

expect(() => schematicRunner.runSchematic('ng-add', defaultOptions, host)).not.toThrowError();
});

});

0 comments on commit 9810c6c

Please sign in to comment.