Skip to content

Commit 31bd12c

Browse files
committed
feat(command): ng test command runs karma
Overrode the ember-cli test command to initialize the karma server Then start the karma server based upon the karma.conf.js config file closes #70
1 parent 0f66aac commit 31bd12c

File tree

3 files changed

+114
-1
lines changed

3 files changed

+114
-1
lines changed

addon/ng2/commands/test.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
'use strict';
2+
3+
var chalk = require('chalk');
4+
var Command = require('ember-cli/lib/models/command');
5+
var Promise = require('ember-cli/lib/ext/promise');
6+
var Project = require('ember-cli/lib/models/project');
7+
var SilentError = require('silent-error');
8+
var validProjectName = require('ember-cli/lib/utilities/valid-project-name');
9+
var normalizeBlueprint = require('ember-cli/lib/utilities/normalize-blueprint-option');
10+
11+
var TestCommand = require('ember-cli/lib/commands/test');
12+
var win = require('ember-cli/lib/utilities/windows-admin');
13+
var path = require('path');
14+
15+
// require dependencies within the target project
16+
function requireDependency (root, moduleName) {
17+
var packageJson = require(path.join(root, 'node_modules', moduleName, 'package.json'));
18+
var main = path.normalize(packageJson.main);
19+
return require(path.join(root, 'node_modules', moduleName, main));
20+
}
21+
22+
module.exports = TestCommand.extend({
23+
24+
init: function(){
25+
if (!this.karmaServer) {
26+
var karma = requireDependency(this.project.root, 'karma');
27+
var karmaConfig = path.join(this.project.root, 'karma.conf');
28+
this.karmaServer = new karma.Server({configFile: karmaConfig});
29+
}
30+
},
31+
32+
run: function(commandOptions, rawArgs) {
33+
var BuildTask = this.tasks.Build;
34+
var buildTask = new BuildTask({
35+
ui: this.ui,
36+
analytics: this.analytics,
37+
project: this.project
38+
});
39+
40+
var buildCommandOptions = {
41+
environment: 'development',
42+
outputPath: 'dist/',
43+
watch: false
44+
};
45+
46+
var self = this;
47+
return win.checkWindowsElevation(this.ui)
48+
.then(function() {
49+
return buildTask.run(buildCommandOptions);
50+
})
51+
.then(function(){
52+
return new Promise(function(){
53+
return self.karmaServer.start();
54+
});
55+
});
56+
}
57+
});
58+
59+
module.exports.overrideCore = true;

addon/ng2/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ module.exports = {
66
includedCommands: function() {
77
return {
88
'new': require('./commands/new'),
9-
'init': require('./commands/init')
9+
'init': require('./commands/init'),
10+
'test': require('./commands/test')
1011
};
1112
}
1213
};

tests/acceptance/test.spec.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
3+
var fs = require('fs-extra');
4+
var ng = require('../helpers/ng');
5+
var existsSync = require('exists-sync');
6+
var expect = require('chai').expect;
7+
var forEach = require('lodash/collection/forEach');
8+
var walkSync = require('walk-sync');
9+
var Blueprint = require('ember-cli/lib/models/blueprint');
10+
var path = require('path');
11+
var tmp = require('../helpers/tmp');
12+
var root = process.cwd();
13+
var util = require('util');
14+
var conf = require('ember-cli/tests/helpers/conf');
15+
var EOL = require('os').EOL;
16+
17+
describe('Acceptance: ng test', function () {
18+
before(conf.setup);
19+
20+
after(conf.restore);
21+
22+
beforeEach(function () {
23+
return tmp.setup('./tmp')
24+
.then(function () {
25+
process.chdir('./tmp');
26+
})
27+
.then(function () {
28+
return ng([
29+
'init',
30+
'--skip-npm',
31+
'--skip-bower'
32+
]);
33+
});
34+
});
35+
36+
afterEach(function () {
37+
this.timeout(10000);
38+
39+
return tmp.teardown('./tmp');
40+
});
41+
42+
it('ng test should excecute a test', function () {
43+
console.log('starting test');
44+
return ng([
45+
'test',
46+
'--skip-npm',
47+
'--skip-bower'
48+
])
49+
.then(function () {
50+
console.log('test completed');
51+
});
52+
});
53+
});

0 commit comments

Comments
 (0)