diff --git a/.env.development b/.env.development index 51af17ea2..ba9d3917f 100644 --- a/.env.development +++ b/.env.development @@ -9,10 +9,11 @@ VITE_KC_SITE_BASE_URL=https://dev.zoo.dev VITE_KC_SITE_APP_URL=https://app.dev.zoo.dev VITE_KC_SKIP_AUTH=false VITE_KC_CONNECTION_TIMEOUT_MS=5000 -#VITE_KC_DEV_TOKEN="optional token from dev.zoo.dev to skip auth in the app" +#VITE_KC_DEV_TOKEN="optional token to skip auth in the app" +#token="required token for playwright. TODO: clean up env vars in #3973" RUST_BACKTRACE=1 PYO3_PYTHON=/usr/local/bin/python3 -#KITTYCAD_API_TOKEN="required token from dev.zoo.dev for engine testing" +#KITTYCAD_API_TOKEN="required token for engine testing" FAIL_ON_CONSOLE_ERRORS=true diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 74705590c..dab5f80cb 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -229,7 +229,6 @@ jobs: max_attempts: 5 env: token: ${{ secrets.KITTYCAD_API_TOKEN_DEV }} - snapshottoken: ${{ secrets.KITTYCAD_API_TOKEN }} TAB_API_URL: ${{ secrets.TAB_API_URL }} TAB_API_KEY: ${{ secrets.TAB_API_KEY }} CI_COMMIT_SHA: ${{ github.event.pull_request.head.sha }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cda4766d1..f21a03c17 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -198,15 +198,9 @@ For more information on fuzzing you can check out ### Playwright tests -You will need a `./e2e/playwright/playwright-secrets.env` file: +Prepare these system dependencies: -```bash -$ touch ./e2e/playwright/playwright-secrets.env -$ cat ./e2e/playwright/playwright-secrets.env -token= -snapshottoken= -``` -or use `export` to set the environment variables `token` and `snapshottoken`. +- Set $token from https://zoo.dev/account/api-tokens #### Snapshot tests (Google Chrome on Ubuntu only) diff --git a/e2e/playwright/fixtures/signInPageFixture.ts b/e2e/playwright/fixtures/signInPageFixture.ts index 7d071533c..9f5ea8296 100644 --- a/e2e/playwright/fixtures/signInPageFixture.ts +++ b/e2e/playwright/fixtures/signInPageFixture.ts @@ -1,5 +1,5 @@ import type { Locator, Page } from '@playwright/test' -import { secrets } from '@e2e/playwright/secrets' +import { token } from '@e2e/playwright/test-utils' export class SignInPageFixture { public page: Page @@ -25,7 +25,7 @@ export class SignInPageFixture { // Device flow: stolen from the tauri days // https://github.com/KittyCAD/modeling-app/blob/d916c7987452e480719004e6d11fd2e595c7d0eb/e2e/tauri/specs/app.spec.ts#L19 const headers = { - Authorization: `Bearer ${secrets.token}`, + Authorization: `Bearer ${token}`, Accept: 'application/json', 'Content-Type': 'application/json', } diff --git a/e2e/playwright/secrets.ts b/e2e/playwright/secrets.ts deleted file mode 100644 index e39f7d00f..000000000 --- a/e2e/playwright/secrets.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { readFileSync } from 'fs' - -const secrets: Record = {} -const secretsPath = './e2e/playwright/playwright-secrets.env' -try { - const file = readFileSync(secretsPath, 'utf8') - file - .split('\n') - .filter((line) => line && line.length > 1) - .forEach((line) => { - // Allow line comments. - if (line.trimStart().startsWith('#')) return - const [key, value] = line.split('=') - // prefer env vars over secrets file - secrets[key] = process.env[key] || (value as any).replaceAll('"', '') - }) -} catch (error: unknown) { - void error - // probably running in CI - console.warn( - `Error reading ${secretsPath}; environment variables will be used` - ) -} -secrets.token = secrets.token || process.env.token || '' -secrets.snapshottoken = secrets.snapshottoken || process.env.snapshottoken || '' -// add more env vars here to make them available in CI - -export { secrets } diff --git a/e2e/playwright/test-utils.ts b/e2e/playwright/test-utils.ts index b93afb186..d258c23dc 100644 --- a/e2e/playwright/test-utils.ts +++ b/e2e/playwright/test-utils.ts @@ -13,11 +13,15 @@ import fsp from 'fs/promises' import pixelMatch from 'pixelmatch' import type { Protocol } from 'playwright-core/types/protocol' import { PNG } from 'pngjs' +import dotenv from 'dotenv' + +const NODE_ENV = process.env.NODE_ENV || 'development' +dotenv.config({ path: [`.env.${NODE_ENV}.local`, `.env.${NODE_ENV}`] }) +export const token = process.env.token || '' import type { ProjectConfiguration } from '@rust/kcl-lib/bindings/ProjectConfiguration' import { isErrorWhitelisted } from '@e2e/playwright/lib/console-error-whitelist' -import { secrets } from '@e2e/playwright/secrets' import { TEST_SETTINGS, TEST_SETTINGS_KEY } from '@e2e/playwright/storageStates' import { test } from '@e2e/playwright/zoo-test' @@ -891,7 +895,7 @@ export async function setup( localStorage.setItem('PLAYWRIGHT_TEST_DIR', PLAYWRIGHT_TEST_DIR) }, { - token: secrets.token, + token, settingsKey: TEST_SETTINGS_KEY, settings: settingsToToml({ settings: { @@ -919,7 +923,7 @@ export async function setup( await context.addCookies([ { name: COOKIE_NAME, - value: secrets.token, + value: token, path: '/', domain: 'localhost', secure: true, diff --git a/package-lock.json b/package-lock.json index 20e075f06..b2cb9144b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2492,6 +2492,7 @@ }, "node_modules/@clack/prompts/node_modules/is-unicode-supported": { "version": "1.3.0", + "extraneous": true, "inBundle": true, "license": "MIT", "engines": { diff --git a/package.json b/package.json index e8d02495e..59ad40f02 100644 --- a/package.json +++ b/package.json @@ -137,8 +137,8 @@ "test:unit:components": "jest -c jest-component-unit-tests/jest.config.ts --rootDir jest-component-unit-tests/", "test:unit:kcl-samples": "vitest run --mode development ./src/lang/kclSamples.test.ts", "test:playwright:electron": "playwright test --config=playwright.electron.config.ts --grep-invert=@snapshot", - "test:playwright:electron:local": "npm run tronb:vite:dev && NODE_ENV=development playwright test --config=playwright.electron.config.ts --grep-invert=@snapshot --grep-invert=\"$(curl --silent https://test-analysis-bot.hawk-dinosaur.ts.net/projects/KittyCAD/modeling-app/tests/disabled/regex)\"", - "test:playwright:electron:local-engine": "npm run tronb:vite:dev && NODE_ENV=development playwright test --config=playwright.electron.config.ts --grep-invert='@snapshot|@skipLocalEngine' --grep-invert=\"$(curl --silent https://test-analysis-bot.hawk-dinosaur.ts.net/projects/KittyCAD/modeling-app/tests/disabled/regex)\"", + "test:playwright:electron:local": "npm run tronb:vite:dev && playwright test --config=playwright.electron.config.ts --grep-invert=@snapshot --grep-invert=\"$(curl --silent https://test-analysis-bot.hawk-dinosaur.ts.net/projects/KittyCAD/modeling-app/tests/disabled/regex)\"", + "test:playwright:electron:local-engine": "npm run tronb:vite:dev && playwright test --config=playwright.electron.config.ts --grep-invert='@snapshot|@skipLocalEngine' --grep-invert=\"$(curl --silent https://test-analysis-bot.hawk-dinosaur.ts.net/projects/KittyCAD/modeling-app/tests/disabled/regex)\"", "test:unit:local": "npm run simpleserver:bg && npm run test:unit; kill-port 3000", "test:unit:kcl-samples:local": "npm run simpleserver:bg && npm run test:unit:kcl-samples; kill-port 3000" },