Skip to content

Commit 964b4cd

Browse files
authored
chore: upgrade dependencie typescript and fix test (#488)
* chore: upgrade dependencie typescript and fix test * test: update test
1 parent 7a43d93 commit 964b4cd

File tree

5 files changed

+63
-34
lines changed

5 files changed

+63
-34
lines changed

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"tsimp": "^2.0.11",
9797
"tsm": "^2.3.0",
9898
"tsx": "^4.15.7",
99-
"typescript": "5.5",
99+
"typescript": "~5.9.3",
100100
"vite": "^7.0.0",
101101
"vitest": "^4.0.6"
102102
},
@@ -108,7 +108,14 @@
108108
"**/*.test.ts"
109109
],
110110
"transform": {
111-
"^.+\\.(ts|tsx)$": "ts-jest"
111+
"^.+\\.(ts|tsx)$": [
112+
"ts-jest",
113+
{
114+
"tsconfig": {
115+
"esModuleInterop": true
116+
}
117+
}
118+
]
112119
}
113120
},
114121
"publishConfig": {

test/typescript-common/index.ts

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,33 @@
1-
'use script'
1+
'use strict'
22

3-
const { test: t } = require('node:test')
3+
const { test: testRunner } = require('node:test')
4+
const assert = require('node:assert/strict')
45
const fastify = require('fastify')
5-
66
const basicApp = require('./basic/app.ts')
77

8-
t.plan(5)
9-
10-
const app = fastify()
11-
12-
app.register(basicApp)
8+
testRunner('integration test with fastify autoload', async (t: any) => {
9+
const app = fastify()
10+
app.register(basicApp)
1311

14-
app.ready(async function (err) {
15-
t.error(err)
12+
await app.ready()
1613

17-
await app
18-
.inject({
14+
await t.test('should return javascript data', async () => {
15+
const res = await app.inject({
1916
url: '/javascript',
2017
})
21-
.then(function (res: any) {
22-
t.equal(res.statusCode, 200)
23-
t.same(JSON.parse(res.payload), { script: 'java' })
24-
})
25-
.catch((err) => {
26-
t.error(err)
27-
})
2818

29-
await app
30-
.inject({
19+
assert.strictEqual(res.statusCode, 200)
20+
assert.deepStrictEqual(res.json(), { script: 'java' })
21+
})
22+
23+
await t.test('should return typescript data', async () => {
24+
const res = await app.inject({
3125
url: '/typescript',
3226
})
33-
.then(function (res: any) {
34-
t.equal(res.statusCode, 200)
35-
t.same(JSON.parse(res.payload), { script: 'type' })
36-
})
37-
.catch((err) => {
38-
t.error(err)
39-
})
27+
28+
assert.strictEqual(res.statusCode, 200)
29+
assert.deepStrictEqual(res.json(), { script: 'type' })
30+
})
31+
32+
await app.close()
4033
})

test/typescript-jest/integration/instance.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ app.register(basicApp)
77
app.listen({
88
port: Math.floor(Math.random() * 3000 + 3000)
99
}, function (err) {
10-
if (err) process.stderr.write('failed')
10+
if (err) {
11+
process.stderr.write('failed')
12+
}
1113
process.stdout.write('success')
1214
app.close()
1315
})
Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
11
import { exec } from 'node:child_process'
2+
import { join } from 'node:path'
23

34
describe('integration test', function () {
5+
const isWindows = process.platform === 'win32'
6+
47
test.concurrent.each(['ts-node', 'ts-node-dev'])(
58
'integration with %s',
69
async function (instance) {
710
await new Promise(function (resolve) {
8-
const child = exec(`${instance} "${process.cwd()}/test/typescript-jest/integration/instance.ts"`)
11+
const compilerOpts = JSON.stringify({
12+
module: 'commonjs',
13+
moduleResolution: 'node',
14+
esModuleInterop: true
15+
})
16+
17+
const optionsArg = isWindows
18+
? `"${compilerOpts.replace(/"/g, '\\"')}"`
19+
: `'${compilerOpts}'`
20+
21+
const filePath = join(
22+
process.cwd(),
23+
'test',
24+
'typescript-jest',
25+
'integration',
26+
'instance.ts'
27+
)
28+
29+
const child = exec(
30+
`npx ${instance} --compiler-options ${optionsArg} "${filePath}"`
31+
)
32+
933
let stderr = ''
1034
child.stderr?.on('data', function (b) {
1135
stderr = stderr + b.toString()
@@ -14,13 +38,14 @@ describe('integration test', function () {
1438
child.stdout?.on('data', function (b) {
1539
stdout = stdout + b.toString()
1640
})
41+
1742
child.once('close', function () {
1843
expect(stderr.includes('failed')).toStrictEqual(false)
1944
expect(stdout.includes('success')).toStrictEqual(true)
2045
resolve('')
2146
})
2247
})
2348
},
24-
30000
49+
isWindows ? 60000 : 30000
2550
)
2651
})

types/index.test-d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import fastify, { FastifyInstance, FastifyPluginCallback } from 'fastify'
22
import { expectType } from 'tsd'
3+
// eslint-disable-next-line import-x/no-duplicates
34
import * as fastifyAutoloadStar from '..'
45
import fastifyAutoloadDefault, { AutoloadPluginOptions, fastifyAutoload as fastifyAutoloadNamed } from '..'
56

6-
import fastifyAutoloadCjsImport = require('..')
7+
// eslint-disable-next-line import-x/no-duplicates
8+
import * as fastifyAutoloadCjsImport from '..'
79
const fastifyAutoloadCjs = require('..')
810

911
const app: FastifyInstance = fastify()

0 commit comments

Comments
 (0)