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

Commit 61be2df

Browse files
committed
fix(test): fix mocha compatible issue
1 parent e1df4bc commit 61be2df

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

Diff for: .travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ script:
3838
- node_modules/.bin/gulp test/node
3939
- node simple-server.js 2>&1> server.log&
4040
- node ./test/webdriver/test.sauce.js
41-
41+
4242
- npm run test:phantomjs-single
4343
- node_modules/.bin/karma start karma-dist-sauce-jasmine3.conf.js --single-run
44+
- node_modules/.bin/karma start karma-build-sauce-selenium3-mocha.conf.js --single-run
4445
- node_modules/.bin/gulp test/node

Diff for: karma-build-sauce-selenium3-mocha.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88

99
module.exports = function (config) {
1010
require('./karma-dist-mocha.conf.js')(config);
11-
require('./sauce-selenium3.conf')(config);
11+
require('./sauce-selenium3.conf')(config, ['SL_IE9']);
1212
};

Diff for: lib/mocha/mocha.ts

-3
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,6 @@
158158

159159
Mocha.Runner.prototype.run = function(fn: Function) {
160160
this.on('test', (e: any) => {
161-
if (Zone.current !== rootZone) {
162-
throw new Error('Unexpected zone: ' + Zone.current.name);
163-
}
164161
testZone = rootZone.fork(new ProxyZoneSpec());
165162
});
166163

Diff for: test/zone-spec/async-test.spec.ts

+48
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,52 @@ describe('AsyncTestZoneSpec', function() {
343343
});
344344
});
345345
});
346+
347+
describe('should be able to handle async for both beforeEach and it', () => {
348+
let log: string[];
349+
const AsyncTestZoneSpec = (Zone as any)['AsyncTestZoneSpec'];
350+
351+
function asyncTest(testBody: () => void, finishCallback: Function, failCallback: Function) {
352+
return function() {
353+
const proxyZoneSpec = Zone.current.get('ProxyZoneSpec');
354+
if (!proxyZoneSpec) {
355+
throw new Error('ProxyZone not found!');
356+
}
357+
const lastDelegate = proxyZoneSpec.getDelegate();
358+
// construct AsyncTestZoneSpec in parent zone
359+
// to prevent infinite loop
360+
Zone.current.parent.run(() => {
361+
proxyZoneSpec.setDelegate(new AsyncTestZoneSpec(() => {
362+
proxyZoneSpec.setDelegate(lastDelegate);
363+
finishCallback();
364+
}, () => {
365+
proxyZoneSpec.setDelegate(lastDelegate);
366+
failCallback();
367+
}), 'async');
368+
});
369+
testBody.apply(this, arguments);
370+
};
371+
}
372+
373+
beforeEach(asyncTest(() => {
374+
log = [];
375+
setTimeout(() => {
376+
log.push('beforeEach');
377+
}, 50);
378+
}, () => {
379+
expect(log).toEqual(['beforeEach']);
380+
}, () => {
381+
fail('should not fail');
382+
}));
383+
384+
it('should support asyncTest with an async beforeEach', asyncTest(() => {
385+
setTimeout(() => {
386+
log.push('timeout');
387+
}, 50);
388+
}, () => {
389+
expect(log).toEqual(['beforeEach', 'timeout']);
390+
}, () => {
391+
fail('should not fail');
392+
}));
393+
});
346394
});

0 commit comments

Comments
 (0)