Commit 6c060f10 authored by Foxandxss's avatar Foxandxss Committed by Ward Bell

chore: enable testing for rc1

closes issue #86
parent a93c713a
...@@ -5,13 +5,15 @@ import { ...@@ -5,13 +5,15 @@ import {
expect, it, iit, xit, expect, it, iit, xit,
describe, ddescribe, xdescribe, describe, ddescribe, xdescribe,
beforeEach, beforeEachProviders, withProviders, beforeEach, beforeEachProviders, withProviders,
async, inject, TestComponentBuilder async, inject
} from 'angular2/testing'; } from '@angular/core/testing';
import { By } from 'angular2/platform/browser'; import { TestComponentBuilder } from '@angular/compiler/testing';
import { provide } from 'angular2/core';
import { ViewMetadata } from 'angular2/core'; import { By } from '@angular/platform-browser';
import { PromiseWrapper } from 'angular2/src/facade/promise'; import { provide } from '@angular/core';
import { ViewMetadata } from '@angular/core';
import { PromiseWrapper } from '@angular/core/src/facade/promise';
//////// SPECS ///////////// //////// SPECS /////////////
......
/*global jasmine, __karma__, window*/ // /*global jasmine, __karma__, window*/
(function () { Error.stackTraceLimit = Infinity;
// Error.stackTraceLimit = Infinity;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000; jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
// Cancel Karma's synchronous start, __karma__.loaded = function () {
// we call `__karma__.start()` later, once all the specs are loaded. };
__karma__.loaded = function () { };
// SET THE RUNTIME APPLICATION ROOT HERE
var appRoot ='app'; // no trailing slash!
// RegExp for client application base path within karma (which always starts 'base\') function isJsFile(path) {
var karmaBase = '^\/base\/'; // RegEx string for base of karma folders return path.slice(-3) == '.js';
var appPackage = 'base/' + appRoot; //e.g., base/app }
var appRootRe = new RegExp(karmaBase + appRoot + '\/');
var onlyAppFilesRe = new RegExp(karmaBase + appRoot + '\/(?!.*\.spec\.js$)([a-z0-9-_\.\/]+)\.js$');
var moduleNames = []; function isSpecFile(path) {
return /\.spec\.js$/.test(path);
}
// Configure systemjs packages to use the .js extension for imports from the app folder function isBuiltFile(path) {
var packages = {}; var builtPath = '/base/app/';
packages[appPackage] = { return isJsFile(path) && (path.substr(0, builtPath.length) == builtPath);
defaultExtension: false, }
format: 'register',
map: Object.keys(window.__karma__.files)
.filter(onlyAppFiles)
// Create local module name mapping to karma file path for app files
// with karma's fingerprint in query string, e.g.:
// './hero.service': '/base/app/hero.service.js?f4523daf879cfb7310ef6242682ccf10b2041b3e'
.reduce(function (pathsMapping, appPath) {
var moduleName = appPath.replace(appRootRe, './').replace(/\.js$/, '');
pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath];
return pathsMapping;
}, {})
}
System.config({ packages: packages }); var allSpecFiles = Object.keys(window.__karma__.files)
.filter(isSpecFile)
.filter(isBuiltFile);
// Load our SystemJS configuration.
var packages ={
'app': { main: 'main.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
};
// Add angular packages to SystemJS config
[
'@angular/common',
'@angular/compiler',
'@angular/core',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/router',
'@angular/router-deprecated',
'@angular/upgrade'
].forEach(function (name) { packages[name] = {main: 'index.js', defaultExtension: 'js'};});
System.config({
baseURL: '/base',
map: {
'rxjs': 'node_modules/rxjs',
'@angular': 'node_modules/@angular',
'app': 'app'
},
packages: packages
});
Promise.all([
System.import('@angular/core/testing'),
System.import('@angular/platform-browser-dynamic/testing')
]).then(function (providers) {
var testing = providers[0];
var testingBrowser = providers[1];
// Configure Angular for the browser and
// with test versions of the platform providers
Promise.all([
System.import('angular2/testing'),
System.import('angular2/platform/testing/browser')
])
.then(function (results) {
var testing = results[0];
var browser = results[1];
testing.setBaseTestProviders( testing.setBaseTestProviders(
browser.TEST_BROWSER_PLATFORM_PROVIDERS, testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
browser.TEST_BROWSER_APPLICATION_PROVIDERS); testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
// Load all spec files }).then(function() {
// (e.g. 'base/app/hero.service.spec.js') // Finally, load all spec files.
// This will run the tests directly.
return Promise.all( return Promise.all(
Object.keys(window.__karma__.files) allSpecFiles.map(function (moduleName) {
.filter(onlySpecFiles)
.map(function (moduleName) {
moduleNames.push(moduleName);
return System.import(moduleName); return System.import(moduleName);
})); }));
}) }).then(__karma__.start, __karma__.error);
.then(success, fail);
////// Helpers //////
function onlyAppFiles(filePath) {
return onlyAppFilesRe.test(filePath);
}
function onlySpecFiles(filePath) {
return /\.spec\.js$/.test(filePath);
}
function success () {
console.log(
'Spec files loaded:\n ' +
moduleNames.join('\n ') +
'\nStarting Jasmine testrunner');
__karma__.start();
}
function fail(error) {
__karma__.error(error.stack || error);
}
})();
...@@ -27,23 +27,21 @@ module.exports = function(config) { ...@@ -27,23 +27,21 @@ module.exports = function(config) {
// Polyfills // Polyfills
'node_modules/es6-shim/es6-shim.js', 'node_modules/es6-shim/es6-shim.js',
'node_modules/angular2/bundles/angular2-polyfills.js',
// Zone.js dependencies // Reflect and Zone.js
// Note - do not include zone.js itself or long-stack-trace-zone.js` here as 'node_modules/reflect-metadata/Reflect.js',
// they are included already in angular2-polyfills 'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/jasmine-patch.js', 'node_modules/zone.js/dist/jasmine-patch.js',
'node_modules/zone.js/dist/async-test.js', 'node_modules/zone.js/dist/async-test.js',
'node_modules/zone.js/dist/fake-async-test.js', 'node_modules/zone.js/dist/fake-async-test.js',
// RxJs // RxJs.
'node_modules/rxjs/bundles/Rx.js', { pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
{ pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },
// Angular 2 itself and the testing library // Angular 2 itself and the testing library
'node_modules/angular2/bundles/angular2.js', {pattern: 'node_modules/@angular/**/*.js', included: false, watched: false},
'node_modules/angular2/bundles/router.dev.js', {pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false},
'node_modules/angular2/bundles/http.dev.js',
'node_modules/angular2/bundles/testing.dev.js',
'karma-test-shim.js', 'karma-test-shim.js',
......
...@@ -11,17 +11,15 @@ module.exports = function () { ...@@ -11,17 +11,15 @@ module.exports = function () {
// Polyfills // Polyfills
{pattern: 'node_modules/es6-shim/es6-shim.js', instrument: false}, {pattern: 'node_modules/es6-shim/es6-shim.js', instrument: false},
{pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', instrument: false},
// Zone.js dependencies // Reflect, Zone.js, and test shims
// Note - do not include zone.js itself or long-stack-trace-zone.js` here as // Rx.js, Angular 2 itself, and the testing library not here because loaded by systemjs
// they are included already in angular2-polyfills {pattern: 'node_modules/reflect-metadata/Reflect.js', instrument: false},
{pattern: 'node_modules/zone.js/dist/zone.js', instrument: false},
{pattern: 'node_modules/zone.js/dist/jasmine-patch.js', instrument: false}, {pattern: 'node_modules/zone.js/dist/jasmine-patch.js', instrument: false},
{pattern: 'node_modules/zone.js/dist/async-test.js', instrument: false}, {pattern: 'node_modules/zone.js/dist/async-test.js', instrument: false},
{pattern: 'node_modules/zone.js/dist/fake-async-test.js', instrument: false}, {pattern: 'node_modules/zone.js/dist/fake-async-test.js', instrument: false},
// Rx.js, Angular 2 itself, and the testing library not here because loaded by systemjs
{pattern: 'app/**/*+(ts|html|css)', load: false}, {pattern: 'app/**/*+(ts|html|css)', load: false},
{pattern: 'app/**/*.spec.ts', ignore: true} {pattern: 'app/**/*.spec.ts', ignore: true}
], ],
...@@ -39,38 +37,45 @@ module.exports = function () { ...@@ -39,38 +37,45 @@ module.exports = function () {
bootstrap: function (wallaby) { bootstrap: function (wallaby) {
wallaby.delayStart(); wallaby.delayStart();
var packages ={
'app': { main: 'main.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
};
// Add angular packages to SystemJS config
[
'@angular/common',
'@angular/compiler',
'@angular/core',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/router',
'@angular/router-deprecated',
'@angular/upgrade'
].forEach(function (name) { packages[name] = {main: 'index.js', defaultExtension: 'js'};});
System.config({ System.config({
defaultJSExtensions: true,
packages: {
app: {
meta: {
'*': {
scriptLoad: true
}
}
}
},
paths: {
'npm:*': 'node_modules/*'
},
map: { map: {
'angular2': 'npm:angular2', 'rxjs': 'node_modules/rxjs',
'rxjs': 'npm:rxjs' '@angular': 'node_modules/@angular',
} 'app': 'app'
},
packages:packages
}); });
// Configure Angular for the browser and
// with test versions of the platform providers
Promise.all([ Promise.all([
System.import('angular2/testing'), System.import('@angular/core/testing'),
System.import('angular2/platform/testing/browser') System.import('@angular/platform-browser-dynamic/testing')
]) ])
.then(function (results) { .then(function (providers) {
var testing = results[0]; var testing = providers[0];
var browser = results[1]; var testingBrowser = providers[1];
testing.setBaseTestProviders( testing.setBaseTestProviders(
browser.TEST_BROWSER_PLATFORM_PROVIDERS, testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
browser.TEST_BROWSER_APPLICATION_PROVIDERS); testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
// Load all spec files // Load all spec files
return Promise.all(wallaby.tests.map(function (specFile) { return Promise.all(wallaby.tests.map(function (specFile) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment