diff --git a/docs/guides/customizations.md b/docs/guides/customizations.md index c56ebcd929..b811b0eb9e 100644 --- a/docs/guides/customizations.md +++ b/docs/guides/customizations.md @@ -161,6 +161,18 @@ If possible, use the Jest update feature **update snapshots** when adapting test When you upgrade the PWA to a new version, those snapshots will most likely have merge conflicts in them. Here you can just accept either modification and update the test snapshots. +You can disable creating component tests by adding the following snippet to your `angular.json`: + +```json + "projects": { + "intershop-pwa": { + "schematics": { + "intershop-schematics:component": { + "skipTests": true + } + }, +``` + ### Styling Changing the styling by applying changes to SCSS files should be done in the custom theme folder `src/styles/themes/`. diff --git a/schematics/src/component/factory.ts b/schematics/src/component/factory.ts index e0a8171caa..5c12fc71c4 100644 --- a/schematics/src/component/factory.ts +++ b/schematics/src/component/factory.ts @@ -8,7 +8,6 @@ import { filter, mergeWith, move, - noop, url, } from '@angular-devkit/schematics'; import { PWAComponentOptionsSchema as Options } from 'schemas/component/schema'; @@ -37,7 +36,14 @@ export function createComponent(options: Options): Rule { operations.push( mergeWith( apply(url('./files'), [ - options.styleFile ? noop() : filter(path => !path.includes('.scss')), + filter(path => { + if (path.endsWith('.scss.template')) { + return options.styleFile; + } else if (path.endsWith('.spec.ts.template')) { + return !options.skipTests; + } + return true; + }), applyTemplates({ ...strings, ...options, diff --git a/schematics/src/component/factory_spec.ts b/schematics/src/component/factory_spec.ts index f7917c27f0..2560092a45 100644 --- a/schematics/src/component/factory_spec.ts +++ b/schematics/src/component/factory_spec.ts @@ -105,6 +105,17 @@ describe('Component Schematic', () => { expect(componentSource).toContain(`styleUrls: ['./foo.component.scss']`); }); + it('should create a component without test file if requested', async () => { + const options = { ...defaultOptions, skipTests: true }; + const tree = await schematicRunner.runSchematic('component', options, appTree); + expect(tree.files.filter(x => x.search('foo.component') >= 0)).toMatchInlineSnapshot(` + [ + "/src/app/foo/foo.component.html", + "/src/app/foo/foo.component.ts", + ] + `); + }); + it('should find the closest module', async () => { const options = { ...defaultOptions }; const fooModule = '/src/app/foo/foo.module.ts'; diff --git a/schematics/src/component/schema.json b/schematics/src/component/schema.json index c987b9256f..8b10c43d59 100644 --- a/schematics/src/component/schema.json +++ b/schematics/src/component/schema.json @@ -64,6 +64,11 @@ "description": "When true, does not import this component into the owning NgModule.", "default": false }, + "skipTests": { + "type": "boolean", + "description": "When true, does not create test.", + "default": false + }, "export": { "type": "boolean", "default": false,