Skip to content

Commit 94b7e3c

Browse files
committed
Turbopack: Simplify emitDecoratorMetadata test
1 parent 8a91d46 commit 94b7e3c

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { createHandler, Get, Param } from 'next-api-decorators'
1+
import 'reflect-metadata'
2+
import { container, singleton } from 'tsyringe'
23

3-
class HelloHandler {
4-
@Get('/:myParam')
5-
// This fails due to library looking for Reflect.getMetadata("design:paramtypes", ...).
6-
// Design:paramtypes is never emitted due to missing SWC flag.
7-
async get(@Param('myParam') myParam) {
8-
return {
9-
myParam,
10-
}
4+
@singleton()
5+
class HelloService {
6+
getHello() {
7+
return 'Hello, world!'
118
}
129
}
1310

14-
export default createHandler(HelloHandler)
11+
const helloService = container.resolve(HelloService)
12+
13+
export default function handler(req, res) {
14+
res.status(200).json({ message: helloService.getHello() })
15+
}

Diff for: test/production/emit-decorator-metadata/index.test.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { join } from 'path'
22
import webdriver, { BrowserInterface } from 'next-webdriver'
3-
import { createNext, FileRef } from 'e2e-utils'
3+
import { createNext } from 'e2e-utils'
44
import { NextInstance } from 'e2e-utils'
55
import { fetchViaHTTP } from 'next-test-utils'
66

@@ -9,12 +9,8 @@ describe('emitDecoratorMetadata SWC option', () => {
99

1010
beforeAll(async () => {
1111
next = await createNext({
12-
files: {
13-
'jsconfig.json': new FileRef(join(__dirname, 'app/jsconfig.json')),
14-
pages: new FileRef(join(__dirname, 'app/pages')),
15-
},
12+
files: join(__dirname, 'app'),
1613
dependencies: {
17-
'next-api-decorators': '2.0.0',
1814
'reflect-metadata': '0.1.13',
1915
'path-to-regexp': '6.2.0',
2016
tsyringe: '4.6.0',
@@ -41,6 +37,6 @@ describe('emitDecoratorMetadata SWC option', () => {
4137
it('should compile with emitDecoratorMetadata enabled for API', async () => {
4238
const res = await fetchViaHTTP(next.url, '/api/something')
4339
expect(res.status).toBe(200)
44-
expect(await res.json()).toEqual({ myParam: 'something' })
40+
expect(await res.json()).toEqual({ message: 'Hello, world!' })
4541
})
4642
})

Diff for: test/turbopack-build-tests-manifest.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -17967,11 +17967,10 @@
1796717967
},
1796817968
"test/production/emit-decorator-metadata/index.test.ts": {
1796917969
"passed": [
17970-
"emitDecoratorMetadata SWC option should compile with emitDecoratorMetadata enabled"
17971-
],
17972-
"failed": [
17970+
"emitDecoratorMetadata SWC option should compile with emitDecoratorMetadata enabled",
1797317971
"emitDecoratorMetadata SWC option should compile with emitDecoratorMetadata enabled for API"
1797417972
],
17973+
"failed": [],
1797517974
"pending": [],
1797617975
"flakey": [],
1797717976
"runtimeError": false

0 commit comments

Comments
 (0)