Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Feb 6, 2022
1 parent e7eef74 commit 9b9190a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ packages/next-env/**/*.d.ts
packages/create-next-app/templates/**
test/integration/eslint/**
test/development/basic/legacy-decorators/**/*
test/development/basic/emit-decorator-metadata/**/*.js
test/production/emit-decorator-metadata/**/*.js
test-timings.json
packages/next-swc/crates/**
bench/nested-deps/pages/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createHandler, Get, Param } from '@storyofams/next-api-decorators'

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

export default createHandler(HelloHandler)
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ export default function Home() {

return <p id="message">{message}</p>
}

export function getServerSideProps() {
return {
props: {
now: Date.now(),
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ import webdriver from 'next-webdriver'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { BrowserInterface } from 'test/lib/browsers/base'
import { fetchViaHTTP } from 'next-test-utils'

describe('emitDecoratorMetadata SWC option', () => {
let next: NextInstance

beforeAll(async () => {
next = await createNext({
files: {
'jsconfig.json': new FileRef(
join(__dirname, 'emit-decorator-metadata/jsconfig.json')
),
pages: new FileRef(join(__dirname, 'emit-decorator-metadata/pages')),
'jsconfig.json': new FileRef(join(__dirname, 'app/jsconfig.json')),
pages: new FileRef(join(__dirname, 'app/pages')),
},
dependencies: {
'@storyofams/next-api-decorators': '1.6.0',
'reflect-metadata': '0.1.13',
'path-to-regexp': '6.2.0',
tsyringe: '4.6.0',
},
})
Expand All @@ -37,4 +38,10 @@ 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' })
})
})

0 comments on commit 9b9190a

Please sign in to comment.