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

fix(test): fix mocha compatible issue #1028

Merged
merged 1 commit into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion karma-build-sauce-selenium3-mocha.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
};
3 changes: 0 additions & 3 deletions lib/mocha/mocha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});

Expand Down
48 changes: 48 additions & 0 deletions test/zone-spec/async-test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}));
});
});