Skip to content

Commit c3dd14c

Browse files
committed
chore: remove angular testing libs from systemjs and update testing shims
1 parent 89cc3a8 commit c3dd14c

File tree

5 files changed

+169
-83
lines changed

5 files changed

+169
-83
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
<a name="0.2.8"></a>
2+
# 0.2.8 (2016-09-01)
3+
* remove @angular test libraries from system.js (now in shim)
4+
* update test related files
5+
* wallaby doesn't completely work. Researching.
16
<a name="0.2.7"></a>
27
# 0.2.7 (2016-08-31)
38
* Angular 2 RC6 version

karma-test-shim.js

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1+
// #docregion
12
// /*global jasmine, __karma__, window*/
2-
Error.stackTraceLimit = Infinity;
3+
Error.stackTraceLimit = 0; // "No stacktrace"" is usually best for app testing.
4+
5+
// Uncomment to get full stacktrace output. Sometimes helpful, usually not.
6+
// Error.stackTraceLimit = Infinity; //
7+
38
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
49

5-
__karma__.loaded = function () {
6-
};
10+
var builtPath = '/base/app/';
11+
12+
__karma__.loaded = function () { };
713

814
function isJsFile(path) {
915
return path.slice(-3) == '.js';
1016
}
1117

1218
function isSpecFile(path) {
13-
return /\.spec\.js$/.test(path);
19+
return /\.spec\.(.*\.)?js$/.test(path);
1420
}
1521

1622
function isBuiltFile(path) {
17-
var builtPath = '/base/app/';
1823
return isJsFile(path) && (path.substr(0, builtPath.length) == builtPath);
1924
}
2025

@@ -24,28 +29,61 @@ var allSpecFiles = Object.keys(window.__karma__.files)
2429

2530
System.config({
2631
baseURL: '/base',
27-
packageWithIndex: true // sadly, we can't use umd packages (yet?)
32+
// Extend usual application package list with test folder
33+
packages: { 'testing': { main: 'index.js', defaultExtension: 'js' } },
34+
35+
// Assume npm: is set in `paths` in systemjs.config
36+
// Map the angular testing umd bundles
37+
map: {
38+
'@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js',
39+
'@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js',
40+
'@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js',
41+
'@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js',
42+
'@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
43+
'@angular/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js',
44+
'@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js',
45+
'@angular/forms/testing': 'npm:@angular/forms/bundles/forms-testing.umd.js',
46+
},
2847
});
2948

3049
System.import('systemjs.config.js')
31-
.then(() => Promise.all([
32-
System.import('@angular/core/testing'),
33-
System.import('@angular/platform-browser-dynamic/testing')
34-
]))
35-
.then((providers) => {
36-
var coreTesting = providers[0];
50+
.then(importSystemJsExtras)
51+
.then(initTestBed)
52+
.then(initTesting);
53+
54+
/** Optional SystemJS configuration extras. Keep going w/o it */
55+
function importSystemJsExtras(){
56+
return System.import('systemjs.config.extras.js')
57+
.catch(function(reason) {
58+
console.log(
59+
'WARNING: System.import could not load "systemjs.config.extras.js"; continuing without it.'
60+
);
61+
console.log(reason);
62+
});
63+
}
64+
65+
function initTestBed(){
66+
return Promise.all([
67+
System.import('@angular/core/testing'),
68+
System.import('@angular/platform-browser-dynamic/testing')
69+
])
70+
71+
.then(function (providers) {
72+
var coreTesting = providers[0];
3773
var browserTesting = providers[1];
38-
coreTesting.TestBed.initTestEnvironment(
39-
browserTesting.BrowserDynamicTestingModule,
40-
browserTesting.platformBrowserDynamicTesting());
4174

75+
coreTesting.TestBed.initTestEnvironment(
76+
browserTesting.BrowserDynamicTestingModule,
77+
browserTesting.platformBrowserDynamicTesting());
4278
})
43-
.then(function () {
44-
// Finally, load all spec files.
45-
// This will run the tests directly.
79+
}
80+
81+
// Import all spec files and start karma
82+
function initTesting () {
4683
return Promise.all(
4784
allSpecFiles.map(function (moduleName) {
4885
return System.import(moduleName);
49-
}));
50-
})
86+
})
87+
)
5188
.then(__karma__.start, __karma__.error);
89+
}

