ts-jest 29.0.1 → 29.0.2

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 (36) hide show
  1. package/.ts-jest-digest +1 -1
  2. package/CHANGELOG.md +19 -0
  3. package/dist/cli/config/init.d.ts +5 -0
  4. package/dist/cli/config/init.js +62 -20
  5. package/dist/cli/config/migrate.js +50 -10
  6. package/dist/cli/help.js +7 -1
  7. package/dist/cli/helpers/presets.js +12 -5
  8. package/dist/cli/index.js +9 -5
  9. package/dist/config/paths-to-module-name-mapper.js +6 -2
  10. package/dist/constants.js +5 -0
  11. package/dist/legacy/compiler/compiler-utils.d.ts +6 -0
  12. package/dist/legacy/compiler/compiler-utils.js +10 -0
  13. package/dist/legacy/compiler/ts-compiler.d.ts +6 -0
  14. package/dist/legacy/compiler/ts-compiler.js +76 -7
  15. package/dist/legacy/compiler/ts-jest-compiler.js +2 -1
  16. package/dist/legacy/config/config-set.d.ts +7 -0
  17. package/dist/legacy/config/config-set.js +91 -12
  18. package/dist/legacy/ts-jest-transformer.d.ts +13 -0
  19. package/dist/legacy/ts-jest-transformer.js +57 -10
  20. package/dist/raw-compiler-options.d.ts +297 -0
  21. package/dist/transformers/hoist-jest.d.ts +4 -0
  22. package/dist/transformers/hoist-jest.js +24 -0
  23. package/dist/types.d.ts +101 -6
  24. package/dist/utils/backports.js +13 -4
  25. package/dist/utils/get-package-version.js +3 -0
  26. package/dist/utils/importer.js +31 -4
  27. package/dist/utils/json.js +9 -0
  28. package/dist/utils/jsonable-value.js +2 -1
  29. package/dist/utils/logger.js +1 -0
  30. package/dist/utils/memoize.js +20 -1
  31. package/dist/utils/messages.js +5 -0
  32. package/dist/utils/normalize-slashes.js +3 -0
  33. package/dist/utils/sha1.js +10 -0
  34. package/dist/utils/ts-error.js +12 -2
  35. package/dist/utils/version-checkers.js +9 -5
  36. package/package.json +4 -4
@@ -2,7 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.factory = exports.name = exports.version = void 0;
4
4
  var bs_logger_1 = require("bs-logger");
5
+ /**
6
+ * Remember to increase the version whenever transformer's content is changed. This is to inform Jest to not reuse
7
+ * the previous cache which contains old transformer's content
8
+ */
5
9
  exports.version = 4;
10
+ // Used for constructing cache key
6
11
  exports.name = 'hoist-jest';
7
12
  var HOIST_METHODS = ['mock', 'unmock', 'enableAutomock', 'disableAutomock', 'deepUnmock'];
8
13
  var JEST_GLOBALS_MODULE_NAME = '@jest/globals';
@@ -22,6 +27,7 @@ function factory(_a) {
22
27
  ts.isPropertyAccessExpression(node.expression) &&
23
28
  HOIST_METHODS.includes(node.expression.name.text)) {
24
29
  if (importNamesOfJestObj.length) {
30
+ // @jest/globals is in used
25
31
  return ((ts.isIdentifier(node.expression.expression) &&
26
32
  importNamesOfJestObj.includes(node.expression.expression.text)) ||
27
33
  (ts.isPropertyAccessExpression(node.expression.expression) &&
@@ -30,12 +36,16 @@ function factory(_a) {
30
36
  shouldHoistExpression(node.expression.expression));
31
37
  }
32
38
  else {
39
+ // @jest/globals is not in used
33
40
  return ((ts.isIdentifier(node.expression.expression) && node.expression.expression.text === JEST_GLOBAL_NAME) ||
34
41
  shouldHoistExpression(node.expression.expression));
35
42
  }
36
43
  }
37
44
  return false;
38
45
  };
46
+ /**
47
+ * Checks whether given node is a statement that we need to hoist
48
+ */
39
49
  var isHoistableStatement = function (node) {
40
50
  return ts.isExpressionStatement(node) && shouldHoistExpression(node.expression);
41
51
  };
@@ -46,6 +56,12 @@ function factory(_a) {
46
56
  node.statements.find(function (stmt) { return isHoistableStatement(stmt); });
47
57
  });
48
58
  };
