I'm facing an issue with my repo where I am running tests using Playwright against a graphQL URL. Despite configuring the tests, there is an error indicating that the environment variable defining the environment cannot be found.
The repository in question can be accessed here - https://github.com/zac11/playwright-graphql-demo
Upon executing the command npm run test-new
, the following output is displayed:
<<< ENVIRONMENT: undefined >>>
Although I have reviewed the code, I am unable to identify the root cause of the inability to pick up the correct environment setting.
There are numerous TypeScript complaints regarding the failure to import files with `.ts` extensions. The `tsconfig.json` file that has been added ought to rectify this, but I suspect this may be contributing to the recognition issue.
Please advise if there are any configuration discrepancies or missing elements within the code.
Below is the stack trace for reference:
npm run test-new
> [email protected] 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