-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(systemjs-loader): systemjs config for karma test runner
An import of a unit test _helper_ module from within a spec was failing (e.g. a module that defines a mock). This was due to the import statement normalization result not having a .js extension. This change splits aurelia-karma into two loader specific implementations, with the SystemJS version adding a package configuration for the base/test path that sets `defaultExtension` to js. `au new` adds an implementation based on the selected loader. closes #648
- Loading branch information
Showing
5 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters