Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turbopack: Simplify emitDecoratorMetadata test #76678

Merged
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
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { createHandler, Get, Param } from 'next-api-decorators'
import 'reflect-metadata'
import { container, singleton } from 'tsyringe'

class HelloHandler {
@Get('/:myParam')
// This fails due to library looking for Reflect.getMetadata("design:paramtypes", ...).
// Design:paramtypes is never emitted due to missing SWC flag.
async get(@Param('myParam') myParam) {
return {
myParam,
}
@singleton()
class HelloService {
getHello() {
return 'Hello, world!'
}
}

export default createHandler(HelloHandler)
const helloService = container.resolve(HelloService)

export default function handler(req, res) {
res.status(200).json({ message: helloService.getHello() })
}
10 changes: 3 additions & 7 deletions test/production/emit-decorator-metadata/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join } from 'path'
import webdriver, { BrowserInterface } from 'next-webdriver'
import { createNext, FileRef } from 'e2e-utils'
import { createNext } from 'e2e-utils'
import { NextInstance } from 'e2e-utils'
import { fetchViaHTTP } from 'next-test-utils'

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

beforeAll(async () => {
next = await createNext({
files: {
'jsconfig.json': new FileRef(join(__dirname, 'app/jsconfig.json')),
pages: new FileRef(join(__dirname, 'app/pages')),
},
files: join(__dirname, 'app'),
dependencies: {
'next-api-decorators': '2.0.0',
'reflect-metadata': '0.1.13',
'path-to-regexp': '6.2.0',
tsyringe: '4.6.0',
Expand All @@ -41,6 +37,6 @@ describe('emitDecoratorMetadata SWC option', () => {
it('should compile with emitDecoratorMetadata enabled for API', async () => {
const res = await fetchViaHTTP(next.url, '/api/something')
expect(res.status).toBe(200)
expect(await res.json()).toEqual({ myParam: 'something' })
expect(await res.json()).toEqual({ message: 'Hello, world!' })
})
})
5 changes: 2 additions & 3 deletions test/turbopack-build-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17967,11 +17967,10 @@
},
"test/production/emit-decorator-metadata/index.test.ts": {
"passed": [
"emitDecoratorMetadata SWC option should compile with emitDecoratorMetadata enabled"
],
"failed": [
"emitDecoratorMetadata SWC option should compile with emitDecoratorMetadata enabled",
"emitDecoratorMetadata SWC option should compile with emitDecoratorMetadata enabled for API"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
Expand Down
Loading