22/* global jasmine */
33import webdriver from 'next-webdriver'
44import { join } from 'path'
5- import { existsSync } from 'fs'
5+ import { existsSync , readdirSync , readFileSync } from 'fs'
66import {
77 killApp ,
88 findPort ,
@@ -15,11 +15,13 @@ import fetch from 'node-fetch'
1515
1616const appDir = join ( __dirname , '../' )
1717const serverlessDir = join ( appDir , '.next/serverless/pages' )
18+ const chunksDir = join ( appDir , '.next/static/chunks' )
19+ const buildIdFile = join ( appDir , '.next/BUILD_ID' )
1820let appPort
1921let app
2022jasmine . DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5
2123
22- describe ( 'Serverless' , ( ) => {
24+ describe ( 'Serverless Trace ' , ( ) => {
2325 beforeAll ( async ( ) => {
2426 await nextBuild ( appDir )
2527 appPort = await findPort ( )
@@ -52,6 +54,11 @@ describe('Serverless', () => {
5254 expect ( html ) . toMatch ( / T h i s p a g e c o u l d n o t b e f o u n d / )
5355 } )
5456
57+ it ( 'should render 404 for /_next/static' , async ( ) => {
58+ const html = await renderViaHTTP ( appPort , '/_next/static' )
59+ expect ( html ) . toMatch ( / T h i s p a g e c o u l d n o t b e f o u n d / )
60+ } )
61+
5562 it ( 'should render an AMP page' , async ( ) => {
5663 const html = await renderViaHTTP ( appPort , '/some-amp?amp=1' )
5764 expect ( html ) . toMatch ( / H i I m a n A M P p a g e / )
@@ -93,6 +100,19 @@ describe('Serverless', () => {
93100 }
94101 } )
95102
103+ it ( 'should not have combined client-side chunks' , ( ) => {
104+ expect ( readdirSync ( chunksDir ) . length ) . toBeGreaterThanOrEqual ( 2 )
105+ const buildId = readFileSync ( buildIdFile , 'utf8' ) . trim ( )
106+
107+ const pageContent = join (
108+ appDir ,
109+ '.next/static' ,
110+ buildId ,
111+ 'pages/dynamic.js'
112+ )
113+ expect ( readFileSync ( pageContent , 'utf8' ) ) . not . toContain ( 'Hello!' )
114+ } )
115+
96116 it ( 'should not output _app.js and _document.js to serverless build' , ( ) => {
97117 expect ( existsSync ( join ( serverlessDir , '_app.js' ) ) ) . toBeFalsy ( )
98118 expect ( existsSync ( join ( serverlessDir , '_document.js' ) ) ) . toBeFalsy ( )
@@ -121,8 +141,28 @@ describe('Serverless', () => {
121141
122142 it ( 'should reply on dynamic API request successfully' , async ( ) => {
123143 const result = await renderViaHTTP ( appPort , '/api/posts/post-1' )
124- const { post } = JSON . parse ( result )
125- expect ( post ) . toBe ( 'post-1' )
144+ const { id } = JSON . parse ( result )
145+ expect ( id ) . toBe ( 'post-1' )
146+ } )
147+
148+ it ( 'should reply on dynamic API request successfully with query parameters' , async ( ) => {
149+ const result = await renderViaHTTP ( appPort , '/api/posts/post-1?param=val' )
150+ const { id, param } = JSON . parse ( result )
151+ expect ( id ) . toBe ( 'post-1' )
152+ expect ( param ) . toBe ( 'val' )
153+ } )
154+
155+ it ( 'should reply on dynamic API index request successfully' , async ( ) => {
156+ const result = await renderViaHTTP ( appPort , '/api/dynamic/post-1' )
157+ const { path } = JSON . parse ( result )
158+ expect ( path ) . toBe ( 'post-1' )
159+ } )
160+
161+ it ( 'should reply on dynamic API index request successfully with query parameters' , async ( ) => {
162+ const result = await renderViaHTTP ( appPort , '/api/dynamic/post-1?param=val' )
163+ const { path, param } = JSON . parse ( result )
164+ expect ( path ) . toBe ( 'post-1' )
165+ expect ( param ) . toBe ( 'val' )
126166 } )
127167
128168 it ( 'should 404 on API request with trailing slash' , async ( ) => {
0 commit comments