ts-jest
Version:
A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript
70 lines (69 loc) • 7.38 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ImportReasons = exports.Deprecations = exports.Helps = exports.Errors = void 0;
exports.interpolate = interpolate;
const diagnostics_1 = require("./diagnostics");
/**
* @internal
*/
var Errors;
(function (Errors) {
Errors["LoadingModuleFailed"] = "Loading module {{module}} failed with error: {{error}}";
Errors["TypeScriptCompilerApiUnavailable"] = "The TypeScript compiler \"{{module}}\" (version {{version}}) does not expose the JavaScript compiler API required by ts-jest. To use TypeScript 7 for project type-checking, install it as \"@typescript/native\" and alias \"@typescript/typescript6\" as \"typescript\" for ts-jest.";
Errors["UnableToLoadOneModule"] = "Unable to load the module {{module}}. {{reason}} To fix it:\n{{fix}}";
Errors["UnableToLoadAnyModule"] = "Unable to load any of these modules: {{module}}. {{reason}}. To fix it:\n{{fix}}";
Errors["UnableToRequireDefinitionFile"] = "Unable to require `.d.ts` file for file: {{file}}.\nThis is usually the result of a faulty configuration or import. Make sure there is a `.js`, `.json` or another executable extension available alongside `{{file}}`.";
Errors["FileNotFound"] = "File not found: {{inputPath}} (resolved as: {{resolvedPath}})";
Errors["UnableToCompileTypeScript"] = "{{diagnostics}}";
Errors["NotMappingMultiStarPath"] = "Not mapping \"{{path}}\" because it has more than one star (`*`).";
Errors["NotMappingPathWithEmptyMap"] = "Not mapping \"{{path}}\" because it has no target.";
Errors["GotJsFileButAllowJsFalse"] = "Got a `.js` file to compile while `allowJs` option is not set to `true` (file: {{path}}). To fix this:\n - if you want TypeScript to process JS files, set `allowJs` to `true` in your TypeScript config (usually tsconfig.json)\n - if you do not want TypeScript to process your `.js` files, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match `.js` files anymore";
Errors["GotUnknownFileTypeWithoutBabel"] = "Got a unknown file type to compile (file: {{path}}). To fix this, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match this kind of files anymore.";
Errors["GotUnknownFileTypeWithBabel"] = "Got a unknown file type to compile (file: {{path}}). To fix this, in your Jest config change the `transform` key which value is `ts-jest` so that it does not match this kind of files anymore. If you still want Babel to process it, add another entry to the `transform` option with value `babel-jest` which key matches this type of files.";
Errors["ConfigNoModuleInterop"] = "If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information.";
Errors["MismatchNodeTargetMapping"] = "There is a mismatch between your NodeJs version {{nodeJsVer}} and your TypeScript target {{compilationTarget}}. This might lead to some unexpected errors when running tests with `ts-jest`. To fix this, you can check https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping";
Errors["CannotProcessFileReturnOriginal"] = "Unable to process '{{file}}', falling back to original file content. You can also configure Jest config option `transformIgnorePatterns` to ignore {{file}} from transformation or make sure that `outDir` in your tsconfig is neither `''` or `'.'`";
Errors["CannotProcessFile"] = "Unable to process '{{file}}', please make sure that `outDir` in your tsconfig is neither `''` or `'.'`. You can also configure Jest config option `transformIgnorePatterns` to inform `ts-jest` to transform {{file}}";
Errors["MissingTransformerName"] = "The AST transformer {{file}} must have an `export const name = <your_transformer_name>`";
Errors["MissingTransformerVersion"] = "The AST transformer {{file}} must have an `export const version = <your_transformer_version>`";
Errors["InvalidModuleKindForEsm"] = "The current compiler option \"module\" value is not suitable for Jest ESM mode. Please either use ES module kinds or Node16/NodeNext module kinds with \"type: module\" in package.json";
})(Errors || (exports.Errors = Errors = {}));
/**
* @internal
*/
exports.Helps = {
FixMissingModule: '{{label}}: `npm i -D {{module}}` (or `yarn add --dev {{module}}`)',
MigrateConfigUsingCLI: 'Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate <config-file>.',
UsingModernNodeResolution: `Using hybrid module kind (Node16/18/Next) is only supported in "isolatedModules: true". Please set "isolatedModules: true" in your tsconfig.json. To disable this message, you can set "diagnostics.ignoreCodes" to include ${diagnostics_1.TsJestDiagnosticCodes.ModernNodeModule} in your ts-jest config. See more at https://kulshekhar.github.io/ts-jest/docs/getting-started/options/diagnostics`,
};
/**
* @internal
*/
var Deprecations;
(function (Deprecations) {
Deprecations["EnvVar"] = "Using env. var \"{{old}}\" is deprecated, use \"{{new}}\" instead.";
Deprecations["ConfigOption"] = "\"[jest-config].{{oldPath}}\" is deprecated, use \"[jest-config].{{newPath}}\" instead.";
Deprecations["ConfigOptionWithNote"] = "\"[jest-config].{{oldPath}}\" is deprecated, use \"[jest-config].{{newPath}}\" instead.\n \u21B3 {{note}}";
Deprecations["ConfigOptionUseBabelRcNote"] = "See `babel-jest` related issue: https://github.com/facebook/jest/issues/3845";
// eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member
Deprecations["GlobalsTsJestConfigOption"] = "Define `ts-jest` config under `globals` is deprecated. Please do\ntransform: {\n <transform_regex>: ['ts-jest', { /* ts-jest config goes here in Jest */ }],\n},\nSee more at https://kulshekhar.github.io/ts-jest/docs/getting-started/presets#advanced";
Deprecations["IsolatedModulesWithTsconfigPath"] = "\n The \"ts-jest\" config option \"isolatedModules\" is deprecated and will be removed in v30.0.0. Please use \"isolatedModules: true\" in {{tsconfigFilePath}} instead, see https://www.typescriptlang.org/tsconfig/#isolatedModules\n ";
Deprecations["IsolatedModulesWithoutTsconfigPath"] = "\n The \"ts-jest\" config option \"isolatedModules\" is deprecated and will be removed in v30.0.0. Please use \"isolatedModules: true\", see https://www.typescriptlang.org/tsconfig/#isolatedModules\n ";
})(Deprecations || (exports.Deprecations = Deprecations = {}));
/**
* @internal
*/
var ImportReasons;
(function (ImportReasons) {
ImportReasons["TsJest"] = "Using \"ts-jest\" requires this package to be installed.";
ImportReasons["BabelJest"] = "Using \"babel-jest\" requires this package to be installed.";
ImportReasons["EsBuild"] = "Using \"esbuild\" requires this package to be installed.";
})(ImportReasons || (exports.ImportReasons = ImportReasons = {}));
/**
* @internal
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function interpolate(msg, vars = {}) {
// eslint-disable-next-line no-useless-escape
return msg.replace(/\{\{([^\}]+)\}\}/g, (_, key) => (key in vars ? vars[key] : _));
}