Skip to content

Commit 094d909

Browse files
authored
Turbopack: Simplify emitDecoratorMetadata test (#76678)
## What? Reuse the same code as is checked in page.js, making them consistent and dropping an additional dependency which also makes it easier to run while testing. <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # -->
1 parent f91192c commit 094d909

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+
}

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
})

test/turbopack-build-tests-manifest.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -17982,11 +17982,10 @@
1798217982
},
1798317983
"test/production/emit-decorator-metadata/index.test.ts": {
1798417984
"passed": [
17985-
"emitDecoratorMetadata SWC option should compile with emitDecoratorMetadata enabled"
17986-
],
17987-
"failed": [
17985+
"emitDecoratorMetadata SWC option should compile with emitDecoratorMetadata enabled",
1798817986
"emitDecoratorMetadata SWC option should compile with emitDecoratorMetadata enabled for API"
1798917987
],
17988+
"failed": [],
1799017989
"pending": [],
1799117990
"flakey": [],
1799217991
"runtimeError": false

0 commit comments

Comments
 (0)