Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 4b104d7

Browse files
committed
docs(testing): update testing setup to use systemjs.config.js
1 parent 650a4d1 commit 4b104d7

File tree

5 files changed

+71
-155
lines changed

5 files changed

+71
-155
lines changed

public/docs/_examples/karma-test-shim.js

Lines changed: 28 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -22,72 +22,33 @@ var allSpecFiles = Object.keys(window.__karma__.files)
2222
.filter(isSpecFile)
2323
.filter(isBuiltFile);
2424

25-
//////////////////////////
26-
// Load our SystemJS configuration.
27-
28-
// map tells the System loader where to look for things
29-
var map = {
30-
'app': 'app',
31-
32-
'@angular': 'node_modules/@angular',
33-
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
34-
'rxjs': 'node_modules/rxjs'
35-
};
36-
37-
// packages tells the System loader how to load when no filename and/or no extension
38-
var packages = {
39-
'app': { main: 'main.js', defaultExtension: 'js' },
40-
'rxjs': { defaultExtension: 'js' },
41-
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
42-
};
43-
44-
var ngPackageNames = [
45-
'common',
46-
'compiler',
47-
'core',
48-
'http',
49-
'platform-browser',
50-
'platform-browser-dynamic',
51-
'router',
52-
'router-deprecated',
53-
'upgrade',
54-
];
55-
56-
// Add package entries for angular packages
57-
ngPackageNames.forEach(function(pkgName) {
58-
59-
// Bundled (~40 requests): DOESN'T WORK IN KARMA OR WALLABY (YET?)
60-
//packages['@angular/'+pkgName] = { main: pkgName + '.umd.js', defaultExtension: 'js' };
61-
62-
// Individual files (~300 requests):
63-
packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };
64-
});
65-
66-
var config = {
25+
System.config({
6726
baseURL: '/base',
68-
map: map,
69-
packages: packages
70-
}
71-
72-
System.config(config);
73-
//////////////
74-
75-
Promise.all([
76-
System.import('@angular/core/testing'),
77-
System.import('@angular/platform-browser-dynamic/testing')
78-
]).then(function (providers) {
79-
var testing = providers[0];
80-
var testingBrowser = providers[1];
81-
82-
testing.setBaseTestProviders(
83-
testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
84-
testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
27+
packageWithIndex: true // sadly, we can't use umd packages (yet?)
28+
});
8529

86-
}).then(function() {
87-
// Finally, load all spec files.
88-
// This will run the tests directly.
89-
return Promise.all(
90-
allSpecFiles.map(function (moduleName) {
91-
return System.import(moduleName);
92-
}));
93-
}).then(__karma__.start, __karma__.error);
30+
System.import('systemjs.config.js')
31+
.then(function () {
32+
return Promise.all([
33+
System.import('@angular/core/testing'),
34+
System.import('@angular/platform-browser-dynamic/testing')
35+
])
36+
})
37+
.then(function (providers) {
38+
var testing = providers[0];
39+
var testingBrowser = providers[1];
40+
41+
testing.setBaseTestProviders(
42+
testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
43+
testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
44+
45+
})
46+
.then(function() {
47+
// Finally, load all spec files.
48+
// This will run the tests directly.
49+
return Promise.all(
50+
allSpecFiles.map(function (moduleName) {
51+
return System.import(moduleName);
52+
}));
53+
})
54+
.then(__karma__.start, __karma__.error);

public/docs/_examples/karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module.exports = function(config) {
4242
{pattern: 'node_modules/@angular/**/*.js', included: false, watched: false},
4343
{pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false},
4444

45+
{pattern: 'systemjs.config.js', included: false, watched: false},
4546
'karma-test-shim.js',
4647

4748
// transpiled application & spec code paths loaded via module imports

public/docs/_examples/systemjs.config.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,20 @@
3232
'upgrade',
3333
];
3434

35-
// Add package entries for angular packages
36-
ngPackageNames.forEach(function(pkgName) {
35+
// Individual files (~300 requests):
36+
function packIndex(pkgName) {
37+
packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };
38+
}
3739

38-
// Bundled (~40 requests):
40+
// Bundled (~40 requests):
41+
function packUmd(pkgName) {
3942
packages['@angular/'+pkgName] = { main: pkgName + '.umd.js', defaultExtension: 'js' };
43+
};
4044

41-
// Individual files (~300 requests):
42-
//packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };
43-
});
45+
var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;
46+
47+
// Add package entries for angular packages
48+
ngPackageNames.forEach(setPackageConfig);
4449

4550
var config = {
4651
map: map,

public/docs/_examples/testing/ts/tsconfig.1.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,5 @@
99
"removeComments": false,
1010
"noImplicitAny": true,
1111
"suppressImplicitAnyIndexErrors": true
12-
},
13-
"exclude": [
14-
"node_modules",
15-
"typings/main",
16-
"typings/main.d.ts"
17-
]
12+
}
1813
}

