Skip to content

Commit

Permalink
adding playwright tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Osbourne committed Sep 9, 2023
1 parent 2e2fdc6 commit 7f2dc62
Show file tree
Hide file tree
Showing 13 changed files with 664 additions and 4 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,13 @@ jobs:
run: npm test
- name: Test E2E
run: npm run test:e2e
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npm test:playwright
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ client/dist/index.js
client/dist/index.js.map
client/dist/index.min.js
client/dist/index.min.js.map
node_modules/
/test-results/
/playwright-report/
/playwright/.cache/
24 changes: 24 additions & 0 deletions examples/basic/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const bs = require("../../packages/browser-sync/dist/index").create();
const path = require("path");
const serverDir = path.join(__dirname, "..", "..", "packages/browser-sync/test/fixtures");

bs.init(
{
server: serverDir,
open: false,
watch: true,
online: false
},
(err, bs) => {
const message = {
kind: "ready",
urls: bs.options.get("urls").toJS(),
cwd: serverDir
};
if (process.send) {
process.send(message);
} else {
console.log(message);
}
}
);
15 changes: 15 additions & 0 deletions examples/snippet/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
/>
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
<h1>Hello world</h1>
</body>
</html>
29 changes: 29 additions & 0 deletions examples/snippet/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const bs = require("../../packages/browser-sync/dist/index").create();
bs.init(
{
server: ".",
open: false,
notify: false,
watch: true,
snippetOptions: {
rule: {
match: /<\/head>/i,
fn: function(snippet, match) {
return snippet + match;
}
}
}
},
(err, bs) => {
const message = {
kind: "ready",
urls: bs.options.get("urls").toJS(),
cwd: __dirname
};
if (process.send) {
process.send(message);
} else {
console.log(message);
}
}
);
61 changes: 60 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
"bootstrap": "lerna bootstrap",
"postinstall": "npm run bootstrap",
"test": "lerna run build && lerna run test --scope browser-sync",
"test:e2e": "cb cy:file-reloading cy:ui-remote-debug cy:connection-notify"
"test:e2e": "echo skipping cypress",
"test:playwright": "playwright test"
},
"devDependencies": {
"lerna": "^6.1.0"
},
"dependencies": {
"@playwright/test": "^1.37.1",
"crossbow": "^4.6.0",
"cypress": "^9.5.1",
"rxjs": "^7.5.4"
"rxjs": "^7.5.4",
"zod": "^3.22.2"
},
"nx": {}
"nx": {}
}
42 changes: 42 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { defineConfig, devices } from "@playwright/test";

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: "./tests",
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : 1,
// workers: 1,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
/* 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',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry"
},
projects: [
{
name: "snippet-options",
use: {
...devices["Desktop Chrome"]
},
testDir: "tests/examples/snippet"
},
{
name: "basic",
use: {
...devices["Desktop Chrome"]
},
testDir: "tests/examples/basic"
},
]
});

0 comments on commit 7f2dc62

Please sign in to comment.