chore: use es6-module-loader
Switch Traceur to use modules=“instantiate” and use es6-module-loader. This setup supports cyclic dependencies.
This commit is contained in:
parent
774901c225
commit
cfc5fdc60d
@ -9,7 +9,6 @@ function file2moduleName(filePath) {
|
|||||||
// module name should not include `src`, `test`, `lib`
|
// module name should not include `src`, `test`, `lib`
|
||||||
.replace(/\/src\//, '/')
|
.replace(/\/src\//, '/')
|
||||||
.replace(/\/lib\//, '/')
|
.replace(/\/lib\//, '/')
|
||||||
.replace(/\/test\//, '/')
|
|
||||||
// module name should not have a suffix
|
// module name should not have a suffix
|
||||||
.replace(/\.\w*$/, '');
|
.replace(/\.\w*$/, '');
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,15 @@ module.exports = function(config) {
|
|||||||
frameworks: ['jasmine'],
|
frameworks: ['jasmine'],
|
||||||
|
|
||||||
files: [
|
files: [
|
||||||
|
// Sources and specs.
|
||||||
|
// Loaded through the es6-module-loader, in `test-main.js`.
|
||||||
|
{pattern: 'modules/**', included: false},
|
||||||
|
{pattern: 'tools/transpiler/**', included: false},
|
||||||
|
|
||||||
'node_modules/traceur/bin/traceur-runtime.js',
|
'node_modules/traceur/bin/traceur-runtime.js',
|
||||||
'modules/**/test_lib/**/*.es6',
|
'node_modules/es6-module-loader/dist/es6-module-loader-sans-promises.src.js',
|
||||||
'modules/**/*.js',
|
'node_modules/systemjs/lib/extension-register.js',
|
||||||
'modules/**/*.es6',
|
|
||||||
'tools/transpiler/spec/**/*.js',
|
|
||||||
'tools/transpiler/spec/**/*.es6',
|
|
||||||
'file2modulename.js',
|
'file2modulename.js',
|
||||||
'test-main.js'
|
'test-main.js'
|
||||||
],
|
],
|
||||||
@ -29,7 +32,7 @@ module.exports = function(config) {
|
|||||||
options: {
|
options: {
|
||||||
outputLanguage: 'es5',
|
outputLanguage: 'es5',
|
||||||
script: false,
|
script: false,
|
||||||
modules: 'register',
|
modules: 'instantiate',
|
||||||
types: true,
|
types: true,
|
||||||
typeAssertions: true,
|
typeAssertions: true,
|
||||||
typeAssertionModule: 'rtts_assert/rtts_assert',
|
typeAssertionModule: 'rtts_assert/rtts_assert',
|
||||||
@ -37,7 +40,7 @@ module.exports = function(config) {
|
|||||||
},
|
},
|
||||||
resolveModuleName: file2moduleName,
|
resolveModuleName: file2moduleName,
|
||||||
transformPath: function(fileName) {
|
transformPath: function(fileName) {
|
||||||
return fileName.replace('.es6', '');
|
return fileName.replace(/\.es6$/, '.js');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
import {assert} from 'rtts_assert/rtts_assert';
|
import {assert} from 'rtts_assert/rtts_assert';
|
||||||
|
|
||||||
|
|
||||||
|
export function main() {
|
||||||
|
|
||||||
// ## Basic Type Check
|
// ## Basic Type Check
|
||||||
// By default, `instanceof` is used to check the type.
|
// By default, `instanceof` is used to check the type.
|
||||||
@ -375,3 +376,5 @@ describe('Traceur', function() {
|
|||||||
// <center><small>
|
// <center><small>
|
||||||
// This documentation was generated from [assert.spec.js](https://github.com/vojtajina/assert/blob/master/test/assert.spec.js) using [Docco](http://jashkenas.github.io/docco/).
|
// This documentation was generated from [assert.spec.js](https://github.com/vojtajina/assert/blob/master/test/assert.spec.js) using [Docco](http://jashkenas.github.io/docco/).
|
||||||
// </small></center>
|
// </small></center>
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
"author": "Tobias Bosch <tbosch@google.com>",
|
"author": "Tobias Bosch <tbosch@google.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"es6-module-loader": "^0.9.2",
|
||||||
|
"systemjs": "^0.9.1",
|
||||||
"gulp": "^3.8.8",
|
"gulp": "^3.8.8",
|
||||||
"gulp-rename": "^1.2.0",
|
"gulp-rename": "^1.2.0",
|
||||||
"gulp-watch": "^1.0.3",
|
"gulp-watch": "^1.0.3",
|
||||||
|
63
test-main.js
63
test-main.js
@ -1,11 +1,60 @@
|
|||||||
var TEST_REGEXP = /_spec.*/;
|
// Use "register" extension from systemjs.
|
||||||
|
// That's what Traceur outputs: `System.register()`.
|
||||||
|
register(System);
|
||||||
|
|
||||||
Object.keys(window.__karma__.files).forEach(function(path) {
|
|
||||||
if (TEST_REGEXP.test(path)) {
|
// Cancel Karma's synchronous start,
|
||||||
var moduleName = window.file2moduleName(path);
|
// we will call `__karma__.start()` later, once all the specs are loaded.
|
||||||
var mod = System.get(moduleName);
|
__karma__.loaded = function() {};
|
||||||
if (mod && mod.main) {
|
|
||||||
mod.main();
|
|
||||||
|
System.baseURL = '/base/modules/';
|
||||||
|
|
||||||
|
// So that we can import packages like `core/foo`, instead of `core/src/foo`.
|
||||||
|
System.paths = {
|
||||||
|
'core/*': './core/src/*.js',
|
||||||
|
'core/test/*': './core/test/*.js',
|
||||||
|
|
||||||
|
'change_detection/*': './change_detection/src/*.js',
|
||||||
|
'change_detection/test/*': './change_detection/test/*.js',
|
||||||
|
|
||||||
|
'facade/*': './facade/src/*.js',
|
||||||
|
'facade/test/*': './facade/test/*.js',
|
||||||
|
|
||||||
|
'di/*': './di/src/*.js',
|
||||||
|
'di/test/*': './di/test/*.js',
|
||||||
|
|
||||||
|
'rtts_assert/*': './rtts_assert/src/*.js',
|
||||||
|
'rtts_assert/test/*': './rtts_assert/test/*.js',
|
||||||
|
|
||||||
|
'test_lib/*': './test_lib/src/*.js',
|
||||||
|
'test_lib/test/*': './test_lib/test/*.js',
|
||||||
|
|
||||||
|
'transpiler/*': '../tools/transpiler/*.js'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Import all the specs, execute their `main()` method and kick off Karma (Jasmine).
|
||||||
|
Promise.all(
|
||||||
|
Object.keys(window.__karma__.files) // All files served by Karma.
|
||||||
|
.filter(onlySpecFiles)
|
||||||
|
.map(window.file2moduleName) // Normalize paths to module names.
|
||||||
|
.map(function(path) {
|
||||||
|
return System.import(path).then(function(module) {
|
||||||
|
if (module.hasOwnProperty('main')) {
|
||||||
|
module.main()
|
||||||
|
} else {
|
||||||
|
throw new Error('Module ' + path + ' does not implement main() method.');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
})).then(function() {
|
||||||
|
__karma__.start();
|
||||||
|
}, function(error) {
|
||||||
|
console.error(error.stack || error)
|
||||||
|
__karma__.start();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function onlySpecFiles(path) {
|
||||||
|
return /_spec\.js$/.test(path);
|
||||||
|
}
|
||||||
|
@ -1,3 +1 @@
|
|||||||
function main() {
|
export function main() {}
|
||||||
assert(true);
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user