Skip to content

feat(new): add flag to ng new/init to skip creating spec files #3825

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

Merged
merged 13 commits into from
Jan 12, 2017
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
8 changes: 4 additions & 4 deletions packages/angular-cli/blueprints/ng2/files/angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
}
}
}
9 changes: 8 additions & 1 deletion packages/angular-cli/blueprints/ng2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');
Expand All @@ -57,7 +59,8 @@ module.exports = {
isMobile: options.mobile,
routing: options.routing,
inlineStyle: options.inlineStyle,
inlineTemplate: options.inlineTemplate
inlineTemplate: options.inlineTemplate,
tests: this.tests
};
},

Expand All @@ -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;
},

Expand Down
3 changes: 2 additions & 1 deletion packages/angular-cli/commands/init.run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
1 change: 1 addition & 0 deletions packages/angular-cli/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'] },
Expand Down
1 change: 1 addition & 0 deletions packages/angular-cli/commands/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'] },
Expand Down
9 changes: 9 additions & 0 deletions tests/acceptance/init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

});
10 changes: 9 additions & 1 deletion tests/acceptance/new.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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);
});
});

});