I am working with a project written by a colleague and it appears to contradict the documentation. Can anyone shed any light on this?
The project runs fine and all tests pass, but when I look closer I notice that the transform
option is set to use babel-jest
and no special command line options are being passed.
When I consult the Jest documentation at is it quite specific:
- Ensure you either disable code transforms by passing transform: {}...
- Execute node with --experimental-vm-modules...
So this project specifically contradicts the instructions given. Further, if I alter the transform
option to {}
in order to comply with item 1. the tests fail to run with a Cannot use import statement outside a module
error.
Can anyone please explain how this is works?
The project is far too large to post it all here but this is the package.json:
{
"name": "sample",
"version": "1.0.0",
"main": "index.mjs",
"directories": {
"test": "tests"
},
"type": "module",
"scripts": {
"test": "jest"
},
"jest": {
"testMatch": [
"<rootDir>/tests/**/*.spec.*"
],
"testEnvironment": "node",
"transform": {
"^.+\\.jsx?$": "babel-jest",
"^.+\\.mjsx?$": "babel-jest"
},
"verbose": true
},
"license": "ISC",
"dependencies": {
"@aws-sdk/client-connect": "^3.490.0",
"@aws-sdk/client-dynamodb": "^3.490.0",
"@aws-sdk/client-firehose": "^3.490.0",
"@aws-sdk/client-sqs": "^3.629.0",
"@aws-sdk/client-ssm": "^3.490.0"
},
"devDependencies": {
"@babel/core": "^7.23.7",
"@babel/preset-env": "^7.23.8",
"@babel/preset-typescript": "^7.23.3",
"@types/jest": "^29.5.11",
"aws-sdk-client-mock": "^4.0.1",
"aws-sdk-client-mock-jest": "^4.0.1",
"babel-jest": "^29.7.0",
"jest": "^29.7.0"
}
}