-
Notifications
You must be signed in to change notification settings - Fork 37
feat: add Bun test runner support #396
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
base: master
Are you sure you want to change the base?
Changes from all commits
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,52 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [master] | ||
| pull_request: | ||
| branches: [master] | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| strategy: | ||
| matrix: | ||
| node-version: [20] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Use Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
| cache: 'npm' | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install --legacy-peer-deps | ||
|
|
||
| - name: Lint | ||
| run: npm run lint | ||
|
|
||
| - name: Typecheck | ||
| run: npm run typecheck | ||
|
|
||
| - name: Test | ||
| run: npm test | ||
|
|
||
| bun-test: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Bun | ||
| uses: oven-sh/setup-bun@v2 | ||
|
|
||
| - name: Install dependencies | ||
| run: bun install | ||
|
|
||
| - name: Run Bun tests | ||
| run: bun test source/bun.test.js |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| declare module 'riteway/bun' { | ||
| interface Assertion<T> { | ||
| readonly given: string; | ||
| readonly should: string; | ||
| readonly actual: T; | ||
| readonly expected: T; | ||
| } | ||
|
|
||
| export function assert<T>(assertion: Assertion<T>): void; | ||
|
|
||
| /** | ||
| * Setup function to extend Bun's expect with a custom RITEway matcher. | ||
| * Call this once in your test setup file or at the top of test files. | ||
| */ | ||
| export function setupRitewayBun(): void; | ||
|
|
||
| // Re-export test and describe from bun:test | ||
| export { test, describe } from 'bun:test'; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { expect, test, describe } from 'bun:test'; | ||
|
|
||
| export { test, describe }; | ||
|
|
||
| const requiredKeys = ['given', 'should', 'actual', 'expected']; | ||
|
|
||
| /** | ||
| * Setup function to extend Bun's expect with a custom RITEway matcher. | ||
| * Call this once in your test setup file or at the top of test files. | ||
| */ | ||
| export const setupRitewayBun = () => { | ||
| expect.extend({ | ||
| toRitewayEqual(received, expected, given, should) { | ||
| const pass = this.equals(received, expected); | ||
|
|
||
| if (pass) { | ||
| return { pass: true }; | ||
| } | ||
|
|
||
| return { | ||
| pass: false, | ||
| message: () => | ||
| `Given ${given}: should ${should}\n\nExpected: ${this.utils.printExpected(expected)}\nReceived: ${this.utils.printReceived(received)}`, | ||
| }; | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| /** | ||
| * Assert function compatible with Bun's expect, using the custom matcher. | ||
| * @param {Object} args - Assertion object with given, should, actual, expected. | ||
| */ | ||
| export const assert = (args = {}) => { | ||
| const missing = requiredKeys.filter((k) => !Object.keys(args).includes(k)); | ||
| if (missing.length) { | ||
| throw new Error( | ||
| `The following parameters are required by \`assert\`: ${missing.join(', ')}` | ||
| ); | ||
| } | ||
|
|
||
| const { given, should, actual, expected } = args; | ||
| expect(actual).toRitewayEqual(expected, given, should); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { test, describe, assert, setupRitewayBun } from './bun.js'; | ||
|
|
||
| setupRitewayBun(); | ||
|
|
||
| describe('riteway/bun', () => { | ||
| test('given: matching primitives, should: pass', () => { | ||
| assert({ | ||
| given: 'two identical numbers', | ||
| should: 'be equal', | ||
| actual: 42, | ||
| expected: 42, | ||
| }); | ||
| }); | ||
|
|
||
| test('given: matching strings, should: pass', () => { | ||
| assert({ | ||
| given: 'two identical strings', | ||
| should: 'be equal', | ||
| actual: 'hello', | ||
| expected: 'hello', | ||
| }); | ||
| }); | ||
|
|
||
| test('given: matching objects, should: pass', () => { | ||
| assert({ | ||
| given: 'two identical objects', | ||
| should: 'be deeply equal', | ||
| actual: { name: 'Bun', version: 1.1 }, | ||
| expected: { name: 'Bun', version: 1.1 }, | ||
| }); | ||
| }); | ||
|
|
||
| test('given: matching arrays, should: pass', () => { | ||
| assert({ | ||
| given: 'two identical arrays', | ||
| should: 'be deeply equal', | ||
| actual: [1, 2, 3], | ||
| expected: [1, 2, 3], | ||
| }); | ||
| }); | ||
|
|
||
| test('given: nested structures, should: pass', () => { | ||
| assert({ | ||
| given: 'two identical nested structures', | ||
| should: 'be deeply equal', | ||
| actual: { users: [{ name: 'Alice' }, { name: 'Bob' }] }, | ||
| expected: { users: [{ name: 'Alice' }, { name: 'Bob' }] }, | ||
| }); | ||
| }); | ||
| }); | ||
|
Comment on lines
+1
to
+50
|
||
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.
For consistency with the vitest adapter (which has exports at lines 54-66 including "./esm/vitest.js" and "./esm/vitest.test.jsx"), consider adding corresponding esm exports for the bun adapter. This would include:
These exports appear to support the package's esm build process (see the "esm" script at line 77).