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

Commit feea2f8

Browse files
committed
fix(test): fix mocha compatible issue
1 parent eefe983 commit feea2f8

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
@@ -42,7 +42,8 @@ script:
4242
- node_modules/.bin/gulp test/node
4343
- node simple-server.js 2>&1> server.log&
4444
- node ./test/webdriver/test.sauce.js
45-
45+
4646
- yarn test:phantomjs-single
4747
- node_modules/.bin/karma start karma-dist-sauce-jasmine3.conf.js --single-run
48+
- node_modules/.bin/karma start karma-build-sauce-selenium3-mocha.conf.js --single-run
4849
- 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
@@ -547,4 +547,52 @@ describe('AsyncTestZoneSpec', function() {
547547
}));
548548
});
549549
});
550+
551+
describe('should be able to handle async for both beforeEach and it', () => {
552+
let log: string[];
553+
const AsyncTestZoneSpec = (Zone as any)['AsyncTestZoneSpec'];
554+
555+
function asyncTest(testBody: () => void, finishCallback: Function, failCallback: Function) {
556+
return function() {
557+
const proxyZoneSpec = Zone.current.get('ProxyZoneSpec');
558+
if (!proxyZoneSpec) {
559+
throw new Error('ProxyZone not found!');
560+
}
561+
const lastDelegate = proxyZoneSpec.getDelegate();
562+
// construct AsyncTestZoneSpec in parent zone
563+
// to prevent infinite loop
564+
Zone.current.parent.run(() => {
565+
proxyZoneSpec.setDelegate(new AsyncTestZoneSpec(() => {
566+
proxyZoneSpec.setDelegate(lastDelegate);
567+
finishCallback();
568+
}, () => {
569+
proxyZoneSpec.setDelegate(lastDelegate);
570+
failCallback();
571+
}), 'async');
572+
});
573+
testBody.apply(this, arguments);
574+
};
575+
}
576+
577+
beforeEach(asyncTest(() => {
578+
log = [];
579+
setTimeout(() => {
580+
log.push('beforeEach');
581+
}, 50);
582+
}, () => {
583+
expect(log).toEqual(['beforeEach']);
584+
}, () => {
585+
fail('should not fail');
586+
}));
587+
588+
it('should support asyncTest with an async beforeEach', asyncTest(() => {
589+
setTimeout(() => {
590+
log.push('timeout');
591+
}, 50);
592+
}, () => {
593+
expect(log).toEqual(['beforeEach', 'timeout']);
594+
}, () => {
595+
fail('should not fail');
596+
}));
597+
});
550598
});

0 commit comments

Comments
 (0)