diff --git a/lib/commands/new/unit-test-runners/karma.js b/lib/commands/new/unit-test-runners/karma.js index 00ae3164a..09174405b 100644 --- a/lib/commands/new/unit-test-runners/karma.js +++ b/lib/commands/new/unit-test-runners/karma.js @@ -17,7 +17,7 @@ module.exports = function(project) { ProjectItem.resource('setup.ext', 'test/setup.js', project.model.transpiler), ProjectItem.resource('app.spec.ext', 'test/app.spec.js', project.model.transpiler) ), - ProjectItem.resource('aurelia-karma.js', 'test/aurelia-karma.js') + ProjectItem.resource('aurelia-karma.js', `test/${project.loader}.aurelia-karma.js`) ) ).addToDevDependencies( 'jasmine-core', diff --git a/lib/dependencies.json b/lib/dependencies.json index 34265b276..9e1978772 100644 --- a/lib/dependencies.json +++ b/lib/dependencies.json @@ -45,6 +45,8 @@ "karma-typescript-preprocessor": "^0.2.1", "minimatch": "^3.0.2", "requirejs": "^2.3.2", + "systemjs":"0.20.13", + "systemjs-plugin-text":"0.0.9", "text": "github:requirejs/text#latest", "through2": "^2.0.1", "tslint": "^3.11.0", diff --git a/lib/resources/test/aurelia-karma.js b/lib/resources/test/require.aurelia-karma.js similarity index 100% rename from lib/resources/test/aurelia-karma.js rename to lib/resources/test/require.aurelia-karma.js diff --git a/lib/resources/test/system.aurelia-karma.js b/lib/resources/test/system.aurelia-karma.js new file mode 100644 index 000000000..c90e3b5bb --- /dev/null +++ b/lib/resources/test/system.aurelia-karma.js @@ -0,0 +1,49 @@ +(function(global) { + var karma = global.__karma__; + var root = 'src'; + karma.config.args.forEach(function(value, index) { + if (value === 'aurelia-root') { + root = karma.config.args[index + 1]; + } + }); + + if (!karma) { + return; + } + + function patchSystemJS() { + SystemJS.config({ + "packages": { + "base/test": { + "defaultExtension": "js" + } + } + }); + + var originalDefine = global.define; + global.define = function(name, deps, m) { + if (typeof name === 'string') { + originalDefine('/base/' + root + '/' + name, [name], function (result) { return result; }); + } + + return originalDefine(name, deps, m); + } + } + + function requireTests() { + var TEST_REGEXP = /(spec)\.js$/i; + var allTestFiles = ['/base/test/unit/setup.js']; + + Object.keys(window.__karma__.files).forEach(function(file) { + if (TEST_REGEXP.test(file)) { + allTestFiles.push(file); + } + }); + + require(allTestFiles, window.__karma__.start); + } + + karma.loaded = function() {}; // make it async + patchSystemJS(); + requireTests(); +})(window); diff --git a/lib/workflow/activities/project-create.js b/lib/workflow/activities/project-create.js index dc796b954..bfb2a4300 100644 --- a/lib/workflow/activities/project-create.js +++ b/lib/workflow/activities/project-create.js @@ -40,6 +40,9 @@ module.exports = class { let configurePlatform = require(`../../commands/new/platforms/${model.platform.id}`); configurePlatform(project, this.options); + let configureLoader = require(`../../commands/new/loaders/${model.loader.id}`); + configureLoader(project, this.options); + let configureTranspiler = require(`../../commands/new/transpilers/${model.transpiler.id}`); configureTranspiler(project, this.options); @@ -55,9 +58,6 @@ module.exports = class { let configureEditor = require(`../../commands/new/editors/${model.editor.id}`); configureEditor(project, this.options); - let configureLoader = require(`../../commands/new/loaders/${model.loader.id}`); - configureLoader(project, this.options); - return project.create(this.ui, this.options.hasFlag('here') ? undefined : process.cwd()) .then(() => this.ui.clearScreen()) .then(() => this.ui.log('Project structure created and configured.'))