feat: add initial playwright/test setup and tests

This commit is contained in:
ndom91 2023-12-19 13:29:43 +01:00
parent 16397aed89
commit 0a7773bd61
5 changed files with 78 additions and 0 deletions

26
.github/workflows/test.yml vendored Normal file
View File

@ -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

4
.gitignore vendored
View File

@ -24,3 +24,7 @@ docker-compose.yml
# cookie file # cookie file
cookies.json cookies.json
# playwright results
test-results
playwright-report

View File

@ -12,6 +12,7 @@
"start": "node src/cobalt", "start": "node src/cobalt",
"setup": "node src/modules/setup", "setup": "node src/modules/setup",
"test": "node src/test/test", "test": "node src/test/test",
"test:playwright": "npx playwright test",
"build": "node src/modules/buildStatic", "build": "node src/modules/buildStatic",
"testFilenames": "node src/test/testFilenamePresets" "testFilenames": "node src/test/testFilenamePresets"
}, },
@ -40,5 +41,8 @@
"undici": "^5.19.1", "undici": "^5.19.1",
"url-pattern": "1.0.3", "url-pattern": "1.0.3",
"youtubei.js": "^6.4.1" "youtubei.js": "^6.4.1"
},
"devDependencies": {
"@playwright/test": "^1.40.1"
} }
} }

29
playwright.config.js Normal file
View File

@ -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',
}]
});

View File

@ -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()
});
})