Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat(new): add flag to ng new/init to skip creating spec files
  • Loading branch information
baruchvlz committed Jan 2, 2017
commit 90d6c88e6c91419fcacf25a235cdcb34e6c7c9a7
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 @@ -69,7 +69,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);
});
});

});
13 changes: 13 additions & 0 deletions tests/acceptance/new.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const util = require('util');
const EOL = require('os').EOL;
const SilentError = require('silent-error');

const denodeify = require('denodeify');

const readFile = denodeify(fs.readFile);


describe('Acceptance: ng new', function () {
beforeEach(function () {
Expand Down Expand Up @@ -169,4 +173,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);
});
});

});