Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
"doc-check": "node src/index.js doc-check",
"spell-check": "node src/index.js spell-check",
"test:node": "node src/index.js test -t node --cov",
"test:bun": "node src/index.js test -t bun",
"test:deno": "node src/index.js test -t deno",
"test:chrome": "node src/index.js test -t browser --cov",
"test:chrome-webworker": "node src/index.js test -t webworker",
Expand All @@ -242,6 +243,7 @@
"@types/mocha": "^10.0.0",
"@types/node": "^24.12.2",
"@typescript-eslint/parser": "^8.32.1",
"bun": "^1.3.14",
"buffer": "^6.0.3",
"bytes": "^3.1.0",
"c8": "^11.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default {
alias: 't',
describe: 'In which target environment to execute the tests',
array: true,
choices: ['node', 'deno', 'browser', 'webworker', 'electron-main', 'electron-renderer', 'react-native-android', 'react-native-ios'],
choices: ['node', 'bun', 'deno', 'browser', 'webworker', 'electron-main', 'electron-renderer', 'react-native-android', 'react-native-ios'],
default: userConfig.test.target
},
watch: {
Expand Down
95 changes: 95 additions & 0 deletions src/test/bun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { createRequire } from 'node:module'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { execa } from 'execa'
import fs from 'fs-extra'
import merge from '../utils/merge-options.js'
import { killIfProcessHangs } from './utils.js'

const require = createRequire(import.meta.url)
const __dirname = path.dirname(fileURLToPath(import.meta.url))

const mochaPackageFile = require.resolve('mocha/package.json')
const mochaManifest = fs.readJSONSync(mochaPackageFile)
const mochaBinary = path.join(path.dirname(mochaPackageFile), mochaManifest.bin._mocha)

const bunPackageFile = require.resolve('bun/package.json')
const bunManifest = fs.readJSONSync(bunPackageFile)
const bunBinary = path.join(path.dirname(bunPackageFile), bunManifest.bin.bun)

/**
* @typedef {import("execa").Options} ExecaOptions
* @typedef {import('../types.js').TestOptions} TestOptions
* @typedef {import('../types.js').GlobalOptions} GlobalOptions
*/

/**
* @param {TestOptions & GlobalOptions} argv
* @param {ExecaOptions} execaOptions
*/
export default async function testBun (argv, execaOptions) {
const progress = argv.progress ? ['--reporter=progress'] : []
const files = argv.files.length > 0
? argv.files
: [
'test/bun.*js',
'test/node.*js',
'test/**/*.spec.*js',
'test/bun.*ts',
'test/node.*ts',
'test/**/*.spec.*ts'
]

const args = [
mochaBinary,
...files,
...progress,
'--ui', 'bdd',
'--require', 'source-map-support/register',
`--timeout=${argv.timeout}`,
'--color', 'true'
]

if (argv.grep) {
args.push(`--grep=${argv.grep}`)
}

if (argv.watch) {
args.push('--watch')
}

if (argv.bail) {
args.push('--bail')
}

if (argv['--']) {
args.push(...argv['--'])
}

// before hook
const before = await argv.fileConfig.test.before(argv)
const beforeEnv = before && before.env ? before.env : {}

// run mocha
const proc = execa(bunBinary, args,
merge(
{
env: {
AEGIR_RUNNER: 'bun',
NODE_ENV: process.env.NODE_ENV || 'test',
...beforeEnv
},
preferLocal: true,
localDir: path.join(__dirname, '../..'),
stdio: argv.cov ? 'pipe' : 'inherit',
forceKillAfterDelay: 1_000
},
execaOptions
)
)

await killIfProcessHangs(proc, argv)

// after hook
await argv.fileConfig.test.after(argv, before)
}
14 changes: 14 additions & 0 deletions src/test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { execa } from 'execa'
import pMap from 'p-map'
import browser from './browser.js'
import bun from './bun.js'
import deno from './deno.js'
import electron from './electron.js'
import node from './node.js'
Expand All @@ -11,6 +12,7 @@ import rn from './react-native.js'
*/
const NO_BUILD = [
'node',
'bun',
'deno',
'electron-main',
'electron-renderer'
Expand Down Expand Up @@ -80,6 +82,18 @@ const TASKS = [
*/
enabled: (ctx) => ctx.target.includes('deno')
},
{
title: 'test bun',
/**
* @param {TestOptions & GlobalOptions} opts
* @param {ExecaOptions} execaOptions
*/
task: (opts, execaOptions) => bun({ ...opts, runner: 'bun' }, execaOptions),
/**
* @param {TestOptions & GlobalOptions} ctx
*/
enabled: (ctx) => ctx.target.includes('bun')
},
{
title: 'test browser',
/**
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ interface TestOptions {
/**
* In which target environment to execute the tests
*/
target: Array<'node' | 'deno' | 'browser' | 'webworker' | 'electron-main' | 'electron-renderer' | 'react-native-android' | 'react-native-ios'>
target: Array<'node' | 'bun' | 'deno' | 'browser' | 'webworker' | 'electron-main' | 'electron-renderer' | 'react-native-android' | 'react-native-ios'>
/**
* Watch files for changes and rerun tests
*/
Expand Down Expand Up @@ -257,7 +257,7 @@ interface TestOptions {
/**
* Runner environment
*/
runner: 'node' | 'deno' | 'browser' | 'webworker' | 'electron-main' | 'electron-renderer' | 'react-native-android' | 'react-native-ios'
runner: 'node' | 'bun' | 'deno' | 'browser' | 'webworker' | 'electron-main' | 'electron-renderer' | 'react-native-android' | 'react-native-ios'
/**
* Browser options
*/
Expand Down
Loading