1 testing automation typescript e2e-testing testcafe
我无法将测试和固定装置导入到一个 main.ts 文件中以立即运行所有测试。出于组织目的,我将测试组织到单独的文件夹中。我收到错误:
ERROR Cannot prepare tests due to an error.
ReferenceError: fixture is not defined
Run Code Online (Sandbox Code Playgroud)
我创建了一个 main.ts 文件来运行所有测试。我导入 Fixture()、Test1() 和 Test2()。
主要.ts
import { Fixture } from "../utils/envUtils";
import { Test1 } from "./testSet1/test1";
import { Test2 } from "./testSet2/test2";
Fixture();
Test1();
Test2();
Run Code Online (Sandbox Code Playgroud)
夹具.ts
export const Fixture = () => {
fixture("Running tests")
}
Run Code Online (Sandbox Code Playgroud)
测试1.ts
export function Test1() {
test("Test1", async (t: TestController) => {
...
}
}
Run Code Online (Sandbox Code Playgroud)
测试2.ts
export function Test2() {
test("Test2", async (t: TestController) => {
...
}
}
Run Code Online (Sandbox Code Playgroud)
如果我手动将 Test1() 和 Test2() 代码复制并粘贴到 main.ts 文件中,它就可以工作。任何帮助表示赞赏。谢谢!
如果其他人遇到此问题,解决方案是将eslint-plugin-testcafe模块添加到您的 eslint 配置中。
TestCafe 文档中引用了这一点: https: //testcafe.io/documentation/402831/guides/basic-guides/organize-tests,如下所示:
Note
If you use eslint in your project, install the TestCafe plugin to
avoid the 'fixture' is not defined and 'test' is not
defined errors.
Run Code Online (Sandbox Code Playgroud)
yarn add -D eslint-plugin-testcafe.eslintrc.json并使用以下设置
更新您的:
{
"plugins": [
"testcafe"
],
"extends": "plugin:testcafe/recommended"
}
Run Code Online (Sandbox Code Playgroud)