Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
fix: Run tests on both the build as well as the dist folder
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Dec 18, 2016
1 parent 20b5a5d commit 10b8ae7
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 16 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ before_script:
- ./scripts/sauce/sauce_connect_block.sh

script:
- node_modules/.bin/karma start karma-sauce-jasmine.conf.js --single-run
- node_modules/.bin/karma start karma-sauce-mocha.conf.js --single-run
- node_modules/.bin/gulp build
- node_modules/.bin/karma start karma-dist-sauce-jasmine.conf.js --single-run
- node_modules/.bin/karma start karma-build-sauce-mocha.conf.js --single-run
- node_modules/.bin/gulp test/node
5 changes: 1 addition & 4 deletions karma.conf.js → karma-base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ module.exports = function (config) {
'node_modules/whatwg-fetch/fetch.js',
{pattern: 'test/assets/**/*.*', watched: true, served: true, included: false},
{pattern: 'build/**/*.js.map', watched: true, served: true, included: false},
{pattern: 'build/**/*.js', watched: true, served: true, included: false},
'build/test/wtf_mock.js',
'build/lib/zone.js',
'build/test/main.js'
{pattern: 'build/**/*.js', watched: true, served: true, included: false}
],

plugins: [
Expand Down
7 changes: 7 additions & 0 deletions karma-build-jasmine.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

module.exports = function (config) {
require('./karma-build.conf.js')(config);

config.plugins.push(require('karma-jasmine'));
config.frameworks.push('jasmine');
};
10 changes: 10 additions & 0 deletions karma-build-mocha.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

module.exports = function (config) {
require('./karma-build.conf.js')(config);

config.plugins.push(require('karma-mocha'));
config.frameworks.push('mocha');
config.client.mocha = {
timeout: 5000 // copied timeout for Jasmine in WebSocket.spec (otherwise Mochas default timeout at 2 sec is to low for the tests)
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

module.exports = function (config) {
require('./karma.conf')(config);
require('./karma-mocha.conf')(config);
require('./karma-dist-mocha.conf.js')(config);
require('./sauce.conf')(config);
};
14 changes: 14 additions & 0 deletions karma-build.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

module.exports = function (config) {
require('./karma-base.conf.js')(config);
config.files.push('build/test/wtf_mock.js');
config.files.push('build/lib/zone.js');
config.files.push('build/test/main.js');
};
2 changes: 1 addition & 1 deletion karma-jasmine.conf.js → karma-dist-jasmine.conf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

module.exports = function (config) {
require('./karma.conf')(config);
require('./karma-dist.conf.js')(config);

config.plugins.push(require('karma-jasmine'));
config.frameworks.push('jasmine');
Expand Down
2 changes: 1 addition & 1 deletion karma-mocha.conf.js → karma-dist-mocha.conf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

module.exports = function (config) {
require('./karma.conf')(config);
require('./karma-dist.conf.js')(config);

config.plugins.push(require('karma-mocha'));
config.frameworks.push('mocha');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

module.exports = function (config) {
require('./karma.conf')(config);
require('./karma-jasmine.conf')(config);
require('./karma-dist-jasmine.conf.js')(config);
require('./sauce.conf')(config);
};
21 changes: 21 additions & 0 deletions karma-dist.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

module.exports = function (config) {
require('./karma-base.conf.js')(config);
config.files.push('build/test/wtf_mock.js');
config.files.push('dist/zone.js');
config.files.push('dist/async-test.js');
config.files.push('dist/fake-async-test.js');
config.files.push('dist/long-stack-trace-zone.js');
config.files.push('dist/proxy.js');
config.files.push('dist/sync-test.js');
config.files.push('dist/task-tracking.js');
config.files.push('dist/wtf.js');
config.files.push('build/test/main.js');
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
"ws-server": "node ./test/ws-server.js",
"tsc": "tsc",
"tsc:w": "tsc -w",
"test": "npm run tsc && concurrently \"npm run tsc:w\" \"npm run ws-server\" \"karma start karma-jasmine.conf.js\"",
"test": "npm run tsc && concurrently \"npm run tsc:w\" \"npm run ws-server\" \"karma start karma-build-jasmine.conf.js\"",
"test-dist": "concurrently \"npm run tsc:w\" \"npm run ws-server\" \"karma start karma-dist-jasmine.conf.js\"",
"test-node": "gulp test/node",
"test-mocha": "npm run tsc && concurrently \"npm run tsc:w\" \"npm run ws-server\" \"karma start karma-mocha.conf.js\"",
"test-mocha": "npm run tsc && concurrently \"npm run tsc:w\" \"npm run ws-server\" \"karma start karma-build-mocha.conf.js\"",
"serve": "python -m SimpleHTTPServer 8000"
},
"repository": {
Expand Down
12 changes: 10 additions & 2 deletions test/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ declare var __karma__: {
__karma__.loaded = function() {};
(window as any).global = window;

System.config({defaultJSExtensions: true});
System.config({ defaultJSExtensions: true });
var browserPatchedPromise = null;
if (window[Zone['__symbol__']('setTimeout')]) {
browserPatchedPromise = Promise.resolve('browserPatched');
} else {
// this means that Zone has not patched the browser yet, which means we must be running in
// build mode and need to load the browser patch.
browserPatchedPromise = System.import('/base/build/test/browser-zone-setup');
}

System.import('/base/build/test/browser-zone-setup').then(() => {
browserPatchedPromise.then(() => {
let testFrameworkPatch = typeof(window as any).Mocha !== 'undefined' ?
'/base/build/test/test-env-setup-mocha' :
'/base/build/test/test-env-setup-jasmine';
Expand Down

0 comments on commit 10b8ae7

Please sign in to comment.