From 11f92085ded08e3abf9295869ec829a9a0843e80 Mon Sep 17 00:00:00 2001 From: Cerosh Date: Mon, 2 Sep 2024 14:03:58 +1000 Subject: [PATCH] fixed the environment variable related issue. --- package-lock.json | 48 +++++++++++++++++++++++++++++++++++++++++ package.json | 2 ++ playwright.config.ts | 8 ++++--- utils/request.helper.ts | 5 +++-- 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 12fe879..052dea5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,8 @@ "license": "ISC", "dependencies": { "@faker-js/faker": "^8.4.1", + "dotenv": "^16.4.5", + "path": "^0.12.7", "xmlbuilder": "^15.1.1" }, "devDependencies": { @@ -59,6 +61,18 @@ "undici-types": "~6.19.2" } }, + "node_modules/dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/fsevents": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", @@ -74,6 +88,22 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, + "node_modules/inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw==", + "license": "ISC" + }, + "node_modules/path": { + "version": "0.12.7", + "resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz", + "integrity": "sha512-aXXC6s+1w7otVF9UletFkFcDsJeO7lSZBPUQhtb5O0xJe8LtYhj/GxldoL09bBj9+ZmE2hNoHqQSFMN5fikh4Q==", + "license": "MIT", + "dependencies": { + "process": "^0.11.1", + "util": "^0.10.3" + } + }, "node_modules/playwright": { "version": "1.46.1", "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.46.1.tgz", @@ -106,6 +136,15 @@ "node": ">=18" } }, + "node_modules/process": { + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", + "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==", + "license": "MIT", + "engines": { + "node": ">= 0.6.0" + } + }, "node_modules/undici-types": { "version": "6.19.8", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", @@ -113,6 +152,15 @@ "dev": true, "license": "MIT" }, + "node_modules/util": { + "version": "0.10.4", + "resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz", + "integrity": "sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==", + "license": "MIT", + "dependencies": { + "inherits": "2.0.3" + } + }, "node_modules/xmlbuilder": { "version": "15.1.1", "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-15.1.1.tgz", diff --git a/package.json b/package.json index 73908a7..8e5a9b4 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,8 @@ }, "dependencies": { "@faker-js/faker": "^8.4.1", + "dotenv": "^16.4.5", + "path": "^0.12.7", "xmlbuilder": "^15.1.1" } } diff --git a/playwright.config.ts b/playwright.config.ts index d4917c2..b22efd9 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,11 +1,13 @@ import { defineConfig, devices } from "@playwright/test"; +import dotenv from "dotenv"; +import path from "path"; /** * Read environment variables from file. * https://github.com/motdotla/dotenv */ -// import dotenv from 'dotenv'; -// dotenv.config({ path: path.resolve(__dirname, '.env') }); + +dotenv.config({ path: path.resolve(__dirname, ".env") }); /** * See https://playwright.dev/docs/test-configuration. @@ -19,7 +21,7 @@ export default defineConfig({ /* Retry on CI only */ retries: process.env.CI ? 0 : 0, /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, + workers: 1, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ reporter: "html", /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ diff --git a/utils/request.helper.ts b/utils/request.helper.ts index 4223a1b..a479e85 100644 --- a/utils/request.helper.ts +++ b/utils/request.helper.ts @@ -1,5 +1,5 @@ import { APIRequestContext } from "@playwright/test"; -import Base_URL from "../playwright.config"; +import config from "../playwright.config"; let cachedToken: string | null = null; let tokenGenerationTime: Date | null = null; @@ -7,7 +7,8 @@ let tokenGenerationTime: Date | null = null; async function fetchChallengerToken( request: APIRequestContext ): Promise { - const response = await request.post(`${Base_URL}/challenger`); + const baseURL = config.use?.baseURL; + const response = await request.post(`${baseURL}/challenger`); if (!response.ok()) { throw new Error("Failed to fetch X-CHALLENGER token");