Skip to content

Commit 6c060f1

Browse files
Foxandxsswardbell
authored andcommitted
chore: enable testing for rc1
closes issue angular#86
1 parent a93c713 commit 6c060f1

File tree

4 files changed

+116
-128
lines changed

4 files changed

+116
-128
lines changed

app/app.component.spec.ts.not.yet renamed to app/app.component.spec.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import {
55
expect, it, iit, xit,
66
describe, ddescribe, xdescribe,
77
beforeEach, beforeEachProviders, withProviders,
8-
async, inject, TestComponentBuilder
9-
} from 'angular2/testing';
8+
async, inject
9+
} from '@angular/core/testing';
1010

11-
import { By } from 'angular2/platform/browser';
12-
import { provide } from 'angular2/core';
13-
import { ViewMetadata } from 'angular2/core';
14-
import { PromiseWrapper } from 'angular2/src/facade/promise';
11+
import { TestComponentBuilder } from '@angular/compiler/testing';
12+
13+
import { By } from '@angular/platform-browser';
14+
import { provide } from '@angular/core';
15+
import { ViewMetadata } from '@angular/core';
16+
import { PromiseWrapper } from '@angular/core/src/facade/promise';
1517

1618
//////// SPECS /////////////
1719

karma-test-shim.js

Lines changed: 64 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,73 @@
1-
/*global jasmine, __karma__, window*/
2-
(function () {
3-
4-
// Error.stackTraceLimit = Infinity;
5-
1+
// /*global jasmine, __karma__, window*/
2+
Error.stackTraceLimit = Infinity;
63
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
74

8-
// Cancel Karma's synchronous start,
9-
// we call `__karma__.start()` later, once all the specs are loaded.
10-
__karma__.loaded = function () { };
11-
12-
// SET THE RUNTIME APPLICATION ROOT HERE
13-
var appRoot ='app'; // no trailing slash!
14-
15-
// RegExp for client application base path within karma (which always starts 'base\')
16-
var karmaBase = '^\/base\/'; // RegEx string for base of karma folders
17-
var appPackage = 'base/' + appRoot; //e.g., base/app
18-
var appRootRe = new RegExp(karmaBase + appRoot + '\/');
19-
var onlyAppFilesRe = new RegExp(karmaBase + appRoot + '\/(?!.*\.spec\.js$)([a-z0-9-_\.\/]+)\.js$');
20-
21-
var moduleNames = [];
22-
23-
// Configure systemjs packages to use the .js extension for imports from the app folder
24-
var packages = {};
25-
packages[appPackage] = {
26-
defaultExtension: false,
27-
format: 'register',
28-
map: Object.keys(window.__karma__.files)
29-
.filter(onlyAppFiles)
30-
// Create local module name mapping to karma file path for app files
31-
// with karma's fingerprint in query string, e.g.:
32-
// './hero.service': '/base/app/hero.service.js?f4523daf879cfb7310ef6242682ccf10b2041b3e'
33-
.reduce(function (pathsMapping, appPath) {
34-
var moduleName = appPath.replace(appRootRe, './').replace(/\.js$/, '');
35-
pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath];
36-
return pathsMapping;
37-
}, {})
38-
}
39-
40-
System.config({ packages: packages });
41-
42-
// Configure Angular for the browser and
43-
// with test versions of the platform providers
44-
Promise.all([
45-
System.import('angular2/testing'),
46-
System.import('angular2/platform/testing/browser')
47-
])
48-
.then(function (results) {
49-
var testing = results[0];
50-
var browser = results[1];
51-
testing.setBaseTestProviders(
52-
browser.TEST_BROWSER_PLATFORM_PROVIDERS,
53-
browser.TEST_BROWSER_APPLICATION_PROVIDERS);
54-
55-
// Load all spec files
56-
// (e.g. 'base/app/hero.service.spec.js')
57-
return Promise.all(
58-
Object.keys(window.__karma__.files)
59-
.filter(onlySpecFiles)
60-
.map(function (moduleName) {
61-
moduleNames.push(moduleName);
62-
return System.import(moduleName);
63-
}));
64-
})
65-
66-
.then(success, fail);
67-
68-
////// Helpers //////
69-
70-
function onlyAppFiles(filePath) {
71-
return onlyAppFilesRe.test(filePath);
72-
}
5+
__karma__.loaded = function () {
6+
};
737

74-
function onlySpecFiles(filePath) {
75-
return /\.spec\.js$/.test(filePath);
8+
function isJsFile(path) {
9+
return path.slice(-3) == '.js';
7610
}
7711

78-
function success () {
79-
console.log(
80-
'Spec files loaded:\n ' +
81-
moduleNames.join('\n ') +
82-
'\nStarting Jasmine testrunner');
83-
__karma__.start();
12+
function isSpecFile(path) {
13+
return /\.spec\.js$/.test(path);
8414
}
8515

86-
function fail(error) {
87-
__karma__.error(error.stack || error);
16+
function isBuiltFile(path) {
17+
var builtPath = '/base/app/';
18+
return isJsFile(path) && (path.substr(0, builtPath.length) == builtPath);
8819
}
8920

90-
})();
21+
var allSpecFiles = Object.keys(window.__karma__.files)
22+
.filter(isSpecFile)
23+
.filter(isBuiltFile);
24+
25+
// Load our SystemJS configuration.
26+
27+
var packages ={
28+
'app': { main: 'main.js', defaultExtension: 'js' },
29+
'rxjs': { defaultExtension: 'js' },
30+
};
31+
32+
// Add angular packages to SystemJS config
33+
[
34+
'@angular/common',
35+
'@angular/compiler',
36+
'@angular/core',
37+
'@angular/http',
38+
'@angular/platform-browser',
39+
'@angular/platform-browser-dynamic',
40+
'@angular/router',
41+
'@angular/router-deprecated',
42+
'@angular/upgrade'
43+
].forEach(function (name) { packages[name] = {main: 'index.js', defaultExtension: 'js'};});
44+
45+
System.config({
46+
baseURL: '/base',
47+
map: {
48+
'rxjs': 'node_modules/rxjs',
49+
'@angular': 'node_modules/@angular',
50+
'app': 'app'
51+
},
52+
packages: packages
53+
});
54+
55+
Promise.all([
56+
System.import('@angular/core/testing'),
57+
System.import('@angular/platform-browser-dynamic/testing')
58+
]).then(function (providers) {
59+
var testing = providers[0];
60+
var testingBrowser = providers[1];
61+
62+
testing.setBaseTestProviders(
63+
testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
64+
testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
65+
66+
}).then(function() {
67+
// Finally, load all spec files.
68+
// This will run the tests directly.
69+
return Promise.all(
70+
allSpecFiles.map(function (moduleName) {
71+
return System.import(moduleName);
72+
}));
73+
}).then(__karma__.start, __karma__.error);

karma.conf.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,21 @@ module.exports = function(config) {
2727

2828
// Polyfills
2929
'node_modules/es6-shim/es6-shim.js',
30-
'node_modules/angular2/bundles/angular2-polyfills.js',
3130

32-
// Zone.js dependencies
33-
// Note - do not include zone.js itself or long-stack-trace-zone.js` here as
34-
// they are included already in angular2-polyfills
31+
// Reflect and Zone.js
32+
'node_modules/reflect-metadata/Reflect.js',
33+
'node_modules/zone.js/dist/zone.js',
3534
'node_modules/zone.js/dist/jasmine-patch.js',
3635
'node_modules/zone.js/dist/async-test.js',
3736
'node_modules/zone.js/dist/fake-async-test.js',
3837

39-
// RxJs
40-
'node_modules/rxjs/bundles/Rx.js',
38+
// RxJs.
39+
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
40+
{ pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },
4141

4242
// Angular 2 itself and the testing library
43-
'node_modules/angular2/bundles/angular2.js',
44-
'node_modules/angular2/bundles/router.dev.js',
45-
'node_modules/angular2/bundles/http.dev.js',
46-
'node_modules/angular2/bundles/testing.dev.js',
43+
{pattern: 'node_modules/@angular/**/*.js', included: false, watched: false},
44+
{pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false},
4745

4846
'karma-test-shim.js',
4947

wallaby.js

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@ module.exports = function () {
1111

1212
// Polyfills
1313
{pattern: 'node_modules/es6-shim/es6-shim.js', instrument: false},
14-
{pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', instrument: false},
1514

16-
// Zone.js dependencies
17-
// Note - do not include zone.js itself or long-stack-trace-zone.js` here as
18-
// they are included already in angular2-polyfills
15+
// Reflect, Zone.js, and test shims
16+
// Rx.js, Angular 2 itself, and the testing library not here because loaded by systemjs
17+
{pattern: 'node_modules/reflect-metadata/Reflect.js', instrument: false},
18+
{pattern: 'node_modules/zone.js/dist/zone.js', instrument: false},
1919
{pattern: 'node_modules/zone.js/dist/jasmine-patch.js', instrument: false},
2020
{pattern: 'node_modules/zone.js/dist/async-test.js', instrument: false},
2121
{pattern: 'node_modules/zone.js/dist/fake-async-test.js', instrument: false},
2222

23-
// Rx.js, Angular 2 itself, and the testing library not here because loaded by systemjs
24-
2523
{pattern: 'app/**/*+(ts|html|css)', load: false},
2624
{pattern: 'app/**/*.spec.ts', ignore: true}
2725
],
@@ -39,38 +37,45 @@ module.exports = function () {
3937
bootstrap: function (wallaby) {
4038
wallaby.delayStart();
4139

40+
var packages ={
41+
'app': { main: 'main.js', defaultExtension: 'js' },
42+
'rxjs': { defaultExtension: 'js' },
43+
};
44+
45+
// Add angular packages to SystemJS config
46+
[
47+
'@angular/common',
48+
'@angular/compiler',
49+
'@angular/core',
50+
'@angular/http',
51+
'@angular/platform-browser',
52+
'@angular/platform-browser-dynamic',
53+
'@angular/router',
54+
'@angular/router-deprecated',
55+
'@angular/upgrade'
56+
].forEach(function (name) { packages[name] = {main: 'index.js', defaultExtension: 'js'};});
57+
4258
System.config({
43-
defaultJSExtensions: true,
44-
packages: {
45-
app: {
46-
meta: {
47-
'*': {
48-
scriptLoad: true
49-
}
50-
}
51-
}
52-
},
53-
paths: {
54-
'npm:*': 'node_modules/*'
55-
},
5659
map: {
57-
'angular2': 'npm:angular2',
58-
'rxjs': 'npm:rxjs'
59-
}
60+
'rxjs': 'node_modules/rxjs',
61+
'@angular': 'node_modules/@angular',
62+
'app': 'app'
63+
},
64+
packages:packages
6065
});
6166

62-
// Configure Angular for the browser and
63-
// with test versions of the platform providers
6467
Promise.all([
65-
System.import('angular2/testing'),
66-
System.import('angular2/platform/testing/browser')
68+
System.import('@angular/core/testing'),
69+
System.import('@angular/platform-browser-dynamic/testing')
6770
])
68-
.then(function (results) {
69-
var testing = results[0];
70-
var browser = results[1];
71+
.then(function (providers) {
72+
var testing = providers[0];
73+
var testingBrowser = providers[1];
74+
7175
testing.setBaseTestProviders(
72-
browser.TEST_BROWSER_PLATFORM_PROVIDERS,
73-
browser.TEST_BROWSER_APPLICATION_PROVIDERS);
76+
testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
77+
testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
78+
7479

7580
// Load all spec files
7681
return Promise.all(wallaby.tests.map(function (specFile) {

0 commit comments

Comments
 (0)