Skip to content

Commit 9fd3993

Browse files
skydeverFrozenPandaz
authored andcommittedSep 14, 2018
fix(schematics): do not modify tests when skipTests is set
1 parent edae03e commit 9fd3993

File tree

2 files changed

+38
-22
lines changed

2 files changed

+38
-22
lines changed
 

‎packages/schematics/src/collection/application/application.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,17 @@ describe('app', () => {
239239
getFileContent(tree, 'apps/my-dir/my-app/src/app/app.component.spec.ts')
240240
).toContain('imports: [RouterTestingModule]');
241241
});
242+
243+
it('should not modify tests when --skip-tests is set', () => {
244+
const tree = schematicRunner.runSchematic(
245+
'app',
246+
{ name: 'myApp', directory: 'myDir', routing: true, skipTests: true },
247+
appTree
248+
);
249+
expect(
250+
tree.exists('apps/my-dir/my-app/src/app/app.component.spec.ts')
251+
).toBeFalsy();
252+
});
242253
});
243254

244255
describe('template generation mode', () => {

‎packages/schematics/src/collection/application/index.ts

+27-22
Original file line numberDiff line numberDiff line change
@@ -73,29 +73,34 @@ function addRouterRootConfiguration(options: NormalizedSchema): Rule {
7373
)
7474
]);
7575

76-
const componentSpecPath = `${
77-
options.appProjectRoot
78-
}/src/app/app.component.spec.ts`;
79-
const componentSpecSource = host.read(componentSpecPath)!.toString('utf-8');
80-
const componentSpecSourceFile = ts.createSourceFile(
81-
componentSpecPath,
82-
componentSpecSource,
83-
ts.ScriptTarget.Latest,
84-
true
85-
);
86-
insert(host, componentSpecPath, [
87-
insertImport(
88-
componentSpecSourceFile,
89-
componentSpecPath,
90-
'RouterTestingModule',
91-
'@angular/router/testing'
92-
),
93-
...addImportToTestBed(
94-
componentSpecSourceFile,
76+
if (options.skipTests !== true) {
77+
const componentSpecPath = `${
78+
options.appProjectRoot
79+
}/src/app/app.component.spec.ts`;
80+
const componentSpecSource = host.read(componentSpecPath)!.toString(
81+
'utf-8'
82+
);
83+
const componentSpecSourceFile = ts.createSourceFile(
9584
componentSpecPath,
96-
`RouterTestingModule`
97-
)
98-
]);
85+
componentSpecSource,
86+
ts.ScriptTarget.Latest,
87+
true
88+
);
89+
insert(host, componentSpecPath, [
90+
insertImport(
91+
componentSpecSourceFile,
92+
componentSpecPath,
93+
'RouterTestingModule',
94+
'@angular/router/testing'
95+
),
96+
...addImportToTestBed(
97+
componentSpecSourceFile,
98+
componentSpecPath,
99+
`RouterTestingModule`
100+
)
101+
]);
102+
}
103+
99104
return host;
100105
};
101106
}

0 commit comments

Comments
 (0)