Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,38 @@
contents: read

jobs:
bun:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install

- name: Run unit tests
run: bun run typescript:bun

deno:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false

- name: Setup Deno
uses: denoland/setup-deno@v2

- name: Install dependencies
run: deno install

- name: Run unit tests
run: deno run typescript:deno

test:
permissions:
contents: write
Expand Down
14 changes: 14 additions & 0 deletions lib/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ function checkEnvVariable (name, value) {
const runtime = {}
// use Object.defineProperties to provide lazy load
Object.defineProperties(runtime, {
bun: {
get () {
cache.bun ??= 'Bun' in globalThis
return cache.bun
}
},
deno: {
get () {
cache.deno ??= 'Deno' in globalThis
return cache.deno
}
},
tsNode: {
get () {
cache.tsNode ??= (
Expand Down Expand Up @@ -108,6 +120,8 @@ Object.defineProperties(runtime, {
get () {
cache.supportTypeScript ??= (
checkEnvVariable('FASTIFY_AUTOLOAD_TYPESCRIPT') ||
runtime.bun ||
runtime.deno ||
runtime.tsNode ||
runtime.vitest ||
runtime.babelNode ||
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"lint:fix": "eslint --fix",
"test": "npm run typescript && npm run typescript:native && npm run typescript:jest && npm run typescript:swc-node-register && npm run typescript:tsm && npm run typescript:tsx && npm run typescript:vitest && npm run typescript:esbuild && npm run unit",
"typescript": "tsd",
"typescript:bun": "bun scripts/unit-typescript-bun-esm.js",
"typescript:deno": "deno -A scripts/unit-typescript-deno-esm.js",
"typescript:jest": "jest",
"typescript:esm": "node scripts/unit-typescript-esm.js",
"typescript:swc-node-register": "node scripts/unit-typescript-swc-node-register.js",
Expand Down
28 changes: 28 additions & 0 deletions scripts/unit-typescript-bun-esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict'

const { exec } = require('node:child_process')
const { argv } = require('node:process')

const args = [
argv[0],
'test',
'./test/typescript-esm/forceESM.ts'
]

const child = exec(args.join(' '), {
shell: true,
env: {
...process.env,
TS_NODE_COMPILER_OPTIONS: JSON.stringify({
module: 'ESNext',
target: 'ES2020',
allowJs: false,
moduleResolution: 'node',
esModuleInterop: true
})
}
})

child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stderr)
child.once('close', process.exit)
29 changes: 29 additions & 0 deletions scripts/unit-typescript-deno-esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict'

const { exec } = require('node:child_process')
const { argv } = require('node:process')

const args = [
argv[0],
'test',
'-A',
'./test/typescript-esm/forceESM.ts'
]

const child = exec(args.join(' '), {
shell: true,
env: {
...process.env,
TS_NODE_COMPILER_OPTIONS: JSON.stringify({
module: 'ESNext',
target: 'ES2020',
allowJs: false,
moduleResolution: 'node',
esModuleInterop: true
})
}
})

child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stderr)
child.once('close', process.exit)
13 changes: 5 additions & 8 deletions test/typescript-esm/forceESM.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test, { describe, before, after } from 'node:test'
import { describe, test } from 'node:test'
import assert from 'node:assert'
import fastify from 'fastify'

Expand All @@ -10,18 +10,15 @@ const __dirname = dirname(fileURLToPath(import.meta.url))

describe('typescript/basic test suite', function () {
const app = fastify()
before(async function () {

test('should load routes and respond correctly', async function () {
app.register(fastifyAutoLoad, { dir: resolve(__dirname, 'app'), forceESM: true })
await app.ready()
})

after(async function () {
await app.close()
})

test('should load routes and respond correctly', async function () {
const res = await app.inject({ url: '/installed' })
assert.strictEqual(res.statusCode, 200)
assert.deepStrictEqual(JSON.parse(res.payload), { result: 'ok' })

await app.close()
})
})
Loading