@depup/ts-jest 29.4.6-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/.lintstagedrc +4 -0
  2. package/.ts-jest-digest +1 -0
  3. package/CHANGELOG.md +2025 -0
  4. package/CONTRIBUTING.md +121 -0
  5. package/LICENSE.md +21 -0
  6. package/README.md +33 -0
  7. package/TROUBLESHOOTING.md +3 -0
  8. package/changes.json +18 -0
  9. package/cli.js +3 -0
  10. package/dist/cli/config/init.d.ts +6 -0
  11. package/dist/cli/config/init.js +139 -0
  12. package/dist/cli/config/migrate.d.ts +1 -0
  13. package/dist/cli/config/migrate.js +177 -0
  14. package/dist/cli/help.d.ts +1 -0
  15. package/dist/cli/help.js +25 -0
  16. package/dist/cli/helpers/presets.d.ts +1 -0
  17. package/dist/cli/helpers/presets.js +41 -0
  18. package/dist/cli/index.d.ts +1 -0
  19. package/dist/cli/index.js +63 -0
  20. package/dist/config/index.d.ts +2 -0
  21. package/dist/config/index.js +18 -0
  22. package/dist/config/paths-to-module-name-mapper.d.ts +9 -0
  23. package/dist/config/paths-to-module-name-mapper.js +52 -0
  24. package/dist/config/types.d.ts +2 -0
  25. package/dist/config/types.js +2 -0
  26. package/dist/constants.d.ts +13 -0
  27. package/dist/constants.js +22 -0
  28. package/dist/index.d.ts +15 -0
  29. package/dist/index.js +31 -0
  30. package/dist/legacy/compiler/compiler-utils.d.ts +8 -0
  31. package/dist/legacy/compiler/compiler-utils.js +32 -0
  32. package/dist/legacy/compiler/index.d.ts +2 -0
  33. package/dist/legacy/compiler/index.js +18 -0
  34. package/dist/legacy/compiler/ts-compiler.d.ts +27 -0
  35. package/dist/legacy/compiler/ts-compiler.js +434 -0
  36. package/dist/legacy/compiler/ts-jest-compiler.d.ts +8 -0
  37. package/dist/legacy/compiler/ts-jest-compiler.js +18 -0
  38. package/dist/legacy/config/config-set.d.ts +36 -0
  39. package/dist/legacy/config/config-set.js +622 -0
  40. package/dist/legacy/index.d.ts +6 -0
  41. package/dist/legacy/index.js +6 -0
  42. package/dist/legacy/ts-jest-transformer.d.ts +28 -0
  43. package/dist/legacy/ts-jest-transformer.js +293 -0
  44. package/dist/presets/all-presets.d.ts +15 -0
  45. package/dist/presets/all-presets.js +42 -0
  46. package/dist/presets/create-jest-preset.d.ts +18 -0
  47. package/dist/presets/create-jest-preset.js +180 -0
  48. package/dist/raw-compiler-options.d.ts +556 -0
  49. package/dist/raw-compiler-options.js +2 -0
  50. package/dist/transformers/hoist-jest.d.ts +9 -0
  51. package/dist/transformers/hoist-jest.js +111 -0
  52. package/dist/transpilers/typescript/transpile-module.d.ts +8 -0
  53. package/dist/transpilers/typescript/transpile-module.js +174 -0
  54. package/dist/types.d.ts +282 -0
  55. package/dist/types.js +3 -0
  56. package/dist/utils/backports.d.ts +1 -0
  57. package/dist/utils/backports.js +118 -0
  58. package/dist/utils/diagnostics.d.ts +5 -0
  59. package/dist/utils/diagnostics.js +8 -0
  60. package/dist/utils/get-package-version.d.ts +1 -0
  61. package/dist/utils/get-package-version.js +14 -0
  62. package/dist/utils/importer.d.ts +1 -0
  63. package/dist/utils/importer.js +146 -0
  64. package/dist/utils/index.d.ts +4 -0
  65. package/dist/utils/index.js +20 -0
  66. package/dist/utils/json.d.ts +2 -0
  67. package/dist/utils/json.js +16 -0
  68. package/dist/utils/jsonable-value.d.ts +10 -0
  69. package/dist/utils/jsonable-value.js +29 -0
  70. package/dist/utils/logger.d.ts +1 -0
  71. package/dist/utils/logger.js +20 -0
  72. package/dist/utils/memoize.d.ts +1 -0
  73. package/dist/utils/memoize.js +60 -0
  74. package/dist/utils/messages.d.ts +1 -0
  75. package/dist/utils/messages.js +21 -0
  76. package/dist/utils/normalize-slashes.d.ts +1 -0
  77. package/dist/utils/normalize-slashes.js +9 -0
  78. package/dist/utils/sha1.d.ts +1 -0
  79. package/dist/utils/sha1.js +38 -0
  80. package/dist/utils/ts-error.d.ts +1 -0
  81. package/dist/utils/ts-error.js +37 -0
  82. package/jest-preset.js +1 -0
  83. package/legacy.js +1 -0
  84. package/package.json +167 -0
  85. package/preprocessor.js +7 -0
  86. package/presets/default/jest-preset.js +1 -0
  87. package/presets/default-esm/jest-preset.js +1 -0
  88. package/presets/default-esm-legacy/jest-preset.js +1 -0
  89. package/presets/default-legacy/jest-preset.js +1 -0
  90. package/presets/index.d.ts +3 -0
  91. package/presets/index.js +3 -0
  92. package/presets/js-with-babel/jest-preset.js +1 -0
  93. package/presets/js-with-babel-esm/jest-preset.js +1 -0
  94. package/presets/js-with-babel-esm-legacy/jest-preset.js +1 -0
  95. package/presets/js-with-babel-legacy/jest-preset.js +1 -0
  96. package/presets/js-with-ts/jest-preset.js +1 -0
  97. package/presets/js-with-ts-esm/jest-preset.js +1 -0
  98. package/presets/js-with-ts-esm-legacy/jest-preset.js +1 -0
  99. package/presets/js-with-ts-legacy/jest-preset.js +1 -0
  100. package/tsconfig.base.json +20 -0
