UNPKG

@swc-node/jest

Version:

swc preprocessor for jest with source map support

32 lines 1.24 kB
"use strict"; const xxhash_1 = require("@node-rs/xxhash"); const core_1 = require("@swc-node/core"); const read_default_tsconfig_1 = require("@swc-node/register/read-default-tsconfig"); function getJestTransformConfig(jestConfig) { var _a, _b; if ('transformerConfig' in jestConfig) { // jest 27 return jestConfig.transformerConfig; } if ('transform' in jestConfig) { // jest 26 return (_b = (_a = jestConfig.transform.find(([, transformerPath]) => transformerPath === __filename)) === null || _a === void 0 ? void 0 : _a[2]) !== null && _b !== void 0 ? _b : {}; } return {}; } const defaultTsConfig = (0, read_default_tsconfig_1.readDefaultTsConfig)(); module.exports = { process(src, path, jestConfig) { if (/\.(tsx?|jsx?|mjs)$/.test(path)) { return (0, core_1.transformJest)(src, path, { ...(0, read_default_tsconfig_1.tsCompilerOptionsToSwcConfig)(defaultTsConfig, path), ...getJestTransformConfig(jestConfig), }); } return src; }, getCacheKey(src, _filepath, config) { return (0, xxhash_1.xxh64)(src + JSON.stringify(config)).toString(16); }, }; //# sourceMappingURL=index.js.map