diff --git a/.travis.yml b/.travis.yml index 97d706205..21504c57e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,7 +42,8 @@ script: - node_modules/.bin/gulp test/node - node simple-server.js 2>&1> server.log& - node ./test/webdriver/test.sauce.js - - yarn add jasmine@3.0.0 jasmine-core@3.0.0 + - yarn add jasmine@3.0.0 jasmine-core@3.0.0 mocha@5.0.1 - yarn test:phantomjs-single - node_modules/.bin/karma start karma-dist-sauce-jasmine3.conf.js --single-run + - node_modules/.bin/karma start karma-build-sauce-selenium3-mocha.conf.js --single-run - node_modules/.bin/gulp test/node diff --git a/karma-build-sauce-selenium3-mocha.conf.js b/karma-build-sauce-selenium3-mocha.conf.js index 6eb77e97a..d23462147 100644 --- a/karma-build-sauce-selenium3-mocha.conf.js +++ b/karma-build-sauce-selenium3-mocha.conf.js @@ -8,5 +8,5 @@ module.exports = function (config) { require('./karma-dist-mocha.conf.js')(config); - require('./sauce-selenium3.conf')(config); + require('./sauce-selenium3.conf')(config, ['SL_IE9']); }; diff --git a/lib/mocha/mocha.ts b/lib/mocha/mocha.ts index f04fe5a8b..10156a82f 100644 --- a/lib/mocha/mocha.ts +++ b/lib/mocha/mocha.ts @@ -158,9 +158,6 @@ Mocha.Runner.prototype.run = function(fn: Function) { this.on('test', (e: any) => { - if (Zone.current !== rootZone) { - throw new Error('Unexpected zone: ' + Zone.current.name); - } testZone = rootZone.fork(new ProxyZoneSpec()); }); diff --git a/test/zone-spec/async-test.spec.ts b/test/zone-spec/async-test.spec.ts index 8d0f59e5e..9050a2a56 100644 --- a/test/zone-spec/async-test.spec.ts +++ b/test/zone-spec/async-test.spec.ts @@ -547,4 +547,52 @@ describe('AsyncTestZoneSpec', function() { })); }); }); + + 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'); + if (!proxyZoneSpec) { + throw new Error('ProxyZone not found!'); + } + const lastDelegate = proxyZoneSpec.getDelegate(); + // 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'); + }); + 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'); + })); + }); });