由于TS配置问题,使用剧作家的GraphQL测试失败



我有一个repo,我试图运行一些测试使用剧作家对graphQL url。我已经配置了测试,但现在我得到错误,它无法找到定义环境的环境变量。

有问题的回购在这里- https://github.com/zac11/playwright-graphql-demo

当我尝试运行这个命令npm run test-new时,我得到这个

<<< ENVIRONMENT: undefined >>>

我已经检查了代码,我无法确定问题,因为它无法获得正确的环境。

我看到有很多ts抱怨无法导入.ts扩展名的文件,但我认为添加的tsconfig.json文件应该能够纠正它。我很困惑,如果这是真正的问题,使它不能正确识别代码。

如果有任何配置问题或代码中缺少的东西,请提出建议/指出。

堆栈跟踪:

npm run test-new
> playwright-graphql-demo@1.0.0 test-new
> cross-env test_env=prod npx playwright test --config=playwright.config.ts --project=graphql

Running 5 tests using 1 worker
✘  1 [graphql] › graphql.spec.ts:16:5 › GRAPHQL DEMO › should list all teas (92ms)
<<< ENVIRONMENT: undefined >>>
<=============SENDING REQUEST==============>
REQUEST URL: 

REQUEST DATA: 
query: { teas { id, name} }
-  2 [graphql] › graphql.spec.ts:20:5 › GRAPHQL DEMO › should add new tea
-  3 [graphql] › graphql.spec.ts:24:5 › GRAPHQL DEMO › should get new tea by name
-  4 …aphql.spec.ts:28:5 › GRAPHQL DEMO › should verify that new tea is in the list of all teas
-  5 [graphql] › graphql.spec.ts:33:5 › GRAPHQL DEMO › should delete newly added tea

1) [graphql] › graphql.spec.ts:16:5 › GRAPHQL DEMO › should list all teas ─────────────────────
Error: apiRequestContext.post: First argument must be either URL string or Request
at ../helperMethods/api.helper.ts:54
52 |     this.logRequestAPI(URL, data);
53 |
> 54 |     const response = await api.post(URL, { data});
|                                ^
55 |     const status = response.status();
56 |     const respJson = await response.json();
57 |   
at GrapQLService.getAllTeas (/UserDir/playwright-graphql-demo/helperMethods/api.helper.ts:54:32)
at /UserDir/playwright-graphql-demo/tests/graphql.spec.ts:17:9
attachment #1: trace (application/zip) ──────────────────────────────────────────────────────
test-results/graphql-GRAPHQL-DEMO-should-list-all-teas-graphql/trace.zip
Usage:
npx playwright show-trace test-results/graphql-GRAPHQL-DEMO-should-list-all-teas-graphql/trace.zip
─────────────────────────────────────────────────────────────────────────────────────────────
1 failed
[graphql] › graphql.spec.ts:16:5 › GRAPHQL DEMO › should list all teas ──────────────────────
4 skipped

可能需要将URL作为命令行参数传递,如:

URL=https://playwright.dev npm run test-new

最新更新