-
Notifications
You must be signed in to change notification settings - Fork 132
Add browser CI workflow #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fcf57f4
e5536fe
a2942c0
fe4d57c
6492826
5a428cf
de4593c
270bfe3
96882f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| name: Browser CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: browser-${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| browser: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v7 | ||
|
|
||
| - uses: actions/setup-node@v7 | ||
| with: | ||
| node-version: "24" | ||
|
|
||
| - run: make -C browser install | ||
| - run: make -C browser test | ||
|
kawanet marked this conversation as resolved.
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Force bash so `set -o pipefail` works in the recipes below. | ||
| SHELL := bash | ||
| .SHELLFLAGS := -eo pipefail -c | ||
|
|
||
| PLAYWRIGHT_VERSION := 1.62.1 | ||
|
|
||
| TEST_SRC := ../test/[12]*.js ../test/6[12]*.js | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Bundling the Useful? React with 👍 / 👎. |
||
| TEST_DST := tests/bundled.js | ||
| BUFFER_SRC := ../node_modules/buffer/index.js | ||
| BUFFER_DST := tests/buffer.shim.js | ||
| ASSERT_SRC := ../node_modules/assert/assert.js | ||
| ASSERT_DST := tests/assert.shim.js | ||
|
|
||
| ALL := $(TEST_DST) $(BUFFER_DST) $(ASSERT_DST) | ||
|
|
||
| all: dist $(ALL) | ||
|
|
||
| bundled: all | ||
|
|
||
| # Keep Playwright out of package.json. CI installs it transiently alongside | ||
| # the project's build dependencies, then downloads only the headless shell. | ||
| install: | ||
| cd .. && PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install playwright@$(PLAYWRIGHT_VERSION) --no-save --ignore-scripts --no-audit --no-fund | ||
| cd .. && npx --no-install playwright install --with-deps --only-shell chromium | ||
|
|
||
| # tests.html loads the shipped bundle, so ask the root Makefile for it | ||
| # first; whether it rebuilds stays the root Makefile's decision. | ||
| dist: | ||
| $(MAKE) -C .. dist/msgpack.min.js | ||
|
|
||
| test: all | ||
| cd .. && node browser/tests.cli.mjs | ||
|
|
||
| $(TEST_DST): $(TEST_SRC) Makefile | ||
| mkdir -p $(dir $@) | ||
| ../node_modules/.bin/rollup $(TEST_SRC) --format iife \ | ||
| --plugin @rollup/plugin-commonjs \ | ||
| --plugin @rollup/plugin-multi-entry \ | ||
| --plugin @rollup/plugin-node-resolve \ | ||
| --external 'assert,../index' |\ | ||
| perl -pe 's#^}\)\(require.*\);#})(assert, msgpack)#' > $@ | ||
|
|
||
| $(BUFFER_DST): $(BUFFER_SRC) Makefile | ||
| mkdir -p $(dir $@) | ||
| ../node_modules/.bin/rollup $< --format iife \ | ||
| --plugin @rollup/plugin-commonjs \ | ||
| --plugin @rollup/plugin-node-resolve \ | ||
| --name "__BUFFER__" | \ | ||
| perl -pe 's#^var __BUFFER__#const {Buffer}#' > $@ | ||
|
|
||
| $(ASSERT_DST): $(ASSERT_SRC) Makefile | ||
| mkdir -p $(dir $@) | ||
| ../node_modules/.bin/rollup $< --format iife \ | ||
| --plugin @rollup/plugin-commonjs \ | ||
| --plugin @rollup/plugin-node-resolve \ | ||
| --name "assert" > $@ | ||
|
|
||
| clean: | ||
| /bin/rm -fr $(ALL) | ||
|
|
||
| .PHONY: all bundled dist install test clean | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import {chromium} from "playwright" | ||
| import {fileURLToPath, pathToFileURL} from "node:url" | ||
|
|
||
| const html = fileURLToPath(new URL("./tests.html", import.meta.url)) | ||
|
|
||
| const run = async () => { | ||
| const browser = await chromium.launch() | ||
|
|
||
| try { | ||
| const page = await browser.newPage() | ||
| const pageErrors = [] | ||
| page.on("pageerror", error => pageErrors.push(error)) | ||
|
|
||
| await page.goto(pathToFileURL(html).href) | ||
|
|
||
| // Completion is a state, not a promise: mocha.run() publishes its | ||
| // stats on window when done, and an unfinished or broken page just | ||
| // never does -- so this times out instead of passing. | ||
| await page.waitForFunction(() => window.mochaStats !== undefined, null, {timeout: 60_000}) | ||
| const {tests, passes, pending, failures, duration} = await page.evaluate(() => window.mochaStats) | ||
| console.log(`${passes} passing, ${failures} failing, ${pending} pending (${tests} tests, ${duration}ms)`) | ||
|
|
||
| if (pageErrors.length) { | ||
| throw new AggregateError(pageErrors, "Browser page errors occurred") | ||
| } | ||
| if (failures) { | ||
| throw new Error(`Mocha reported ${failures} failed test(s)`) | ||
| } | ||
| if (!tests) { | ||
| throw new Error("Mocha ran no tests") | ||
| } | ||
| } finally { | ||
| await browser.close() | ||
| } | ||
| } | ||
|
|
||
| run().catch(error => { | ||
| console.error(error) | ||
| process.exitCode = 1 | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"/> | ||
| <title>msgpack-lite browser test</title> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"/> | ||
| <link rel="stylesheet" href="../node_modules/mocha/mocha.css"/> | ||
| </head> | ||
| <body> | ||
| <div id="mocha"></div> | ||
| <script src="../node_modules/mocha/mocha.js"></script> | ||
| <script class="mocha-init"> | ||
| mocha.setup("bdd"); | ||
| mocha.checkLeaks(); | ||
| </script> | ||
| <script src="../dist/msgpack.min.js"></script> | ||
| <script src="./tests/assert.shim.js"></script> | ||
| <script src="./tests/buffer.shim.js"></script> | ||
| <script src="./tests/bundled.js"></script> | ||
| <script>const runner = mocha.run(() => (window.mochaStats = runner.stats));</script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,9 @@ | |
| "description": "Fast Pure JavaScript MessagePack Encoder and Decoder", | ||
| "version": "0.2.1", | ||
| "author": "@kawanet", | ||
| "allowScripts": { | ||
| "msgpackr-extract": false | ||
| }, | ||
|
Comment on lines
+6
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
On regular installs such as the Node CI workflow's Useful? React with 👍 / 👎.
Comment on lines
+6
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When developers or the existing Node.js CI run plain Useful? React with 👍 / 👎. |
||
| "bin": { | ||
| "msgpack": "./bin/msgpack" | ||
| }, | ||
|
|
@@ -29,15 +32,27 @@ | |
| }, | ||
| "devDependencies": { | ||
| "@msgpack/msgpack": "^3.1.3", | ||
| "@rollup/plugin-commonjs": "^29.0.3", | ||
| "@rollup/plugin-multi-entry": "^7.1.0", | ||
| "@rollup/plugin-node-resolve": "^16.0.3", | ||
| "assert": "^1.5.1", | ||
| "browserify": "^17.0.1", | ||
| "concat-stream": "^2.0.0", | ||
| "jshint": "^2.13.6", | ||
| "mocha": "^11.8.0", | ||
| "msgpack5": "^6.0.2", | ||
| "msgpackr": "^2.0.6", | ||
| "notepack.io": "^3.0.1", | ||
| "rollup": "^4.63.1", | ||
| "uglify-js": "^3.19.3" | ||
| }, | ||
| "devEngines": { | ||
| "runtime": { | ||
| "name": "node", | ||
| "version": ">=22.18.0", | ||
| "onFail": "warn" | ||
| } | ||
| }, | ||
| "files": [ | ||
| "LICENSE", | ||
| "README.md", | ||
|
|
@@ -85,5 +100,6 @@ | |
| "make": "make", | ||
| "size": "make clean dist/msgpack.min.js && gzip -9fkv dist/msgpack.min.js && ls -l dist", | ||
| "test": "make test" | ||
| } | ||
| }, | ||
| "type": "commonjs" | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This workflow only runs after a commit reaches
main(or when manually dispatched), so browser-only regressions introduced by a pull request cannot be detected before merge; the existing Node workflow does not executemake -C browser test. Add apull_requesttrigger so this new suite can serve as a pre-merge CI check.Useful? React with 👍 / 👎.