I had jest v27.2.4 and ts-jest v27.0.5 and tests worked on, on the latest versions (I think they are 27.4.x) tests don't run anymore since jest complains about a .js file inside node_modules
I tried to downgrade by setting the specific version in package.json (i.e. without the ^) but since jest itself has dependencies on other libraries with ^ it is still upgrading them
The error when running the tests:
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
By default "node_modules" folder is ignored by transformers.
Details:
/home/me/code/node_modules/@middy/core/index.js:2
plugin?.beforePrefetch?.()
^
SyntaxError: Unexpected token '.'
1 | import { logger } from "@libs/logger";
> 2 | import middy from "@middy/core";
| ^
at Runtime.createScriptFromCode (../../../node_modules/jest-runtime/build/index.js:1728:14)
at Object.<anonymous> (../../libs/middleware/src/index.ts:2:1)
my jest.config.js file:
module.exports = {
//clearMocks: true,
//coverageDirectory: "coverage",
//collectCoverage: true,
verbose: true,
globals: {
"ts-jest": {
tsconfig: "tsconfig.json",
},
},
modulePathIgnorePatterns: ["dist"],
transform: {
"^.+\\.(ts|tsx)$": "ts-jest",
},
testEnvironment: "node",
testMatch: ["**/__tests__/*.+(ts|tsx|js)", "**/*.spec.+(ts|tsx|js)"],
};
my tsconfig.json file:
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node 14",
"compilerOptions": {
"incremental": true,
"target": "ES2019",
"module": "commonjs",
"lib": [
"ES2019"
],
"declaration": true,
"sourceMap": true,
"composite": false,
"removeComments": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"moduleResolution": "node",
"types": [
"node"
],
"esModuleInterop": true,
"skipLibCheck": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"forceConsistentCasingInFileNames": true
}
}
Any clues how to fix this?