jest.config.ts:从 Github Actions 运行 jest 时出现“registerer.enabled is not a function”错误

问题描述 投票:0回答:2

在本地运行 jest 时,它会实例化我的应用程序并毫无问题地运行测试。

在 github 操作中运行 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

node.js jestjs github-actions tsconfig ts-jest
2个回答
1
投票

所以我完全绕过了对我的笑话配置使用打字稿,并使用了一个基于文档的等效jest.config.js文件。现在在 Github Actions 中工作,runner 不会失败! \o/


我仍然不确定问题出在哪里,但我认为 ts-node 只是没有正确处理配置文件。我觉得真正的失败是尝试加载 .ts 配置文件,特别是 在源代码中的这一点 尝试调用 registerer.enabled().


0
投票

可以通过升级到"ts-node": "^8.5.0"

来修复
© www.soinside.com 2019 - 2024. All rights reserved.