diff --git a/packages/angular-cli/blueprints/ng2/files/angular-cli.json b/packages/angular-cli/blueprints/ng2/files/angular-cli.json index 4fd88b98c1cf..239ffb31f171 100644 --- a/packages/angular-cli/blueprints/ng2/files/angular-cli.json +++ b/packages/angular-cli/blueprints/ng2/files/angular-cli.json @@ -49,11 +49,11 @@ }, "spec": { "class": false, - "component": true, - "directive": true, + "component": <%= tests %>, + "directive": <%= tests %>, "module": false, - "pipe": true, - "service": true + "pipe": <%= tests %>, + "service": <%= tests %> } } } diff --git a/packages/angular-cli/blueprints/ng2/index.js b/packages/angular-cli/blueprints/ng2/index.js index 2829f591eec0..49fca45ad622 100644 --- a/packages/angular-cli/blueprints/ng2/index.js +++ b/packages/angular-cli/blueprints/ng2/index.js @@ -32,6 +32,8 @@ module.exports = { locals: function(options) { this.styleExt = options.style; this.version = require(path.resolve(__dirname, '../../package.json')).version; + // set this.tests to opposite of skipTest options, meaning if tests are being skipped then the default.spec.BLUEPRINT will be false + this.tests = options.skipTests ? false : true; // Split/join with / not path.sep as reference to typings require forward slashes. const relativeRootPath = options.sourceDir.split('/').map(() => '..').join('/'); @@ -57,7 +59,8 @@ module.exports = { isMobile: options.mobile, routing: options.routing, inlineStyle: options.inlineStyle, - inlineTemplate: options.inlineTemplate + inlineTemplate: options.inlineTemplate, + tests: this.tests }; }, @@ -77,6 +80,10 @@ module.exports = { fileList = fileList.filter(p => p.indexOf('gitignore') < 0); } + if (this.options && this.options.skipTests) { + fileList = fileList.filter(p => p.indexOf('app.component.spec.ts') < 0); + } + return fileList; }, diff --git a/packages/angular-cli/commands/init.run.ts b/packages/angular-cli/commands/init.run.ts index 0707ccb4135c..0ef9f64bf2b1 100644 --- a/packages/angular-cli/commands/init.run.ts +++ b/packages/angular-cli/commands/init.run.ts @@ -70,7 +70,8 @@ export default function initRun(commandOptions: any, rawArgs: string[]) { inlineStyle: commandOptions.inlineStyle, inlineTemplate: commandOptions.inlineTemplate, ignoredUpdateFiles: ['favicon.ico'], - skipGit: commandOptions.skipGit + skipGit: commandOptions.skipGit, + skipTests: commandOptions.skipTests }; if (!validProjectName(packageName)) { diff --git a/packages/angular-cli/commands/init.ts b/packages/angular-cli/commands/init.ts index 7eae7c70b485..de47429b9d88 100644 --- a/packages/angular-cli/commands/init.ts +++ b/packages/angular-cli/commands/init.ts @@ -12,6 +12,7 @@ const InitCommand: any = Command.extend({ { name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] }, { name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] }, { name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] }, + { name: 'skip-tests', type: Boolean, default: false, aliases: ['st'] }, { name: 'skip-commit', type: Boolean, default: false, aliases: ['sc'] }, { name: 'name', type: String, default: '', aliases: ['n'] }, { name: 'source-dir', type: String, default: 'src', aliases: ['sd'] }, diff --git a/packages/angular-cli/commands/new.ts b/packages/angular-cli/commands/new.ts index c30de3ff3186..9b58b21f2c96 100644 --- a/packages/angular-cli/commands/new.ts +++ b/packages/angular-cli/commands/new.ts @@ -19,6 +19,7 @@ const NewCommand = Command.extend({ { name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] }, { name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] }, { name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] }, + { name: 'skip-tests', type: Boolean, default: false, aliases: ['st'] }, { name: 'skip-commit', type: Boolean, default: false, aliases: ['sc'] }, { name: 'directory', type: String, aliases: ['dir'] }, { name: 'source-dir', type: String, default: 'src', aliases: ['sd'] }, diff --git a/tests/acceptance/init.spec.js b/tests/acceptance/init.spec.js index bb9ddd6265c5..9d70aad87168 100644 --- a/tests/acceptance/init.spec.js +++ b/tests/acceptance/init.spec.js @@ -201,4 +201,13 @@ describe('Acceptance: ng init', function () { expect(existsSync(styleFile)).to.equal(false); }); }); + + it('should skip spec files when passed --skip-tests', () => { + return ng(['init', '--skip-npm', '--skip-git', '--skip-tests']) + .then(() => { + const specFile = path.join('src', 'app', 'app.component.spec.ts'); + expect(existsSync(specFile)).to.equal(false); + }); + }); + }); diff --git a/tests/acceptance/new.spec.ts b/tests/acceptance/new.spec.ts index 546d584154dc..89e6a2cbc582 100644 --- a/tests/acceptance/new.spec.ts +++ b/tests/acceptance/new.spec.ts @@ -12,7 +12,6 @@ const util = require('util'); const EOL = require('os').EOL; const SilentError = require('silent-error'); - describe('Acceptance: ng new', function () { beforeEach(function () { return tmp.setup('./tmp').then(function () { @@ -169,4 +168,13 @@ describe('Acceptance: ng new', function () { expect(existsSync(styleFile)).to.equal(false); }); }); + + it('should skip spec files when passed --skip-tests', () => { + return ng(['new', 'foo', '--skip-npm', '--skip-git', '--skip-tests']) + .then(() => { + const specFile = path.join('src', 'app', 'app.component.spec.ts'); + expect(existsSync(specFile)).to.equal(false); + }); + }); + });