Skip to content

Commit

Permalink
fix(schematics): migrate spec to skipTest to be in line with Angular CLI
Browse files Browse the repository at this point in the history
Closes: ngrx#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

```
  • Loading branch information
Jefiozie committed Nov 18, 2019
1 parent ce6ebb3 commit 8461052
Show file tree
Hide file tree
Showing 40 changed files with 124 additions and 116 deletions.
14 changes: 9 additions & 5 deletions modules/effects/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('Effects ng-add Schematic', () => {
name: 'foo',
skipPackageJson: false,
project: 'bar',
spec: true,
module: 'app',
flat: false,
group: false,
Expand Down Expand Up @@ -124,8 +123,8 @@ describe('Effects ng-add Schematic', () => {
expect(thrownError).toBeDefined();
});

it('should respect the spec flag', () => {
const options = { ...defaultOptions, spec: false };
it('should respect the skipTest flag', () => {
const options = { ...defaultOptions, skipTest: true };

const tree = schematicRunner.runSchematic('ng-add', options, appTree);
const files = tree.files;
Expand Down Expand Up @@ -200,7 +199,12 @@ describe('Effects ng-add Schematic', () => {
});

it('should group within an "effects" folder if group is set', () => {
const options = { ...defaultOptions, flat: true, spec: false, group: true };
const options = {
...defaultOptions,
flat: true,
skipTest: true,
group: true,
};

const tree = schematicRunner.runSchematic('ng-add', options, appTree);
const files = tree.files;
Expand All @@ -210,7 +214,7 @@ describe('Effects ng-add Schematic', () => {
});

it('should inject the effect service correctly', async () => {
const options = { ...defaultOptions, spec: true };
const options = { ...defaultOptions, skipTest: false };
const tree = await schematicRunner
.runSchematicAsync('ng-add', options, appTree)
.toPromise();
Expand Down
6 changes: 3 additions & 3 deletions modules/effects/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ export default function(options: EffectOptions): Rule {
options.path = parsedPath.path;

const templateSource = apply(url('./files'), [
options.spec
? noop()
: filter(path => !path.endsWith('.spec.ts.template')),
options.skipTest
? filter(path => !path.endsWith('.spec.ts.template'))
: noop(),
options.minimal ? filter(_ => false) : noop(),
applyTemplates({
...stringUtils,
Expand Down
6 changes: 3 additions & 3 deletions modules/effects/schematics/ng-add/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
"default": true,
"description": "Flag to indicate if a dir is created."
},
"spec": {
"skipTest": {
"type": "boolean",
"default": true,
"description": "Specifies if a spec file is generated."
"default": false,
"description": "When true, does not create test files."
},
"project": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion modules/effects/schematics/ng-add/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface Schema {
skipPackageJson?: boolean;
path?: string;
flat?: boolean;
spec?: boolean;
skipTest?: boolean;
project?: string;
module?: string;
group?: boolean;
Expand Down
20 changes: 16 additions & 4 deletions modules/schematics/src/action/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('Action Schematic', () => {
const defaultOptions: ActionOptions = {
name: 'foo',
project: 'bar',
spec: false,
group: false,
flat: true,
};
Expand Down Expand Up @@ -61,10 +60,23 @@ describe('Action Schematic', () => {
).toBeGreaterThanOrEqual(0);
});

it('should create two files if spec is true', () => {
it('should create two files test files by default', () => {
const options = {
...defaultOptions,
spec: true,
};
const tree = schematicRunner.runSchematic('action', options, appTree);
expect(
tree.files.indexOf(`${projectPath}/src/app/foo.actions.spec.ts`)
).toBeGreaterThanOrEqual(0);
expect(
tree.files.indexOf(`${projectPath}/src/app/foo.actions.ts`)
).toBeGreaterThanOrEqual(0);
});

it('should not create two files test files when skipTests is set to true', () => {
const options = {
...defaultOptions,
skipTests: false,
};
const tree = schematicRunner.runSchematic('action', options, appTree);
expect(
Expand Down Expand Up @@ -116,7 +128,7 @@ describe('Action Schematic', () => {
});

it('should create spec class with right imports', () => {
const options = { ...defaultOptions, spec: true };
const options = { ...defaultOptions };
const tree = schematicRunner.runSchematic('action', options, appTree);
const fileContent = tree.readContent(
`${projectPath}/src/app/foo.actions.spec.ts`
Expand Down
6 changes: 3 additions & 3 deletions modules/schematics/src/action/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export default function(options: ActionOptions): Rule {
const templateSource = apply(
url(options.creators ? './creator-files' : './files'),
[
options.spec
? noop()
: filter(path => !path.endsWith('.spec.ts.template')),
options.skipTests
? filter(path => !path.endsWith('.spec.ts.template'))
: noop(),
applyTemplates({
...stringUtils,
'if-flat': (s: string) =>
Expand Down
4 changes: 2 additions & 2 deletions modules/schematics/src/action/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"description": "The name of the project.",
"aliases": ["p"]
},
"spec": {
"skipTest": {
"type": "boolean",
"description": "Specifies if a spec file is generated.",
"description": "When true, does not create test files.",
"default": false
},
"flat": {
Expand Down
4 changes: 2 additions & 2 deletions modules/schematics/src/action/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export interface Schema {
project?: string;

/**
* Specifies if a spec file is generated.
* When true, does not create test files.
*/
spec?: boolean;
skipTests?: boolean;

/**
* Flag to indicate if a dir is created.
Expand Down
9 changes: 4 additions & 5 deletions modules/schematics/src/container/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('Container Schematic', () => {
inlineTemplate: false,
changeDetection: 'Default',
styleext: 'css',
spec: true,
module: undefined,
export: false,
prefix: 'app',
Expand Down Expand Up @@ -110,7 +109,7 @@ describe('Container Schematic', () => {
});

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

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

it('should inject Store correctly', async () => {
const options = { ...defaultOptions, spec: true };
const options = { ...defaultOptions };
const tree = await schematicRunner
.runSchematicAsync('container', options, appTree)
.toPromise();
Expand All @@ -145,7 +144,7 @@ describe('Container Schematic', () => {
});

it('should use StoreModule if integration test', async () => {
const options = { ...defaultOptions, spec: true };
const options = { ...defaultOptions };
const tree = await schematicRunner
.runSchematicAsync('container', options, appTree)
.toPromise();
Expand Down
6 changes: 3 additions & 3 deletions modules/schematics/src/container/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ export default function(options: ContainerOptions): Rule {
const templateSource = apply(
url(options.testDepth === 'unit' ? './files' : './integration-files'),
[
options.spec
? noop()
: filter(path => !path.endsWith('.spec.ts.template')),
options.skipTest
? filter(path => !path.endsWith('.spec.ts.template'))
: noop(),
applyTemplates({
'if-flat': (s: string) => (options.flat ? '' : s),
...stringUtils,
Expand Down
6 changes: 3 additions & 3 deletions modules/schematics/src/container/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
"type": "string",
"default": "css"
},
"spec": {
"skipTest": {
"type": "boolean",
"description": "Specifies if a spec file is generated.",
"default": true
"description": "When true, does not create test files.",
"default": false
},
"flat": {
"type": "boolean",
Expand Down
4 changes: 2 additions & 2 deletions modules/schematics/src/container/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export interface Schema {
*/
styleext?: string;
/**
* Specifies if a spec file is generated.
* When true, does not create test files.
*/
spec?: boolean;
skipTest?: boolean;
/**
* Flag to indicate if a dir is created.
*/
Expand Down
12 changes: 5 additions & 7 deletions modules/schematics/src/data/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('Data Schematic', () => {
const defaultOptions: DataOptions = {
name: 'foo',
project: 'bar',
spec: false,
group: false,
flat: true,
};
Expand Down Expand Up @@ -60,10 +59,9 @@ describe('Data Schematic', () => {
).toBeGreaterThanOrEqual(0);
});

it('should create two files if spec is true', () => {
it('should create two files if skipTest is false(as it is by default)', () => {
const options = {
...defaultOptions,
spec: true,
};
const tree = schematicRunner.runSchematic('data', options, appTree);
expect(
Expand All @@ -76,7 +74,7 @@ describe('Data Schematic', () => {

describe('service class', () => {
it('should import the correct model', () => {
const options = { ...defaultOptions, spec: true };
const options = { ...defaultOptions };
const tree = schematicRunner.runSchematic('data', options, appTree);
const fileContent = tree.readContent(
`${projectPath}/src/app/foo.service.ts`
Expand All @@ -86,7 +84,7 @@ describe('Data Schematic', () => {
});

it('should extending EntityCollectionServiceBase', () => {
const options = { ...defaultOptions, spec: true };
const options = { ...defaultOptions };
const tree = schematicRunner.runSchematic('data', options, appTree);
const fileContent = tree.readContent(
`${projectPath}/src/app/foo.service.ts`
Expand All @@ -101,7 +99,7 @@ describe('Data Schematic', () => {
});

it('should create model', () => {
const options = { ...defaultOptions, spec: true };
const options = { ...defaultOptions };
const tree = schematicRunner.runSchematic('data', options, appTree);
const fileContent = tree.readContent(`${projectPath}/src/app/foo.ts`);

Expand All @@ -110,7 +108,7 @@ describe('Data Schematic', () => {
});

it('should create spec class with right imports', () => {
const options = { ...defaultOptions, spec: true };
const options = { ...defaultOptions };
const tree = schematicRunner.runSchematic('data', options, appTree);
const fileContent = tree.readContent(
`${projectPath}/src/app/foo.service.spec.ts`
Expand Down
6 changes: 3 additions & 3 deletions modules/schematics/src/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export default function(options: DataOptions): Rule {
options.path = parsedPath.path;

const templateSource = apply(url('./files'), [
options.spec
? noop()
: filter(path => !path.endsWith('.spec.ts.template')),
options.skipTest
? filter(path => !path.endsWith('.spec.ts.template'))
: noop(),
applyTemplates({
...stringUtils,
'if-flat': (s: string) =>
Expand Down
4 changes: 2 additions & 2 deletions modules/schematics/src/data/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"description": "The name of the project.",
"aliases": ["p"]
},
"spec": {
"skipTest": {
"type": "boolean",
"description": "Specifies if a spec file is generated.",
"description": "When true, does not create test files.",
"default": false
},
"flat": {
Expand Down
4 changes: 2 additions & 2 deletions modules/schematics/src/data/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export interface Schema {
project?: string;

/**
* Specifies if a spec file is generated.
* When true, does not create test files.
*/
spec?: boolean;
skipTest?: boolean;

/**
* Flag to indicate if a dir is created.
Expand Down
16 changes: 10 additions & 6 deletions modules/schematics/src/effect/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('Effect Schematic', () => {
const defaultOptions: EffectOptions = {
name: 'foo',
project: 'bar',
spec: true,
module: undefined,
flat: false,
feature: false,
Expand Down Expand Up @@ -104,8 +103,8 @@ describe('Effect Schematic', () => {
expect(thrownError).toBeDefined();
});

it('should respect the spec flag', () => {
const options = { ...defaultOptions, spec: false };
it('should respect the skipTest flag', () => {
const options = { ...defaultOptions, skipTest: true };

const tree = schematicRunner.runSchematic('effect', options, appTree);
const files = tree.files;
Expand Down Expand Up @@ -241,7 +240,12 @@ describe('Effect Schematic', () => {
});

it('should group within an "effects" folder if group is set', () => {
const options = { ...defaultOptions, flat: true, spec: false, group: true };
const options = {
...defaultOptions,
flat: true,
skipTest: true,
group: true,
};

const tree = schematicRunner.runSchematic('effect', options, appTree);
const files = tree.files;
Expand All @@ -253,7 +257,7 @@ describe('Effect Schematic', () => {
it('should group and nest the effect within a feature', () => {
const options = {
...defaultOptions,
spec: false,
skipTest: true,
group: true,
flat: false,
feature: true,
Expand Down Expand Up @@ -405,7 +409,7 @@ describe('Effect Schematic', () => {
});

it('should inject the effect service correctly', async () => {
const options = { ...defaultOptions, spec: true };
const options = { ...defaultOptions };
const tree = await schematicRunner
.runSchematicAsync('effect', options, appTree)
.toPromise();
Expand Down
6 changes: 3 additions & 3 deletions modules/schematics/src/effect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ export default function(options: EffectOptions): Rule {
options.path = parsedPath.path;

const templateSource = apply(url('./files'), [
options.spec
? noop()
: filter(path => !path.endsWith('.spec.ts.template')),
options.skipTest
? filter(path => !path.endsWith('.spec.ts.template'))
: noop(),
options.root && options.minimal ? filter(_ => false) : noop(),
applyTemplates({
...stringUtils,
Expand Down
Loading

0 comments on commit 8461052

Please sign in to comment.