From 9b221ff45939985740f5f8b9ad833badbbe38354 Mon Sep 17 00:00:00 2001 From: Mike Brocchi Date: Wed, 17 Feb 2016 20:21:38 -0500 Subject: [PATCH] chore(refactor): Refactor test command to use test task --- addon/ng2/commands/test.js | 26 +++++++------------------- addon/ng2/tasks/test.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 19 deletions(-) create mode 100644 addon/ng2/tasks/test.js diff --git a/addon/ng2/commands/test.js b/addon/ng2/commands/test.js index bf77181e8c37..ef842062dc4e 100644 --- a/addon/ng2/commands/test.js +++ b/addon/ng2/commands/test.js @@ -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: [ @@ -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', @@ -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); }); } }); diff --git a/addon/ng2/tasks/test.js b/addon/ng2/tasks/test.js new file mode 100644 index 000000000000..278a0924efcf --- /dev/null +++ b/addon/ng2/tasks/test.js @@ -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(); + }); + } +});