Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ jobs:
with:
node-version: lts/*
cache: "pnpm"

- name: Setup Bun
uses: oven-sh/setup-bun@735343b667d3e6f658f44d0eca948eb6282f2b76 # v2.0.2
with:
bun-version: latest

- name: Install dependencies
run: pnpm install
Expand Down
1 change: 1 addition & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default defineBuildConfig({
],
externals: [
'#dirs',
'bun:test',
'#app/entry',
'#build/root-component.mjs',
'#imports',
Expand Down
5 changes: 5 additions & 0 deletions examples/app-bun/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div>
<NuxtWelcome />
</div>
</template>
7 changes: 7 additions & 0 deletions examples/app-bun/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineNuxtConfig } from 'nuxt/config'

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
devtools: { enabled: true },
compatibilityDate: '2024-04-03',
})
22 changes: 22 additions & 0 deletions examples/app-bun/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "example-app-jest",
"private": true,
"type": "module",
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
"test": "bun test"
},
"dependencies": {
"nuxt": "^3.17.0"
},
"devDependencies": {
"@nuxt/test-utils": "latest",
"@types/bun": "1.2.10",
"playwright-core": "1.52.0",
"typescript": "5.8.3"
}
}
18 changes: 18 additions & 0 deletions examples/app-bun/test/browser.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { fileURLToPath } from 'node:url'
import { describe, it, expect } from 'bun:test'
import { createPage, setup } from '@nuxt/test-utils/e2e'
import { isWindows } from 'std-env'

await setup({
rootDir: fileURLToPath(new URL('../', import.meta.url)),
browser: true,
})

describe('browser', () => {
it('runs a test', async () => {
const page = await createPage('/')
const text = await page.getByRole('heading', { name: 'Welcome to Nuxt!' }).textContent()
expect(text).toContain('Welcome to Nuxt!')
await page.close()
}, isWindows ? 120000 : 20000)
})
15 changes: 15 additions & 0 deletions examples/app-bun/test/dev.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { fileURLToPath } from 'node:url'
import { describe, it, expect } from 'bun:test'
import { $fetch, setup } from '@nuxt/test-utils/e2e'

await setup({
rootDir: fileURLToPath(new URL('../', import.meta.url)),
dev: true,
})

describe('server (dev)', () => {
it('runs a test', async () => {
const html = await $fetch('/')
expect(html.slice(0, 15)).toMatchInlineSnapshot(`"<!DOCTYPE html>"`)
})
})
14 changes: 14 additions & 0 deletions examples/app-bun/test/server.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { fileURLToPath } from 'node:url'
import { describe, it, expect } from 'bun:test'
import { $fetch, setup } from '@nuxt/test-utils/e2e'

await setup({
rootDir: fileURLToPath(new URL('../', import.meta.url)),
})

describe('app', () => {
it('runs a test', async () => {
const html = await $fetch('/')
expect(html.slice(0, 15)).toMatchInlineSnapshot(`"<!DOCTYPE html>"`)
})
})
14 changes: 14 additions & 0 deletions examples/app-bun/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./.nuxt/tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"esModuleInterop": true,
"moduleResolution": "Bundler",
"verbatimModuleSyntax": false,
"target": "ESNext",
"types": [
"bun"
],
"resolveJsonModule": true
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"@nuxt/eslint-config": "1.3.0",
"@playwright/test": "1.52.0",
"@testing-library/vue": "8.1.0",
"@types/bun": "1.2.10",
"@types/estree": "1.0.7",
"@types/jsdom": "21.1.7",
"@types/node": "22.15.3",
Expand Down
36 changes: 36 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/core/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { resolve } from 'node:path'
import { defu } from 'defu'
import { withTrailingSlash } from 'ufo'
import type { DateString } from 'compatx'
import { isWindows } from 'std-env'
import { isBun, isWindows } from 'std-env'
import type { TestContext, TestOptions } from './types'

let currentContext: TestContext | undefined
Expand Down Expand Up @@ -44,6 +44,9 @@ export function createTestContext(options: Partial<TestOptions>): TestContext {
else if (process.env.JEST_WORKER_ID) {
_options.runner ||= 'jest'
}
else if (isBun) {
_options.runner ||= 'bun'
}

return setTestContext({
options: _options as TestOptions,
Expand Down
14 changes: 14 additions & 0 deletions src/core/setup/bun.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { TestHooks } from '../types'

export default async function setupBun(hooks: TestHooks) {
// @ts-expect-error we do not want bun types present in global context
const bunTest = await import('bun:test')

// eslint-disable-next-line @typescript-eslint/no-explicit-any
hooks.ctx.mockFn = bunTest.mock as any

bunTest.beforeAll(hooks.beforeAll)
bunTest.beforeEach(hooks.beforeEach)
bunTest.afterEach(hooks.afterEach)
bunTest.afterAll(hooks.afterAll)
}
2 changes: 2 additions & 0 deletions src/core/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { buildFixture, loadFixture } from '../nuxt'
import { startServer, stopServer } from '../server'
import { createBrowser } from '../browser'
import type { TestHooks, TestOptions } from '../types'
import setupBun from './bun'
import setupCucumber from './cucumber'
import setupJest from './jest'
import setupVitest from './vitest'

export const setupMaps = {
bun: setupBun,
cucumber: setupCucumber,
jest: setupJest,
vitest: setupVitest,
Expand Down
4 changes: 2 additions & 2 deletions src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Browser, LaunchOptions } from 'playwright-core'
import type { exec } from 'tinyexec'
import type { StartServerOptions } from './server'

export type TestRunner = 'vitest' | 'jest' | 'cucumber'
export type TestRunner = 'vitest' | 'jest' | 'cucumber' | 'bun'

export interface TestOptions {
testDir: string
Expand Down Expand Up @@ -43,7 +43,7 @@ export interface TestOptions {
*/
browser: boolean
/**
* Specify the runner for the test suite. One of `'vitest' | 'jest' | 'cucumber'`.
* Specify the runner for the test suite. One of `'vitest' | 'jest' | 'cucumber' | 'bun'`.
* @default `vitest`
*/
runner: TestRunner
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "./.nuxt/tsconfig.json",
"compilerOptions": {
"moduleResolution": "Bundler",
"moduleResolution": "Bundler"
},
"exclude": [
"config.d.ts",
Expand Down