Skip to content

Commit

Permalink
feat: support testing on bun (#18)
Browse files Browse the repository at this point in the history
Run node tests with bun using env var `NODE_EXEC=bun`

---------

Co-authored-by: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com>
  • Loading branch information
achingbrain and SgtPooki committed Apr 23, 2024
1 parent 58f9c4d commit 73085b7
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bin/test-node-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { execa } from 'execa'

for (const file of process.argv.slice(2)) {
// run test
await execa('node', [file], {
await execa(process.env.NODE_EXEC ?? 'node', [file], {
stdio: 'inherit'
})
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@
"scripts": {
"clean": "aegir clean",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"dep-check": "aegir dep-check -i bun",
"build": "aegir build --bundle false",
"test:node": "aegir test -t node -f ./dist/test/node.spec.js",
"test:node": "aegir test -t node -f ./dist/test/node.spec.js -f ./dist/test/bun.spec.js",
"test:chrome": "aegir test -t node -f ./dist/test/browser.spec.js",
"release": "aegir release",
"docs": "aegir docs"
Expand All @@ -176,6 +176,7 @@
"uint8arrays": "^5.0.1"
},
"devDependencies": {
"aegir": "^42.2.3"
"aegir": "^42.2.3",
"bun": "^1.1.3"
}
}
3 changes: 2 additions & 1 deletion src/node/match-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export async function matchOutput (matcher: RegExp, command: string, args: strin
const proc = execaUtil(command, args, { ...opts, all: true }, (exec) => {
exec.all?.on('data', (data) => {
process.stdout.write(data)
output += uint8ArrayToString(data)

output += typeof data === 'string' ? data : uint8ArrayToString(data)

const matches = matcher.exec(output)

Expand Down
2 changes: 1 addition & 1 deletion src/node/wait-for-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function waitForOutput (expectedOutput: string, command: string, ar
const proc = execaUtil(command, args, { ...opts, all: true }, (exec) => {
exec.all?.on('data', (data) => {
process.stdout.write(data)
output += uint8ArrayToString(data)
output += typeof data === 'string' ? data : uint8ArrayToString(data)

if (output.includes(expectedOutput)) {
foundExpectedOutput = true
Expand Down
41 changes: 41 additions & 0 deletions test/bun.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { execa } from 'execa'

describe('bun', function () {
// slow CI is slow
this.timeout(540000)
this.slow(60000)

it('should match output', async () => {
await execa('./bin/test-node-example.js', [
'./test/fixtures/node/match-output.spec.js'
], {
stdio: 'inherit',
env: {
NODE_EXEC: 'bun'
}
})
})

it('should wait for output', async () => {
await execa('./bin/test-node-example.js', [
'./test/fixtures/node/wait-for-output.spec.js'
], {
stdio: 'inherit',
env: {
NODE_EXEC: 'bun'
}
})
})

it('should test multiple files', async () => {
await execa('./bin/test-node-example.js', [
'./test/fixtures/node/wait-for-output.spec.js',
'./test/fixtures/node/match-output.spec.js'
], {
stdio: 'inherit',
env: {
NODE_EXEC: 'bun'
}
})
})
})

0 comments on commit 73085b7

Please sign in to comment.