Skip to content

Commit

Permalink
fix(@schematics/angular): set skipTest flag for resolvers when usin…
Browse files Browse the repository at this point in the history
…g ng new --skip-tests
  • Loading branch information
Lehoczky authored and dgp1130 committed Jan 10, 2022
1 parent 509322b commit aadfc79
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
25 changes: 17 additions & 8 deletions packages/schematics/angular/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,23 @@ function addAppToWorkspaceFile(
}

if (options.skipTests || options.minimal) {
['class', 'component', 'directive', 'guard', 'interceptor', 'pipe', 'service'].forEach(
(type) => {
if (!(`@schematics/angular:${type}` in schematics)) {
schematics[`@schematics/angular:${type}`] = {};
}
(schematics[`@schematics/angular:${type}`] as JsonObject).skipTests = true;
},
);
const schematicsWithTests = [
'class',
'component',
'directive',
'guard',
'interceptor',
'pipe',
'resolver',
'service',
];

schematicsWithTests.forEach((type) => {
if (!(`@schematics/angular:${type}` in schematics)) {
schematics[`@schematics/angular:${type}`] = {};
}
(schematics[`@schematics/angular:${type}`] as JsonObject).skipTests = true;
});
}

if (options.strict) {
Expand Down
18 changes: 18 additions & 0 deletions packages/schematics/angular/application/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,24 @@ describe('Application Schematic', () => {
expect(karmaConf).toContain(`dir: require('path').join(__dirname, '../../coverage/foo')`);
});

it('should set the skipTests flag for other schematics when using --skipTests=true', async () => {
const options: ApplicationOptions = { ...defaultOptions, skipTests: true };
const tree = await schematicRunner
.runSchematicAsync('application', options, workspaceTree)
.toPromise();
const config = JSON.parse(tree.readContent('/angular.json'));
const schematics = config.projects.foo.schematics;

expect(schematics['@schematics/angular:class']).toEqual({ skipTests: true });
expect(schematics['@schematics/angular:component']).toEqual({ skipTests: true });
expect(schematics['@schematics/angular:directive']).toEqual({ skipTests: true });
expect(schematics['@schematics/angular:guard']).toEqual({ skipTests: true });
expect(schematics['@schematics/angular:interceptor']).toEqual({ skipTests: true });
expect(schematics['@schematics/angular:pipe']).toEqual({ skipTests: true });
expect(schematics['@schematics/angular:resolver']).toEqual({ skipTests: true });
expect(schematics['@schematics/angular:service']).toEqual({ skipTests: true });
});

it('minimal=true should not create e2e and test targets', async () => {
const options = { ...defaultOptions, minimal: true };
const tree = await schematicRunner
Expand Down

0 comments on commit aadfc79

Please sign in to comment.