MCPcopy Index your code
hub / github.com/angular/angular / patchMocha

Function patchMocha

packages/zone.js/lib/mocha/mocha.ts:13–192  ·  view source on GitHub ↗
(Zone: ZoneType)

Source from the content-addressed store, hash-verified

11('use strict');
12
13export function patchMocha(Zone: ZoneType): void {
14 Zone.__load_patch('mocha', (global: any, Zone: ZoneType) => {
15 const Mocha = global.Mocha;
16
17 if (typeof Mocha === 'undefined') {
18 // return if Mocha is not available, because now zone-testing
19 // will load mocha patch with jasmine/jest patch
20 return;
21 }
22
23 if (typeof Zone === 'undefined') {
24 throw new Error('Missing Zone.js');
25 }
26
27 const ProxyZoneSpec = (Zone as any)['ProxyZoneSpec'];
28 const SyncTestZoneSpec = (Zone as any)['SyncTestZoneSpec'];
29
30 if (!ProxyZoneSpec) {
31 throw new Error('Missing ProxyZoneSpec');
32 }
33
34 if (Mocha['__zone_patch__']) {
35 throw new Error('"Mocha" has already been patched with "Zone".');
36 }
37
38 Mocha['__zone_patch__'] = true;
39
40 const rootZone = Zone.current;
41 const syncZone = rootZone.fork(new SyncTestZoneSpec('Mocha.describe'));
42 let testZone: Zone | null = null;
43 const suiteZone = rootZone.fork(new ProxyZoneSpec());
44
45 const mochaOriginal = {
46 after: global.after,
47 afterEach: global.afterEach,
48 before: global.before,
49 beforeEach: global.beforeEach,
50 describe: global.describe,
51 it: global.it,
52 };
53
54 function modifyArguments(args: IArguments, syncTest: Function, asyncTest?: Function): any[] {
55 for (let i = 0; i < args.length; i++) {
56 let arg = args[i];
57 if (typeof arg === 'function') {
58 // The `done` callback is only passed through if the function expects at
59 // least one argument.
60 // Note we have to make a function with correct number of arguments,
61 // otherwise mocha will
62 // think that all functions are sync or async.
63 args[i] = arg.length === 0 ? syncTest(arg) : asyncTest!(arg);
64 // Mocha uses toString to view the test body in the result list, make sure we return the
65 // correct function body
66 args[i].toString = function () {
67 return arg.toString();
68 };
69 }
70 }

Callers 2

rollup-mocha.tsFile · 0.90
rollupTestingFunction · 0.90

Calls 10

wrapSuiteInZoneFunction · 0.85
wrapDescribeInZoneFunction · 0.70
wrapTestInZoneFunction · 0.70
__load_patchMethod · 0.65
forkMethod · 0.65
applyMethod · 0.65
scheduleMicroTaskMethod · 0.65
getMethod · 0.65
onMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…