(Zone: ZoneType)
| 11 | ('use strict'); |
| 12 | |
| 13 | export 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 | } |
no test coverage detected
searching dependent graphs…