create-jest-runner 抛出“无法读取未定义的属性”错误

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

我正在使用

jest
create-jest-runner

创建自定义跑步者

我正在遵循示例,但我不断收到错误

TypeError: Cannot read properties of undefined (reading 'startsWith')
    at new Worker (/Users/redacted/git/redacted/redacted/redacted/node_modules/create-jest-runner/node_modules/jest-worker/build/index.js:120:20)
    at BaseTestRunner._createParallelTestRun (/Users/redacted/git/redacted/redacted/redacted/node_modules/create-jest-runner/build/createJestRunner.js:63:22)
    at BaseTestRunner.runTests (/Users/redacted/git/redacted/redacted/redacted/node_modules/create-jest-runner/build/createJestRunner.js:40:119)
    at TestScheduler.scheduleTests (/Users/redacted/git/redacted/redacted/redacted/node_modules/@jest/core/build/TestScheduler.js:331:30)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async runJest (/Users/redacted/git/redacted/redacted/redacted/node_modules/@jest/core/build/runJest.js:376:19)
    at async _run10000 (/Users/redacted/git/redacted/redacted/redacted/node_modules/@jest/core/build/cli/index.js:416:7)
    at async runCLI (/Users/redacted/git/redacted/redacted/redacted/node_modules/@jest/core/build/cli/index.js:271:3)
    at async Object.run (/Users/redacted/git/redacted/redacted/redacted/node_modules/jest-cli/build/cli/index.js:163:37)

我很困惑。在抛出错误之前它甚至没有到达

runner
我还没有看到任何有关如何解决此问题的文档。我一定错过了一些东西。

这是我的设置:

"jest": "^26.6.3",
"create-jest-runner": "^0.12.3",

自定义runner.js

const { createJestRunner } = require("create-jest-runner");

const runner = async ({ testPath }) => {
    // Do Something
};

module.exports = createJestRunner(runner);

jest.config.js

module.exports = {
    ...regularSettings,
    runner: "./custom-runner.js",
};
javascript reactjs jestjs
1个回答
0
投票

您遇到的错误可能源于兼容性问题或配置错误。解决方法如下:

通过将 jest 和 create-jest-runner 更新到最新版本来确保兼容性:

npm install --save-dev jest@latest create-jest-runner@latest

确保您的自定义跑步者设置正确:

const { createJestRunner } = require("create-jest-runner");

const runner = async ({ testPath, config, globalConfig }) => {
    // Your custom logic
};

module.exports = createJestRunner(runner);

验证 jest.config.js 是否正确引用您的自定义运行器:

module.exports = {
    ...regularSettings,
    runner: "./custom-runner.js",
};

使用最少的设置进行测试,并在运行程序中添加 console.log 语句以查明问题。

如果错误仍然存在,请考虑在 jest's GitHub 存储库上报告并提供详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.