Skip to content

Commit

Permalink
chore(refactor): Refactor test command to use test task
Browse files Browse the repository at this point in the history
Close #216
  • Loading branch information
Brocco authored and filipesilva committed Feb 18, 2016
1 parent 52b1b21 commit de16404
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
26 changes: 7 additions & 19 deletions addon/ng2/commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ 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 TestTask = require('../tasks/test');
var win = require('ember-cli/lib/utilities/windows-admin');
var path = require('path');

// require dependencies within the target project
function requireDependency (root, moduleName) {
var packageJson = require(path.join(root, 'node_modules', moduleName, 'package.json'));
var main = path.normalize(packageJson.main);
return require(path.join(root, 'node_modules', moduleName, main));
}

module.exports = TestCommand.extend({
availableOptions: [
Expand All @@ -37,6 +32,11 @@ module.exports = TestCommand.extend({
analytics: this.analytics,
project: this.project
});
var testTask = new TestTask({
ui: this.ui,
analytics: this.analytics,
project: this.project
});

var buildCommandOptions = {
environment: 'development',
Expand All @@ -51,19 +51,7 @@ module.exports = TestCommand.extend({
return buildTask.run(buildCommandOptions);
})
.then(function(){
return new Promise(function(resolve, reject){
var karma = requireDependency(projectRoot, 'karma');
var karmaConfig = path.join(projectRoot, 'karma.conf');

// Convert browsers from a string to an array
if (commandOptions.browsers){
commandOptions.browsers = commandOptions.browsers.split(',');
}
commandOptions.configFile = karmaConfig;
var karmaServer = new karma.Server(commandOptions, resolve);

karmaServer.start();
});
return testTask.run(commandOptions);
});
}
});
Expand Down
33 changes: 33 additions & 0 deletions addon/ng2/tasks/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* jshint node: true */
'use strict';

var Promise = require('ember-cli/lib/ext/promise');
var Task = require('ember-cli/lib/models/task');
var path = require('path');

// require dependencies within the target project
function requireDependency(root, moduleName) {
var packageJson = require(path.join(root, 'node_modules', moduleName, 'package.json'));
var main = path.normalize(packageJson.main);
return require(path.join(root, 'node_modules', moduleName, main));
}

module.exports = Task.extend({

run: function (options) {
var projectRoot = this.project.root;
return new Promise(function (resolve, reject) {
var karma = requireDependency(projectRoot, 'karma');
var karmaConfig = path.join(projectRoot, 'karma.conf');

// Convert browsers from a string to an array
if (options.browsers) {
options.browsers = options.browsers.split(',');
}
options.configFile = karmaConfig;
var karmaServer = new karma.Server(options, resolve);

karmaServer.start();
});
}
});

0 comments on commit de16404

Please sign in to comment.