Skip to content

Commit

Permalink
Run headless browser tests in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Nov 30, 2024
1 parent 3dc2547 commit 74fbd12
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
- run: npm config set fund false
- run: make tests
- run: make integration-tests
- run: npx playwright install chromium
- run: make browser-tests-headless
- run: make lint
benchmark:
runs-on: ubuntu-22.04
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ else
@echo Open "build/js/index.html" in your browser.
endif

browser-tests-headless: node_modules $(BUILDDIR)/$(JSON_ACIS) $(BUILDDIR)/$(BYTECODES)
npm run test:browser

integration-tests: $(INTEGRATION_TESTS) | node_modules $(BUILDDIR)/$(JSON_ACIS)
@for file in $^; do bash $${file}; done

Expand Down
48 changes: 48 additions & 0 deletions package-lock.json

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

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"eslint-plugin-import": "2.29.1",
"html-webpack-plugin": "^5.6.3",
"nyc": "17.0.0",
"playwright": "^1.49.0",
"process": "^0.11.10",
"stream-browserify": "^3.0.0",
"tape": "5.8.1",
Expand All @@ -64,7 +65,8 @@
"files": [
"tests/**/*",
"!tests/test.js",
"!tests/benchmark/*"
"!tests/benchmark/*",
"!tests/browser/run.js"
]
},
"nyc": {
Expand All @@ -81,6 +83,7 @@
"prepare": "npm run build",
"test": "ava --verbose",
"test:watch": "ava --verbose --watch",
"test:browser": "npm run browser-test-bundle && node ./tests/browser/run.js",
"lint": "eslint src tests"
}
}
21 changes: 21 additions & 0 deletions tests/browser/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import path from 'path'
import { chromium } from 'playwright'

const browser = await chromium.launch()
const page = await browser.newPage()
await page.goto(`file://${path.resolve('./build/js/index.html')}`)

page.on('console', async (msg) => {
const text = msg.text()
console.log(text) // eslint-disable-line no-console

if (text.startsWith('# fail')) {
await browser.close()
process.exit(+text.replace('# fail', ''))
}

if (text === '# ok') {
await browser.close()
process.exit(0)
}
})

0 comments on commit 74fbd12

Please sign in to comment.