From c0604f525787cb9d398b4ebae1d24ad6b4cb2fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=A1ko=20Hevery?= Date: Sun, 18 Dec 2016 10:49:09 -0800 Subject: [PATCH] fix: Run tests on both the build as well as the dist folder (#514) --- .travis.yml | 5 +++-- karma.conf.js => karma-base.conf.js | 5 +---- karma-build-jasmine.conf.js | 7 +++++++ karma-build-mocha.conf.js | 10 +++++++++ ...conf.js => karma-build-sauce-mocha.conf.js | 3 +-- karma-build.conf.js | 14 +++++++++++++ ...mine.conf.js => karma-dist-jasmine.conf.js | 2 +- ...-mocha.conf.js => karma-dist-mocha.conf.js | 2 +- ...onf.js => karma-dist-sauce-jasmine.conf.js | 3 +-- karma-dist.conf.js | 21 +++++++++++++++++++ package.json | 5 +++-- test/main.ts | 12 +++++++++-- 12 files changed, 73 insertions(+), 16 deletions(-) rename karma.conf.js => karma-base.conf.js (91%) create mode 100644 karma-build-jasmine.conf.js create mode 100644 karma-build-mocha.conf.js rename karma-sauce-mocha.conf.js => karma-build-sauce-mocha.conf.js (78%) create mode 100644 karma-build.conf.js rename karma-jasmine.conf.js => karma-dist-jasmine.conf.js (74%) rename karma-mocha.conf.js => karma-dist-mocha.conf.js (87%) rename karma-sauce-jasmine.conf.js => karma-dist-sauce-jasmine.conf.js (78%) create mode 100644 karma-dist.conf.js diff --git a/.travis.yml b/.travis.yml index e3e09781c..9e78dc49f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/karma.conf.js b/karma-base.conf.js similarity index 91% rename from karma.conf.js rename to karma-base.conf.js index 10d0982b3..d4dc0f165 100644 --- a/karma.conf.js +++ b/karma-base.conf.js @@ -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: [ diff --git a/karma-build-jasmine.conf.js b/karma-build-jasmine.conf.js new file mode 100644 index 000000000..29747ca33 --- /dev/null +++ b/karma-build-jasmine.conf.js @@ -0,0 +1,7 @@ + +module.exports = function (config) { + require('./karma-build.conf.js')(config); + + config.plugins.push(require('karma-jasmine')); + config.frameworks.push('jasmine'); +}; diff --git a/karma-build-mocha.conf.js b/karma-build-mocha.conf.js new file mode 100644 index 000000000..2a00246f5 --- /dev/null +++ b/karma-build-mocha.conf.js @@ -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) + }; +}; diff --git a/karma-sauce-mocha.conf.js b/karma-build-sauce-mocha.conf.js similarity index 78% rename from karma-sauce-mocha.conf.js rename to karma-build-sauce-mocha.conf.js index fd6423d25..c35699113 100644 --- a/karma-sauce-mocha.conf.js +++ b/karma-build-sauce-mocha.conf.js @@ -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); }; diff --git a/karma-build.conf.js b/karma-build.conf.js new file mode 100644 index 000000000..d0eba8bb6 --- /dev/null +++ b/karma-build.conf.js @@ -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'); +}; diff --git a/karma-jasmine.conf.js b/karma-dist-jasmine.conf.js similarity index 74% rename from karma-jasmine.conf.js rename to karma-dist-jasmine.conf.js index 55808ddd4..9d6cb428d 100644 --- a/karma-jasmine.conf.js +++ b/karma-dist-jasmine.conf.js @@ -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'); diff --git a/karma-mocha.conf.js b/karma-dist-mocha.conf.js similarity index 87% rename from karma-mocha.conf.js rename to karma-dist-mocha.conf.js index 291fdef94..6f9ac7324 100644 --- a/karma-mocha.conf.js +++ b/karma-dist-mocha.conf.js @@ -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'); diff --git a/karma-sauce-jasmine.conf.js b/karma-dist-sauce-jasmine.conf.js similarity index 78% rename from karma-sauce-jasmine.conf.js rename to karma-dist-sauce-jasmine.conf.js index 3732e1f60..401ac3b71 100644 --- a/karma-sauce-jasmine.conf.js +++ b/karma-dist-sauce-jasmine.conf.js @@ -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); }; diff --git a/karma-dist.conf.js b/karma-dist.conf.js new file mode 100644 index 000000000..bc4adf047 --- /dev/null +++ b/karma-dist.conf.js @@ -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'); +}; diff --git a/package.json b/package.json index a0eedc21f..edf18c449 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/main.ts b/test/main.ts index 52cc70e07..ff3180f22 100644 --- a/test/main.ts +++ b/test/main.ts @@ -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';