@@ -0,0 +1,556 @@
1
+ /**
2
+ * @deprecated This interface will be replaced with {@link TsConfigJson.CompilerOptions} in the next major release.
3
+ */
4
+ export interface RawCompilerOptions {
5
+ /**
6
+ * Enable importing files with any extension, provided a declaration file is present.
7
+ */
8
+ allowArbitraryExtensions?: boolean | null;
9
+ /**
10
+ * Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set.
11
+ */
12
+ allowImportingTsExtensions?: boolean | null;
13
+ /**
14
+ * No longer supported. In early versions, manually set the text encoding for reading files.
15
+ */
16
+ charset?: string | null;
17
+ /**
18
+ * Enable constraints that allow a TypeScript project to be used with project references.
19
+ */
20
+ composite?: boolean | null;
21
+ /**
22
+ * Conditions to set in addition to the resolver-specific defaults when resolving imports.
23
+ */
24
+ customConditions?: Array<string | null> | null;
25
+ /**
26
+ * Generate .d.ts files from TypeScript and JavaScript files in your project.
27
+ */
28
+ declaration?: boolean | null;
29
+ /**
30
+ * Specify the output directory for generated declaration files.
31
+ */
32
+ declarationDir?: string | null;
33
+ /**
34
+ * Output compiler performance information after building.
35
+ */
36
+ diagnostics?: boolean | null;
37
+ /**
38
+ * Reduce the number of projects loaded automatically by TypeScript.
39
+ */
40
+ disableReferencedProjectLoad?: boolean | null;
41
+ /**
42
+ * Enforces using indexed accessors for keys declared using an indexed type
43
+ */
44
+ noPropertyAccessFromIndexSignature?: boolean | null;
45
+ /**
46
+ * Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files.
47
+ */
48
+ emitBOM?: boolean | null;
49
+ /**
50
+ * Only output d.ts files and not JavaScript files.
51
+ */
52
+ emitDeclarationOnly?: boolean | null;
53
+ /**
54
+ * Differentiate between undefined and not present when type checking
55
+ */
56
+ exactOptionalPropertyTypes?: boolean | null;
57
+ /**
58
+ * Enable incremental compilation. Requires TypeScript version 3.4 or later.
59
+ */
60
+ incremental?: boolean | null;
61
+ /**
62
+ * Specify the folder for .tsbuildinfo incremental compilation files.
63
+ */
64
+ tsBuildInfoFile?: string | null;
65
+ /**
66
+ * Include sourcemap files inside the emitted JavaScript.
67
+ */
68
+ inlineSourceMap?: boolean | null;
69
+ /**
70
+ * Include source code in the sourcemaps inside the emitted JavaScript.
71
+ */
72
+ inlineSources?: boolean | null;
73
+ /**
74
+ * Specify what JSX code is generated.
75
+ */
76
+ jsx?: 'preserve' | 'react' | 'react-jsx' | 'react-jsxdev' | 'react-native';
77
+ /**
78
+ * Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit.
79
+ */
80
+ reactNamespace?: string | null;
81
+ /**
82
+ * Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'
83
+ */
84
+ jsxFactory?: string | null;
85
+ /**
86
+ * Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'.
87
+ */
88
+ jsxFragmentFactory?: string | null;
89
+ /**
90
+ * Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx`.
91
+ */
92
+ jsxImportSource?: string | null;
93
+ /**
94
+ * Print all of the files read during the compilation.
95
+ */
96
+ listFiles?: boolean | null;
97
+ /**
98
+ * Specify the location where debugger should locate map files instead of generated locations.
99
+ */
100
+ mapRoot?: string | null;
101
+ /**
102
+ * Specify what module code is generated.
103
+ */
104
+ module?: ('CommonJS' | 'AMD' | 'System' | 'UMD' | 'ES6' | 'ES2015' | 'ES2020' | 'ESNext' | 'None' | 'ES2022' | 'Node16' | 'NodeNext' | 'Preserve') & (((('CommonJS' | 'AMD' | 'System' | 'UMD' | 'ES6' | 'ES2015' | 'ES2020' | 'ESNext' | 'None' | 'ES2022' | 'Node16' | 'NodeNext' | 'Preserve') | {
105
+ [k: string]: unknown;
106
+ }) & string) | ((('CommonJS' | 'AMD' | 'System' | 'UMD' | 'ES6' | 'ES2015' | 'ES2020' | 'ESNext' | 'None' | 'ES2022' | 'Node16' | 'NodeNext' | 'Preserve') | {
107
+ [k: string]: unknown;
108
+ }) & null));
109
+ /**
110
+ * Specify how TypeScript looks up a file from a given module specifier.
111
+ */
112
+ moduleResolution?: ('Classic' | 'Node' | 'Node10' | 'Node16' | 'NodeNext' | 'Bundler') & (((('Classic' | 'Node' | 'Node10' | 'Node16' | 'NodeNext' | 'Bundler') | {
113
+ [k: string]: unknown;
114
+ }) & string) | ((('Classic' | 'Node' | 'Node10' | 'Node16' | 'NodeNext' | 'Bundler') | {
115
+ [k: string]: unknown;
116
+ }) & null));
117
+ /**
118
+ * Set the newline character for emitting files.
119
+ */
120
+ newLine?: ('crlf' | 'lf') & (((('crlf' | 'lf') | {
121
+ [k: string]: unknown;
122
+ }) & string) | ((('crlf' | 'lf') | {
123
+ [k: string]: unknown;
124
+ }) & null));
125
+ /**
126
+ * Disable emitting file from a compilation.
127
+ */
128
+ noEmit?: boolean | null;
129
+ /**
130
+ * Disable generating custom helper functions like `__extends` in compiled output.
131
+ */
132
+ noEmitHelpers?: boolean | null;
133
+ /**
134
+ * Disable emitting files if any type checking errors are reported.
135
+ */
136
+ noEmitOnError?: boolean | null;
137
+ /**
138
+ * Enable error reporting for expressions and declarations with an implied `any` type..
139
+ */
140
+ noImplicitAny?: boolean | null;
141
+ /**
142
+ * Enable error reporting when `this` is given the type `any`.
143
+ */
144
+ noImplicitThis?: boolean | null;
145
+ /**
146
+ * Enable error reporting when a local variables aren't read.
147
+ */
148
+ noUnusedLocals?: boolean | null;
149
+ /**
150
+ * Raise an error when a function parameter isn't read
151
+ */
152
+ noUnusedParameters?: boolean | null;
153
+ /**
154
+ * Disable including any library files, including the default lib.d.ts.
155
+ */
156
+ noLib?: boolean | null;
157
+ /**
158
+ * Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project.
159
+ */
160
+ noResolve?: boolean | null;
161
+ /**
162
+ * Disable strict checking of generic signatures in function types.
163
+ */
164
+ noStrictGenericChecks?: boolean | null;
165
+ /**
166
+ * Skip type checking .d.ts files that are included with TypeScript.
167
+ */
168
+ skipDefaultLibCheck?: boolean | null;
169
+ /**
170
+ * Skip type checking all .d.ts files.
171
+ */
172
+ skipLibCheck?: boolean | null;
173
+ /**
174
+ * Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output.
175
+ */
176
+ outFile?: string | null;
177
+ /**
178
+ * Specify an output folder for all emitted files.
179
+ */
180
+ outDir?: string | null;
181
+ /**
182
+ * Disable erasing `const enum` declarations in generated code.
183
+ */
184
+ preserveConstEnums?: boolean | null;
185
+ /**
186
+ * Disable resolving symlinks to their realpath. This correlates to the same flag in node.
187
+ */
188
+ preserveSymlinks?: boolean | null;
189
+ /**
190
+ * Preserve unused imported values in the JavaScript output that would otherwise be removed
191
+ */
192
+ preserveValueImports?: boolean | null;
193
+ /**
194
+ * Disable wiping the console in watch mode
195
+ */
196
+ preserveWatchOutput?: boolean | null;
197
+ /**
198
+ * Enable color and formatting in output to make compiler errors easier to read
199
+ */
200
+ pretty?: boolean | null;
201
+ /**
202
+ * Disable emitting comments.
203
+ */
204
+ removeComments?: boolean | null;
205
+ /**
206
+ * Specify the root folder within your source files.
207
+ */
208
+ rootDir?: string | null;
209
+ /**
210
+ * Ensure that each file can be safely transpiled without relying on other imports.
211
+ */
212
+ isolatedModules?: boolean | null;
213
+ /**
214
+ * Create source map files for emitted JavaScript files.
215
+ */
216
+ sourceMap?: boolean | null;
217
+ /**
218
+ * Specify the root path for debuggers to find the reference source code.
219
+ */
220
+ sourceRoot?: string | null;
221
+ /**
222
+ * Disable reporting of excess property errors during the creation of object literals.
223
+ */
224
+ suppressExcessPropertyErrors?: boolean | null;
225
+ /**
226
+ * Suppress `noImplicitAny` errors when indexing objects that lack index signatures.
227
+ */
228
+ suppressImplicitAnyIndexErrors?: boolean | null;
229
+ /**
230
+ * Set the JavaScript language version for emitted JavaScript and include compatible library declarations.
231
+ */
232
+ target?: ('ES3' | 'ES5' | 'ES6' | 'ES2015' | 'ES2016' | 'ES2017' | 'ES2018' | 'ES2019' | 'ES2020' | 'ES2021' | 'ES2022' | 'ES2023' | 'ESNext') & (((('ES3' | 'ES5' | 'ES6' | 'ES2015' | 'ES2016' | 'ES2017' | 'ES2018' | 'ES2019' | 'ES2020' | 'ES2021' | 'ES2022' | 'ES2023' | 'ESNext') | {
233
+ [k: string]: unknown;
234
+ }) & string) | ((('ES3' | 'ES5' | 'ES6' | 'ES2015' | 'ES2016' | 'ES2017' | 'ES2018' | 'ES2019' | 'ES2020' | 'ES2021' | 'ES2022' | 'ES2023' | 'ESNext') | {
235
+ [k: string]: unknown;
236
+ }) & null));
237
+ /**
238
+ * Default catch clause variables as `unknown` instead of `any`.
239
+ */
240
+ useUnknownInCatchVariables?: boolean | null;
241
+ /**
242
+ * Watch input files.
243
+ */
244
+ watch?: boolean | null;
245
+ /**
246
+ * Specify the polling strategy to use when the system runs out of or doesn't support native file watchers. Requires TypeScript version 3.8 or later.
247
+ */
248
+ fallbackPolling?: 'fixedPollingInterval' | 'priorityPollingInterval' | 'dynamicPriorityPolling' | 'fixedInterval' | 'priorityInterval' | 'dynamicPriority' | 'fixedChunkSize';
249
+ /**
250
+ * Specify the strategy for watching directories under systems that lack recursive file-watching functionality. Requires TypeScript version 3.8 or later.
251
+ */
252
+ watchDirectory?: 'useFsEvents' | 'fixedPollingInterval' | 'dynamicPriorityPolling' | 'fixedChunkSizePolling';
253
+ /**
254
+ * Specify the strategy for watching individual files. Requires TypeScript version 3.8 or later.
255
+ */
256
+ watchFile?: 'fixedPollingInterval' | 'priorityPollingInterval' | 'dynamicPriorityPolling' | 'useFsEvents' | 'useFsEventsOnParentDirectory' | 'fixedChunkSizePolling';
257
+ /**
258
+ * Enable experimental support for TC39 stage 2 draft decorators.
259
+ */
260
+ experimentalDecorators?: boolean | null;
261
+ /**
262
+ * Emit design-type metadata for decorated declarations in source files.
263
+ */
264
+ emitDecoratorMetadata?: boolean | null;
265
+ /**
266
+ * Disable error reporting for unused labels.
267
+ */
268
+ allowUnusedLabels?: boolean | null;
269
+ /**
270
+ * Enable error reporting for codepaths that do not explicitly return in a function.
271
+ */
272
+ noImplicitReturns?: boolean | null;
273
+ /**
274
+ * Add `undefined` to a type when accessed using an index.
275
+ */
276
+ noUncheckedIndexedAccess?: boolean | null;
277
+ /**
278
+ * Enable error reporting for fallthrough cases in switch statements.
279
+ */
280
+ noFallthroughCasesInSwitch?: boolean | null;
281
+ /**
282
+ * Ensure overriding members in derived classes are marked with an override modifier.
283
+ */
284
+ noImplicitOverride?: boolean | null;
285
+ /**
286
+ * Disable error reporting for unreachable code.
287
+ */
288
+ allowUnreachableCode?: boolean | null;
289
+ /**
290
+ * Ensure that casing is correct in imports.
291
+ */
292
+ forceConsistentCasingInFileNames?: boolean | null;
293
+ /**
294
+ * Emit a v8 CPU profile of the compiler run for debugging.
295
+ */
296
+ generateCpuProfile?: string | null;
297
+ /**
298
+ * Specify the base directory to resolve non-relative module names.
299
+ */
300
+ baseUrl?: string | null;
301
+ /**
302
+ * Specify a set of entries that re-map imports to additional lookup locations.
303
+ */
304
+ paths?: {
305
+ [k: string]: Array<string | null> | null;
306
+ } | null;
307
+ /**
308
+ * Specify a list of language service plugins to include.
309
+ */
310
+ plugins?: Array<{
311
+ /**
312
+ * Plugin name.
313
+ */
314
+ name?: string | null;
315
+ [k: string]: unknown;
316
+ } | null> | null;
317
+ /**
318
+ * Allow multiple folders to be treated as one when resolving modules.
319
+ */
320
+ rootDirs?: Array<string | null> | null;
321
+ /**
322
+ * Specify multiple folders that act like `./node_modules/@types`.
323
+ */
324
+ typeRoots?: Array<string | null> | null;
325
+ /**
326
+ * Specify type package names to be included without being referenced in a source file.
327
+ */
328
+ types?: Array<string | null> | null;
329
+ /**
330
+ * Enable tracing of the name resolution process. Requires TypeScript version 2.0 or later.
331
+ */
332
+ traceResolution?: boolean | null;
333
+ /**
334
+ * Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files.
335
+ */
336
+ allowJs?: boolean | null;
337
+ /**
338
+ * Disable truncating types in error messages.
339
+ */
340
+ noErrorTruncation?: boolean | null;
341
+ /**
342
+ * Allow 'import x from y' when a module doesn't have a default export.
343
+ */
344
+ allowSyntheticDefaultImports?: boolean | null;
345
+ /**
346
+ * Disable adding 'use strict' directives in emitted JavaScript files.
347
+ */
348
+ noImplicitUseStrict?: boolean | null;
349
+ /**
350
+ * Print the names of emitted files after a compilation.
351
+ */
352
+ listEmittedFiles?: boolean | null;
353
+ /**
354
+ * Remove the 20mb cap on total source code size for JavaScript files in the TypeScript language server.
355
+ */
356
+ disableSizeLimit?: boolean | null;
357
+ /**
358
+ * Specify a set of bundled library declaration files that describe the target runtime environment.
359
+ */
360
+ lib?: Array<(('ES5' | 'ES6' | 'ES2015' | 'ES2015.Collection' | 'ES2015.Core' | 'ES2015.Generator' | 'ES2015.Iterable' | 'ES2015.Promise' | 'ES2015.Proxy' | 'ES2015.Reflect' | 'ES2015.Symbol.WellKnown' | 'ES2015.Symbol' | 'ES2016' | 'ES2016.Array.Include' | 'ES2017' | 'ES2017.Intl' | 'ES2017.Object' | 'ES2017.SharedMemory' | 'ES2017.String' | 'ES2017.TypedArrays' | 'ES2018' | 'ES2018.AsyncGenerator' | 'ES2018.AsyncIterable' | 'ES2018.Intl' | 'ES2018.Promise' | 'ES2018.Regexp' | 'ES2019' | 'ES2019.Array' | 'ES2019.Intl' | 'ES2019.Object' | 'ES2019.String' | 'ES2019.Symbol' | 'ES2020' | 'ES2020.BigInt' | 'ES2020.Promise' | 'ES2020.String' | 'ES2020.Symbol.WellKnown' | 'ESNext' | 'ESNext.Array' | 'ESNext.AsyncIterable' | 'ESNext.BigInt' | 'ESNext.Intl' | 'ESNext.Promise' | 'ESNext.String' | 'ESNext.Symbol' | 'DOM' | 'DOM.AsyncIterable' | 'DOM.Iterable' | 'ScriptHost' | 'WebWorker' | 'WebWorker.AsyncIterable' | 'WebWorker.ImportScripts' | 'Webworker.Iterable' | 'ES7' | 'ES2021' | 'ES2020.SharedMemory' | 'ES2020.Intl' | 'ES2020.Date' | 'ES2020.Number' | 'ES2021.Promise' | 'ES2021.String' | 'ES2021.WeakRef' | 'ESNext.WeakRef' | 'ES2021.Intl' | 'ES2022' | 'ES2022.Array' | 'ES2022.Error' | 'ES2022.Intl' | 'ES2022.Object' | 'ES2022.String' | 'ES2022.SharedMemory' | 'ES2022.RegExp' | 'ES2023' | 'ES2023.Array' | 'Decorators' | 'Decorators.Legacy' | 'ES2017.Date' | 'ES2023.Collection' | 'ESNext.Decorators' | 'ESNext.Disposable') | {
361
+ [k: string]: unknown;
362
+ } | {
363
+ [k: string]: unknown;
364
+ } | {
365
+ [k: string]: unknown;
366
+ } | {
367
+ [k: string]: unknown;
368
+ } | {
369
+ [k: string]: unknown;
370
+ } | {
371
+ [k: string]: unknown;
372
+ } | {
373
+ [k: string]: unknown;
374
+ } | {
375
+ [k: string]: unknown;
376
+ } | {
377
+ [k: string]: unknown;
378
+ } | {
379
+ [k: string]: unknown;
380
+ } | {
381
+ [k: string]: unknown;
382
+ } | {
383
+ [k: string]: unknown;
384
+ } | {
385
+ [k: string]: unknown;
386
+ } | {
387
+ [k: string]: unknown;
388
+ } | {
389
+ [k: string]: unknown;
390
+ }) & (((('ES5' | 'ES6' | 'ES2015' | 'ES2015.Collection' | 'ES2015.Core' | 'ES2015.Generator' | 'ES2015.Iterable' | 'ES2015.Promise' | 'ES2015.Proxy' | 'ES2015.Reflect' | 'ES2015.Symbol.WellKnown' | 'ES2015.Symbol' | 'ES2016' | 'ES2016.Array.Include' | 'ES2017' | 'ES2017.Intl' | 'ES2017.Object' | 'ES2017.SharedMemory' | 'ES2017.String' | 'ES2017.TypedArrays' | 'ES2018' | 'ES2018.AsyncGenerator' | 'ES2018.AsyncIterable' | 'ES2018.Intl' | 'ES2018.Promise' | 'ES2018.Regexp' | 'ES2019' | 'ES2019.Array' | 'ES2019.Intl' | 'ES2019.Object' | 'ES2019.String' | 'ES2019.Symbol' | 'ES2020' | 'ES2020.BigInt' | 'ES2020.Promise' | 'ES2020.String' | 'ES2020.Symbol.WellKnown' | 'ESNext' | 'ESNext.Array' | 'ESNext.AsyncIterable' | 'ESNext.BigInt' | 'ESNext.Intl' | 'ESNext.Promise' | 'ESNext.String' | 'ESNext.Symbol' | 'DOM' | 'DOM.AsyncIterable' | 'DOM.Iterable' | 'ScriptHost' | 'WebWorker' | 'WebWorker.AsyncIterable' | 'WebWorker.ImportScripts' | 'Webworker.Iterable' | 'ES7' | 'ES2021' | 'ES2020.SharedMemory' | 'ES2020.Intl' | 'ES2020.Date' | 'ES2020.Number' | 'ES2021.Promise' | 'ES2021.String' | 'ES2021.WeakRef' | 'ESNext.WeakRef' | 'ES2021.Intl' | 'ES2022' | 'ES2022.Array' | 'ES2022.Error' | 'ES2022.Intl' | 'ES2022.Object' | 'ES2022.String' | 'ES2022.SharedMemory' | 'ES2022.RegExp' | 'ES2023' | 'ES2023.Array' | 'Decorators' | 'Decorators.Legacy' | 'ES2017.Date' | 'ES2023.Collection' | 'ESNext.Decorators' | 'ESNext.Disposable') | {
391
+ [k: string]: unknown;
392
+ } | {
393
+ [k: string]: unknown;
394
+ } | {
395
+ [k: string]: unknown;
396
+ } | {
397
+ [k: string]: unknown;
398
+ } | {
399
+ [k: string]: unknown;
400
+ } | {
401
+ [k: string]: unknown;
402
+ } | {
403
+ [k: string]: unknown;
404
+ } | {
405
+ [k: string]: unknown;
406
+ } | {
407
+ [k: string]: unknown;
408
+ } | {
409
+ [k: string]: unknown;
410
+ } | {
411
+ [k: string]: unknown;
412
+ } | {
413
+ [k: string]: unknown;
414
+ } | {
415
+ [k: string]: unknown;
416
+ } | {
417
+ [k: string]: unknown;
418
+ } | {
419
+ [k: string]: unknown;
420
+ }) & string) | ((('ES5' | 'ES6' | 'ES2015' | 'ES2015.Collection' | 'ES2015.Core' | 'ES2015.Generator' | 'ES2015.Iterable' | 'ES2015.Promise' | 'ES2015.Proxy' | 'ES2015.Reflect' | 'ES2015.Symbol.WellKnown' | 'ES2015.Symbol' | 'ES2016' | 'ES2016.Array.Include' | 'ES2017' | 'ES2017.Intl' | 'ES2017.Object' | 'ES2017.SharedMemory' | 'ES2017.String' | 'ES2017.TypedArrays' | 'ES2018' | 'ES2018.AsyncGenerator' | 'ES2018.AsyncIterable' | 'ES2018.Intl' | 'ES2018.Promise' | 'ES2018.Regexp' | 'ES2019' | 'ES2019.Array' | 'ES2019.Intl' | 'ES2019.Object' | 'ES2019.String' | 'ES2019.Symbol' | 'ES2020' | 'ES2020.BigInt' | 'ES2020.Promise' | 'ES2020.String' | 'ES2020.Symbol.WellKnown' | 'ESNext' | 'ESNext.Array' | 'ESNext.AsyncIterable' | 'ESNext.BigInt' | 'ESNext.Intl' | 'ESNext.Promise' | 'ESNext.String' | 'ESNext.Symbol' | 'DOM' | 'DOM.AsyncIterable' | 'DOM.Iterable' | 'ScriptHost' | 'WebWorker' | 'WebWorker.AsyncIterable' | 'WebWorker.ImportScripts' | 'Webworker.Iterable' | 'ES7' | 'ES2021' | 'ES2020.SharedMemory' | 'ES2020.Intl' | 'ES2020.Date' | 'ES2020.Number' | 'ES2021.Promise' | 'ES2021.String' | 'ES2021.WeakRef' | 'ESNext.WeakRef' | 'ES2021.Intl' | 'ES2022' | 'ES2022.Array' | 'ES2022.Error' | 'ES2022.Intl' | 'ES2022.Object' | 'ES2022.String' | 'ES2022.SharedMemory' | 'ES2022.RegExp' | 'ES2023' | 'ES2023.Array' | 'Decorators' | 'Decorators.Legacy' | 'ES2017.Date' | 'ES2023.Collection' | 'ESNext.Decorators' | 'ESNext.Disposable') | {
421
+ [k: string]: unknown;
422
+ } | {
423
+ [k: string]: unknown;
424
+ } | {
425
+ [k: string]: unknown;
426
+ } | {
427
+ [k: string]: unknown;
428
+ } | {
429
+ [k: string]: unknown;
430
+ } | {
431
+ [k: string]: unknown;
432
+ } | {
433
+ [k: string]: unknown;
434
+ } | {
435
+ [k: string]: unknown;
436
+ } | {
437
+ [k: string]: unknown;
438
+ } | {
439
+ [k: string]: unknown;
440
+ } | {
441
+ [k: string]: unknown;
442
+ } | {
443
+ [k: string]: unknown;
444
+ } | {
445
+ [k: string]: unknown;
446
+ } | {
447
+ [k: string]: unknown;
448
+ } | {
449
+ [k: string]: unknown;
450
+ }) & null))> | null;
451
+ /**
452
+ * Specify how TypeScript determine a file as module.
453
+ */
454
+ moduleDetection?: 'auto' | 'legacy' | 'force';
455
+ /**
456
+ * When type checking, take into account `null` and `undefined`.
457
+ */
458
+ strictNullChecks?: boolean | null;
459
+ /**
460
+ * Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`.
461
+ */
462
+ maxNodeModuleJsDepth?: number | null;
463
+ /**
464
+ * Allow importing helper functions from tslib once per project, instead of including them per-file.
465
+ */
466
+ importHelpers?: boolean | null;
467
+ /**
468
+ * Specify emit/checking behavior for imports that are only used for types.
469
+ */
470
+ importsNotUsedAsValues?: 'remove' | 'preserve' | 'error';
471
+ /**
472
+ * Ensure 'use strict' is always emitted.
473
+ */
474
+ alwaysStrict?: boolean | null;
475
+ /**
476
+ * Enable all strict type checking options.
477
+ */
478
+ strict?: boolean | null;
479
+ /**
480
+ * Check that the arguments for `bind`, `call`, and `apply` methods match the original function.
481
+ */
482
+ strictBindCallApply?: boolean | null;
483
+ /**
484
+ * Emit more compliant, but verbose and less performant JavaScript for iteration.
485
+ */
486
+ downlevelIteration?: boolean | null;
487
+ /**
488
+ * Enable error reporting in type-checked JavaScript files.
489
+ */
490
+ checkJs?: boolean | null;
491
+ /**
492
+ * When assigning functions, check to ensure parameters and the return values are subtype-compatible.
493
+ */
494
+ strictFunctionTypes?: boolean | null;
495
+ /**
496
+ * Check for class properties that are declared but not set in the constructor.
497
+ */
498
+ strictPropertyInitialization?: boolean | null;
499
+ /**
500
+ * Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility.
501
+ */
502
+ esModuleInterop?: boolean | null;
503
+ /**
504
+ * Allow accessing UMD globals from modules.
505
+ */
506
+ allowUmdGlobalAccess?: boolean | null;
507
+ /**
508
+ * Make keyof only return strings instead of string, numbers or symbols. Legacy option.
509
+ */
510
+ keyofStringsOnly?: boolean | null;
511
+ /**
512
+ * Emit ECMAScript-standard-compliant class fields.
513
+ */
514
+ useDefineForClassFields?: boolean | null;
515
+ /**
516
+ * Create sourcemaps for d.ts files.
517
+ */
518
+ declarationMap?: boolean | null;
519
+ /**
520
+ * Enable importing .json files
521
+ */
522
+ resolveJsonModule?: boolean | null;
523
+ /**
524
+ * Use the package.json 'exports' field when resolving package imports.
525
+ */
526
+ resolvePackageJsonExports?: boolean | null;
527
+ /**
528
+ * Use the package.json 'imports' field when resolving imports.
529
+ */
530
+ resolvePackageJsonImports?: boolean | null;
531
+ /**
532
+ * Have recompiles in '--incremental' and '--watch' assume that changes within a file will only affect files directly depending on it. Requires TypeScript version 3.8 or later.
533
+ */
534
+ assumeChangesOnlyAffectDirectDependencies?: boolean | null;
535
+ /**
536
+ * Output more detailed compiler performance information after building.
537
+ */
538
+ extendedDiagnostics?: boolean | null;
539
+ /**
540
+ * Print names of files that are part of the compilation and then stop processing.
541
+ */
542
+ listFilesOnly?: boolean | null;
543
+ /**
544
+ * Disable preferring source files instead of declaration files when referencing composite projects
545
+ */
546
+ disableSourceOfProjectReferenceRedirect?: boolean | null;
547
+ /**
548
+ * Opt a project out of multi-project reference checking when editing.
549
+ */
550
+ disableSolutionSearching?: boolean | null;
551
+ /**
552
+ * Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting.
553
+ */
554
+ verbatimModuleSyntax?: boolean | null;
555
+ [k: string]: unknown;
556
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import type _ts from 'typescript';
2
+ import type { TsCompilerInstance } from '../types';
3
+ /**
4
+ * Remember to increase the version whenever transformer's content is changed. This is to inform Jest to not reuse
5
+ * the previous cache which contains old transformer's content
6
+ */
7
+ export declare const version = 4;
8
+ export declare const name = "hoist-jest";
9
+ export declare function factory({ configSet }: TsCompilerInstance): (ctx: _ts.TransformationContext) => _ts.Transformer<_ts.SourceFile>;
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.name = exports.version = void 0;
4
+ exports.factory = factory;
5
+ const bs_logger_1 = require("bs-logger");
6
+ /**
7
+ * Remember to increase the version whenever transformer's content is changed. This is to inform Jest to not reuse
8
+ * the previous cache which contains old transformer's content
9
+ */
10
+ exports.version = 4;
11
+ // Used for constructing cache key
12
+ exports.name = 'hoist-jest';
13
+ const HOIST_METHODS = ['mock', 'unmock', 'enableAutomock', 'disableAutomock', 'deepUnmock'];
14
+ const JEST_GLOBALS_MODULE_NAME = '@jest/globals';
15
+ const JEST_GLOBAL_NAME = 'jest';
16
+ function factory({ configSet }) {
17
+ const logger = configSet.logger.child({ namespace: exports.name });
18
+ const ts = configSet.compilerModule;
19
+ const importNamesOfJestObj = [];
20
+ const isJestGlobalImport = (node) => {
21
+ return (ts.isImportDeclaration(node) &&
22
+ ts.isStringLiteral(node.moduleSpecifier) &&
23
+ node.moduleSpecifier.text === JEST_GLOBALS_MODULE_NAME);
24
+ };
25
+ const shouldHoistExpression = (node) => {
26
+ if (ts.isCallExpression(node) &&
27
+ ts.isPropertyAccessExpression(node.expression) &&
28
+ HOIST_METHODS.includes(node.expression.name.text)) {
29
+ if (importNamesOfJestObj.length) {
30
+ // @jest/globals is in used
31
+ return ((ts.isIdentifier(node.expression.expression) &&
32
+ importNamesOfJestObj.includes(node.expression.expression.text)) ||
33
+ (ts.isPropertyAccessExpression(node.expression.expression) &&
34
+ ts.isIdentifier(node.expression.expression.expression) &&
35
+ importNamesOfJestObj.includes(node.expression.expression.expression.text)) ||
36
+ shouldHoistExpression(node.expression.expression));
37
+ }
38
+ else {
39
+ // @jest/globals is not in used
40
+ return ((ts.isIdentifier(node.expression.expression) && node.expression.expression.text === JEST_GLOBAL_NAME) ||
41
+ shouldHoistExpression(node.expression.expression));
42
+ }
43
+ }
44
+ return false;
45
+ };
46
+ /**
47
+ * Checks whether given node is a statement that we need to hoist
48
+ */
49
+ const isHoistableStatement = (node) => {
50
+ return ts.isExpressionStatement(node) && shouldHoistExpression(node.expression);
51
+ };
52
+ const canHoistInBlockScope = (node) => !!node.statements.find((stmt) => ts.isVariableStatement(stmt) &&
53
+ stmt.declarationList.declarations.find((decl) => ts.isIdentifier(decl.name) && decl.name.text !== JEST_GLOBAL_NAME) &&
54
+ node.statements.find((stmt) => isHoistableStatement(stmt)));
55
+ /**
56
+ * Sort statements according to priority
57
+ * - Import Jest object from `@jest/globals`
58
+ * - Hoistable methods
59
+ * - Non-hoistable methods
60
+ */
61
+ const sortStatements = (statements) => {
62
+ if (statements.length <= 1) {
63
+ return statements;
64
+ }
65
+ return statements.sort((stmtA, stmtB) => isJestGlobalImport(stmtA) ||
66
+ (isHoistableStatement(stmtA) && !isHoistableStatement(stmtB) && !isJestGlobalImport(stmtB))
67
+ ? -1
68
+ : 1);
69
+ };
70
+ const createVisitor = (ctx, _) => {
71
+ const visitor = (node) => {
72
+ const resultNode = ts.visitEachChild(node, visitor, ctx);
73
+ // Since we use `visitEachChild`, we go upwards tree so all children node elements are checked first
74
+ if (ts.isBlock(resultNode) && canHoistInBlockScope(resultNode)) {
75
+ const newNodeArrayStatements = ts.factory.createNodeArray(sortStatements(resultNode.statements));
76
+ return ts.factory.updateBlock(resultNode, newNodeArrayStatements);
77
+ }
78
+ else {
79
+ if (ts.isSourceFile(resultNode)) {
80
+ resultNode.statements.forEach((stmt) => {
81
+ /**
82
+ * Gather all possible import names, from different types of import syntax including:
83
+ * - named import, e.g. `import { jest } from '@jest/globals'`
84
+ * - aliased named import, e.g. `import {jest as aliasedJest} from '@jest/globals'`
85
+ * - namespace import, e.g `import * as JestGlobals from '@jest/globals'`
86
+ */
87
+ if (isJestGlobalImport(stmt) &&
88
+ stmt.importClause?.namedBindings &&
89
+ (ts.isNamespaceImport(stmt.importClause.namedBindings) ||
90
+ ts.isNamedImports(stmt.importClause.namedBindings))) {
91
+ const { namedBindings } = stmt.importClause;
92
+ const jestImportName = ts.isNamespaceImport(namedBindings)
93
+ ? namedBindings.name.text
94
+ : namedBindings.elements.find((element) => element.name.text === JEST_GLOBAL_NAME || element.propertyName?.text === JEST_GLOBAL_NAME)?.name.text;
95
+ if (jestImportName) {
96
+ importNamesOfJestObj.push(jestImportName);
97
+ }
98
+ }
99
+ });
100
+ const newNodeArrayStatements = ts.factory.createNodeArray(sortStatements(resultNode.statements));
101
+ importNamesOfJestObj.length = 0;
102
+ return ts.factory.updateSourceFile(resultNode, newNodeArrayStatements, resultNode.isDeclarationFile, resultNode.referencedFiles, resultNode.typeReferenceDirectives, resultNode.hasNoDefaultLib, resultNode.libReferenceDirectives);
103
+ }
104
+ return resultNode;
105
+ }
106
+ };
107
+ return visitor;
108
+ };
109
+ // returns the transformer factory
110
+ return (ctx) => logger.wrap({ [bs_logger_1.LogContexts.logLevel]: bs_logger_1.LogLevels.debug, call: null }, 'visitSourceFileNode(): hoist jest', (sf) => ts.visitNode(sf, createVisitor(ctx, sf)));
111
+ }