Skip to content

Commit e6b0171

Browse files
author
Aaron Hardy
committed
test: migrate to Vitest Browser Mode + Playwright and streamline test
suite` - replace Karma/custom runner with Vitest Browser Mode + Playwright (chromium/firefox/edge/webkit) - add Playwright file-protocol test runner and CI browser matrix - clean up/rename test structure (`manual` -> `fileProtocol`, `types-test` -> `types`, script naming to camelCase) - simplify fixtures and remove dead/legacy test artifacts - centralize test cleanup in `test/setup.ts` and simplify `globalSetup` to single fixture port - remove redundant invariant/property suite and tighten communication coverage - modernize type tests (`expectTypeOf`, `assertType` from Vitest) and keep negative checks via `@ts-expect-error` - add `CONTRIBUTING.md` with full script docs and keep README consumer-focused
1 parent 3acb681 commit e6b0171

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+5982
-6432
lines changed

.github/workflows/tests.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
browser:
11+
name: Browser (${{ matrix.browser }})
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
include:
17+
- browser: chromium
18+
os: ubuntu-latest
19+
- browser: firefox
20+
os: ubuntu-latest
21+
- browser: webkit
22+
os: ubuntu-latest
23+
- browser: edge
24+
os: windows-latest
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Setup Node
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: 22
33+
cache: npm
34+
35+
- name: Install dependencies
36+
run: npm ci
37+
38+
- name: Install Playwright browsers (Linux)
39+
if: runner.os == 'Linux'
40+
run: npx playwright install --with-deps chromium firefox webkit
41+
42+
- name: Run browser tests
43+
run: npm run test:${{ matrix.browser }}
44+
45+
types:
46+
name: Type Tests
47+
runs-on: ubuntu-latest
48+
steps:
49+
- name: Checkout
50+
uses: actions/checkout@v4
51+
52+
- name: Setup Node
53+
uses: actions/setup-node@v4
54+
with:
55+
node-version: 22
56+
cache: npm
57+
58+
- name: Install dependencies
59+
run: npm ci
60+
61+
- name: Run type tests
62+
run: npm run test:types

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
npx lint-staged
55
npm run test
6+
npm run test:types

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ dist
22
lib
33
cjs
44
package-lock.json
5+
test/childFixtures/vendor/**

CONTRIBUTING.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Contributing to Penpal
2+
3+
Thanks for contributing to Penpal.
4+
5+
## Development Setup
6+
7+
1. Install dependencies:
8+
- `npm install`
9+
2. Run tests:
10+
- `npm test`
11+
12+
## Testing Overview
13+
14+
Penpal uses Vitest Browser Mode with Playwright for browser-based tests.
15+
16+
- Browser suites live in `test/**/*.spec.ts`.
17+
- File-protocol tests live in `test/fileProtocol` and are run via `scripts/testFileProtocol.js`.
18+
- Type tests live in `test/types` and run via `tsc --noEmit`.
19+
20+
By default, `npm test` runs Chromium coverage (`test:chromium`), which includes both:
21+
22+
- the main browser suite
23+
- the file-protocol test
24+
25+
Additional browser runs:
26+
27+
- `npm run test:firefox`
28+
- `npm run test:webkit`
29+
- `npm run test:edge` (requires Microsoft Edge installed locally)
30+
31+
To run the full browser matrix:
32+
33+
- `npm run test:all-browsers`
34+
35+
## NPM Scripts
36+
37+
All scripts below are defined in `package.json`.
38+
39+
- `npm run build`
40+
- Builds ESM, CJS, and IIFE bundles, then builds a minified IIFE bundle.
41+
- `npm run build:analysis`
42+
- Prints minified bundle size analysis for `dist/penpal.min.js`.
43+
- `npm run lint`
44+
- Runs ESLint with autofix and cache enabled.
45+
- `npm run format`
46+
- Runs Prettier on JSON, TS, JS, CJS, Markdown, and HTML files.
47+
- `npm test`
48+
- Alias for `npm run test:chromium`.
49+
- `npm run test:watch`
50+
- Alias for `npm run test:watch:chromium`.
51+
- `npm run prepublishOnly`
52+
- Runs formatting, linting, Chromium tests, type tests, and build before publish.
53+
- `npm run prepare`
54+
- Installs Husky git hooks.
55+
- `npm run test:watch:chromium`
56+
- Runs Vitest Browser Mode in watch mode using Chromium.
57+
- `npm run test:chromium:browser`
58+
- Runs the main browser test suite in Chromium.
59+
- `npm run test:firefox:browser`
60+
- Runs the main browser test suite in Firefox.
61+
- `npm run test:edge:browser`
62+
- Runs the main browser test suite in Edge channel via Playwright.
63+
- `npm run test:webkit:browser`
64+
- Runs the main browser test suite in WebKit.
65+
- `npm run test:file`
66+
- Runs file-protocol tests using the browser selected by `BROWSER`.
67+
- `npm run test:file:chromium`
68+
- Runs file-protocol tests in Chromium.
69+
- `npm run test:file:firefox`
70+
- Runs file-protocol tests in Firefox.
71+
- `npm run test:file:edge`
72+
- Runs file-protocol tests in Edge.
73+
- `npm run test:file:webkit`
74+
- Runs file-protocol tests in WebKit.
75+
- `npm run test:chromium`
76+
- Runs Chromium browser suite and Chromium file-protocol tests.
77+
- `npm run test:firefox`
78+
- Runs Firefox browser suite and Firefox file-protocol tests.
79+
- `npm run test:edge`
80+
- Runs Edge browser suite and Edge file-protocol tests.
81+
- `npm run test:webkit`
82+
- Runs WebKit browser suite and WebKit file-protocol tests.
83+
- `npm run test:all-browsers`
84+
- Runs Chromium, Firefox, Edge, and WebKit full test commands.
85+
- `npm run test:types`
86+
- Runs TypeScript type tests with `tsconfig.typesTest.json`.
87+
- `npm run test:legacy:vendor -- <6.x.x-version>`
88+
- Downloads and vendors a Penpal 6 build used by backward-compatibility fixtures.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,3 +872,7 @@ This library is inspired by:
872872
## License
873873

874874
MIT
875+
876+
## Contributing
877+
878+
If you'd like to contribute or run the full local test/build workflows, see [CONTRIBUTING.md](./CONTRIBUTING.md).

eslint.config.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default tseslint.config(
2626
},
2727
},
2828
{
29-
ignores: ['dist/', 'lib/', 'cjs/'],
29+
ignores: ['dist/', 'lib/', 'cjs/', 'test/childFixtures/vendor/**'],
3030
},
3131
{
3232
files: ['*.cjs'],
@@ -38,17 +38,44 @@ export default tseslint.config(
3838
},
3939
},
4040
{
41-
files: ['test/types-test/**/*'],
41+
files: ['test/types/**/*'],
4242
rules: {
4343
'@typescript-eslint/no-unused-vars': 'off',
4444
},
4545
},
4646
{
47-
files: ['scripts/**/*', 'karma.conf.cjs'],
47+
files: ['scripts/**/*', 'vitest.browser.config.ts'],
4848
languageOptions: {
4949
ecmaVersion: ECMA_VERSION,
5050
globals: globals.node,
5151
},
52+
rules: {
53+
'import/extensions': 'off',
54+
},
55+
},
56+
{
57+
files: ['test/childFixtures/workers/**/*.js'],
58+
languageOptions: {
59+
globals: {
60+
...globals.worker,
61+
...globals.serviceworker,
62+
Penpal: 'readonly',
63+
},
64+
},
65+
rules: {
66+
'@typescript-eslint/no-empty-function': 'off',
67+
},
68+
},
69+
{
70+
files: ['test/childFixtures/pages/**/*.js'],
71+
languageOptions: {
72+
globals: {
73+
...globals.browser,
74+
Penpal: 'readonly',
75+
PenpalFixture: 'readonly',
76+
PenpalLegacyFixture: 'readonly',
77+
},
78+
},
5279
},
5380
// See https://www.npmjs.com/package/eslint-plugin-unused-imports
5481
{

karma.conf.cjs

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)