59
+ /**
60
+ * Sort statements according to priority
61
+ * - Import Jest object from `@jest/globals`
62
+ * - Hoistable methods
63
+ * - Non-hoistable methods
64
+ */
49
65
  var sortStatements = function (statements) {
50
66
  if (statements.length <= 1) {
51
67
  return statements;
@@ -60,6 +76,7 @@ function factory(_a) {
60
76
  var createVisitor = function (ctx, _) {
61
77
  var visitor = function (node) {
62
78
  var resultNode = ts.visitEachChild(node, visitor, ctx);
79
+ // Since we use `visitEachChild`, we go upwards tree so all children node elements are checked first
63
80
  if (ts.isBlock(resultNode) && canHoistInBlockScope(resultNode)) {
64
81
  var newNodeArrayStatements = ts.factory.createNodeArray(sortStatements(resultNode.statements));
65
82
  return ts.factory.updateBlock(resultNode, newNodeArrayStatements);
@@ -68,6 +85,12 @@ function factory(_a) {
68
85
  if (ts.isSourceFile(resultNode)) {
69
86
  resultNode.statements.forEach(function (stmt) {
70
87
  var _a, _b;
88
+ /**
89
+ * Gather all possible import names, from different types of import syntax including:
90
+ * - named import, e.g. `import { jest } from '@jest/globals'`
91
+ * - aliased named import, e.g. `import {jest as aliasedJest} from '@jest/globals'`
92
+ * - namespace import, e.g `import * as JestGlobals from '@jest/globals'`
93
+ */
71
94
  if (isJestGlobalImport(stmt) &&
72
95
  ((_a = stmt.importClause) === null || _a === void 0 ? void 0 : _a.namedBindings) &&
73
96
  (ts.isNamespaceImport(stmt.importClause.namedBindings) ||
@@ -90,6 +113,7 @@ function factory(_a) {
90
113
  };
91
114
  return visitor;
92
115
  };
116
+ // returns the transformer factory
93
117
  return function (ctx) {
94
118
  var _a;
95
119
  return logger.wrap((_a = {}, _a[bs_logger_1.LogContexts.logLevel] = bs_logger_1.LogLevels.debug, _a.call = null, _a), 'visitSourceFileNode(): hoist jest', function (sf) {
package/dist/types.d.ts CHANGED
@@ -7,11 +7,18 @@ import type { RawCompilerOptions } from './raw-compiler-options';
7
7
  declare module '@jest/types' {
8
8
  namespace Config {
9
9
  interface ConfigGlobals {
10
- 'ts-jest': TsJestGlobalOptions;
10
+ /**
11
+ * strangely `@ts-expect-error` doesn't work in this case when running
12
+ * `npm run build` vs `npm run pretest`
13
+ */
14
+ 'ts-jest'?: TsJestGlobalOptions;
11
15
  }
12
16
  }
13
17
  }
14
18
  export declare type TTypeScript = typeof _ts;
19
+ /**
20
+ * Don't mark as internal because it is used in TsJestGlobalOptions which is an exposed type
21
+ */
15
22
  export declare type BabelConfig = _babel.TransformOptions;
16
23
  export declare type TsJestPresets = Pick<Config.InitialOptions, 'extensionsToTreatAsEsm' | 'moduleFileExtensions' | 'transform' | 'testMatch'>;
17
24
  export interface AstTransformer<T = Record<string, unknown>> {
@@ -23,40 +30,129 @@ export interface ConfigCustomTransformer {
23
30
  after?: Array<string | AstTransformer>;
24
31
  afterDeclarations?: Array<string | AstTransformer>;
25
32
  }
33
+ /**
34
+ * @deprecated use `TsJestTransformerOptions` instead
35
+ */
26
36
  export interface TsJestGlobalOptions {
37
+ /**
38
+ * Compiler options. It can be:
39
+ * - `true` (or `undefined`, it's the default): use default tsconfig file
40
+ * - `false`: do NOT use default config file
41
+ * - `path/to/tsconfig.json`: path to a specific tsconfig file (<rootDir> can be used)
42
+ * - `{...}`: an object with inline compiler options
43
+ *
44
+ * @default undefined uses the default tsconfig file
45
+ */
27
46
  tsconfig?: boolean | string | RawCompilerOptions;
47
+ /**
48
+ * Compiles files as isolated modules (disables some features and type-checking)
49
+ *
50
+ * @default undefined (disabled)
51
+ */
28
52
  isolatedModules?: boolean;
53
+ /**
54
+ * Compiler to use
55
+ *
56
+ * @default 'typescript'
57
+ */
29
58
  compiler?: 'typescript' | 'ttypescript' | string;
59
+ /**
60
+ * Custom transformers (mostly used by jest presets)
61
+ */
30
62
  astTransformers?: ConfigCustomTransformer;
63
+ /**
64
+ * TS diagnostics - less to be reported if `isolatedModules` is `true`. It can be:
65
+ * - `true` (or `undefined`, it's the default): show all diagnostics
66
+ * - `false`: hide diagnostics of all files (kind of useless)
67
+ * - `{...}`: an inline object with fine grained settings
68
+ *
69
+ * @default undefined shows all diagnostics
70
+ */
31
71
  diagnostics?: boolean | {
72
+ /**
73
+ * Enables colorful and pretty output of errors
74
+ *
75
+ * @default undefined (enabled)
76
+ */
32
77
  pretty?: boolean;
78
+ /**
79
+ * List of TypeScript diagnostic error codes to ignore
80
+ * [here](https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json).
81
+ *
82
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json
83
+ * @default [6059,18002,18003]
84
+ */
33
85
  ignoreCodes?: number | string | Array<number | string>;
86
+ /**
87
+ * If specified, diagnostics of source files which path **matches** will be ignored
88
+ */
34
89
  exclude?: string[];
90
+ /**
91
+ * Logs TypeScript errors to stderr instead of throwing exceptions
92
+ *
93
+ * @default undefined (disabled)
94
+ */
35
95
  warnOnly?: boolean;
36
96
  };
97
+ /**
98
+ * Babel config. It can be:
99
+ * - `false` (or `undefined`, it's the default): do NOT use babel
100
+ * - `true`: use babel using default babelrc file
101
+ * - `path/to/.babelrc`: path to a babelrc file (<rootDir> can be used)
102
+ * - `{...}`: an object with inline babel options
103
+ *
104
+ * @default undefined does NOT use babel
105
+ */
37
106
  babelConfig?: boolean | string | BabelConfig;
107
+ /**
108
+ * Kept for backward compatibility to handle __TRANSFORM_HTML__
109
+ * Any file which will match this regex will be transpiled as a module
110
+ * exporting the content of the file as a string
111
+ */
38
112
  stringifyContentPathRegex?: string | RegExp;
113
+ /**
114
+ * Tell `ts-jest` to transform codes to ESM format. This only works in combination with `jest-runtime` ESM option
115
+ * `supportsStaticESM` true which is passed into Jest transformer
116
+ */
39
117
  useESM?: boolean;
40
118
  }
119
+ /**
120
+ * For transformers which extends `ts-jest`
121
+ * @deprecated use `JestConfigWithTsJest` instead
122
+ */
41
123
  export interface ProjectConfigTsJest extends Config.ProjectConfig {
42
124
  globals: GlobalConfigTsJest;
43
125
  }
126
+ /**
127
+ * @deprecated use `JestConfigWithTsJest` instead
128
+ */
44
129
  export interface TransformOptionsTsJest extends TransformOptions {
45
130
  config: ProjectConfigTsJest;
46
131
  }
132
+ /**
133
+ * For typings in `jest.config.ts`
134
+ * @deprecated use `JestConfigWithTsJest` instead
135
+ */
47
136
  export interface GlobalConfigTsJest extends Config.ConfigGlobals {
48
- 'ts-jest': TsJestGlobalOptions;
137
+ 'ts-jest'?: TsJestGlobalOptions;
49
138
  }
139
+ /**
140
+ * @deprecated use `JestConfigWithTsJest` instead
141
+ */
50
142
  export interface InitialOptionsTsJest extends Config.InitialOptions {
51
143
  globals?: GlobalConfigTsJest;
52
144
  }
53
- declare type TsJestTransformerOptions = TsJestGlobalOptions;
54
- export interface JestConfigWithTsJest extends Partial<Omit<Config.ProjectConfig, 'transform'>> {
55
- transform: {
145
+ export declare type TsJestTransformerOptions = TsJestGlobalOptions;
146
+ export interface JestConfigWithTsJest extends Omit<Config.InitialOptions, 'transform'> {
147
+ transform?: {
56
148
  [regex: string]: 'ts-jest' | ['ts-jest', TsJestTransformerOptions] | string | [string, Record<string, unknown>];
57
149
  };
58
150
  }
59
151
  export declare type StringMap = Map<string, string>;
152
+ export interface DepGraphInfo {
153
+ fileContent: string;
154
+ resolvedModuleNames: string[];
155
+ }
60
156
  export interface TsJestCompileOptions {
61
157
  depGraphs: Map<string, DepGraphInfo>;
62
158
  watchMode: boolean;
@@ -84,4 +180,3 @@ export interface TsJestAstTransformer {
84
180
  after: AstTransformerDesc[];
85
181
  afterDeclarations: AstTransformerDesc[];
86
182
  }
87
- export {};
@@ -16,15 +16,20 @@ exports.backportTsJestDebugEnvVar = exports.backportJestConfig = void 0;
16
16
  var bs_logger_1 = require("bs-logger");
17
17
  var messages_1 = require("./messages");
18
18
  var context = (_a = {}, _a[bs_logger_1.LogContexts.namespace] = 'backports', _a);
19
+ /**
20
+ * @internal
21
+ */
19
22
  var backportJestConfig = function (logger, config) {
20
23
  logger.debug(__assign(__assign({}, context), { config: config }), 'backporting config');
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
25
  var _a = (config || {}).globals, globals = _a === void 0 ? {} : _a;
22
26
  var _b = globals["ts-jest"], tsJest = _b === void 0 ? {} : _b;
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
28
  var mergeTsJest = {};
24
29
  var hadWarnings = false;
25
30
  var warnConfig = function (oldPath, newPath, note) {
26
31
  hadWarnings = true;
27
- logger.warn(context, (0, messages_1.interpolate)(note ? "\"[jest-config].{{oldPath}}\" is deprecated, use \"[jest-config].{{newPath}}\" instead.\n \u21B3 {{note}}" : "\"[jest-config].{{oldPath}}\" is deprecated, use \"[jest-config].{{newPath}}\" instead.", {
32
+ logger.warn(context, (0, messages_1.interpolate)(note ? "\"[jest-config].{{oldPath}}\" is deprecated, use \"[jest-config].{{newPath}}\" instead.\n \u21B3 {{note}}" /* Deprecations.ConfigOptionWithNote */ : "\"[jest-config].{{oldPath}}\" is deprecated, use \"[jest-config].{{newPath}}\" instead." /* Deprecations.ConfigOption */, {
28
33
  oldPath: oldPath,
29
34
  newPath: newPath,
30
35
  note: note,
@@ -76,7 +81,7 @@ var backportJestConfig = function (logger, config) {
76
81
  delete tsJest.enableTsDiagnostics;
77
82
  }
78
83
  if ('useBabelrc' in tsJest) {
79
- warnConfig('globals.ts-jest.useBabelrc', 'globals.ts-jest.babelConfig', "See `babel-jest` related issue: https://github.com/facebook/jest/issues/3845");
84
+ warnConfig('globals.ts-jest.useBabelrc', 'globals.ts-jest.babelConfig', "See `babel-jest` related issue: https://github.com/facebook/jest/issues/3845" /* Deprecations.ConfigOptionUseBabelRcNote */);
80
85
  if (tsJest.useBabelrc != null) {
81
86
  mergeTsJest.babelConfig = tsJest.useBabelrc ? true : {};
82
87
  }
@@ -89,12 +94,16 @@ var backportJestConfig = function (logger, config) {
89
94
  }
90
95
  delete tsJest.skipBabel;
91
96
  }
97
+ // if we had some warnings we can inform the user about the CLI tool
92
98
  if (hadWarnings) {
93
- logger.warn(context, "Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate <config-file>.");
99
+ logger.warn(context, "Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate <config-file>." /* Helps.MigrateConfigUsingCLI */);
94
100
  }
95
101
  return __assign(__assign({}, config), { globals: __assign(__assign({}, globals), { 'ts-jest': __assign(__assign({}, mergeTsJest), tsJest) }) });
96
102
  };
97
103
  exports.backportJestConfig = backportJestConfig;
104
+ /**
105
+ * @internal
106
+ */
98
107
  var backportTsJestDebugEnvVar = function (logger) {
99
108
  if ('TS_JEST_DEBUG' in process.env) {
100
109
  var shouldLog = !/^\s*(?:0|f(?:alse)?|no?|disabled?|off|)\s*$/i.test(process.env.TS_JEST_DEBUG || '');
@@ -102,7 +111,7 @@ var backportTsJestDebugEnvVar = function (logger) {
102
111
  if (shouldLog) {
103
112
  process.env.TS_JEST_LOG = 'ts-jest.log,stderr:warn';
104
113
  }
105
- logger.warn(context, (0, messages_1.interpolate)("Using env. var \"{{old}}\" is deprecated, use \"{{new}}\" instead.", {
114
+ logger.warn(context, (0, messages_1.interpolate)("Using env. var \"{{old}}\" is deprecated, use \"{{new}}\" instead." /* Deprecations.EnvVar */, {
106
115
  old: 'TS_JEST_DEBUG',
107
116
  new: 'TS_JEST_LOG',
108
117
  }));
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPackageVersion = void 0;
4
+ /**
5
+ * @internal
6
+ */
4
7
  function getPackageVersion(moduleName) {
5
8
  try {
6
9
  return require("".concat(moduleName, "/package.json")).version;
@@ -48,11 +48,15 @@ var memoize_1 = require("./memoize");
48
48
  var messages_1 = require("./messages");
49
49
  var version_checkers_1 = require("./version-checkers");
50
50
  var logger = logger_1.rootLogger.child({ namespace: 'Importer' });
51
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
52
  var passThru = function (action) { return function (input) {
52
53
  action();
53
54
  return input;
54
55
  }; };
55
- var Importer = (function () {
56
+ /**
57
+ * @internal
58
+ */
59
+ var Importer = /** @class */ (function () {
56
60
  function Importer(_patches) {
57
61
  if (_patches === void 0) { _patches = {}; }
58
62
  this._patches = _patches;
@@ -60,6 +64,9 @@ var Importer = (function () {
60
64
  Object.defineProperty(Importer, "instance", {
61
65
  get: function () {
62
66
  logger.debug('creating Importer singleton');
67
+ // here we can define patches to apply to modules.
68
+ // it could be fixes that are not deployed, or
69
+ // abstractions so that multiple versions work the same
63
70
  return new Importer({
64
71
  '@babel/core': [passThru(version_checkers_1.VersionCheckers.babelCore.warn)],
65
72
  'babel-jest': [passThru(version_checkers_1.VersionCheckers.babelJest.warn)],
@@ -92,25 +99,34 @@ var Importer = (function () {
92
99
  var tries = __spreadArray([moduleName], __read(fallbacks), false);
93
100
  while ((name = tries.shift()) !== undefined) {
94
101
  var req = requireWrapper(name);
102
+ // remove exports from what we're going to log
103
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
95
104
  var contextReq = __assign({}, req);
96
105
  delete contextReq.exports;
97
106
  if (req.exists) {
107
+ // module exists
98
108
  loaded = req;
99
109
  if (loaded.error) {
110
+ // require-ing it failed
100
111
  logger.error({ requireResult: contextReq }, "failed loading module '".concat(name, "'"), loaded.error.message);
101
112
  }
102
113
  else {
114
+ // it has been loaded, let's patch it
103
115
  logger.debug({ requireResult: contextReq }, 'loaded module', name);
104
116
  loaded.exports = this._patch(name, loaded.exports);
105
117
  }
106
118
  break;
107
119
  }
108
120
  else {
121
+ // module does not exists in the path
109
122
  logger.debug({ requireResult: contextReq }, "module '".concat(name, "' not found"));
110
123
  }
111
124
  }
125
+ // return the loaded one, could be one that has been loaded, or one which has failed during load
126
+ // but not one which does not exists
112
127
  return loaded;
113
128
  };
129
+ // eslint-disable-next-line no-dupe-class-members
114
130
  Importer.prototype.tryTheseOr = function (moduleNames, missingResult, allowLoadError) {
115
131
  if (allowLoadError === void 0) { allowLoadError = false; }
116
132
  var args = Array.isArray(moduleNames) ? moduleNames : [moduleNames];
@@ -132,19 +148,23 @@ var Importer = (function () {
132
148
  };
133
149
  Importer.prototype._import = function (why, moduleName, _a) {
134
150
  var _b = _a === void 0 ? {} : _a, _c = _b.alternatives, alternatives = _c === void 0 ? [] : _c, _d = _b.installTip, installTip = _d === void 0 ? moduleName : _d;
151
+ // try to load any of the alternative after trying main one
135
152
  var res = this.tryThese.apply(this, __spreadArray([moduleName], __read(alternatives), false));
153
+ // if we could load one, return it
136
154
  if (res && res.exists) {
137
155
  if (!res.error)
138
156
  return res.exports;
139
- throw new Error((0, messages_1.interpolate)("Loading module {{module}} failed with error: {{error}}", { module: res.given, error: res.error.message }));
157
+ // it could not load because of a failure while importing, but it exists
158
+ throw new Error((0, messages_1.interpolate)("Loading module {{module}} failed with error: {{error}}" /* Errors.LoadingModuleFailed */, { module: res.given, error: res.error.message }));
140
159
  }
141
- var msg = alternatives.length ? "Unable to load any of these modules: {{module}}. {{reason}}. To fix it:\n{{fix}}" : "Unable to load the module {{module}}. {{reason}} To fix it:\n{{fix}}";
160
+ // if it couldn't load, build a nice error message so the user can fix it by himself
161
+ var msg = alternatives.length ? "Unable to load any of these modules: {{module}}. {{reason}}. To fix it:\n{{fix}}" /* Errors.UnableToLoadAnyModule */ : "Unable to load the module {{module}}. {{reason}} To fix it:\n{{fix}}" /* Errors.UnableToLoadOneModule */;
142
162
  var loadModule = __spreadArray([moduleName], __read(alternatives), false).map(function (m) { return "\"".concat(m, "\""); }).join(', ');
143
163
  if (typeof installTip === 'string') {
144
164
  installTip = [{ module: installTip, label: "install \"".concat(installTip, "\"") }];
145
165
  }
146
166
  var fix = installTip
147
- .map(function (tip) { return " ".concat(installTip.length === 1 ? '↳' : '•', " ").concat((0, messages_1.interpolate)("{{label}}: `npm i -D {{module}}` (or `yarn add --dev {{module}}`)", tip)); })
167
+ .map(function (tip) { return " ".concat(installTip.length === 1 ? '↳' : '•', " ").concat((0, messages_1.interpolate)("{{label}}: `npm i -D {{module}}` (or `yarn add --dev {{module}}`)" /* Helps.FixMissingModule */, tip)); })
148
168
  .join('\n');
149
169
  throw new Error((0, messages_1.interpolate)(msg, {
150
170
  module: loadModule,
@@ -170,6 +190,9 @@ var Importer = (function () {
170
190
  return Importer;
171
191
  }());
172
192
  exports.Importer = Importer;
193
+ /**
194
+ * @internal
195
+ */
173
196
  exports.importer = Importer.instance;
174
197
  function requireWrapper(moduleName) {
175
198
  var path;
@@ -197,6 +220,10 @@ function requireWrapper(moduleName) {
197
220
  }
198
221
  var requireModule = function (mod) { return require(mod); };
199
222
  var resolveModule = function (mod) { return require.resolve(mod, { paths: [process.cwd(), __dirname] }); };
223
+ /**
224
+ * @internal
225
+ */
226
+ // so that we can test easier
200
227
  function __requireModule(localRequire, localResolve) {
201
228
  requireModule = localRequire;
202
229
  resolveModule = localResolve;
@@ -4,16 +4,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.normalize = exports.parse = exports.stringify = void 0;
7
+ /* eslint-disable no-redeclare */
7
8
  var fast_json_stable_stringify_1 = __importDefault(require("fast-json-stable-stringify"));
8
9
  var UNDEFINED = 'undefined';
9
10
  function stringify(input) {
10
11
  return input === undefined ? UNDEFINED : (0, fast_json_stable_stringify_1.default)(input);
11
12
  }
12
13
  exports.stringify = stringify;
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
15
  function parse(input) {
14
16
  return input === UNDEFINED ? undefined : JSON.parse(input);
15
17
  }
16
18
  exports.parse = parse;
19
+ /**
20
+ * @internal
21
+ */
17
22
  function normalize(input, _a) {
18
23
  var _b = _a === void 0 ? {} : _a, _c = _b.parse, parser = _c === void 0 ? parse : _c;
19
24
  var result;
@@ -30,6 +35,10 @@ function normalize(input, _a) {
30
35
  return result === undefined ? input : result;
31
36
  }
32
37
  exports.normalize = normalize;
38
+ /**
39
+ * @internal
40
+ */
41
+ // eslint-disable-next-line @typescript-eslint/no-namespace
33
42
  (function (normalize) {
34
43
  normalize.cache = new Map();
35
44
  })(normalize = exports.normalize || (exports.normalize = {}));
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JsonableValue = void 0;
4
4
  var json_1 = require("./json");
5
- var JsonableValue = (function () {
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
+ var JsonableValue = /** @class */ (function () {
6
7
  function JsonableValue(value) {
7
8
  this.value = value;
8
9
  }
@@ -17,6 +17,7 @@ var buildOptions = function () {
17
17
  };
18
18
  exports.rootLogger = (0, bs_logger_1.createLogger)(buildOptions());
19
19
  (0, backports_1.backportTsJestDebugEnvVar)(exports.rootLogger);
20
+ // re-create the logger if the env var has been backported
20
21
  if (original !== process.env.TS_JEST_LOG) {
21
22
  exports.rootLogger = (0, bs_logger_1.createLogger)(buildOptions());
22
23
  }
@@ -1,10 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Memoize = void 0;
4
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
5
  var cacheProp = Symbol.for('[memoize]');
6
+ /**
7
+ * @internal
8
+ */
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
10
  function Memoize(keyBuilder) {
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
12
  return function (_, propertyKey, descriptor) {
7
13
  if (descriptor.value != null) {
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
15
  descriptor.value = memoize(propertyKey, descriptor.value, keyBuilder || (function (v) { return v; }));
9
16
  }
10
17
  else if (descriptor.get != null) {
@@ -13,6 +20,8 @@ function Memoize(keyBuilder) {
13
20
  };
14
21
  }
15
22
  exports.Memoize = Memoize;
23
+ // See https://github.com/microsoft/TypeScript/issues/1863#issuecomment-579541944
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
25
  function ensureCache(target, reset) {
17
26
  if (reset === void 0) { reset = false; }
18
27
  if (reset || !target[cacheProp]) {
@@ -23,15 +32,24 @@ function ensureCache(target, reset) {
23
32
  }
24
33
  return target[cacheProp];
25
34
  }
35
+ // See https://github.com/microsoft/TypeScript/issues/1863#issuecomment-579541944
36
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
37
  function ensureChildCache(target, key, reset) {
27
38
  if (reset === void 0) { reset = false; }
28
39
  var dict = ensureCache(target);
29
40
  if (reset || !dict[key]) {
41
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
42
  dict[key] = new Map();
31
43
  }
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
45
  return dict[key];
33
46
  }
34
- function memoize(namespace, func, keyBuilder) {
47
+ function memoize(namespace,
48
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
+ func,
50
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
+ keyBuilder) {
52
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
53
  return function () {
36
54
  var args = [];
37
55
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -41,6 +59,7 @@ function memoize(namespace, func, keyBuilder) {
41
59
  var key = keyBuilder.apply(this, args);
42
60
  if (cache.has(key))
43
61
  return cache.get(key);
62
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
63
  var res = func.apply(this, args);
45
64
  cache.set(key, res);
46
65
  return res;
@@ -1,8 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.interpolate = void 0;
4
+ /**
5
+ * @internal
6
+ */
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
8
  function interpolate(msg, vars) {
5
9
  if (vars === void 0) { vars = {}; }
10
+ // eslint-disable-next-line no-useless-escape
6
11
  return msg.replace(/\{\{([^\}]+)\}\}/g, function (_, key) { return (key in vars ? vars[key] : _); });
7
12
  }
8
13
  exports.interpolate = interpolate;
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeSlashes = void 0;
4
+ /**
5
+ * @internal
6
+ */
4
7
  function normalizeSlashes(value) {
5
8
  return value.replace(/\\/g, '/');
6
9
  }
@@ -2,13 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sha1 = exports.cache = void 0;
4
4
  var crypto_1 = require("crypto");
5
+ /**
6
+ * @internal
7
+ */
8
+ // stores hashes made out of only one argument being a string
5
9
  exports.cache = Object.create(null);
10
+ /**
11
+ * @internal
12
+ */
6
13
  function sha1() {
7
14
  var data = [];
8
15
  for (var _i = 0; _i < arguments.length; _i++) {
9
16
  data[_i] = arguments[_i];
10
17
  }
11
18
  var canCache = data.length === 1 && typeof data[0] === 'string';
19
+ // caching
12
20
  var cacheKey;
13
21
  if (canCache) {
14
22
  cacheKey = data[0];
@@ -16,6 +24,8 @@ function sha1() {
16
24
  return exports.cache[cacheKey];
17
25
  }
18
26
  }
27
+ // we use SHA1 because it's the fastest provided by node
28
+ // and we are not concerned about security here
19
29
  var hash = (0, crypto_1.createHash)('sha1');
20
30
  data.forEach(function (item) {
21
31
  if (typeof item === 'string')
@@ -21,20 +21,30 @@ var make_error_1 = require("make-error");
21
21
  var logger_1 = require("./logger");
22
22
  var messages_1 = require("./messages");
23
23
  var logger = logger_1.rootLogger.child({ namespace: 'TSError' });
24
+ /**
25
+ * @internal
26
+ */
24
27
  exports.INSPECT_CUSTOM = util_1.inspect.custom || 'inspect';
25
- var TSError = (function (_super) {
28
+ /**
29
+ * TypeScript diagnostics error.
30
+ *
31
+ * @internal
32
+ */
33
+ var TSError = /** @class */ (function (_super) {
26
34
  __extends(TSError, _super);
27
35
  function TSError(diagnosticText, diagnosticCodes) {
28
- var _this = _super.call(this, (0, messages_1.interpolate)("{{diagnostics}}", {
36
+ var _this = _super.call(this, (0, messages_1.interpolate)("{{diagnostics}}" /* Errors.UnableToCompileTypeScript */, {
29
37
  diagnostics: diagnosticText.trim(),
30
38
  })) || this;
31
39
  _this.diagnosticText = diagnosticText;
32
40
  _this.diagnosticCodes = diagnosticCodes;
33
41
  _this.name = 'TSError';
34
42
  logger.debug({ diagnosticCodes: diagnosticCodes, diagnosticText: diagnosticText }, 'created new TSError');
43
+ // ensure we blacklist any of our code
35
44
  Object.defineProperty(_this, 'stack', { value: '' });
36
45
  return _this;
37
46
  }
47
+ /* istanbul ignore next */
38
48
  TSError.prototype[exports.INSPECT_CUSTOM] = function () {
39
49
  return this.diagnosticText;
40
50
  };
@@ -6,12 +6,16 @@ var get_package_version_1 = require("./get-package-version");
6
6
  var logger_1 = require("./logger");
7
7
  var messages_1 = require("./messages");
8
8
  var logger = logger_1.rootLogger.child({ namespace: 'versions' });
9
+ /**
10
+ * @internal
11
+ */
9
12
  exports.VersionCheckers = {
10
- jest: createVersionChecker('jest', ">=29.0.0 <30"),
11
- typescript: createVersionChecker('typescript', ">=4.3 <5"),
12
- babelJest: createVersionChecker('babel-jest', ">=29.0.0 <30"),
13
- babelCore: createVersionChecker('@babel/core', ">=7.0.0-beta.0 <8"),
13
+ jest: createVersionChecker('jest', ">=29.0.0 <30" /* ExpectedVersions.Jest */),
14
+ typescript: createVersionChecker('typescript', ">=4.3 <5" /* ExpectedVersions.TypeScript */),
15
+ babelJest: createVersionChecker('babel-jest', ">=29.0.0 <30" /* ExpectedVersions.BabelJest */),
16
+ babelCore: createVersionChecker('@babel/core', ">=7.0.0-beta.0 <8" /* ExpectedVersions.BabelCore */),
14
17
  };
18
+ // eslint-disable-next-line no-redeclare
15
19
  function checkVersion(name, expectedRange, action) {
16
20
  if (action === void 0) { action = 'warn'; }
17
21
  var success = true;
@@ -24,7 +28,7 @@ function checkVersion(name, expectedRange, action) {
24
28
  }, 'checking version of %s: %s', name, success ? 'OK' : 'NOT OK');
25
29
  if (!action || success)
26
30
  return success;
27
- var message = (0, messages_1.interpolate)(version ? "Version {{actualVersion}} of {{module}} installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version ({{expectedVersion}}). Please do not report issues in ts-jest if you are using unsupported versions." : "Module {{module}} is not installed. If you're experiencing issues, consider installing a supported version ({{expectedVersion}}).", {
31
+ var message = (0, messages_1.interpolate)(version ? "Version {{actualVersion}} of {{module}} installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version ({{expectedVersion}}). Please do not report issues in ts-jest if you are using unsupported versions." /* Errors.UntestedDependencyVersion */ : "Module {{module}} is not installed. If you're experiencing issues, consider installing a supported version ({{expectedVersion}})." /* Errors.MissingDependency */, {
28
32
  module: name,
29
33
  actualVersion: version || '??',
30
34
  expectedVersion: rangeToHumanString(expectedRange),