Skip to content

Commit

Permalink
chore: Add Playwright tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Feb 8, 2024
1 parent 4d06da4 commit 217e947
Show file tree
Hide file tree
Showing 8 changed files with 388 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/browser-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Browser Tests
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
browser-tests:
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: yarn install
- name: Build artifacts
run: yarn build
- name: Install browser test dependencies
working-directory: browser-test
run: npm ci
- name: Install Playwright Browsers
working-directory: browser-test
run: npx playwright install --with-deps
- name: Run Playwright tests
working-directory: browser-test
run: npx playwright test
- uses: actions/upload-artifact@v3
if: always()
with:
name: browser-test-report
path: browser-test/playwright-report/
retention-days: 30
5 changes: 5 additions & 0 deletions browser-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
7 changes: 7 additions & 0 deletions browser-test/assets/endo-bundled-ses.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!doctype html>
<title>Testing</title>
<script src="../../packages/ses/dist/ses.umd.js"></script>
<script>
lockdown();
document.querySelector('title').innerText = 'Pass';
</script>
15 changes: 15 additions & 0 deletions browser-test/debug-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const path = require('path');
const http = require('http');
const handler = require('serve-handler');

const config = {
public: path.resolve(__dirname, '..'),
};

const server = http.createServer((request, response) =>
handler(request, response, config));

server.listen(0, '127.0.0.1', () => {
const { port } = server.address();
console.log(`http://127.0.0.1:${port}`);
});
205 changes: 205 additions & 0 deletions browser-test/package-lock.json

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

14 changes: 14 additions & 0 deletions browser-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "browser-test",
"private": true,
"author": "Endo Contributors",
"license": "Apache-2.0",
"scripts": {
"test": "playwright test"
},
"devDependencies": {
"serve-handler": "^6.1.5",
"@playwright/test": "^1.41.2",
"@types/node": "^20.11.16"
}
}
79 changes: 79 additions & 0 deletions browser-test/playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// @ts-check
const { defineConfig, devices } = require('@playwright/test');

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = 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 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* 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',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});

29 changes: 29 additions & 0 deletions browser-test/tests/canary.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// @ts-check
const path = require('path');
const http = require('http');
const handler = require('serve-handler');
const { test, expect } = require('@playwright/test');

const config = {
public: path.resolve(__dirname, '..', '..'),
};

const server = http.createServer((request, response) => handler(request, response, config));
const listening = new Promise((resolve, reject) => {
server.listen(0, '127.0.0.1', error => {
if (error) {
reject(error);
} else {
resolve(server.address());
}
});
});

test('bundled-ses lockdown runs to completion', async ({ page }) => {
const { address, port } = await listening;

await page.goto(`http://${address}:${port}/browser-test/assets/endo-bundled-ses`);

// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Pass/);
});

0 comments on commit 217e947

Please sign in to comment.