jest.config.ts: "registerer.enabled is not a function" 当 运行 从 Github 操作开玩笑时出错

jest.config.ts: "registerer.enabled is not a function" error when running jest from Github Actions

当 运行 在本地开玩笑时,它会实例化我的应用程序并运行测试,没有任何问题。

当 运行 在 github 操作中开玩笑时,出现此错误:

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

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


我仍然不确定问题出在哪里,但我认为 ts-node 只是没有正确处理配置文件。我觉得真正的失败是尝试加载 .ts 配置文件,特别是 at this point in the source code 当它试图调用 registerer.enabled().