karma.conf.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
// #docregion
12
module.exports = function(config) {
23

3-
var appBase = 'app/'; // transpiled app JS files
4-
var appAssets ='/base/app/'; // component assets fetched by Angular's compiler
4+
var appBase = 'app/'; // transpiled app JS and map files
5+
var appSrcBase = 'app/'; // app source TS files
6+
var appAssets = '/base/app/'; // component assets fetched by Angular's compiler
7+
8+
var testBase = 'testing/'; // transpiled test JS and map files
9+
var testSrcBase = 'testing/'; // test source TS files
510

611
config.set({
712
basePath: '',
@@ -26,9 +31,9 @@ module.exports = function(config) {
2631

2732
// Polyfills
2833
'node_modules/core-js/client/shim.js',
29-
30-
// Reflect and Zone.js
3134
'node_modules/reflect-metadata/Reflect.js',
35+
36+
// zone.js
3237
'node_modules/zone.js/dist/zone.js',
3338
'node_modules/zone.js/dist/long-stack-trace-zone.js',
3439
'node_modules/zone.js/dist/proxy.js',
@@ -37,31 +42,37 @@ module.exports = function(config) {
3742
'node_modules/zone.js/dist/async-test.js',
3843
'node_modules/zone.js/dist/fake-async-test.js',
3944

40-
// RxJs.
45+
// RxJs
4146
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
4247
{ pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },
4348

44-
// Angular 2 itself and the testing library
49+
// Paths loaded via module imports:
50+
// Angular itself
4551
{pattern: 'node_modules/@angular/**/*.js', included: false, watched: false},
4652
{pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false},
4753

4854
{pattern: 'systemjs.config.js', included: false, watched: false},
55+
{pattern: 'systemjs.config.extras.js', included: false, watched: false},
4956
'karma-test-shim.js',
5057

5158
// transpiled application & spec code paths loaded via module imports
5259
{pattern: appBase + '**/*.js', included: false, watched: true},
60+
{pattern: testBase + '**/*.js', included: false, watched: true},
61+
5362

54-
// asset (HTML & CSS) paths loaded via Angular's component compiler
63+
// Asset (HTML & CSS) paths loaded via Angular's component compiler
5564
// (these paths need to be rewritten, see proxies section)
5665
{pattern: appBase + '**/*.html', included: false, watched: true},
5766
{pattern: appBase + '**/*.css', included: false, watched: true},
5867

59-
// paths for debugging with source maps in dev tools
60-
{pattern: appBase + '**/*.ts', included: false, watched: false},
61-
{pattern: appBase + '**/*.js.map', included: false, watched: false}
68+
// Paths for debugging with source maps in dev tools
69+
{pattern: appSrcBase + '**/*.ts', included: false, watched: false},
70+
{pattern: appBase + '**/*.js.map', included: false, watched: false},
71+
{pattern: testSrcBase + '**/*.ts', included: false, watched: false},
72+
{pattern: testBase + '**/*.js.map', included: false, watched: false}
6273
],
6374

64-
// proxied base paths for loading assets
75+
// Proxied base paths for loading assets
6576
proxies: {
6677
// required for component assets fetched by Angular's compiler
6778
"/app/": appAssets

systemjs.config.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,8 @@
2323
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
2424
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
2525

26-
// angular testing umd bundles
27-
'@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js',
28-
'@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js',
29-
'@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js',
30-
'@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js',
31-
'@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
32-
'@angular/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js',
33-
'@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js',
34-
'@angular/forms/testing': 'npm:@angular/forms/bundles/forms-testing.umd.js',
35-
3626
// other libraries
37-
'rxjs': 'npm:rxjs',
27+
'rxjs': 'npm:rxjs',
3828
'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api',
3929
},
4030
// packages tells the System loader how to load when no filename and/or no extension

wallaby.js

Lines changed: 83 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,31 @@
33
// Note: Wallaby is not open source and costs money
44

55
module.exports = function () {
6-
76
return {
87
files: [
98
// System.js for module loading
109
{pattern: 'node_modules/systemjs/dist/system.js', instrument: false},
1110
{pattern: 'systemjs.config.js', instrument: false},
11+
{pattern: 'systemjs.config.extras.js', instrument: false},
1212

1313
// Polyfills
1414
{pattern: 'node_modules/core-js/client/shim.min.js', instrument: false},
15-
16-
// Reflect, Zone.js, and test shims
17-
// Rx.js, Angular 2 itself, and the testing library not here because loaded by systemjs
1815
{pattern: 'node_modules/reflect-metadata/Reflect.js', instrument: false},
16+
17+
// zone.js
1918
{pattern: 'node_modules/zone.js/dist/zone.js', instrument: false},
19+
{pattern: 'node_modules/zone.js/dist/long-stack-trace-zone.js', instrument: false},
20+
{pattern: 'node_modules/zone.js/dist/proxy.js', instrument: false},
21+
{pattern: 'node_modules/zone.js/dist/sync-test.js', instrument: false},
2022
{pattern: 'node_modules/zone.js/dist/jasmine-patch.js', instrument: false},
2123
{pattern: 'node_modules/zone.js/dist/async-test.js', instrument: false},
2224
{pattern: 'node_modules/zone.js/dist/fake-async-test.js', instrument: false},
2325

26+
// application (but not specs) loaded via module imports
2427
{pattern: 'app/**/*+(ts|html|css)', load: false},
25-
{pattern: 'app/**/*.spec.ts', ignore: true}
28+
{pattern: 'app/**/*.spec.ts', ignore: true},
29+
30+
{pattern: 'testing/**/*+(ts|html|css)', load: false},
2631
],
2732

2833
tests: [
@@ -37,41 +42,78 @@ module.exports = function () {
3742

3843
debug: true,
3944

40-
bootstrap: function (wallaby) {
41-
wallaby.delayStart();
42-
43-
System.config({
44-
packageWithIndex: true // sadly, we can't use umd packages (yet?)
45-
});
46-
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);
74-
});
75-
}
45+
bootstrap: bootstrap
7646
};
7747
};
48+
49+
// Like karma-test-shim.js
50+
function bootstrap (wallaby) {
51+
wallaby.delayStart();
52+
53+
System.config({
54+
// Extend usual application package list with test folder
55+
packages: { 'testing': { main: 'index.js', defaultExtension: 'js' } },
56+
57+
// Assume npm: is set in `paths` in systemjs.config
58+
// Map the angular testing umd bundles
59+
map: {
60+
'@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js',
61+
'@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js',
62+
'@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js',
63+
'@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js',
64+
'@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
65+
'@angular/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js',
66+
'@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js',
67+
'@angular/forms/testing': 'npm:@angular/forms/bundles/forms-testing.umd.js',
68+
},
69+
});
70+
71+
System.import('systemjs.config.js')
72+
.then(importSystemJsExtras)
73+
.then(initTestBed)
74+
.then(initTesting);
75+
76+
/** Optional SystemJS configuration extras. Keep going w/o it */
77+
function importSystemJsExtras(){
78+
return System.import('systemjs.config.extras.js')
79+
.catch(function(reason) {
80+
console.log(
81+
'WARNING: System.import could not load "systemjs.config.extras.js"; continuing without it.'
82+
);
83+
console.log(reason);
84+
});
85+
}
86+
87+
function initTestBed(){
88+
return Promise.all([
89+
System.import('@angular/core/testing'),
90+
System.import('@angular/platform-browser-dynamic/testing')
91+
])
92+
93+
.then(function (providers) {
94+
var coreTesting = providers[0];
95+
var browserTesting = providers[1];
96+
97+
coreTesting.TestBed.initTestEnvironment(
98+
browserTesting.BrowserDynamicTestingModule,
99+
browserTesting.platformBrowserDynamicTesting());
100+
})
101+
}
102+
103+
// Load all spec files and start wallaby
104+
function initTesting () {
105+
return Promise.all(
106+
wallaby.tests.map(function (specFile) {
107+
return System.import(specFile);
108+
})
109+
)
110+
.then(function () {
111+
wallaby.start();
112+
})
113+
.catch(function (e) {
114+
setTimeout(function () {
115+
throw e;
116+
}, 0);
117+
});
118+
}
119+
}

0 commit comments

Comments
 (0)