umijs / umi

A framework in react community ✨
https://umijs.org
MIT License
15.39k stars 2.65k forks source link

[Bug] umi simple app,无法运行 umi g jest 配置的测试 #12733

Open tanukihee opened 1 month ago

tanukihee commented 1 month ago

What happens?

新建 umi simple app 后,使用 umi g jest 增加 jest 配置,无法运行 test。

Mini Showcase Repository(REQUIRED)

Please provide a minimal reproduction then upload to your GitHub. 请提供 最小重现,并上传到你的 GitHub 仓库

https://stackblitz.com/edit/umi-edm1pg

How To Reproduce

Steps to reproduce the behavior:

  1. 使用 pnpm create umi 生成 Simple App
  2. 使用 pnpm umi g jest 配置使用 jest
  3. 使用 pnpm test 运行测试

Expected behavior

  1. 测试运行通过

Actual behavior


> @ test /home/projects/vitejs-vite-edm1pg
> cross-env TS_NODE_TRANSPILE_ONLY=yes jest --passWithNoTests

Error: Jest: Failed to parse the TypeScript config file /home/projects/vitejs-vite-edm1pg/jest.config.ts
  TSError: ⨯ Unable to compile TypeScript:
error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.

    at readConfigFileAndSetRootDir (/home/projects/vitejs-vite-edm1pg/node_modules/.pnpm/jest-config@29.7.0_@types+node@22.7.5_ts-node@10.9.2/node_modules/jest-config/build/readConfigFileAndSetRootDir.js:116:13)
    at async readInitialOptions (/home/projects/vitejs-vite-edm1pg/node_modules/.pnpm/jest-config@29.7.0_@types+node@22.7.5_ts-node@10.9.2/node_modules/jest-config/build/index.js:403:13)
    at async readConfig (/home/projects/vitejs-vite-edm1pg/node_modules/.pnpm/jest-config@29.7.0_@types+node@22.7.5_ts-node@10.9.2/node_modules/jest-config/build/index.js:147:48)
    at async readConfigs (/home/projects/vitejs-vite-edm1pg/node_modules/.pnpm/jest-config@29.7.0_@types+node@22.7.5_ts-node@10.9.2/node_modules/jest-config/build/index.js:424:26)
    at async runCLI (/home/projects/vitejs-vite-edm1pg/node_modules/.pnpm/@jest+core@29.7.0_ts-node@10.9.2/node_modules/@jest/core/build/cli/index.js:151:59)
    at async Object.run (/home/projects/vitejs-vite-edm1pg/node_modules/.pnpm/jest-cli@29.7.0_@types+node@22.7.5_ts-node@10.9.2/node_modules/jest-cli/build/run.js:130:37)
 ELIFECYCLE  Test failed. See above for more details.

Temporary workaround:

  1. 已确认 src/.umi/tsconfig.json 中已设置 "module": "esnext",,注释掉 "moduleResolution": "bundler", 后,测试可正常运行,但此时所有模块导出均错误。

Context

lingjieding commented 2 weeks ago

https://github.com/cypress-io/cypress/issues/27731#issuecomment-1715685684