diff --git a/.env.ci b/.env.ci new file mode 100644 index 0000000..56c3a40 --- /dev/null +++ b/.env.ci @@ -0,0 +1,2 @@ +VITE_CODEX_API_URL=http://localhost:8080 +VITE_GEO_IP_URL=https://geoip.codex.storage \ No newline at end of file diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index f40d2e5..5f5c411 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -110,11 +110,6 @@ jobs: - name: Install dependencies run: npm ci - - name: Run the marketplace - run: | - npm run dev & - sleep 5 - - name: Install Playwright Browsers run: npx playwright install --with-deps diff --git a/e2e/availabilities.spec.ts b/e2e/availabilities.spec.ts index f0522f4..ce823d2 100644 --- a/e2e/availabilities.spec.ts +++ b/e2e/availabilities.spec.ts @@ -1,8 +1,7 @@ import test, { expect } from "@playwright/test"; -import { APP_URL } from './constants'; test('creates an availability', async ({ page }) => { - await page.goto(APP_URL + '/dashboard'); + await page.goto('/dashboard'); await page.getByRole('link', { name: 'Sales' }).click(); await page.getByRole('button').first().click(); await page.getByLabel('Total size').click(); @@ -26,7 +25,7 @@ test('creates an availability', async ({ page }) => { }) test('availability navigation buttons', async ({ page }) => { - await page.goto(APP_URL + '/dashboard/availabilities'); + await page.goto('/dashboard/availabilities'); await page.getByRole('button').first().click(); await expect(page.locator('.stepper-number-done')).not.toBeVisible() await expect(page.locator('.stepper-number-active')).toBeVisible() diff --git a/e2e/constants.ts b/e2e/constants.ts deleted file mode 100644 index 44414c2..0000000 --- a/e2e/constants.ts +++ /dev/null @@ -1 +0,0 @@ -export const APP_URL = "http://localhost:5173" \ No newline at end of file diff --git a/e2e/settings.spec.ts b/e2e/settings.spec.ts index e64e07a..48db1dd 100644 --- a/e2e/settings.spec.ts +++ b/e2e/settings.spec.ts @@ -1,8 +1,7 @@ import test, { expect } from "@playwright/test"; -import { APP_URL } from './constants'; test('update the log level', async ({ page }) => { - await page.goto(APP_URL + '/dashboard'); + await page.goto('/dashboard'); await page.getByRole('link', { name: 'Settings' }).click(); await page.getByLabel('Log level').selectOption('TRACE'); await page.getByRole('main').locator('div').filter({ hasText: 'Log' }).getByRole('button').click(); diff --git a/e2e/storage-requests.spec.ts b/e2e/storage-requests.spec.ts index 504a547..54dbcb4 100644 --- a/e2e/storage-requests.spec.ts +++ b/e2e/storage-requests.spec.ts @@ -1,13 +1,12 @@ import test, { expect } from "@playwright/test"; import path, { dirname } from "path"; import { fileURLToPath } from "url"; -import { APP_URL } from './constants'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); test('creates a storage request', async ({ page }) => { - await page.goto(APP_URL + '/dashboard'); + await page.goto('/dashboard'); await page.getByRole('link', { name: 'Purchases' }).click(); await page.getByRole('button', { name: 'Storage Request' }).click(); await page.locator('div').getByTestId("upload").setInputFiles([ @@ -24,7 +23,7 @@ test('creates a storage request', async ({ page }) => { }) test('select a uploaded cid when creating a storage request', async ({ page }) => { - await page.goto(APP_URL + '/dashboard'); + await page.goto('/dashboard'); await page.locator('div').getByTestId("upload").setInputFiles([ path.join(__dirname, "assets", 'chatgpt.jpg'), ]); @@ -36,7 +35,7 @@ test('select a uploaded cid when creating a storage request', async ({ page }) = }) test('storage request navigation buttons', async ({ page }) => { - await page.goto(APP_URL + '/dashboard/purchases'); + await page.goto('/dashboard/purchases'); await page.getByRole('button', { name: 'Storage Request' }).click(); await expect(page.locator('.stepper-number-done')).not.toBeVisible() await expect(page.locator('.stepper-number-active')).toBeVisible() diff --git a/e2e/upload.spec.ts b/e2e/upload.spec.ts index 785523c..0a49bb5 100644 --- a/e2e/upload.spec.ts +++ b/e2e/upload.spec.ts @@ -3,13 +3,12 @@ import { Buffer } from 'buffer'; import { readFileSync } from 'fs'; import path, { dirname } from 'path'; import { fileURLToPath } from 'url'; -import { APP_URL } from './constants'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); test('upload one file', async ({ page }) => { - await page.goto(APP_URL + '/dashboard'); + await page.goto('/dashboard'); await page.getByText('browse').click(); await page.locator('div').getByTestId("upload").setInputFiles([ path.join(__dirname, "assets", 'chatgpt.jpg'), @@ -19,7 +18,7 @@ test('upload one file', async ({ page }) => { }); test('multiple files upload', async ({ page }) => { - await page.goto(APP_URL + '/dashboard'); + await page.goto('/dashboard'); await page.getByText('browse').click(); await page.locator('div').getByTestId("upload").setInputFiles([ path.join(__dirname, "assets", 'chatgpt.jpg'), @@ -38,7 +37,7 @@ test('multiple files upload', async ({ page }) => { }); test('drag and drop file', async ({ page }) => { - await page.goto(APP_URL + '/dashboard'); + await page.goto('/dashboard'); const buffer = readFileSync(path.join(__dirname, "assets", 'chatgpt.jpg')); @@ -57,7 +56,7 @@ test('drag and drop file', async ({ page }) => { }); test('stop an upload display a message', async ({ page }) => { - await page.goto(APP_URL + '/dashboard'); + await page.goto('/dashboard'); await page.getByText('browse').click(); const buffer = Buffer.alloc(10_000_000); diff --git a/package-lock.json b/package-lock.json index bb5f10a..080a04a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,7 @@ "@typescript-eslint/eslint-plugin": "^8.7.0", "@typescript-eslint/parser": "^8.7.0", "@vitejs/plugin-react": "^4.3.1", + "dotenv": "^16.4.5", "eslint": "^8.57.0", "eslint-plugin-react-hooks": "^4.6.2", "eslint-plugin-react-refresh": "^0.4.12", @@ -2232,6 +2233,18 @@ "node": ">=6.0.0" } }, + "node_modules/dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/echarts": { "version": "5.5.1", "resolved": "https://registry.npmjs.org/echarts/-/echarts-5.5.1.tgz", diff --git a/package.json b/package.json index 9fd3459..6b12d23 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "preview": "vite preview", "format": "prettier --write ./src", - "test": "npx playwright test" + "test": "npx playwright test --ui" }, "keywords": [ "Codex", @@ -47,6 +47,7 @@ "@typescript-eslint/eslint-plugin": "^8.7.0", "@typescript-eslint/parser": "^8.7.0", "@vitejs/plugin-react": "^4.3.1", + "dotenv": "^16.4.5", "eslint": "^8.57.0", "eslint-plugin-react-hooks": "^4.6.2", "eslint-plugin-react-refresh": "^0.4.12", @@ -61,4 +62,4 @@ "author": "Codex team", "readme": "README.md", "license": "MIT" -} \ No newline at end of file +} diff --git a/playwright.config.ts b/playwright.config.ts index e5c3f04..97af063 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,12 +1,16 @@ import { defineConfig, devices } from '@playwright/test'; +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + /** * Read environment variables from file. * https://github.com/motdotla/dotenv */ -// import dotenv from 'dotenv'; -// import path from 'path'; -// dotenv.config({ path: path.resolve(__dirname, '.env') }); +import dotenv from 'dotenv'; +import path, { dirname } from 'path'; +import { fileURLToPath } from 'url'; +dotenv.config({ path: path.resolve(__dirname, '.env.ci') }); /** * See https://playwright.dev/docs/test-configuration. @@ -26,7 +30,7 @@ export default defineConfig({ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { /* Base URL to use in actions like `await page.goto('/')`. */ - // baseURL: 'http://127.0.0.1:3000', + baseURL: 'http://127.0.0.1:5173', /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', @@ -71,9 +75,9 @@ export default defineConfig({ ], /* Run your local dev server before starting the tests */ - // webServer: { - // command: 'npm run start', - // url: 'http://127.0.0.1:3000', - // reuseExistingServer: !process.env.CI, - // }, + webServer: { + command: 'npm run dev', + url: 'http://127.0.0.1:5173', + reuseExistingServer: !process.env.CI, + }, });