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

Commit f1f56ef

Browse files
committed
add more bdd API and timeout/pending support to mocha
1 parent 0793637 commit f1f56ef

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

lib/jasmine/jasmine-patch.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,26 @@ Zone.__load_patch('jasmine', (global: any) => {
6161
jasmineEnv[symbol(methodName)] = originalJasmineFn;
6262
jasmineEnv[methodName] = function(
6363
description: string, specDefinitions: Function, timeout: number) {
64-
arguments[1] = wrapTestInZone(specDefinitions);
65-
return originalJasmineFn.apply(this, arguments);
64+
if (typeof timeout !== 'number') {
65+
timeout = (jasmine as any)[symbol('mochaTimeout')];
66+
}
67+
const wrappedSpecDef = wrapTestInZone(specDefinitions);
68+
return originalJasmineFn.apply(
69+
this,
70+
typeof timeout === 'number' ? [description, wrappedSpecDef, timeout] :
71+
[description, wrappedSpecDef]);
6672
};
6773
});
6874
['beforeEach', 'afterEach'].forEach(methodName => {
6975
let originalJasmineFn: Function = jasmineEnv[methodName];
7076
jasmineEnv[symbol(methodName)] = originalJasmineFn;
7177
jasmineEnv[methodName] = function(specDefinitions: Function, timeout: number) {
72-
arguments[0] = wrapTestInZone(specDefinitions);
73-
return originalJasmineFn.apply(this, arguments);
78+
if (typeof timeout !== 'number') {
79+
timeout = (jasmine as any)[symbol('mochaTimeout')];
80+
}
81+
const wrappedSpecDef = wrapTestInZone(specDefinitions);
82+
return originalJasmineFn.apply(
83+
this, typeof timeout === 'number' ? [wrappedSpecDef, timeout] : [wrappedSpecDef]);
7484
};
7585
});
7686

@@ -81,6 +91,19 @@ Zone.__load_patch('jasmine', (global: any) => {
8191
*/
8292
function wrapDescribeInZone(describeBody: Function): Function {
8393
return function() {
94+
(jasmine as any)[symbol('mochaTimeout')] = null;
95+
if (this && !this.timeout) {
96+
this.timeout = function(timeout: number) {
97+
(jasmine as any)[symbol('mochaTimeout')] = timeout;
98+
}
99+
}
100+
if (this && !this.skip) {
101+
this.skip = function() {
102+
if (typeof global['pending'] === 'function') {
103+
global['pending']();
104+
}
105+
}
106+
}
84107
return syncZone.run(describeBody, this, (arguments as any) as any[]);
85108
};
86109
}

lib/jasmine/mocha-bridge/mocha.bdd.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
export function mappingBDD(Mocha: any, jasmine: any, global: any) {
1010
const mappings: {Mocha: string, jasmine: string, target?: any}[] = [
1111
{jasmine: 'beforeAll', Mocha: 'before'}, {jasmine: 'afterAll', Mocha: 'after'},
12+
{jasmine: 'beforeEach', Mocha: 'setup'}, {jasmine: 'afterEach', Mocha: 'tearDown'},
1213
{jasmine: 'it', Mocha: 'it'}, {jasmine: 'it', Mocha: 'specify'}, {jasmine: 'it', Mocha: 'test'},
13-
{jasmine: 'describe', Mocha: 'suite'}, {jasmine: 'beforeAll', Mocha: 'suiteSetup'},
14-
{jasmine: 'afterAll', Mocha: 'suiteTeardown'},
14+
{jasmine: 'describe', Mocha: 'suite'}, {jasmine: 'describe', Mocha: 'context'},
15+
{jasmine: 'beforeAll', Mocha: 'suiteSetup'}, {jasmine: 'afterAll', Mocha: 'suiteTeardown'},
1516
{jasmine: 'xdescribe', Mocha: 'skip', target: global['describe']},
1617
{jasmine: 'fdescribe', Mocha: 'only', target: global['describe']},
1718
{jasmine: 'xit', Mocha: 'skip', target: global['it']}, {jasmine: 'fit', Mocha: 'only'}

0 commit comments

Comments
 (0)