Skip to content

Commit 714ae5f

Browse files
Jefioziebrandonroberts
authored andcommitted
fix(schematics): migrate spec to skipTest to be in line with Angular CLI (#2253)
Closes: #2242 BREAKING CHANGES: To be inline with the Angular CLI, we migrated the `--spec` to `--skipTest`. By default skipTest is false, this way you will always be provided with `*.spec.ts files` BEFORE: ```sh ng generate action User --spec ``` AFTER: ```sh ng generate action User ```
1 parent 2cc8885 commit 714ae5f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+139
-138
lines changed

modules/effects/schematics/ng-add/index.spec.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ describe('Effects ng-add Schematic', () => {
2121
name: 'foo',
2222
skipPackageJson: false,
2323
project: 'bar',
24-
spec: true,
2524
module: 'app',
2625
flat: false,
2726
group: false,
@@ -125,8 +124,8 @@ describe('Effects ng-add Schematic', () => {
125124
expect(thrownError).toBeDefined();
126125
});
127126

128-
it('should respect the spec flag', () => {
129-
const options = { ...defaultOptions, spec: false };
127+
it('should respect the skipTest flag', () => {
128+
const options = { ...defaultOptions, skipTest: true };
130129

131130
const tree = schematicRunner.runSchematic('ng-add', options, appTree);
132131
const files = tree.files;
@@ -201,7 +200,12 @@ describe('Effects ng-add Schematic', () => {
201200
});
202201

203202
it('should group within an "effects" folder if group is set', () => {
204-
const options = { ...defaultOptions, flat: true, spec: false, group: true };
203+
const options = {
204+
...defaultOptions,
205+
flat: true,
206+
skipTest: true,
207+
group: true,
208+
};
205209

206210
const tree = schematicRunner.runSchematic('ng-add', options, appTree);
207211
const files = tree.files;
@@ -211,7 +215,7 @@ describe('Effects ng-add Schematic', () => {
211215
});
212216

213217
it('should inject the effect service correctly', async () => {
214-
const options = { ...defaultOptions, spec: true };
218+
const options = { ...defaultOptions, skipTest: false };
215219
const tree = await schematicRunner
216220
.runSchematicAsync('ng-add', options, appTree)
217221
.toPromise();

modules/effects/schematics/ng-add/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ export default function(options: EffectOptions): Rule {
129129
options.path = parsedPath.path;
130130

131131
const templateSource = apply(url('./files'), [
132-
options.spec
133-
? noop()
134-
: filter(path => !path.endsWith('.spec.ts.template')),
132+
options.skipTest
133+
? filter(path => !path.endsWith('.spec.ts.template'))
134+
: noop(),
135135
options.minimal ? filter(_ => false) : noop(),
136136
applyTemplates({
137137
...stringUtils,

modules/effects/schematics/ng-add/schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
"default": true,
2727
"description": "Flag to indicate if a dir is created."
2828
},
29-
"spec": {
29+
"skipTest": {
3030
"type": "boolean",
31-
"default": true,
32-
"description": "Specifies if a spec file is generated."
31+
"default": false,
32+
"description": "When true, does not create test files."
3333
},
3434
"project": {
3535
"type": "string",

modules/effects/schematics/ng-add/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export interface Schema {
33
skipPackageJson?: boolean;
44
path?: string;
55
flat?: boolean;
6-
spec?: boolean;
6+
skipTest?: boolean;
77
project?: string;
88
module?: string;
99
group?: boolean;

modules/schematics-core/testing/create-workspace.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ export const defaultAppOptions = {
2020
skipTests: false,
2121
};
2222

23-
const defaultModuleOptions = {
24-
name: 'foo',
25-
spec: true,
26-
module: undefined,
27-
flat: false,
28-
};
29-
3023
const defaultLibOptions = {
3124
name: 'baz',
3225
};

modules/schematics/src/action/index.spec.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ describe('Action Schematic', () => {
1919
const defaultOptions: ActionOptions = {
2020
name: 'foo',
2121
project: 'bar',
22-
spec: false,
2322
group: false,
2423
flat: true,
2524
};
@@ -61,10 +60,23 @@ describe('Action Schematic', () => {
6160
).toBeGreaterThanOrEqual(0);
6261
});
6362

64-
it('should create two files if spec is true', () => {
63+
it('should create two files test files by default', () => {
6564
const options = {
6665
...defaultOptions,
67-
spec: true,
66+
};
67+
const tree = schematicRunner.runSchematic('action', options, appTree);
68+
expect(
69+
tree.files.indexOf(`${projectPath}/src/app/foo.actions.spec.ts`)
70+
).toBeGreaterThanOrEqual(0);
71+
expect(
72+
tree.files.indexOf(`${projectPath}/src/app/foo.actions.ts`)
73+
).toBeGreaterThanOrEqual(0);
74+
});
75+
76+
it('should not create two files test files when skipTests is set to true', () => {
77+
const options = {
78+
...defaultOptions,
79+
skipTests: false,
6880
};
6981
const tree = schematicRunner.runSchematic('action', options, appTree);
7082
expect(
@@ -118,7 +130,7 @@ describe('Action Schematic', () => {
118130
});
119131

120132
it('should create spec class with right imports', () => {
121-
const options = { ...actionClassesDefaultOptions, spec: true };
133+
const options = { ...actionClassesDefaultOptions };
122134
const tree = schematicRunner.runSchematic('action', options, appTree);
123135
const fileContent = tree.readContent(
124136
`${projectPath}/src/app/foo.actions.spec.ts`

modules/schematics/src/action/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export default function(options: ActionOptions): Rule {
3232
const templateSource = apply(
3333
url(options.creators ? './creator-files' : './files'),
3434
[
35-
options.spec
36-
? noop()
37-
: filter(path => !path.endsWith('.spec.ts.template')),
35+
options.skipTests
36+
? filter(path => !path.endsWith('.spec.ts.template'))
37+
: noop(),
3838
applyTemplates({
3939
...stringUtils,
4040
'if-flat': (s: string) =>

modules/schematics/src/action/schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
"description": "The name of the project.",
2525
"aliases": ["p"]
2626
},
27-
"spec": {
27+
"skipTest": {
2828
"type": "boolean",
29-
"description": "Specifies if a spec file is generated.",
29+
"description": "When true, does not create test files.",
3030
"default": false
3131
},
3232
"flat": {

modules/schematics/src/action/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export interface Schema {
1515
project?: string;
1616

1717
/**
18-
* Specifies if a spec file is generated.
18+
* When true, does not create test files.
1919
*/
20-
spec?: boolean;
20+
skipTests?: boolean;
2121

2222
/**
2323
* Flag to indicate if a dir is created.

modules/schematics/src/container/index.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ describe('Container Schematic', () => {
2222
inlineTemplate: false,
2323
changeDetection: 'Default',
2424
style: 'css',
25-
spec: true,
2625
module: undefined,
2726
export: false,
2827
prefix: 'app',
@@ -110,7 +109,7 @@ describe('Container Schematic', () => {
110109
});
111110

112111
it('should update the component spec', async () => {
113-
const options = { ...defaultOptions, spec: true, testDepth: 'unit' };
112+
const options = { ...defaultOptions, testDepth: 'unit' };
114113
const tree = await schematicRunner
115114
.runSchematicAsync('container', options, appTree)
116115
.toPromise();
@@ -123,7 +122,7 @@ describe('Container Schematic', () => {
123122
});
124123

125124
it('should use the provideMockStore helper if unit', async () => {
126-
const options = { ...defaultOptions, spec: true, testDepth: 'unit' };
125+
const options = { ...defaultOptions, testDepth: 'unit' };
127126
const tree = await schematicRunner
128127
.runSchematicAsync('container', options, appTree)
129128
.toPromise();
@@ -134,7 +133,7 @@ describe('Container Schematic', () => {
134133
});
135134

136135
it('should inject Store correctly', async () => {
137-
const options = { ...defaultOptions, spec: true };
136+
const options = { ...defaultOptions };
138137
const tree = await schematicRunner
139138
.runSchematicAsync('container', options, appTree)
140139
.toPromise();
@@ -145,7 +144,7 @@ describe('Container Schematic', () => {
145144
});
146145

147146
it('should use StoreModule if integration test', async () => {
148-
const options = { ...defaultOptions, spec: true };
147+
const options = { ...defaultOptions };
149148
const tree = await schematicRunner
150149
.runSchematicAsync('container', options, appTree)
151150
.toPromise();

0 commit comments

Comments
 (0)