Skip to content

Commit

Permalink
feat(command): ng test command runs karma
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Brocco committed Dec 3, 2015
1 parent 87bfa14 commit f12424b
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
30 changes: 30 additions & 0 deletions addon/ng2/commands/test.js
@@ -0,0 +1,30 @@
'use strict';

var chalk = require('chalk');
var Command = require('ember-cli/lib/models/command');
var Promise = require('ember-cli/lib/ext/promise');
var Project = require('ember-cli/lib/models/project');
var SilentError = require('silent-error');
var validProjectName = require('ember-cli/lib/utilities/valid-project-name');
var normalizeBlueprint = require('ember-cli/lib/utilities/normalize-blueprint-option');

var TestCommand = require('ember-cli/lib/commands/test');
var childProcess = require('child_process')

module.exports = TestCommand.extend({

init: function(){
var cwd = process.cwd();
this.karma = this.karma || require(cwd + '/node_modules/karma/lib/index');
this.karmaConfig = this.karmaConfig || cwd + '/karma.conf';
this.server = this.server || new this.karma.Server({configFile: this.karmaConfig});
},

run: function(commandOptions, rawArgs) {
return new Promise(function(){
return this.server.start();
}.bind(this));
}
});

module.exports.overrideCore = true;
3 changes: 2 additions & 1 deletion addon/ng2/index.js
Expand Up @@ -6,7 +6,8 @@ module.exports = {
includedCommands: function() {
return {
'new': require('./commands/new'),
'init': require('./commands/init')
'init': require('./commands/init'),
'test': require('./commands/test')
};
}
};
53 changes: 53 additions & 0 deletions tests/acceptance/test.spec.js
@@ -0,0 +1,53 @@
'use strict';

var fs = require('fs-extra');
var ng = require('../helpers/ng');
var existsSync = require('exists-sync');
var expect = require('chai').expect;
var forEach = require('lodash/collection/forEach');
var walkSync = require('walk-sync');
var Blueprint = require('ember-cli/lib/models/blueprint');
var path = require('path');
var tmp = require('../helpers/tmp');
var root = process.cwd();
var util = require('util');
var conf = require('ember-cli/tests/helpers/conf');
var EOL = require('os').EOL;

describe('Acceptance: ng test', function () {
before(conf.setup);

after(conf.restore);

beforeEach(function () {
return tmp.setup('./tmp')
.then(function () {
process.chdir('./tmp');
})
.then(function () {
return ng([
'init',
'--skip-npm',
'--skip-bower'
]);
});
});

afterEach(function () {
this.timeout(10000);

return tmp.teardown('./tmp');
});

it('ng test should excecute a test', function () {
console.log('starting test');
return ng([
'test',
'--skip-npm',
'--skip-bower'
])
.then(function () {
console.log('test completed');
});
});
});

0 comments on commit f12424b

Please sign in to comment.