|
6 | 6 | * found in the LICENSE file at https://angular.io/license |
7 | 7 | */ |
8 | 8 |
|
9 | | -// Avoid using `declare const` because it caused conflicts inside Google |
10 | | -// with the real typings for these symbols. We use `declare interface` instead |
11 | | -// of just `interface` for interop with Closure Compiler (prevents property renaming): |
12 | | -// https://github.com/angular/tsickle/blob/master/README.md#differences-from-typescript |
13 | | -declare interface TestGlobals { |
14 | | - jasmine: unknown; |
15 | | - __karma__: unknown; |
16 | | - jest: unknown; |
17 | | - Mocha: unknown; |
18 | | -} |
19 | | - |
20 | | -let testGlobals: TestGlobals; |
21 | | - |
22 | | -// We check the Node-specific `global` first, because tools tend to add a fake |
23 | | -// `window` in Node environments which won't actually receive global variables. |
24 | | -if (typeof global !== 'undefined') { |
25 | | - testGlobals = global as {} as TestGlobals; |
26 | | -} else if (typeof window !== 'undefined') { |
27 | | - testGlobals = window as {} as TestGlobals; |
28 | | -} else { |
29 | | - testGlobals = {} as TestGlobals; |
30 | | -} |
31 | | - |
32 | 9 | /** Gets whether the code is currently running in a test environment. */ |
33 | 10 | export function _isTestEnvironment(): boolean { |
34 | | - return (typeof testGlobals.__karma__ !== 'undefined' && !!testGlobals.__karma__) || |
35 | | - (typeof testGlobals.jasmine !== 'undefined' && !!testGlobals.jasmine) || |
36 | | - (typeof testGlobals.jest !== 'undefined' && !!testGlobals.jest) || |
37 | | - (typeof testGlobals.Mocha !== 'undefined' && !!testGlobals.Mocha); |
| 11 | + // We can't use `declare const` because it causes conflicts inside Google with the real typings |
| 12 | + // for these symbols and we can't read them off the global object, because they don't appear to |
| 13 | + // be attached there for some runners like Jest. |
| 14 | + // (see: https://github.com/angular/components/issues/23365#issuecomment-938146643) |
| 15 | + return ( |
| 16 | + // @ts-ignore |
| 17 | + (typeof __karma__ !== 'undefined' && !!__karma__) || |
| 18 | + // @ts-ignore |
| 19 | + (typeof jasmine !== 'undefined' && !!jasmine) || |
| 20 | + // @ts-ignore |
| 21 | + (typeof jest !== 'undefined' && !!jest) || |
| 22 | + // @ts-ignore |
| 23 | + (typeof Mocha !== 'undefined' && !!Mocha) |
| 24 | + ); |
38 | 25 | } |
0 commit comments