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

标签 node.js jestjs github-actions tsconfig ts-jest

在本地运行 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/

相关文章:

node.js - 方法应该在 Mongoose 中的模型上定义还是在单独的层中定义?

javascript - 如何将数据从服务器代码传递到 ejs 模板?

azure - 运行可重用工作流程时出错 - Github 操作

github - GitHub 操作的官方徽章

javascript - 是否可以防止在每个 HTTP 请求中发送 cookie?

javascript - 如何添加 http ://to a URL if no protocol is defined in JavaScript?

javascript - react-native-testing-library 和 styled-components 无法访问 Prop

jestjs - 我如何使用 jest 来测试带有 DOM 元素的 javascript 代码

typescript - NestJs + TypeScript + Jest - TypeError : Class extends value undefined is not a constructor or null

github-actions - github Action 矩阵中的配对值