在本地运行 jest 时,它会实例化我的应用程序并运行测试,没有任何问题。
在 github actions 中运行 jest 时,出现此错误:
Error: Jest: Failed to parse the TypeScript config file /home/runner/work/myproject/myproject/jest.config.ts
TypeError: registerer.enabled is not a function
at readConfigFileAndSetRootDir (/home/runner/work/myproject/myproject/node_modules/@jest/core/node_modules/jest-config/build/readConfigFileAndSetRootDir.js:118:13)
package.json
脚本条目只是:"test": "jest"
并且jest.config.ts
文件是:
import tsJestUtils from 'ts-jest/utils'
import tsConf from './tsconfig.json'
const rootDir = __dirname
const { pathsToModuleNameMapper } = tsJestUtils
const {
compilerOptions: { paths },
} = tsConf
const config = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: [`${rootDir}/src`],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
moduleNameMapper: pathsToModuleNameMapper(paths, {
prefix: `${rootDir}/src`,
}),
}
export default config
最佳答案
因此,我完全绕过了在 jest 配置中使用 typescript,并使用了基于 the docs 的等效 jest.config.js
文件。 。现在可以在 Github Actions 中运行,运行器不会失败!\o/
我仍然不确定问题是什么,但我认为 ts-node
只是没有正确处理配置文件。我觉得实际的失败是尝试加载 .ts 配置文件,特别是 at this point in the source code当它尝试调用registerer.enabled()
时。
关于node.js - Jest .config.ts : "registerer.enabled is not a function" error when running jest from Github Actions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68960179/