gpt4 book ai didi

javascript - 类型错误 : createTestCafe is not a function

转载 作者:行者123 更新时间:2023-11-28 20:21:35 24 4
gpt4 key购买 nike

当我从 TestCafe 站点复制运行程序代码并尝试运行它时出现此错误。我在 Ubuntu 18.04 上有 testcafe 1.6.0

下面是我的运行者,

const createTestCafe = require('/usr/local/bin/testcafe');
let testcafe = null;

createTestCafe('localhost', 1337, 1338)
.then(tc => {
testcafe = tc;
const runner = testcafe.createRunner();

return runner
//.src(['__test__/*.js', 'tests/func/fixture3.js'])
//.browsers(['chrome:headless --no-sandbox --disable-gpu', 'safari'])

.src(['./__tests__/testcafe1.js'])
.browsers(['chrome'])
.run();
})
.then(failedCount => {
console.log('Tests failed: ' + failedCount);

testcafe.close();
});

下面是我的package.json

{
"private": true,
"scripts": {
"test": "testcafe 'chrome:headless --no-sandbox' ./__tests__/*.js --hostname localhost"
},
"devDependencies": {
"chalk": "^2.4.2",
"prettier": "^1.18.2",
"testcafe": "*",
"rimraf": "^2.6.3"
}
}

错误如下:

ERROR Cannot prepare tests due to an error.

TypeError: createTestCafe is not a function
at Object.createTestCafe (/app/code/testcafe_runner.js:6:1)
at Function._execAsModule (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:50:13)
at ESNextTestFileCompiler._runCompiledCode (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:150:42)
at ESNextTestFileCompiler.execute (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:174:21)
at ESNextTestFileCompiler.compile (/usr/local/lib/node_modules/testcafe/src/compiler/test-file/api-based.js:180:21)
at Compiler._getTests (/usr/local/lib/node_modules/testcafe/src/compiler/index.js:86:31)
at Compiler._compileTestFiles (/usr/local/lib/node_modules/testcafe/src/compiler/index.js:98:35)
at Compiler.getTests (/usr/local/lib/node_modules/testcafe/src/compiler/index.js:111:34)
at Bootstrapper._getTests (/usr/local/lib/node_modules/testcafe/src/runner/bootstrapper.js:81:26)
at Bootstrapper._bootstrapParallel (/usr/local/lib/node_modules/testcafe/src/runner/bootstrapper.js:214:39)

我正在遵循来自 Testcafe https://devexpress.github.io/testcafe/documentation/using-testcafe/programming-interface/runner.html 的代码

我在这里做错了什么?

最佳答案

您尝试要求 TestCafe 的可执行文件而不是 TestCafe 的库。它可能位于 /usr/lib/node_modules/testcafe/usr/local/lib/node_modules/testcafe 中。您可以使用以下命令查找全局安装模块的路径:

npm ls -g

但是,如果您想将 TestCafe 作为库使用,最好在本地安装它。如果您计划将测试运行器脚本作为独立的 CLI 工具运行和分发,您可以通过创建 NPM 包并将运行器脚本添加到 package.json< 中的 bin 部分来实现。/:https://docs.npmjs.com/files/package.json#bin

关于javascript - 类型错误 : createTestCafe is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58564472/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com