Skip to content

Commit e3b32c5

Browse files
committed
chore(tests): Auto run tests after builds
When running `ng build` or `ng build --watch` karma tests are run after builds `--no-test` swtich to turn it off
1 parent 97cd0d3 commit e3b32c5

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

addon/ng2/commands/build.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
'use strict';
2+
3+
var path = require('path');
4+
var Command = require('ember-cli/lib/models/command');
5+
var win = require('ember-cli/lib/utilities/windows-admin');
6+
var BuildCommand = require('ember-cli/lib/commands/build');
7+
var BuildTask = require('ember-cli/lib/tasks/build');
8+
var BuildWatchTask = require('ember-cli/lib/tasks/build-watch');
9+
var TestTask = require('../tasks/test');
10+
11+
module.exports = BuildCommand.extend({
12+
name: 'build',
13+
description: 'Builds your app and places it into the output path (dist/ by default).',
14+
aliases: ['b'],
15+
16+
availableOptions: [
17+
{ name: 'environment', type: String, default: 'development', aliases: ['e', { 'dev': 'development' }, { 'prod': 'production' }] },
18+
{ name: 'output-path', type: path, default: 'dist/', aliases: ['o'] },
19+
{ name: 'watch', type: Boolean, default: false, aliases: ['w'] },
20+
{ name: 'watcher', type: String },
21+
{ name: 'no-test', type: Boolean, default: false}
22+
],
23+
24+
run: function(commandOptions){
25+
var BuildTask = this.tasks.Build;
26+
var buildTask = new BuildTask({
27+
ui: this.ui,
28+
analytics: this.analytics,
29+
project: this.project
30+
});
31+
var BuildWatchTask = this.tasks.BuildWatch;
32+
var buildWatchTask = new BuildWatchTask({
33+
ui: this.ui,
34+
analytics: this.analytics,
35+
project: this.project
36+
});
37+
var testTask = new TestTask({
38+
ui: this.ui,
39+
analytics: this.analytics,
40+
project: this.project
41+
});
42+
43+
if (commandOptions.watch){
44+
return win.checkWindowsElevation(this.ui)
45+
.then(function() {
46+
commandOptions.buildCompleted = function(){
47+
return testTask.run({singleRun: true});
48+
};
49+
return buildWatchTask.run(commandOptions);
50+
});
51+
} else {
52+
return win.checkWindowsElevation(this.ui)
53+
.then(function() {
54+
commandOptions.buildCompleted = function(){
55+
return testTask.run({singleRun: true});
56+
};
57+
return buildTask.run(commandOptions);
58+
});
59+
}
60+
}
61+
});
62+
63+
module.exports.overrideCore = true;

addon/ng2/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ module.exports = {
55
name: 'ng2',
66
includedCommands: function() {
77
return {
8+
'build' : require('./commands/build'),
89
'new' : require('./commands/new'),
910
'init' : require('./commands/init'),
1011
'install' : require('./commands/install'),
1112
'uninstall' : require('./commands/uninstall'),
1213
'test' : require('./commands/test'),
13-
'e2e' : require('./commands/e2e'),
14+
'e2e' : require('./commands/e2e'),
1415
'lint' : require('./commands/lint'),
1516
'format' : require('./commands/format')
1617
};

0 commit comments

Comments
 (0)