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): respect the skipTests option #370

Merged
merged 2 commits into from
Dec 1, 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
12 changes: 12 additions & 0 deletions projects/spectator/schematics/src/spectator/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/spectator/schematics/src/spectator/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 25 additions & 4 deletions projects/spectator/schematics/src/spectator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export function spectatorComponentSchematic(options: ComponentOptions): Rule {
skipTests: true,
spec: false
}),
(tree: Tree, _context: SchematicContext): Rule => {
(tree: Tree, _context: SchematicContext): Tree | Rule => {
if (options.skipTests) {
return tree;
}

_ensurePath(tree, options);
const movePath = options.flat ? (options.path as string) : normalize(options.path + '/' + strings.dasherize(options.name) || '');

Expand All @@ -37,6 +41,7 @@ export function spectatorComponentSchematic(options: ComponentOptions): Rule {
move(movePath)
]
);

return mergeWith(specTemplateRule, MergeStrategy.Default);
}
]);
Expand All @@ -49,7 +54,11 @@ export function spectatorServiceSchematic(options: ServiceOptions): Rule {
skipTests: true,
spec: false
}),
(tree: Tree, _context: SchematicContext): Rule => {
(tree: Tree, _context: SchematicContext): Tree | Rule => {
if (options.skipTests) {
return tree;
}

_ensurePath(tree, options);
const movePath = normalize(options.path || '');
const specTemplateRule = apply(url(`./files/${options.isDataService ? 'data-service' : `service`}`), [
Expand All @@ -59,6 +68,7 @@ export function spectatorServiceSchematic(options: ServiceOptions): Rule {
}),
move(movePath)
]);

return mergeWith(specTemplateRule, MergeStrategy.Default);
}
]);
Expand All @@ -71,7 +81,11 @@ export function spectatorDirectiveSchematic(options: DirectiveOptions): Rule {
skipTests: true,
spec: false
}),
(tree: Tree, _context: SchematicContext): Rule => {
(tree: Tree, _context: SchematicContext): Tree | Rule => {
if (options.skipTests) {
return tree;
}

_ensurePath(tree, options);
const movePath = normalize(options.path || '');
const specTemplateRule = apply(url(`./files/directive`), [
Expand All @@ -81,6 +95,7 @@ export function spectatorDirectiveSchematic(options: DirectiveOptions): Rule {
}),
move(movePath)
]);

return mergeWith(specTemplateRule, MergeStrategy.Default);
}
]);
Expand All @@ -93,7 +108,11 @@ export function spectatorPipeSchematic(options: DirectiveOptions): Rule {
skipTests: true,
spec: false
}),
(tree: Tree, _context: SchematicContext): Rule => {
(tree: Tree, _context: SchematicContext): Tree | Rule => {
if (options.skipTests) {
return tree;
}

_ensurePath(tree, options);
const movePath = normalize(options.path || '');
const specTemplateRule = apply(url(`./files/pipe`), [
Expand All @@ -103,6 +122,7 @@ export function spectatorPipeSchematic(options: DirectiveOptions): Rule {
}),
move(movePath)
]);

return mergeWith(specTemplateRule, MergeStrategy.Default);
}
]);
Expand All @@ -113,6 +133,7 @@ function _ensurePath(tree: Tree, options: any): void {
if (!options.project) {
options.project = Object.keys(workspace.projects)[0];
}

const project = workspace.projects[options.project];
if (options.path === undefined) {
const root = project.sourceRoot ? `/${project.sourceRoot}/` : `/${project.root}/src/app`;
Expand Down
2 changes: 1 addition & 1 deletion projects/spectator/schematics/src/spectator/schema.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions projects/spectator/schematics/src/spectator/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export class ComponentOptions {
* Flag to skip the module import.
*/
skipImport?: boolean;
/**
* When true, does not create test files.
*/
skipTests?: boolean;
/**
* Specifies if a spec file is generated.
*/
Expand Down