From fed65b11e9021ad0fc1c691d8688e4da83d9d0c8 Mon Sep 17 00:00:00 2001 From: "JiaLi.Passion" Date: Fri, 16 Mar 2018 19:44:45 +0900 Subject: [PATCH] fix(test): karma-dist should test bundle under dist --- gulpfile.js | 24 +- karma-base.conf.js | 30 +-- karma-dist-mocha.conf.js | 7 +- karma-dist.conf.js | 12 +- sauce.conf.js | 112 +++----- test/browser-zone-setup.ts | 2 + test/browser/MediaQuery.spec.ts | 2 - test/browser/Notification.spec.ts | 2 - test/main.ts | 29 +-- test/node_entry_point.ts | 1 + test/zone-spec/async-test.spec.ts | 340 ++++++++++++++----------- test/zone-spec/fake-async-test.spec.ts | 98 +++---- test/zone-spec/proxy.spec.ts | 16 +- test/zone-spec/sync-test.spec.ts | 1 - test/zone-spec/task-tracking.spec.ts | 2 - 15 files changed, 331 insertions(+), 347 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 2bab13d6f..88a9f7ee7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -42,7 +42,9 @@ function generateScript(inFile, outFile, minify, callback) { 'rxjs/Observable': 'Rx', 'rxjs/Subscriber': 'Rx', 'rxjs/Subscription': 'Rx', + 'rxjs/Scheduler': 'Rx', 'rxjs/scheduler/asap': 'Rx.Scheduler', + 'rxjs/scheduler/async': 'Rx.Scheduler', 'rxjs/symbol/rxSubscriber': 'Rx.Symbol' } }, @@ -221,19 +223,23 @@ gulp.task('build/zone-patch-socket-io.min.js', ['compile-esm'], function(cb) { }); gulp.task('build/zone-patch-promise-testing.js', ['compile-esm'], function(cb) { - return generateScript('./lib/testing/promise-testing.ts', 'zone-patch-promise-test.js', false, cb); + return generateScript( + './lib/testing/promise-testing.ts', 'zone-patch-promise-test.js', false, cb); }); gulp.task('build/zone-patch-promise-testing.min.js', ['compile-esm'], function(cb) { - return generateScript('./lib/testing/promise-testing.ts', 'zone-patch-promise-test.min.js', true, cb); + return generateScript( + './lib/testing/promise-testing.ts', 'zone-patch-promise-test.min.js', true, cb); }); gulp.task('build/zone-patch-resize-observer.js', ['compile-esm'], function(cb) { - return generateScript('./lib/browser/webapis-resize-observer.ts', 'zone-patch-resize-observer.js', false, cb); + return generateScript( + './lib/browser/webapis-resize-observer.ts', 'zone-patch-resize-observer.js', false, cb); }); gulp.task('build/zone-patch-resize-observer.min.js', ['compile-esm'], function(cb) { - return generateScript('./lib/browser/webapis-resize-observer.ts', 'zone-patch-resize-observer.min.js', true, cb); + return generateScript( + './lib/browser/webapis-resize-observer.ts', 'zone-patch-resize-observer.min.js', true, cb); }); gulp.task('build/bluebird.js', ['compile-esm'], function(cb) { @@ -245,11 +251,11 @@ gulp.task('build/bluebird.min.js', ['compile-esm'], function(cb) { }); gulp.task('build/zone-patch-jsonp.js', ['compile-esm'], function(cb) { - return generateScript('./lib/extra/jsonp.ts', 'zone-patch-jsonp.js', false, cb); + return generateScript('./lib/extra/jsonp.ts', 'zone-patch-jsonp.js', false, cb); }); gulp.task('build/zone-patch-jsonp.min.js', ['compile-esm'], function(cb) { - return generateScript('./lib/extra/jsonp.ts', 'zone-patch-jsonp.min.js', true, cb); + return generateScript('./lib/extra/jsonp.ts', 'zone-patch-jsonp.min.js', true, cb); }); gulp.task('build/jasmine-patch.js', ['compile-esm'], function(cb) { @@ -323,11 +329,13 @@ gulp.task('build/rxjs.min.js', ['compile-esm'], function(cb) { }); gulp.task('build/rxjs-fake-async.js', ['compile-esm'], function(cb) { - return generateScript('./lib/rxjs/rxjs-fake-async.ts', 'zone-patch-rxjs-fake-async.js', false, cb); + return generateScript( + './lib/rxjs/rxjs-fake-async.ts', 'zone-patch-rxjs-fake-async.js', false, cb); }); gulp.task('build/rxjs-fake-async.min.js', ['compile-esm'], function(cb) { - return generateScript('./lib/rxjs/rxjs-fake-async.ts', 'zone-patch-rxjs-fake-async.min.js', true, cb); + return generateScript( + './lib/rxjs/rxjs-fake-async.ts', 'zone-patch-rxjs-fake-async.min.js', true, cb); }); gulp.task('build/closure.js', function() { diff --git a/karma-base.conf.js b/karma-base.conf.js index 26ffa771a..d31a4310f 100644 --- a/karma-base.conf.js +++ b/karma-base.conf.js @@ -6,45 +6,39 @@ * found in the LICENSE file at https://angular.io/license */ -module.exports = function (config) { +module.exports = function(config) { config.set({ basePath: '', files: [ - 'node_modules/systemjs/dist/system-polyfills.js', - 'node_modules/systemjs/dist/system.src.js', + 'node_modules/systemjs/dist/system-polyfills.js', 'node_modules/systemjs/dist/system.src.js', 'node_modules/whatwg-fetch/fetch.js', - {pattern: 'node_modules/rxjs/**/**/*.js', included: false, watched: false }, - {pattern: 'node_modules/rxjs/**/**/*.js.map', included: false, watched: false }, - {pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false }, - {pattern: 'node_modules/es6-promise/**/*.js', included: false, watched: false }, - {pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false }, + {pattern: 'node_modules/rxjs/**/**/*.js', included: false, watched: false}, + {pattern: 'node_modules/rxjs/**/**/*.js.map', included: false, watched: false}, + {pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false}, + {pattern: 'node_modules/es6-promise/**/*.js', included: false, watched: false}, + {pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false}, {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} ], plugins: [ - require('karma-chrome-launcher'), - require('karma-firefox-launcher'), + require('karma-chrome-launcher'), require('karma-firefox-launcher'), require('karma-sourcemap-loader') ], - preprocessors: { - '**/*.js': ['sourcemap'] - }, + preprocessors: {'**/*.js': ['sourcemap']}, - exclude: [ - 'test/microtasks.spec.ts' - ], + exclude: ['test/microtasks.spec.ts'], reporters: ['progress'], - //port: 9876, + // port: 9876, colors: true, logLevel: config.LOG_INFO, - browsers: ['Firefox'], + browsers: ['Chrome'], captureTimeout: 60000, diff --git a/karma-dist-mocha.conf.js b/karma-dist-mocha.conf.js index 6f9ac7324..60b1f3f08 100644 --- a/karma-dist-mocha.conf.js +++ b/karma-dist-mocha.conf.js @@ -1,10 +1,13 @@ -module.exports = function (config) { +module.exports = function(config) { require('./karma-dist.conf.js')(config); + config.files.push('dist/mocha-patch.js'); + config.files.push('build/test/test-env-setup-mocha.js'); 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) + 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-dist.conf.js b/karma-dist.conf.js index a96fe0993..761ff7277 100644 --- a/karma-dist.conf.js +++ b/karma-dist.conf.js @@ -6,20 +6,18 @@ * found in the LICENSE file at https://angular.io/license */ -module.exports = function (config) { +module.exports = function(config) { require('./karma-base.conf.js')(config); config.files.push('build/test/wtf_mock.js'); config.files.push('build/test/test_fake_polyfill.js'); config.files.push('build/test/custom_error.js'); config.files.push('dist/zone.js'); + config.files.push('dist/webapis-media-query.js'); config.files.push('dist/zone-patch-user-media.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/zone-patch-resize-observer.js'); + config.files.push('dist/webapis-notification.js'); config.files.push('dist/task-tracking.js'); config.files.push('dist/wtf.js'); - config.files.push('dist/zone-patch-promise-test.js'); + config.files.push('dist/zone-testing.js'); config.files.push('build/test/main.js'); }; diff --git a/sauce.conf.js b/sauce.conf.js index a6026ad50..1aac560bd 100644 --- a/sauce.conf.js +++ b/sauce.conf.js @@ -1,54 +1,26 @@ // Sauce configuration -module.exports = function (config, ignoredLaunchers) { +module.exports = function(config, ignoredLaunchers) { // The WS server is not available with Sauce config.files.unshift('test/saucelabs.js'); var basicLaunchers = { - 'SL_CHROME': { - base: 'SauceLabs', - browserName: 'chrome', - version: '48' - }, - 'SL_CHROME_60': { - base: 'SauceLabs', - browserName: 'chrome', - version: '60' - }, - 'SL_FIREFOX': { - base: 'SauceLabs', - browserName: 'firefox', - version: '52' - }, - 'SL_FIREFOX_54': { - base: 'SauceLabs', - browserName: 'firefox', - version: '54' - }, + 'SL_CHROME': {base: 'SauceLabs', browserName: 'chrome', version: '48'}, + 'SL_CHROME_60': {base: 'SauceLabs', browserName: 'chrome', version: '60'}, + 'SL_FIREFOX': {base: 'SauceLabs', browserName: 'firefox', version: '52'}, + 'SL_FIREFOX_54': {base: 'SauceLabs', browserName: 'firefox', version: '54'}, /*'SL_SAFARI7': { base: 'SauceLabs', browserName: 'safari', platform: 'OS X 10.9', version: '7.0' },*/ - 'SL_SAFARI8': { - base: 'SauceLabs', - browserName: 'safari', - platform: 'OS X 10.10', - version: '8.0' - }, - 'SL_SAFARI9': { - base: 'SauceLabs', - browserName: 'safari', - platform: 'OS X 10.11', - version: '9.0' - }, - 'SL_SAFARI10': { - base: 'SauceLabs', - browserName: 'safari', - platform: 'OS X 10.11', - version: '10.0' - }, + 'SL_SAFARI8': + {base: 'SauceLabs', browserName: 'safari', platform: 'OS X 10.10', version: '8.0'}, + 'SL_SAFARI9': + {base: 'SauceLabs', browserName: 'safari', platform: 'OS X 10.11', version: '9.0'}, + 'SL_SAFARI10': + {base: 'SauceLabs', browserName: 'safari', platform: 'OS X 10.11', version: '10.0'}, /* no longer supported in SauceLabs 'SL_IOS7': { @@ -57,24 +29,14 @@ module.exports = function (config, ignoredLaunchers) { platform: 'OS X 10.10', version: '7.1' },*/ - 'SL_IOS8': { + /*'SL_IOS8': { base: 'SauceLabs', browserName: 'iphone', platform: 'OS X 10.10', version: '8.4' - }, - 'SL_IOS9': { - base: 'SauceLabs', - browserName: 'iphone', - platform: 'OS X 10.10', - version: '9.3' - }, - 'SL_IOS10': { - base: 'SauceLabs', - browserName: 'iphone', - platform: 'OS X 10.10', - version: '10.2' - }, + },*/ + 'SL_IOS9': {base: 'SauceLabs', browserName: 'iphone', platform: 'OS X 10.10', version: '9.3'}, + 'SL_IOS10': {base: 'SauceLabs', browserName: 'iphone', platform: 'OS X 10.10', version: '10.2'}, 'SL_IE9': { base: 'SauceLabs', browserName: 'internet explorer', @@ -125,24 +87,9 @@ module.exports = function (config, ignoredLaunchers) { platform: 'Linux', version: '4.3' },*/ - 'SL_ANDROID4.4': { - base: 'SauceLabs', - browserName: 'android', - platform: 'Linux', - version: '4.4' - }, - 'SL_ANDROID5.1': { - base: 'SauceLabs', - browserName: 'android', - platform: 'Linux', - version: '5.1' - }, - 'SL_ANDROID6.0': { - base: 'SauceLabs', - browserName: 'android', - platform: 'Linux', - version: '6.0' - }, + 'SL_ANDROID4.4': {base: 'SauceLabs', browserName: 'android', platform: 'Linux', version: '4.4'}, + 'SL_ANDROID5.1': {base: 'SauceLabs', browserName: 'android', platform: 'Linux', version: '5.1'}, + 'SL_ANDROID6.0': {base: 'SauceLabs', browserName: 'android', platform: 'Linux', version: '6.0'}, 'SL_ANDROID7.1': { base: 'SauceLabs', browserName: 'Chrome', @@ -158,7 +105,11 @@ module.exports = function (config, ignoredLaunchers) { customLaunchers = basicLaunchers; } else { Object.keys(basicLaunchers).forEach(function(key) { - if (ignoredLaunchers.filter(function(ignore) {return ignore === key;}).length === 0) { + if (ignoredLaunchers + .filter(function(ignore) { + return ignore === key; + }) + .length === 0) { customLaunchers[key] = basicLaunchers[key]; } }); @@ -173,11 +124,11 @@ module.exports = function (config, ignoredLaunchers) { startConnect: false, recordVideo: false, recordScreenshots: false, - options: { - 'selenium-version': '2.53.0', - 'command-timeout': 600, - 'idle-timeout': 600, - 'max-duration': 5400 + options: { + 'selenium-version': '2.53.0', + 'command-timeout': 600, + 'idle-timeout': 600, + 'max-duration': 5400 } }, @@ -189,13 +140,12 @@ module.exports = function (config, ignoredLaunchers) { singleRun: true, - plugins: [ - 'karma-*' - ] + plugins: ['karma-*'] }); if (process.env.TRAVIS) { - config.sauceLabs.build = 'TRAVIS #' + process.env.TRAVIS_BUILD_NUMBER + ' (' + process.env.TRAVIS_BUILD_ID + ')'; + config.sauceLabs.build = + 'TRAVIS #' + process.env.TRAVIS_BUILD_NUMBER + ' (' + process.env.TRAVIS_BUILD_ID + ')'; config.sauceLabs.tunnelIdentifier = process.env.TRAVIS_JOB_NUMBER; process.env.SAUCE_ACCESS_KEY = process.env.SAUCE_ACCESS_KEY.split('').reverse().join(''); diff --git a/test/browser-zone-setup.ts b/test/browser-zone-setup.ts index 476ffdb0d..07b3ee154 100644 --- a/test/browser-zone-setup.ts +++ b/test/browser-zone-setup.ts @@ -11,6 +11,7 @@ if (typeof window !== 'undefined') { import '../lib/common/to-string'; import '../lib/browser/browser'; import '../lib/browser/webapis-user-media'; +import '../lib/browser/webapis-media-query'; import '../lib/zone-spec/async-test'; import '../lib/zone-spec/fake-async-test'; import '../lib/zone-spec/long-stack-trace'; @@ -21,3 +22,4 @@ import '../lib/zone-spec/wtf'; import '../lib/extra/cordova'; import '../lib/testing/promise-testing'; import '../lib/browser/webapis-resize-observer'; +import '../lib/rxjs/rxjs-fake-async'; diff --git a/test/browser/MediaQuery.spec.ts b/test/browser/MediaQuery.spec.ts index 465d23102..fcb6dfb39 100644 --- a/test/browser/MediaQuery.spec.ts +++ b/test/browser/MediaQuery.spec.ts @@ -6,8 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import '../../lib/browser/webapis-media-query'; - import {zoneSymbol} from '../../lib/common/utils'; import {ifEnvSupports} from '../test-util'; declare const global: any; diff --git a/test/browser/Notification.spec.ts b/test/browser/Notification.spec.ts index 5c23fccab..8e0273991 100644 --- a/test/browser/Notification.spec.ts +++ b/test/browser/Notification.spec.ts @@ -6,8 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import '../../lib/browser/webapis-notification'; - import {zoneSymbol} from '../../lib/common/utils'; import {ifEnvSupports} from '../test-util'; declare const window: any; diff --git a/test/main.ts b/test/main.ts index f8c33f3ea..5fb669dde 100644 --- a/test/main.ts +++ b/test/main.ts @@ -28,22 +28,21 @@ if ((window as any)[(Zone as any).__symbol__('setTimeout')]) { } 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'); + browserPatchedPromise = System.import('/base/build/test/browser-zone-setup').then(() => { + let testFrameworkPatch = typeof(window as any).Mocha !== 'undefined' ? + '/base/build/test/test-env-setup-mocha' : + '/base/build/test/test-env-setup-jasmine'; + return System.import(testFrameworkPatch); + }); } browserPatchedPromise.then(() => { - let testFrameworkPatch = typeof(window as any).Mocha !== 'undefined' ? - '/base/build/test/test-env-setup-mocha' : - '/base/build/test/test-env-setup-jasmine'; - // Setup test environment - System.import(testFrameworkPatch).then(() => { - System.import('/base/build/test/browser_entry_point') - .then( - () => { - __karma__.start(); - }, - (error) => { - console.error(error.stack || error); - }); - }); + System.import('/base/build/test/browser_entry_point') + .then( + () => { + __karma__.start(); + }, + (error) => { + console.error(error.stack || error); + }); }); diff --git a/test/node_entry_point.ts b/test/node_entry_point.ts index 27ba367ca..6cc4b79c9 100644 --- a/test/node_entry_point.ts +++ b/test/node_entry_point.ts @@ -25,6 +25,7 @@ import '../lib/zone-spec/wtf'; import '../lib/rxjs/rxjs'; import '../lib/testing/promise-testing'; +import '../lib/rxjs/rxjs-fake-async'; // Setup test environment import './test-env-setup-jasmine'; diff --git a/test/zone-spec/async-test.spec.ts b/test/zone-spec/async-test.spec.ts index 98610da00..befb93988 100644 --- a/test/zone-spec/async-test.spec.ts +++ b/test/zone-spec/async-test.spec.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import '../../lib/zone-spec/async-test'; import {ifEnvSupports} from '../test-util'; describe('AsyncTestZoneSpec', function() { @@ -351,18 +350,21 @@ describe('AsyncTestZoneSpec', function() { function testAsync(fn: Function, doneFn?: Function) { return function(done: any) { - runInTestZone(fn, this, function() { - if (doneFn) { - doneFn(); - } - done(); - }, (err: any) => { - if (typeof err === 'string') { - return done.fail(new Error(err)); - } else { - done.fail(err); - } - }); + runInTestZone( + fn, this, + function() { + if (doneFn) { + doneFn(); + } + done(); + }, + (err: any) => { + if (typeof err === 'string') { + return done.fail(new Error(err)); + } else { + done.fail(err); + } + }); }; } @@ -405,167 +407,196 @@ describe('AsyncTestZoneSpec', function() { describe('test without beforeEach', () => { const logs: string[] = []; - it('should automatically done after async tasks finished', testAsync(() => { - setTimeout(() => { - logs.push('timeout'); - }, 100); - }, () => { - expect(logs).toEqual(['timeout']); - logs.splice(0); - })); - - it('should automatically done after all nested async tasks finished', testAsync(() => { - setTimeout(() => { - logs.push('timeout'); - setTimeout(() => { - logs.push('nested timeout'); - }, 100); - }, 100); - }, () => { - expect(logs).toEqual(['timeout', 'nested timeout']); - logs.splice(0); - })); - - it('should automatically done after multiple async tasks finished', testAsync(() => { - setTimeout(() => { - logs.push('1st timeout'); - }, 100); - - setTimeout(() => { - logs.push('2nd timeout'); - }, 100); - }, () => { - expect(logs).toEqual(['1st timeout', '2nd timeout']); - logs.splice(0); - })); + it('should automatically done after async tasks finished', + testAsync( + () => { + setTimeout(() => { + logs.push('timeout'); + }, 100); + }, + () => { + expect(logs).toEqual(['timeout']); + logs.splice(0); + })); + + it('should automatically done after all nested async tasks finished', + testAsync( + () => { + setTimeout(() => { + logs.push('timeout'); + setTimeout(() => { + logs.push('nested timeout'); + }, 100); + }, 100); + }, + () => { + expect(logs).toEqual(['timeout', 'nested timeout']); + logs.splice(0); + })); + + it('should automatically done after multiple async tasks finished', + testAsync( + () => { + setTimeout(() => { + logs.push('1st timeout'); + }, 100); + + setTimeout(() => { + logs.push('2nd timeout'); + }, 100); + }, + () => { + expect(logs).toEqual(['1st timeout', '2nd timeout']); + logs.splice(0); + })); }); - + describe('test with sync beforeEach', () => { const logs: string[] = []; - + beforeEach(() => { logs.splice(0); logs.push('beforeEach'); }); - - it('should automatically done after async tasks finished', testAsync(() => { - setTimeout(() => { - logs.push('timeout'); - }, 100); - }, () => { - expect(logs).toEqual(['beforeEach', 'timeout']); - })); + + it('should automatically done after async tasks finished', + testAsync( + () => { + setTimeout(() => { + logs.push('timeout'); + }, 100); + }, + () => { + expect(logs).toEqual(['beforeEach', 'timeout']); + })); }); - + describe('test with async beforeEach', () => { const logs: string[] = []; - + beforeEach(testAsync(() => { setTimeout(() => { logs.splice(0); logs.push('beforeEach'); }, 100); })); - - it('should automatically done after async tasks finished', testAsync(() => { - setTimeout(() => { - logs.push('timeout'); - }, 100); - }, () => { - expect(logs).toEqual(['beforeEach', 'timeout']); - })); - - it('should automatically done after all nested async tasks finished', testAsync(() => { - setTimeout(() => { - logs.push('timeout'); - setTimeout(() => { - logs.push('nested timeout'); - }, 100); - }, 100); - }, () => { - expect(logs).toEqual(['beforeEach', 'timeout', 'nested timeout']); - })); - - it('should automatically done after multiple async tasks finished', testAsync(() => { - setTimeout(() => { - logs.push('1st timeout'); - }, 100); - - setTimeout(() => { - logs.push('2nd timeout'); - }, 100); - }, () => { - expect(logs).toEqual(['beforeEach', '1st timeout', '2nd timeout']); - })); + + it('should automatically done after async tasks finished', + testAsync( + () => { + setTimeout(() => { + logs.push('timeout'); + }, 100); + }, + () => { + expect(logs).toEqual(['beforeEach', 'timeout']); + })); + + it('should automatically done after all nested async tasks finished', + testAsync( + () => { + setTimeout(() => { + logs.push('timeout'); + setTimeout(() => { + logs.push('nested timeout'); + }, 100); + }, 100); + }, + () => { + expect(logs).toEqual(['beforeEach', 'timeout', 'nested timeout']); + })); + + it('should automatically done after multiple async tasks finished', + testAsync( + () => { + setTimeout(() => { + logs.push('1st timeout'); + }, 100); + + setTimeout(() => { + logs.push('2nd timeout'); + }, 100); + }, + () => { + expect(logs).toEqual(['beforeEach', '1st timeout', '2nd timeout']); + })); }); - + describe('test with async beforeEach and sync afterEach', () => { const logs: string[] = []; - + beforeEach(testAsync(() => { setTimeout(() => { expect(logs).toEqual([]); logs.push('beforeEach'); }, 100); })); - + afterEach(() => { logs.splice(0); }); - - it('should automatically done after async tasks finished', testAsync(() => { - setTimeout(() => { - logs.push('timeout'); - }, 100); - }, () => { - expect(logs).toEqual(['beforeEach', 'timeout']); - })); + + it('should automatically done after async tasks finished', + testAsync( + () => { + setTimeout(() => { + logs.push('timeout'); + }, 100); + }, + () => { + expect(logs).toEqual(['beforeEach', 'timeout']); + })); }); - + describe('test with async beforeEach and async afterEach', () => { const logs: string[] = []; - + beforeEach(testAsync(() => { setTimeout(() => { expect(logs).toEqual([]); logs.push('beforeEach'); }, 100); })); - + afterEach(testAsync(() => { setTimeout(() => { logs.splice(0); }, 100); })); - - it('should automatically done after async tasks finished', testAsync(() => { - setTimeout(() => { - logs.push('timeout'); - }, 100); - }, () => { - expect(logs).toEqual(['beforeEach', 'timeout']); - })); + + it('should automatically done after async tasks finished', + testAsync( + () => { + setTimeout(() => { + logs.push('timeout'); + }, 100); + }, + () => { + expect(logs).toEqual(['beforeEach', 'timeout']); + })); }); describe('return promise', () => { let value = 'init'; - it('should only call finish once', testAsync(() => { - return new Promise((resolve, _) => { - setTimeout(() => { - value = 'timeout'; - resolve(); - }, 100); - }); - }, () => { - expect(value).toEqual('timeout'); - })); + it('should only call finish once', testAsync( + () => { + return new Promise((resolve, _) => { + setTimeout(() => { + value = 'timeout'; + resolve(); + }, 100); + }); + }, + () => { + expect(value).toEqual('timeout'); + })); }); }); describe('should be able to handle async for both beforeEach and it', () => { let log: string[]; const AsyncTestZoneSpec = (Zone as any)['AsyncTestZoneSpec']; - + function asyncTest(testBody: () => void, finishCallback: Function, failCallback: Function) { return function() { const proxyZoneSpec = Zone.current.get('ProxyZoneSpec'); @@ -576,37 +607,48 @@ describe('AsyncTestZoneSpec', function() { // construct AsyncTestZoneSpec in parent zone // to prevent infinite loop Zone.current.parent.run(() => { - proxyZoneSpec.setDelegate(new AsyncTestZoneSpec(() => { - proxyZoneSpec.setDelegate(lastDelegate); - finishCallback(); - }, () => { - proxyZoneSpec.setDelegate(lastDelegate); - failCallback(); - }), 'async'); + proxyZoneSpec.setDelegate( + new AsyncTestZoneSpec( + () => { + proxyZoneSpec.setDelegate(lastDelegate); + finishCallback(); + }, + () => { + proxyZoneSpec.setDelegate(lastDelegate); + failCallback(); + }), + 'async'); }); testBody.apply(this, arguments); }; } - beforeEach(asyncTest(() => { - log = []; - setTimeout(() => { - log.push('beforeEach'); - }, 50); - }, () => { - expect(log).toEqual(['beforeEach']); - }, () => { - fail('should not fail'); - })); - - it('should support asyncTest with an async beforeEach', asyncTest(() => { - setTimeout(() => { - log.push('timeout'); - }, 50); - }, () => { - expect(log).toEqual(['beforeEach', 'timeout']); - }, () => { - fail('should not fail'); - })); + beforeEach(asyncTest( + () => { + log = []; + setTimeout(() => { + log.push('beforeEach'); + }, 50); + }, + () => { + expect(log).toEqual(['beforeEach']); + }, + () => { + fail('should not fail'); + })); + + it('should support asyncTest with an async beforeEach', + asyncTest( + () => { + setTimeout(() => { + log.push('timeout'); + }, 50); + }, + () => { + expect(log).toEqual(['beforeEach', 'timeout']); + }, + () => { + fail('should not fail'); + })); }); }); diff --git a/test/zone-spec/fake-async-test.spec.ts b/test/zone-spec/fake-async-test.spec.ts index 9889cff39..3979ea797 100644 --- a/test/zone-spec/fake-async-test.spec.ts +++ b/test/zone-spec/fake-async-test.spec.ts @@ -6,13 +6,13 @@ * found in the LICENSE file at https://angular.io/license */ -import '../../lib/zone-spec/fake-async-test'; +import 'rxjs/add/operator/delay'; +import '../../lib/rxjs/rxjs-fake-async'; + +import {Observable} from 'rxjs/Observable'; import {isNode, patchMacroTask} from '../../lib/common/utils'; import {ifEnvSupports} from '../test-util'; -import {Observable} from 'rxjs/Observable'; -import 'rxjs/add/operator/delay'; -import '../../lib/rxjs/rxjs-fake-async'; function supportNode() { return isNode; @@ -212,7 +212,7 @@ describe('FakeAsyncTestZoneSpec', () => { let id = setTimeout((arg1, arg2) => { value = arg1 + arg2; }, 0, 'expected', ' value'); - + testZoneSpec.tick(); expect(value).toEqual('expected value'); }); @@ -245,7 +245,7 @@ describe('FakeAsyncTestZoneSpec', () => { let id = setInterval((arg1, arg2) => { value = arg1 + arg2; }, 10, 'expected', ' value'); - + testZoneSpec.tick(10); expect(value).toEqual('expected value'); }); @@ -859,8 +859,7 @@ describe('FakeAsyncTestZoneSpec', () => { let fakeAsyncTestZone: Zone; beforeEach(() => { - testZoneSpec = new FakeAsyncTestZoneSpec( - 'name', false); + testZoneSpec = new FakeAsyncTestZoneSpec('name', false); fakeAsyncTestZone = Zone.current.fork(testZoneSpec); }); @@ -874,46 +873,50 @@ describe('FakeAsyncTestZoneSpec', () => { }); }); - describe('fakeAsyncTest should patch jasmine.clock', ifEnvSupports(() => { - return typeof jasmine.clock === 'function'; - }, () => { - beforeEach(() => { - jasmine.clock().install(); - }); + describe( + 'fakeAsyncTest should patch jasmine.clock', + ifEnvSupports( + () => { + return typeof jasmine.clock === 'function'; + }, + () => { + beforeEach(() => { + jasmine.clock().install(); + }); - afterEach(() => { - jasmine.clock().uninstall(); - }); + afterEach(() => { + jasmine.clock().uninstall(); + }); - it('should get date diff correctly', () => { - const start = Date.now(); - jasmine.clock().tick(100); - const end = Date.now(); - expect(end - start).toBe(100); - }); - - it('should mock date correctly', () => { - const baseTime = new Date(2013, 9, 23); - jasmine.clock().mockDate(baseTime); - const start = Date.now(); - expect(start).toBe(baseTime.getTime()); - jasmine.clock().tick(100); - const end = Date.now(); - expect(end - start).toBe(100); - expect(end).toBe(baseTime.getTime() + 100); - }); - - it('should handle new Date correctly', () => { - const baseTime = new Date(2013, 9, 23); - jasmine.clock().mockDate(baseTime); - const start = new Date(); - expect(start.getTime()).toBe(baseTime.getTime()); - jasmine.clock().tick(100); - const end = new Date(); - expect(end.getTime() - start.getTime()).toBe(100); - expect(end.getTime()).toBe(baseTime.getTime() + 100); - }); - })); + it('should get date diff correctly', () => { + const start = Date.now(); + jasmine.clock().tick(100); + const end = Date.now(); + expect(end - start).toBe(100); + }); + + it('should mock date correctly', () => { + const baseTime = new Date(2013, 9, 23); + jasmine.clock().mockDate(baseTime); + const start = Date.now(); + expect(start).toBe(baseTime.getTime()); + jasmine.clock().tick(100); + const end = Date.now(); + expect(end - start).toBe(100); + expect(end).toBe(baseTime.getTime() + 100); + }); + + it('should handle new Date correctly', () => { + const baseTime = new Date(2013, 9, 23); + jasmine.clock().mockDate(baseTime); + const start = new Date(); + expect(start.getTime()).toBe(baseTime.getTime()); + jasmine.clock().tick(100); + const end = new Date(); + expect(end.getTime() - start.getTime()).toBe(100); + expect(end.getTime()).toBe(baseTime.getTime() + 100); + }); + })); describe('fakeAsyncTest should patch rxjs scheduler', () => { let FakeAsyncTestZoneSpec = (Zone as any)['FakeAsyncTestZoneSpec']; @@ -921,8 +924,7 @@ describe('FakeAsyncTestZoneSpec', () => { let fakeAsyncTestZone: Zone; beforeEach(() => { - testZoneSpec = new FakeAsyncTestZoneSpec( - 'name', false); + testZoneSpec = new FakeAsyncTestZoneSpec('name', false); fakeAsyncTestZone = Zone.current.fork(testZoneSpec); }); diff --git a/test/zone-spec/proxy.spec.ts b/test/zone-spec/proxy.spec.ts index d815ce631..950353fef 100644 --- a/test/zone-spec/proxy.spec.ts +++ b/test/zone-spec/proxy.spec.ts @@ -6,8 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import '../../lib/zone-spec/proxy'; - describe('ProxySpec', () => { let ProxyZoneSpec: any; let delegate: ZoneSpec; @@ -192,16 +190,10 @@ describe('ProxySpec', () => { setTimeout(() => { expect(log).toEqual([ - 'zoneSpec1 hasTask: false,true', - 'zoneSpec2 hasTask: false,true', - 'zoneSpec2 hasTask: true,true', - 'zoneSpec2 hasTask: true,true', - 'then in zoneSpec2', - 'then in zoneSpec2', - 'zoneSpec2 hasTask: false,true', - 'timeout in zoneSpec1', - 'timeout in null spec', - 'zoneSpec2 hasTask: false,false' + 'zoneSpec1 hasTask: false,true', 'zoneSpec2 hasTask: false,true', + 'zoneSpec2 hasTask: true,true', 'zoneSpec2 hasTask: true,true', 'then in zoneSpec2', + 'then in zoneSpec2', 'zoneSpec2 hasTask: false,true', 'timeout in zoneSpec1', + 'timeout in null spec', 'zoneSpec2 hasTask: false,false' ]); done(); }, 300); diff --git a/test/zone-spec/sync-test.spec.ts b/test/zone-spec/sync-test.spec.ts index 2dbe9cb1b..d51dff686 100644 --- a/test/zone-spec/sync-test.spec.ts +++ b/test/zone-spec/sync-test.spec.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import '../../lib/zone-spec/sync-test'; import {ifEnvSupports} from '../test-util'; describe('SyncTestZoneSpec', () => { diff --git a/test/zone-spec/task-tracking.spec.ts b/test/zone-spec/task-tracking.spec.ts index e9537579c..1c7115d2a 100644 --- a/test/zone-spec/task-tracking.spec.ts +++ b/test/zone-spec/task-tracking.spec.ts @@ -6,8 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import '../../lib/zone-spec/task-tracking'; - import {supportPatchXHROnProperty} from '../test-util'; declare const global: any;