Skip to content

Commit

Permalink
Switch ci to github actions (Strilanc#459)
Browse files Browse the repository at this point in the history
- Use puppeteer to run unit tests
  • Loading branch information
Strilanc authored Sep 14, 2020
1 parent 1b9172b commit d995a7a
Show file tree
Hide file tree
Showing 7 changed files with 3,850 additions and 23 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: ci
on: [push]
jobs:
build-and-run-unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
- run: npm install
- run: grunt build-test-page
- run: node PuppeteerRunTests.js
screenshot-circuit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
- run: npm install
- run: npm run build
- run: node PuppeteerScreenshotCircuit.js
- uses: actions/upload-artifact@v2
with:
name: screenshot
path: screenshot.png
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

27 changes: 27 additions & 0 deletions PuppeteerRunTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const puppeteer = require('puppeteer');

(async () => {
try {
const browser = await puppeteer.launch();
const page = await browser.newPage();
let caughtPageError = false;
page.on('console', message => console.log(message.text()));
page.on('pageerror', ({message}) => {
caughtPageError = true;
console.error("Page error bubbled into PuppeteerRunTests.js: " + message);
});

const outDirUrl = 'file:///' + __dirname.split('\\').join('/') + '/out/';
await page.goto(outDirUrl + 'test.html#blocking');
await page.waitForSelector('#done', {timeout: 5 * 60 * 1000});
let anyFailures = await page.evaluate('__any_failures');

await browser.close();
if (anyFailures || caughtPageError) {
process.exit(1);
}
} catch (ex) {
console.error("Error bubbled up into PuppeteerRunTests.js: " + ex);
process.exit(1);
}
})();
23 changes: 23 additions & 0 deletions PuppeteerScreenshotCircuit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const puppeteer = require('puppeteer');

(async () => {
try {
const browser = await puppeteer.launch();
const page = await browser.newPage();
let caughtPageError = false;
page.on('console', message => console.log(message.text()));
page.on('pageerror', ({message}) => {
caughtPageError = true;
console.error("Page error bubbled into PuppeteerSampleCircuit.js: " + message);
});
const outDirUrl = 'file:///' + __dirname.split('\\').join('/') + '/out/';
const circuitJson = '{"cols":[["H"],["Bloch"],["Amps1"],[],["Density"],["•","X"],["Chance2"]]}';
await page.goto(outDirUrl + 'quirk.html#circuit=' + circuitJson);
await page.waitForSelector('#loading-div', {visible: false, timeout: 5 * 1000});
await page.screenshot({path: 'screenshot.png'});
await browser.close();
} catch (ex) {
console.error("Error bubbled up into PuppeteerSampleCircuit.js: " + ex);
process.exit(1);
}
})();
Loading

0 comments on commit d995a7a

Please sign in to comment.