Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(refactor): Refactor test command to use test task #216

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
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();
});
}
});