diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..cac4e468 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,26 @@ +name: Test + +on: + push: + pull_request: + branches: + - main + +jobs: + build: + name: Install deps + runs-on: ubuntu-latest + steps: + + test: + name: Test + runs-on: ubuntu-latest + env: + CI: true + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + - name: Install dependencies + run: npm ci + - name: Run root tests + run: npm run test:playwright diff --git a/.gitignore b/.gitignore index a21273d6..78414871 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,7 @@ docker-compose.yml # cookie file cookies.json + +# playwright results +test-results +playwright-report diff --git a/package.json b/package.json index 43e293f7..7a55a034 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "start": "node src/cobalt", "setup": "node src/modules/setup", "test": "node src/test/test", + "test:playwright": "npx playwright test", "build": "node src/modules/buildStatic", "testFilenames": "node src/test/testFilenamePresets" }, @@ -40,5 +41,8 @@ "undici": "^5.19.1", "url-pattern": "1.0.3", "youtubei.js": "^6.4.1" + }, + "devDependencies": { + "@playwright/test": "^1.40.1" } } diff --git a/playwright.config.js b/playwright.config.js new file mode 100644 index 00000000..bc198ba8 --- /dev/null +++ b/playwright.config.js @@ -0,0 +1,29 @@ +import { defineConfig, devices } from '@playwright/test'; + +export default defineConfig({ + fullyParallel: true, + retries: process.env.CI ? 2 : 0, + workers: process.env.CI ? 1 : undefined, + reporter: 'list', + testMatch: 'src/testPlaywright/**/*.spec.js', + use: { + // Base URL to use in actions like `await page.goto('/')`. + baseURL: 'http://127.0.0.1:9001', + trace: 'on-first-retry', + }, + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + ], + webServer: [{ + // Web + command: 'webURL=http://localhost:9001 apiURL=http://localhost:9000 node src/cobalt.js', + url: 'http://127.0.0.1:9001', + }, { + // API + command: 'apiURL=http://localhost:9000 node src/cobalt.js', + url: 'http://127.0.0.1:9000', + }] +}); diff --git a/src/testPlaywright/start.spec.js b/src/testPlaywright/start.spec.js new file mode 100644 index 00000000..89b17f7a --- /dev/null +++ b/src/testPlaywright/start.spec.js @@ -0,0 +1,15 @@ +import { test, expect } from '@playwright/test'; + +test.describe('initial setup', () => { + test('web app is up', async ({ page }) => { + await page.goto('/'); + + await expect(page).toHaveTitle(/cobalt/); + }); + test('api is up', async ({ request }) => { + const response = await request.get('http://localhost:9000/api/serverInfo') + const responseBody = JSON.parse(await response.text()) + + expect(responseBody.version).toBeDefined() + }); +})