Files
angular__angular/test/karma-test-shim.js
T
2017-05-12 14:30:12 -07:00

96 lines
3.5 KiB
JavaScript

/*global jasmine, __karma__, window*/
Error.stackTraceLimit = Infinity;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 3000;
__karma__.loaded = function () {};
var baseDir = '/base';
var specFiles = Object.keys(window.__karma__.files).filter(isMaterialSpecFile);
// Configure the base path and map the different node packages.
System.config({
baseURL: baseDir,
paths: {
'node:*': 'node_modules/*'
},
map: {
'rxjs': 'node:rxjs',
'main': 'main.js',
// Angular specific mappings.
'@angular/core': 'node:@angular/core/bundles/core.umd.js',
'@angular/core/testing': 'node:@angular/core/bundles/core-testing.umd.js',
'@angular/common': 'node:@angular/common/bundles/common.umd.js',
'@angular/common/testing': 'node:@angular/common/bundles/common-testing.umd.js',
'@angular/compiler': 'node:@angular/compiler/bundles/compiler.umd.js',
'@angular/compiler/testing': 'node:@angular/compiler/bundles/compiler-testing.umd.js',
'@angular/http': 'node:@angular/http/bundles/http.umd.js',
'@angular/http/testing': 'node:@angular/http/bundles/http-testing.umd.js',
'@angular/forms': 'node:@angular/forms/bundles/forms.umd.js',
'@angular/forms/testing': 'node:@angular/forms/bundles/forms-testing.umd.js',
'@angular/animations': 'node:@angular/animations/bundles/animations.umd.js',
'@angular/animations/browser': 'node:@angular/animations/bundles/animations-browser.umd.js',
'@angular/platform-browser/animations':
'node:@angular/platform-browser/bundles/platform-browser-animations.umd',
'@angular/platform-browser':
'node:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser/testing':
'node:@angular/platform-browser/bundles/platform-browser-testing.umd.js',
'@angular/platform-browser-dynamic':
'node:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/platform-browser-dynamic/testing':
'node:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
// Path mappings for local packages that can be imported inside of tests.
'@angular/material': 'dist/packages/material/index.js',
'@angular/cdk': 'dist/packages/cdk/index.js',
},
packages: {
// Thirdparty barrels.
'rxjs': {main: 'index'},
// Set the default extension for the root package, because otherwise the demo-app can't
// be built within the production mode. Due to missing file extensions.
'.': {
defaultExtension: 'js'
}
}
});
// Configure the Angular test bed and run all specs once configured.
configureTestBed()
.then(runMaterialSpecs)
.then(__karma__.start, __karma__.error);
/** Runs the Angular Material specs in Karma. */
function runMaterialSpecs() {
// By importing all spec files, Karma will run the tests directly.
return Promise.all(specFiles.map(function(fileName) {
return System.import(fileName);
}));
}
/** Whether the specified file is part of Angular Material. */
function isMaterialSpecFile(path) {
return path.slice(-8) === '.spec.js' && path.indexOf('node_modules') === -1;
}
/** Configures Angular's TestBed. */
function configureTestBed() {
return 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];
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
testing.TestBed.initTestEnvironment(
testingBrowser.BrowserDynamicTestingModule,
testingBrowser.platformBrowserDynamicTesting()
);
});
}