Skip to content

Commit 9b07191

Browse files
Lehoczkydgp1130
authored andcommittedJan 10, 2022
fix(@schematics/angular): set skipTest flag for resolvers when using ng new --skip-tests
(cherry picked from commit aadfc79)
1 parent 39c95da commit 9b07191

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed
 

‎packages/schematics/angular/application/index.ts

+17-8
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,23 @@ function addAppToWorkspaceFile(
9292
}
9393

9494
if (options.skipTests || options.minimal) {
95-
['class', 'component', 'directive', 'guard', 'interceptor', 'pipe', 'service'].forEach(
96-
(type) => {
97-
if (!(`@schematics/angular:${type}` in schematics)) {
98-
schematics[`@schematics/angular:${type}`] = {};
99-
}
100-
(schematics[`@schematics/angular:${type}`] as JsonObject).skipTests = true;
101-
},
102-
);
95+
const schematicsWithTests = [
96+
'class',
97+
'component',
98+
'directive',
99+
'guard',
100+
'interceptor',
101+
'pipe',
102+
'resolver',
103+
'service',
104+
];
105+
106+
schematicsWithTests.forEach((type) => {
107+
if (!(`@schematics/angular:${type}` in schematics)) {
108+
schematics[`@schematics/angular:${type}`] = {};
109+
}
110+
(schematics[`@schematics/angular:${type}`] as JsonObject).skipTests = true;
111+
});
103112
}
104113

105114
if (options.strict) {

‎packages/schematics/angular/application/index_spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,24 @@ describe('Application Schematic', () => {
179179
expect(karmaConf).toContain(`dir: require('path').join(__dirname, '../../coverage/foo')`);
180180
});
181181

182+
it('should set the skipTests flag for other schematics when using --skipTests=true', async () => {
183+
const options: ApplicationOptions = { ...defaultOptions, skipTests: true };
184+
const tree = await schematicRunner
185+
.runSchematicAsync('application', options, workspaceTree)
186+
.toPromise();
187+
const config = JSON.parse(tree.readContent('/angular.json'));
188+
const schematics = config.projects.foo.schematics;
189+
190+
expect(schematics['@schematics/angular:class']).toEqual({ skipTests: true });
191+
expect(schematics['@schematics/angular:component']).toEqual({ skipTests: true });
192+
expect(schematics['@schematics/angular:directive']).toEqual({ skipTests: true });
193+
expect(schematics['@schematics/angular:guard']).toEqual({ skipTests: true });
194+
expect(schematics['@schematics/angular:interceptor']).toEqual({ skipTests: true });
195+
expect(schematics['@schematics/angular:pipe']).toEqual({ skipTests: true });
196+
expect(schematics['@schematics/angular:resolver']).toEqual({ skipTests: true });
197+
expect(schematics['@schematics/angular:service']).toEqual({ skipTests: true });
198+
});
199+
182200
it('minimal=true should not create e2e and test targets', async () => {
183201
const options = { ...defaultOptions, minimal: true };
184202
const tree = await schematicRunner

0 commit comments

Comments
 (0)
Please sign in to comment.