提交 12f1a634 编写于 作者: J Junyoung Choi 提交者: JJ Kasper

Expose next function type (#7726)

* Expose next function type

* Add type testing for typescript custom server

* Move types test to integration folder
上级 e00a2c5d
......@@ -13,6 +13,8 @@ import {
import { PageConfig } from 'next-server/types'
import next from 'next/dist/server/next'
// Extend the React types with missing properties
declare module 'react' {
// <html amp=""> support
......@@ -52,3 +54,5 @@ export {
NextApiRequest,
PageConfig,
}
export default next
server.js
pages/index.jsx
\ No newline at end of file
/// <reference types="next" />
/// <reference types="next/types/global" />
export default () => <p>hello world</p>
import next from 'next'
import http from 'http'
const dir = __dirname
const port = process.env.PORT || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev, dir })
const handleNextRequests = app.getRequestHandler()
app.prepare().then(() => {
const server = new http.Server((req, res) => {
handleNextRequests(req, res)
})
server.listen(port)
})
/* eslint-env jest */
/* global jasmine */
import { join } from 'path'
import { buildTS } from 'next-test-utils'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
const appDir = join(__dirname, '../')
describe('Custom Server TypeScript', () => {
it('should build server.ts correctly', async () => {
await buildTS([], appDir)
})
})
{
"compilerOptions": {
"esModuleInterop": true,
"module": "esnext",
"jsx": "preserve",
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true
},
"exclude": [
"node_modules"
],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
]
}
......@@ -176,6 +176,32 @@ export function nextStart (dir, port, opts = {}) {
return runNextCommandDev(['start', '-p', port, dir], undefined, opts)
}
export function buildTS (args = [], cwd, env = {}) {
cwd = cwd || path.dirname(require.resolve('next/package'))
env = { ...process.env, NODE_ENV: undefined, ...env }
return new Promise((resolve, reject) => {
const instance = spawn(
'node',
[require.resolve('typescript/lib/tsc'), ...args],
{ cwd, env }
)
let output = ''
const handleData = chunk => {
output += chunk.toString()
}
instance.stdout.on('data', handleData)
instance.stderr.on('data', handleData)
instance.on('exit', code => {
if (code) { return reject(new Error('exited with code: ' + code + '\n' + output)) }
resolve()
})
})
}
// Kill a launched app
export async function killApp (instance) {
await new Promise((resolve, reject) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册