Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(schematics): migrate spec to skipTest to be in line with Angular CLI #2253

Merged
merged 4 commits into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -125,8 +124,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 @@ -201,7 +200,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 @@ -211,7 +215,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
7 changes: 0 additions & 7 deletions modules/schematics-core/testing/create-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ export const defaultAppOptions = {
skipTests: false,
};

const defaultModuleOptions = {
name: 'foo',
spec: true,
module: undefined,
flat: false,
};

const defaultLibOptions = {
name: 'baz',
};
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 @@ -118,7 +130,7 @@ describe('Action Schematic', () => {
});

it('should create spec class with right imports', () => {
const options = { ...actionClassesDefaultOptions, spec: true };
const options = { ...actionClassesDefaultOptions };
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',
style: '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
8 changes: 4 additions & 4 deletions modules/schematics/src/container/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,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 All @@ -155,7 +155,7 @@ export default function(options: ContainerOptions): Rule {
return chain([
externalSchematic('@schematics/angular', 'component', {
...opts,
skipTests: true,
skipTests: true
}),
addStateToComponent(options),
mergeWith(templateSource),
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 @@ -61,10 +61,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 {
*/
style?: 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
Loading