Skip to content

Commit 8efbdb5

Browse files
JiaLiPassionalxhub
authored andcommitted
fix(zone.js): patch global instead of Mocha object (#45047)
Close #42834 In the new version fo Mocha, all global test functions are from `global` object instead of `Mocha` object. Adn the current `zone.js` Mocha patch's logic looks like this. ``` global.describe = Mocha.describe = function() { return originalMochaDescribe.apply(this, arguments); } ``` and `originalMochaDescribe` is the unpathced Mocha implementation looks like this ``` function describe() { return context.describe(...); } ``` And the `context` will finally delegate to `global.describe()`, so the current `zone.js` patch causes infinite loop. This commit will not patch function of `Mocha` object any longer. PR Close #45047
1 parent 6769f94 commit 8efbdb5

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

packages/zone.js/lib/mocha/mocha.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ Zone.__load_patch('mocha', (global: any, Zone: ZoneType) => {
4040
const suiteZone = rootZone.fork(new ProxyZoneSpec());
4141

4242
const mochaOriginal = {
43-
after: Mocha.after,
44-
afterEach: Mocha.afterEach,
45-
before: Mocha.before,
46-
beforeEach: Mocha.beforeEach,
47-
describe: Mocha.describe,
48-
it: Mocha.it
43+
after: global.after,
44+
afterEach: global.afterEach,
45+
before: global.before,
46+
beforeEach: global.beforeEach,
47+
describe: global.describe,
48+
it: global.it
4949
};
5050

5151
function modifyArguments(args: IArguments, syncTest: Function, asyncTest?: Function): any[] {
@@ -111,43 +111,43 @@ Zone.__load_patch('mocha', (global: any, Zone: ZoneType) => {
111111
return modifyArguments(args, syncTest, asyncTest);
112112
}
113113

114-
global.describe = global.suite = Mocha.describe = function() {
114+
global.describe = global.suite = function() {
115115
return mochaOriginal.describe.apply(this, wrapDescribeInZone(arguments));
116116
};
117117

118-
global.xdescribe = global.suite.skip = Mocha.describe.skip = function() {
118+
global.xdescribe = global.suite.skip = function() {
119119
return mochaOriginal.describe.skip.apply(this, wrapDescribeInZone(arguments));
120120
};
121121

122-
global.describe.only = global.suite.only = Mocha.describe.only = function() {
122+
global.describe.only = global.suite.only = function() {
123123
return mochaOriginal.describe.only.apply(this, wrapDescribeInZone(arguments));
124124
};
125125

126-
global.it = global.specify = global.test = Mocha.it = function() {
126+
global.it = global.specify = global.test = function() {
127127
return mochaOriginal.it.apply(this, wrapTestInZone(arguments));
128128
};
129129

130-
global.xit = global.xspecify = Mocha.it.skip = function() {
130+
global.xit = global.xspecify = function() {
131131
return mochaOriginal.it.skip.apply(this, wrapTestInZone(arguments));
132132
};
133133

134-
global.it.only = global.test.only = Mocha.it.only = function() {
134+
global.it.only = global.test.only = function() {
135135
return mochaOriginal.it.only.apply(this, wrapTestInZone(arguments));
136136
};
137137

138-
global.after = global.suiteTeardown = Mocha.after = function() {
138+
global.after = global.suiteTeardown = function() {
139139
return mochaOriginal.after.apply(this, wrapSuiteInZone(arguments));
140140
};
141141

142-
global.afterEach = global.teardown = Mocha.afterEach = function() {
142+
global.afterEach = global.teardown = function() {
143143
return mochaOriginal.afterEach.apply(this, wrapTestInZone(arguments));
144144
};
145145

146-
global.before = global.suiteSetup = Mocha.before = function() {
146+
global.before = global.suiteSetup = function() {
147147
return mochaOriginal.before.apply(this, wrapSuiteInZone(arguments));
148148
};
149149

150-
global.beforeEach = global.setup = Mocha.beforeEach = function() {
150+
global.beforeEach = global.setup = function() {
151151
return mochaOriginal.beforeEach.apply(this, wrapTestInZone(arguments));
152152
};
153153

0 commit comments

Comments
 (0)