(Zone: ZoneType)
| 12 | declare let jest: any; |
| 13 | |
| 14 | export function patchJest(Zone: ZoneType): void { |
| 15 | Zone.__load_patch('jest', (context: any, Zone: ZoneType, api: _ZonePrivate) => { |
| 16 | if (typeof jest === 'undefined' || jest['__zone_patch__']) { |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | // From jest 29 and jest-preset-angular v13, the module transform logic |
| 21 | // changed, and now jest-preset-angular use the use the tsconfig target |
| 22 | // other than the hardcoded one, https://github.com/thymikee/jest-preset-angular/issues/2010 |
| 23 | // But jest-angular-preset doesn't introduce the @babel/plugin-transform-async-to-generator |
| 24 | // which is needed by angular since `async/await` still need to be transformed |
| 25 | // to promise for ES2017+ target. |
| 26 | // So for now, we disable to output the uncaught error console log for a temp solution, |
| 27 | // until jest-preset-angular find a proper solution. |
| 28 | (Zone as any)[api.symbol('ignoreConsoleErrorUncaughtError')] = true; |
| 29 | jest['__zone_patch__'] = true; |
| 30 | |
| 31 | const ProxyZoneSpec = (Zone as any)['ProxyZoneSpec']; |
| 32 | const SyncTestZoneSpec = (Zone as any)['SyncTestZoneSpec']; |
| 33 | |
| 34 | if (!ProxyZoneSpec) { |
| 35 | throw new Error('Missing ProxyZoneSpec'); |
| 36 | } |
| 37 | |
| 38 | const rootZone = Zone.current; |
| 39 | const syncZone = rootZone.fork(new SyncTestZoneSpec('jest.describe')); |
| 40 | const proxyZoneSpec = new ProxyZoneSpec(); |
| 41 | const proxyZone = rootZone.fork(proxyZoneSpec); |
| 42 | |
| 43 | function wrapDescribeFactoryInZone(originalJestFn: Function) { |
| 44 | return function (this: unknown, ...tableArgs: any[]) { |
| 45 | const originalDescribeFn = originalJestFn.apply(this, tableArgs); |
| 46 | return function (this: unknown, ...args: any[]) { |
| 47 | args[1] = wrapDescribeInZone(args[1]); |
| 48 | return originalDescribeFn.apply(this, args); |
| 49 | }; |
| 50 | }; |
| 51 | } |
| 52 | |
| 53 | function wrapTestFactoryInZone(originalJestFn: Function) { |
| 54 | return function (this: unknown, ...tableArgs: any[]) { |
| 55 | return function (this: unknown, ...args: any[]) { |
| 56 | args[1] = wrapTestInZone(args[1]); |
| 57 | return originalJestFn.apply(this, tableArgs).apply(this, args); |
| 58 | }; |
| 59 | }; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Gets a function wrapping the body of a jest `describe` block to execute in a |
| 64 | * synchronous-only zone. |
| 65 | */ |
| 66 | function wrapDescribeInZone(describeBody: Function): Function { |
| 67 | return function (this: unknown, ...args: any[]) { |
| 68 | return syncZone.run(describeBody, this, args); |
| 69 | }; |
| 70 | } |
| 71 |
no test coverage detected
searching dependent graphs…