Skip to content

Commit eed1dc2

Browse files
committed
added browser tests
1 parent 5d4c471 commit eed1dc2

File tree

4 files changed

+154
-0
lines changed

4 files changed

+154
-0
lines changed

.github/workflows/test-browser.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Browser Tests
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
branches: [ main ]
7+
jobs:
8+
tests:
9+
timeout-minutes: 10
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Setup Node 22.x
15+
uses: actions/setup-node@v4
16+
with:
17+
node-version: 22.x
18+
19+
- name: Install npm dependencies
20+
run: npm install -y
21+
22+
- name: Install Playwright Browsers
23+
run: npx playwright install --with-deps
24+
25+
- name: Run Playwright tests
26+
run: npx playwright test
27+
28+
- uses: actions/upload-artifact@v4
29+
if: always()
30+
with:
31+
name: playwright-report
32+
path: playwright-report/
33+
retention-days: 30

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
"homepage": "https://github.com/brainfoolong/js-aes-php",
1818
"devDependencies": {
19+
"@playwright/test": "^1.46.0",
1920
"typescript": "^5.5.4"
2021
},
2122
"engines": {

playwright.config.ts

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import type { PlaywrightTestConfig } from '@playwright/test'
2+
import { devices } from '@playwright/test'
3+
4+
/**
5+
* Read environment variables from file.
6+
* https://github.com/motdotla/dotenv
7+
*/
8+
// require('dotenv').config();
9+
10+
/**
11+
* See https://playwright.dev/docs/test-configuration.
12+
*/
13+
const config: PlaywrightTestConfig = {
14+
testDir: './tests',
15+
/* Maximum time one test can run for. */
16+
timeout: 30 * 1000,
17+
expect: {
18+
/**
19+
* Maximum time expect() should wait for the condition to be met.
20+
* For example in `await expect(locator).toHaveText();`
21+
*/
22+
timeout: 5000
23+
},
24+
/* Run tests in files in parallel */
25+
fullyParallel: true,
26+
/* Fail the build on CI if you accidentally left test.only in the source code. */
27+
forbidOnly: !!process.env.CI,
28+
/* Retry on CI only */
29+
retries: process.env.CI ? 2 : 0,
30+
/* Opt out of parallel tests on CI. */
31+
workers: process.env.CI ? 1 : undefined,
32+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
33+
reporter: 'html',
34+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
35+
use: {
36+
ignoreHTTPSErrors: true,
37+
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
38+
actionTimeout: 0,
39+
/* Base URL to use in actions like `await page.goto('/')`. */
40+
// baseURL: 'http://localhost:3000',
41+
42+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
43+
trace: 'on-first-retry',
44+
},
45+
46+
/* Configure projects for major browsers */
47+
projects: [
48+
{
49+
name: 'chromium',
50+
use: {
51+
...devices['Desktop Chrome'],
52+
},
53+
},
54+
55+
{
56+
name: 'firefox',
57+
use: {
58+
...devices['Desktop Firefox'],
59+
},
60+
},
61+
62+
{
63+
name: 'webkit',
64+
use: {
65+
...devices['Desktop Safari'],
66+
},
67+
},
68+
69+
/* Test against mobile viewports. */
70+
{
71+
name: 'Mobile Chrome',
72+
use: {
73+
...devices['Pixel 5'],
74+
},
75+
},
76+
{
77+
name: 'Mobile Safari',
78+
use: {
79+
...devices['iPhone 12'],
80+
},
81+
},
82+
83+
/* Test against branded browsers. */
84+
{
85+
name: 'Microsoft Edge',
86+
use: {
87+
channel: 'msedge',
88+
},
89+
},
90+
{
91+
name: 'Google Chrome',
92+
use: {
93+
channel: 'chrome',
94+
},
95+
},
96+
],
97+
98+
/* Folder for test artifacts such as screenshots, videos, traces, etc. */
99+
// outputDir: 'test-results/',
100+
101+
/* Run your local dev server before starting the tests */
102+
// webServer: {
103+
// command: 'npm run start',
104+
// port: 3000,
105+
// },
106+
}
107+
108+
export default config

tests/test-browser.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { expect, test } from '@playwright/test'
2+
3+
test('Run all tests', async ({ page }) => {
4+
page.on('console', msg => {
5+
if (msg.type() === 'error')
6+
throw new Error(`Console Error: "${msg.text()}"`)
7+
})
8+
await page.goto('http://127.0.0.1:6597/tests/test-browser.html')
9+
await expect(page.locator('#console')).toContainText('TEST SUCCESSFUL', { timeout: 20000 })
10+
await page.goto('http://127.0.0.1:6597/tests/test-browser-module.html')
11+
await expect(page.locator('#console')).toContainText('TEST SUCCESSFUL', { timeout: 20000 })
12+
})

0 commit comments

Comments
 (0)