@@ -2,7 +2,36 @@ import { getPortPromise } from 'portfinder';
22import { TestEnv } from '../../../../../../node-integration-tests/utils' ;
33import * as http from 'http' ;
44import * as path from 'path' ;
5- import { createNextServer , startServer } from '../../utils/common' ;
5+ import { createServer , Server } from 'http' ;
6+ import { parse } from 'url' ;
7+ import next from 'next' ;
8+
9+ // Type not exported from NextJS
10+ // @ts -ignore
11+ export const createNextServer = async config => {
12+ const app = next ( config ) ;
13+ const handle = app . getRequestHandler ( ) ;
14+ await app . prepare ( ) ;
15+
16+ return createServer ( ( req , res ) => {
17+ const { url } = req ;
18+
19+ if ( ! url ) {
20+ throw new Error ( 'No url' ) ;
21+ }
22+
23+ handle ( req , res , parse ( url , true ) ) ;
24+ } ) ;
25+ } ;
26+
27+ export const startServer = async ( server : Server , port : string | number ) => {
28+ return new Promise ( resolve => {
29+ server . listen ( port || 0 , ( ) => {
30+ const url = `http://localhost:${ port } ` ;
31+ resolve ( { server, url } ) ;
32+ } ) ;
33+ } ) ;
34+ } ;
635
736export class NextTestEnv extends TestEnv {
837 private constructor ( public readonly server : http . Server , public readonly url : string ) {
0 commit comments