public/docs/_examples/wallaby.js

Lines changed: 30 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = function () {
88
files: [
99
// System.js for module loading
1010
{pattern: 'node_modules/systemjs/dist/system.js', instrument: false},
11+
{pattern: 'systemjs.config.js', instrument: false},
1112

1213
// Polyfills
1314
{pattern: 'node_modules/core-js/client/shim.min.js', instrument: false},
@@ -38,86 +39,39 @@ module.exports = function () {
3839

3940
bootstrap: function (wallaby) {
4041
wallaby.delayStart();
41-
systemConfig();
4242

43-
Promise.all([
44-
System.import('@angular/core/testing'),
45-
System.import('@angular/platform-browser-dynamic/testing')
46-
])
47-
.then(function (providers) {
48-
var testing = providers[0];
49-
var testingBrowser = providers[1];
50-
51-
testing.setBaseTestProviders(
52-
testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
53-
testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
54-
55-
56-
// Load all spec files
57-
return Promise.all(wallaby.tests.map(function (specFile) {
58-
return System.import(specFile);
59-
}));
60-
})
61-
.then(function () {
62-
wallaby.start();
63-
})
64-
.catch(function (e) {
65-
setTimeout(function () {
66-
throw e;
67-
}, 0);
43+
System.config({
44+
packageWithIndex: true // sadly, we can't use umd packages (yet?)
6845
});
6946

70-
//////////////////////////
71-
// SystemJS configuration.
72-
function systemConfig() {
73-
74-
// map tells the System loader where to look for things
75-
var map = {
76-
'app': 'app',
77-
78-
'@angular': 'node_modules/@angular',
79-
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
80-
'rxjs': 'node_modules/rxjs'
81-
};
82-
83-
// packages tells the System loader how to load when no filename and/or no extension
84-
var packages = {
85-
'app': { main: 'main.js', defaultExtension: 'js' },
86-
'rxjs': { defaultExtension: 'js' },
87-
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
88-
};
89-
90-
var ngPackageNames = [
91-
'common',
92-
'compiler',
93-
'core',
94-
'http',
95-
'platform-browser',
96-
'platform-browser-dynamic',
97-
'router',
98-
'router-deprecated',
99-
'upgrade',
100-
];
101-
102-
// Add package entries for angular packages
103-
ngPackageNames.forEach(function(pkgName) {
104-
105-
// Bundled (~40 requests): DOESN'T WORK IN WALLABY OR KARMA (YET?)
106-
// packages['@angular/'+pkgName] = { main: pkgName + '.umd.js', defaultExtension: 'js' };
107-
108-
// Individual files (~300 requests):
109-
packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };
47+
System.import('systemjs.config.js')
48+
.then(function () {
49+
return Promise.all([
50+
System.import('@angular/core/testing'),
51+
System.import('@angular/platform-browser-dynamic/testing')
52+
])
53+
})
54+
.then(function (providers) {
55+
var testing = providers[0];
56+
var testingBrowser = providers[1];
57+
58+
testing.setBaseTestProviders(
59+
testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
60+
testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
61+
62+
// Load all spec files
63+
return Promise.all(wallaby.tests.map(function (specFile) {
64+
return System.import(specFile);
65+
}));
66+
})
67+
.then(function () {
68+
wallaby.start();
69+
})
70+
.catch(function (e) {
71+
setTimeout(function () {
72+
throw e;
73+
}, 0);
11074
});
111-
112-
var config = {
113-
map: map,
114-
packages: packages
115-
}
116-
117-
System.config(config);
118-
}
119-
//////////////////
12075
}
12176
};
122-
12377
};

0 commit comments

Comments
 (0)