Skip to content

Commit

Permalink
test(ses): add a smoke test for SES lockdown in chrome dev
Browse files Browse the repository at this point in the history
  • Loading branch information
naugtur committed Jan 17, 2024
1 parent 5792949 commit c30c4e1
Show file tree
Hide file tree
Showing 5 changed files with 709 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/lockdown-smoke.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Lockdown Canary
## detects lockdown issues on latest chrome

on:
push:
branches:
- lockdown-canary
schedule:
- cron: '0 0 * * *' # Runs every day at midnight

jobs:
chrome-dev:
runs-on: ubuntu-latest
# runs-on: macos-latest
## chrome-canary is not supported on linux o_O
## but canary on mac won't connect

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Use Node.js stable
uses: actions/setup-node@v3

- name: Setup Chrome
uses: browser-actions/setup-chrome@v1
id: setup-chrome
with:
chrome-version: 'dev'

- name: build ses
run: |
cd ./packages/ses/
yarn
- name: install dependencies
run: |
cd ./packages/ses/smoke-test/
yarn install
- name: Run tests
run: |
${{ steps.setup-chrome.outputs.chrome-path }} --version
node ./packages/ses/smoke-test/index.js ${{ steps.setup-chrome.outputs.chrome-path }}
11 changes: 11 additions & 0 deletions packages/ses/smoke-test/fixture/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="../../dist/lockdown.umd.js"></script>
</body>
</html>
56 changes: 56 additions & 0 deletions packages/ses/smoke-test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* eslint-disable @endo/no-polymorphic-call */
/* global process */

import puppeteer from 'puppeteer-core';

Check failure on line 4 in packages/ses/smoke-test/index.js

View workflow job for this annotation

GitHub Actions / lint (16.x, ubuntu-latest)

Unable to resolve path to module 'puppeteer-core'
import assert from 'assert';

const chromePath = process.argv[2];
console.log(`chromePath ${chromePath}`);

let browser;

async function runTests() {
// Launch the browser
browser = await puppeteer.launch({
headless: 'new',
executablePath: chromePath,
protocolTimeout: 30000,
});

// Open a new page
const page = await browser.newPage();
page.on('pageerror', async err => {
console.error(`Page error: ${err.toString()}`);
});

const pathToIndex = new URL('./fixture/index.html', import.meta.url).href;
console.log(`opening ${pathToIndex}`);

await page.goto(pathToIndex, { waitUntil: 'domcontentloaded' });
// await page.goto(pathToIndex);
// await page.goto(pathToIndex, { waitUntil: 'load' });

assert.equal(
await page.evaluate(`typeof lockdown;`),
'function',
'lockdown is not a function. did you build and include SES?',
);
const result = await page.evaluate(`
try {
lockdown();
'success';
}
catch (e) {
e.toString();
}
`);
assert.equal(result, 'success', 'lockdown failed');

await browser.close();
}

runTests().catch(error => {
console.error(error);
browser && browser.close();
process.exit(1);
});
11 changes: 11 additions & 0 deletions packages/ses/smoke-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "ses-smoke-test",
"version": "1.0.1",
"description": "Browser smoke test for SES lockdown",
"license": "Apache-2.0",
"type": "module",
"dependencies": {
"puppeteer-core": "^21.7.0"
},
"private": true
}
Loading

0 comments on commit c30c4e1

Please sign in to comment.