最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jestjs - Jest ESM support - Stack Overflow

programmeradmin3浏览0评论

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:

  1. Ensure you either disable code transforms by passing transform: {}...
  2. 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"
  }
}
发布评论

评论列表(0)

  1. 暂无评论