Skip to content

Commit 7f2dc62

Browse files
author
Shane Osbourne
committed
adding playwright tests
1 parent 2e2fdc6 commit 7f2dc62

File tree

13 files changed

+664
-4
lines changed

13 files changed

+664
-4
lines changed

.github/workflows/main.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,13 @@ jobs:
3939
run: npm test
4040
- name: Test E2E
4141
run: npm run test:e2e
42+
- name: Install Playwright Browsers
43+
run: npx playwright install --with-deps
44+
- name: Run Playwright tests
45+
run: npm test:playwright
46+
- uses: actions/upload-artifact@v3
47+
if: always()
48+
with:
49+
name: playwright-report
50+
path: playwright-report/
51+
retention-days: 30

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ client/dist/index.js
2525
client/dist/index.js.map
2626
client/dist/index.min.js
2727
client/dist/index.min.js.map
28+
node_modules/
29+
/test-results/
30+
/playwright-report/
31+
/playwright/.cache/

examples/basic/run.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const bs = require("../../packages/browser-sync/dist/index").create();
2+
const path = require("path");
3+
const serverDir = path.join(__dirname, "..", "..", "packages/browser-sync/test/fixtures");
4+
5+
bs.init(
6+
{
7+
server: serverDir,
8+
open: false,
9+
watch: true,
10+
online: false
11+
},
12+
(err, bs) => {
13+
const message = {
14+
kind: "ready",
15+
urls: bs.options.get("urls").toJS(),
16+
cwd: serverDir
17+
};
18+
if (process.send) {
19+
process.send(message);
20+
} else {
21+
console.log(message);
22+
}
23+
}
24+
);

examples/snippet/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta
6+
name="viewport"
7+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
8+
/>
9+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
10+
<title>Document</title>
11+
</head>
12+
<body>
13+
<h1>Hello world</h1>
14+
</body>
15+
</html>

examples/snippet/run.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const bs = require("../../packages/browser-sync/dist/index").create();
2+
bs.init(
3+
{
4+
server: ".",
5+
open: false,
6+
notify: false,
7+
watch: true,
8+
snippetOptions: {
9+
rule: {
10+
match: /<\/head>/i,
11+
fn: function(snippet, match) {
12+
return snippet + match;
13+
}
14+
}
15+
}
16+
},
17+
(err, bs) => {
18+
const message = {
19+
kind: "ready",
20+
urls: bs.options.get("urls").toJS(),
21+
cwd: __dirname
22+
};
23+
if (process.send) {
24+
process.send(message);
25+
} else {
26+
console.log(message);
27+
}
28+
}
29+
);

package-lock.json

Lines changed: 60 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
"bootstrap": "lerna bootstrap",
66
"postinstall": "npm run bootstrap",
77
"test": "lerna run build && lerna run test --scope browser-sync",
8-
"test:e2e": "cb cy:file-reloading cy:ui-remote-debug cy:connection-notify"
8+
"test:e2e": "echo skipping cypress",
9+
"test:playwright": "playwright test"
910
},
1011
"devDependencies": {
1112
"lerna": "^6.1.0"
1213
},
1314
"dependencies": {
15+
"@playwright/test": "^1.37.1",
1416
"crossbow": "^4.6.0",
1517
"cypress": "^9.5.1",
16-
"rxjs": "^7.5.4"
18+
"rxjs": "^7.5.4",
19+
"zod": "^3.22.2"
1720
},
18-
"nx": {}
21+
"nx": {}
1922
}

playwright.config.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { defineConfig, devices } from "@playwright/test";
2+
3+
/**
4+
* See https://playwright.dev/docs/test-configuration.
5+
*/
6+
export default defineConfig({
7+
testDir: "./tests",
8+
/* Run tests in files in parallel */
9+
fullyParallel: true,
10+
/* Fail the build on CI if you accidentally left test.only in the source code. */
11+
forbidOnly: !!process.env.CI,
12+
/* Retry on CI only */
13+
retries: process.env.CI ? 2 : 0,
14+
/* Opt out of parallel tests on CI. */
15+
workers: process.env.CI ? 1 : 1,
16+
// workers: 1,
17+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
18+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
19+
use: {
20+
/* Base URL to use in actions like `await page.goto('/')`. */
21+
// baseURL: 'http://127.0.0.1:3000',
22+
23+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
24+
trace: "on-first-retry"
25+
},
26+
projects: [
27+
{
28+
name: "snippet-options",
29+
use: {
30+
...devices["Desktop Chrome"]
31+
},
32+
testDir: "tests/examples/snippet"
33+
},
34+
{
35+
name: "basic",
36+
use: {
37+
...devices["Desktop Chrome"]
38+
},
39+
testDir: "tests/examples/basic"
40+
},
41+
]
42+
});

0 commit comments

Comments
 (0)