Skip to content

Commit 4c2f06a

Browse files
baruchvlzhansl
authored andcommitted
feat(new): add --skip-tests flag to ng new/init to skip creating spec files (angular#3825)
1 parent b3ef6a4 commit 4c2f06a

File tree

7 files changed

+34
-7
lines changed

7 files changed

+34
-7
lines changed

packages/angular-cli/blueprints/ng2/files/angular-cli.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@
4949
},
5050
"spec": {
5151
"class": false,
52-
"component": true,
53-
"directive": true,
52+
"component": <%= tests %>,
53+
"directive": <%= tests %>,
5454
"module": false,
55-
"pipe": true,
56-
"service": true
55+
"pipe": <%= tests %>,
56+
"service": <%= tests %>
5757
}
5858
}
5959
}

packages/angular-cli/blueprints/ng2/index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ module.exports = {
3232
locals: function(options) {
3333
this.styleExt = options.style;
3434
this.version = require(path.resolve(__dirname, '../../package.json')).version;
35+
// set this.tests to opposite of skipTest options, meaning if tests are being skipped then the default.spec.BLUEPRINT will be false
36+
this.tests = options.skipTests ? false : true;
3537

3638
// Split/join with / not path.sep as reference to typings require forward slashes.
3739
const relativeRootPath = options.sourceDir.split('/').map(() => '..').join('/');
@@ -57,7 +59,8 @@ module.exports = {
5759
isMobile: options.mobile,
5860
routing: options.routing,
5961
inlineStyle: options.inlineStyle,
60-
inlineTemplate: options.inlineTemplate
62+
inlineTemplate: options.inlineTemplate,
63+
tests: this.tests
6164
};
6265
},
6366

@@ -77,6 +80,10 @@ module.exports = {
7780
fileList = fileList.filter(p => p.indexOf('gitignore') < 0);
7881
}
7982

83+
if (this.options && this.options.skipTests) {
84+
fileList = fileList.filter(p => p.indexOf('app.component.spec.ts') < 0);
85+
}
86+
8087
return fileList;
8188
},
8289

packages/angular-cli/commands/init.run.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ export default function initRun(commandOptions: any, rawArgs: string[]) {
7070
inlineStyle: commandOptions.inlineStyle,
7171
inlineTemplate: commandOptions.inlineTemplate,
7272
ignoredUpdateFiles: ['favicon.ico'],
73-
skipGit: commandOptions.skipGit
73+
skipGit: commandOptions.skipGit,
74+
skipTests: commandOptions.skipTests
7475
};
7576

7677
if (!validProjectName(packageName)) {

packages/angular-cli/commands/init.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const InitCommand: any = Command.extend({
1212
{ name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] },
1313
{ name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] },
1414
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
15+
{ name: 'skip-tests', type: Boolean, default: false, aliases: ['st'] },
1516
{ name: 'skip-commit', type: Boolean, default: false, aliases: ['sc'] },
1617
{ name: 'name', type: String, default: '', aliases: ['n'] },
1718
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },

packages/angular-cli/commands/new.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const NewCommand = Command.extend({
1919
{ name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] },
2020
{ name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] },
2121
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
22+
{ name: 'skip-tests', type: Boolean, default: false, aliases: ['st'] },
2223
{ name: 'skip-commit', type: Boolean, default: false, aliases: ['sc'] },
2324
{ name: 'directory', type: String, aliases: ['dir'] },
2425
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },

tests/acceptance/init.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,13 @@ describe('Acceptance: ng init', function () {
201201
expect(existsSync(styleFile)).to.equal(false);
202202
});
203203
});
204+
205+
it('should skip spec files when passed --skip-tests', () => {
206+
return ng(['init', '--skip-npm', '--skip-git', '--skip-tests'])
207+
.then(() => {
208+
const specFile = path.join('src', 'app', 'app.component.spec.ts');
209+
expect(existsSync(specFile)).to.equal(false);
210+
});
211+
});
212+
204213
});

tests/acceptance/new.spec.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const util = require('util');
1212
const EOL = require('os').EOL;
1313
const SilentError = require('silent-error');
1414

15-
1615
describe('Acceptance: ng new', function () {
1716
beforeEach(function () {
1817
return tmp.setup('./tmp').then(function () {
@@ -169,4 +168,13 @@ describe('Acceptance: ng new', function () {
169168
expect(existsSync(styleFile)).to.equal(false);
170169
});
171170
});
171+
172+
it('should skip spec files when passed --skip-tests', () => {
173+
return ng(['new', 'foo', '--skip-npm', '--skip-git', '--skip-tests'])
174+
.then(() => {
175+
const specFile = path.join('src', 'app', 'app.component.spec.ts');
176+
expect(existsSync(specFile)).to.equal(false);
177+
});
178+
});
179+
172180
});

0 commit comments

Comments
 (0)