@@ -13,18 +13,18 @@ describe("build commands", () => {
13
13
beforeEach ( ( ) => {
14
14
tmpDir = generateTmpDir ( ) ;
15
15
outputBundleOptions = {
16
- bundleYamlPath : path . join ( tmpDir , ".apphosting/ bundle.yaml" ) ,
16
+ bundleYamlPath : path . join ( tmpDir , ".apphosting" , " bundle.yaml") ,
17
17
outputDirectoryBasePath : path . join ( tmpDir , ".apphosting" ) ,
18
- outputDirectoryAppPath : path . join ( tmpDir , ".apphosting " ) ,
19
- outputPublicDirectoryPath : path . join ( tmpDir , ".apphosting/ public" ) ,
20
- outputStaticDirectoryPath : path . join ( tmpDir , ".apphosting/ .next/ static" ) ,
21
- serverFilePath : path . join ( tmpDir , ".apphosting/ server.js" ) ,
18
+ outputDirectoryAppPath : path . join ( tmpDir , ".next" , "standalone ") ,
19
+ outputPublicDirectoryPath : path . join ( tmpDir , ".next" , "standalone" , " public") ,
20
+ outputStaticDirectoryPath : path . join ( tmpDir , ".next" , "standalone" , " .next" , " static") ,
21
+ serverFilePath : path . join ( tmpDir , ".next" , "standalone" , " server.js") ,
22
22
} ;
23
23
defaultNextVersion = "14.0.3" ;
24
24
} ) ;
25
25
26
26
it ( "expects all output bundle files to be generated" , async ( ) => {
27
- const { generateOutputDirectory , validateOutputDirectory, createMetadata } = await importUtils ;
27
+ const { generateBuildOutput , validateOutputDirectory, createMetadata } = await importUtils ;
28
28
const files = {
29
29
".next/standalone/server.js" : "" ,
30
30
".next/static/staticfile" : "" ,
@@ -36,27 +36,21 @@ describe("build commands", () => {
36
36
} ;
37
37
const packageVersion = createMetadata ( defaultNextVersion ) . adapterVersion ;
38
38
generateTestFiles ( tmpDir , files ) ;
39
- await generateOutputDirectory (
39
+ await generateBuildOutput (
40
40
tmpDir ,
41
41
tmpDir ,
42
42
outputBundleOptions ,
43
43
path . join ( tmpDir , ".next" ) ,
44
44
defaultNextVersion ,
45
45
) ;
46
- await validateOutputDirectory ( outputBundleOptions ) ;
46
+ await validateOutputDirectory ( outputBundleOptions , path . join ( tmpDir , ".next" ) ) ;
47
47
48
48
const expectedFiles = {
49
- ".apphosting/.next/static/staticfile" : "" ,
50
- ".apphosting/server.js" : "" ,
51
- ".apphosting/bundle.yaml" : `headers: []
52
- redirects: []
53
- rewrites: []
54
- runCommand: node .apphosting/server.js
55
- neededDirs:
56
- - .apphosting
57
- staticAssets:
58
- - .apphosting/public
59
- env: []
49
+ ".next/standalone/.next/static/staticfile" : "" ,
50
+ ".next/standalone/server.js" : "" ,
51
+ ".apphosting/bundle.yaml" : `version: v1
52
+ serverConfig:
53
+ runCommand: node .next/standalone/server.js
60
54
metadata:
61
55
adapterPackageName: "@apphosting/adapter-nextjs"
62
56
adapterVersion: ${ packageVersion }
@@ -68,155 +62,123 @@ metadata:
68
62
} ) ;
69
63
70
64
it ( "moves files into correct location in a monorepo setup" , async ( ) => {
71
- const { generateOutputDirectory } = await importUtils ;
65
+ const { generateBuildOutput } = await importUtils ;
72
66
const files = {
73
67
".next/standalone/apps/next-app/standalonefile" : "" ,
74
68
".next/static/staticfile" : "" ,
75
69
"public/publicfile" : "" ,
76
- ".next/routes-manifest.json" : `{
77
- "headers":[],
78
- "rewrites":[],
79
- "redirects":[]
80
- }` ,
81
70
} ;
82
71
generateTestFiles ( tmpDir , files ) ;
83
- await generateOutputDirectory (
72
+ await generateBuildOutput (
84
73
tmpDir ,
85
74
"apps/next-app" ,
86
75
{
87
- bundleYamlPath : path . join ( tmpDir , ".apphosting/ bundle.yaml" ) ,
76
+ bundleYamlPath : path . join ( tmpDir , ".apphosting" , " bundle.yaml") ,
88
77
outputDirectoryBasePath : path . join ( tmpDir , ".apphosting" ) ,
89
- outputDirectoryAppPath : path . join ( tmpDir , ".apphosting/apps/next-app" ) ,
90
- outputPublicDirectoryPath : path . join ( tmpDir , ".apphosting/apps/next-app/public" ) ,
91
- outputStaticDirectoryPath : path . join ( tmpDir , ".apphosting/apps/next-app/.next/static" ) ,
92
- serverFilePath : path . join ( tmpDir , ".apphosting/apps/next-app/server.js" ) ,
78
+ outputDirectoryAppPath : path . join ( tmpDir , ".next" , "standalone" , "apps" , "next-app" ) ,
79
+ outputPublicDirectoryPath : path . join (
80
+ tmpDir ,
81
+ ".next" ,
82
+ "standalone" ,
83
+ "apps" ,
84
+ "next-app" ,
85
+ "public" ,
86
+ ) ,
87
+ outputStaticDirectoryPath : path . join (
88
+ tmpDir ,
89
+ ".next" ,
90
+ "standalone" ,
91
+ "apps" ,
92
+ "next-app" ,
93
+ ".next" ,
94
+ "static" ,
95
+ ) ,
96
+ serverFilePath : path . join ( tmpDir , ".next" , "standalone" , "apps" , "next-app" , "server.js" ) ,
93
97
} ,
94
98
path . join ( tmpDir , ".next" ) ,
95
99
defaultNextVersion ,
96
100
) ;
97
101
98
102
const expectedFiles = {
99
- ".apphosting /apps/next-app/.next/static/staticfile" : "" ,
100
- ".apphosting /apps/next-app/standalonefile" : "" ,
103
+ ".next/standalone /apps/next-app/.next/static/staticfile" : "" ,
104
+ ".next/standalone /apps/next-app/standalonefile" : "" ,
101
105
} ;
102
106
const expectedPartialYaml = {
103
- headers : [ ] ,
104
- rewrites : [ ] ,
105
- redirects : [ ] ,
106
- runCommand : "node .apphosting/apps/next-app/server.js" ,
107
- neededDirs : [ ".apphosting" ] ,
108
- staticAssets : [ ".apphosting/apps/next-app/public" ] ,
107
+ version : "v1" ,
108
+ serverConfig : { runCommand : "node .next/standalone/apps/next-app/server.js" } ,
109
109
} ;
110
110
validateTestFiles ( tmpDir , expectedFiles ) ;
111
111
validatePartialYamlContents ( tmpDir , ".apphosting/bundle.yaml" , expectedPartialYaml ) ;
112
112
} ) ;
113
113
114
- it ( "expects directories and other files to be copied over " , async ( ) => {
115
- const { generateOutputDirectory , validateOutputDirectory } = await importUtils ;
114
+ it ( "test failed validateOutputDirectory " , async ( ) => {
115
+ const { generateBuildOutput , validateOutputDirectory } = await importUtils ;
116
116
const files = {
117
- ".next/standalone/server .js" : "" ,
117
+ ".next/standalone/notserver .js" : "" ,
118
118
".next/static/staticfile" : "" ,
119
- "public/publicfile" : "" ,
120
- extrafile : "" ,
121
119
".next/routes-manifest.json" : `{
122
- "headers":[],
123
- "rewrites":[],
124
- "redirects":[]
120
+ "headers":[{"source":"source", "headers":["header1"]} ],
121
+ "rewrites":[{"source":"source", "destination":"destination"} ],
122
+ "redirects":[{"source":"source", "destination":"destination"} ]
125
123
}` ,
126
124
} ;
127
125
generateTestFiles ( tmpDir , files ) ;
128
- await generateOutputDirectory (
126
+ await generateBuildOutput (
129
127
tmpDir ,
130
128
tmpDir ,
131
129
outputBundleOptions ,
132
130
path . join ( tmpDir , ".next" ) ,
133
131
defaultNextVersion ,
134
132
) ;
135
- await validateOutputDirectory ( outputBundleOptions ) ;
136
-
137
- const expectedFiles = {
138
- ".apphosting/.next/static/staticfile" : "" ,
139
- ".apphosting/server.js" : "" ,
140
- ".apphosting/public/publicfile" : "" ,
141
- ".apphosting/extrafile" : "" ,
142
- } ;
143
- const expectedPartialYaml = {
144
- headers : [ ] ,
145
- rewrites : [ ] ,
146
- redirects : [ ] ,
147
- runCommand : "node .apphosting/server.js" ,
148
- neededDirs : [ ".apphosting" ] ,
149
- staticAssets : [ ".apphosting/public" ] ,
150
- } ;
151
- validateTestFiles ( tmpDir , expectedFiles ) ;
152
- validatePartialYamlContents ( tmpDir , ".apphosting/bundle.yaml" , expectedPartialYaml ) ;
133
+ assert . rejects (
134
+ async ( ) => await validateOutputDirectory ( outputBundleOptions , path . join ( tmpDir , ".next" ) ) ,
135
+ ) ;
153
136
} ) ;
154
-
155
- it ( "expects bundle.yaml headers/rewrites/redirects to be generated" , async ( ) => {
156
- const { generateOutputDirectory, validateOutputDirectory } = await importUtils ;
137
+ it ( "expects directories and other files to be copied over" , async ( ) => {
138
+ const { generateBuildOutput, validateOutputDirectory } = await importUtils ;
157
139
const files = {
158
140
".next/standalone/server.js" : "" ,
159
141
".next/static/staticfile" : "" ,
142
+ "public/publicfile" : "" ,
143
+ extrafile : "" ,
160
144
".next/routes-manifest.json" : `{
161
- "headers":[{"source":"source", "headers":["header1"]} ],
162
- "rewrites":[{"source":"source", "destination":"destination"} ],
163
- "redirects":[{"source":"source", "destination":"destination"} ]
145
+ "headers":[],
146
+ "rewrites":[],
147
+ "redirects":[]
164
148
}` ,
165
149
} ;
166
150
generateTestFiles ( tmpDir , files ) ;
167
- await generateOutputDirectory (
151
+ await generateBuildOutput (
168
152
tmpDir ,
169
153
tmpDir ,
170
154
outputBundleOptions ,
171
155
path . join ( tmpDir , ".next" ) ,
172
156
defaultNextVersion ,
173
157
) ;
174
- await validateOutputDirectory ( outputBundleOptions ) ;
158
+ await validateOutputDirectory ( outputBundleOptions , path . join ( tmpDir , ".next" ) ) ;
175
159
176
160
const expectedFiles = {
177
- ".apphosting/.next/static/staticfile" : "" ,
178
- ".apphosting/server.js" : "" ,
179
- } ;
180
- const expectedPartialYaml = {
181
- headers : [ { source : "source" , headers : [ "header1" ] } ] ,
182
- rewrites : [ { source : "source" , destination : "destination" } ] ,
183
- redirects : [ { source : "source" , destination : "destination" } ] ,
161
+ ".next/standalone/.next/static/staticfile" : "" ,
162
+ ".next/standalone/server.js" : "" ,
163
+ ".next/standalone/public/publicfile" : "" ,
164
+ ".next/standalone/extrafile" : "" ,
184
165
} ;
185
166
validateTestFiles ( tmpDir , expectedFiles ) ;
186
- validatePartialYamlContents ( tmpDir , ".apphosting/bundle.yaml" , expectedPartialYaml ) ;
187
- } ) ;
188
- it ( "test failed validateOutputDirectory" , async ( ) => {
189
- const { generateOutputDirectory, validateOutputDirectory } = await importUtils ;
190
- const files = {
191
- ".next/standalone/notserver.js" : "" ,
192
- ".next/static/staticfile" : "" ,
193
- ".next/routes-manifest.json" : `{
194
- "headers":[{"source":"source", "headers":["header1"]}],
195
- "rewrites":[{"source":"source", "destination":"destination"}],
196
- "redirects":[{"source":"source", "destination":"destination"}]
197
- }` ,
198
- } ;
199
- generateTestFiles ( tmpDir , files ) ;
200
- await generateOutputDirectory (
201
- tmpDir ,
202
- tmpDir ,
203
- outputBundleOptions ,
204
- path . join ( tmpDir , ".next" ) ,
205
- defaultNextVersion ,
206
- ) ;
207
- assert . rejects ( async ( ) => await validateOutputDirectory ( outputBundleOptions ) ) ;
208
167
} ) ;
209
168
it ( "test populate output bundle options" , async ( ) => {
210
169
const { populateOutputBundleOptions } = await importUtils ;
211
170
const expectedOutputBundleOptions = {
212
171
bundleYamlPath : "test/.apphosting/bundle.yaml" ,
213
172
outputDirectoryBasePath : "test/.apphosting" ,
214
- outputDirectoryAppPath : "test/.apphosting " ,
215
- outputPublicDirectoryPath : "test/.apphosting /public" ,
216
- outputStaticDirectoryPath : "test/.apphosting /.next/static" ,
217
- serverFilePath : "test/.apphosting /server.js" ,
173
+ outputDirectoryAppPath : "test/.next/standalone " ,
174
+ outputPublicDirectoryPath : "test/.next/standalone /public" ,
175
+ outputStaticDirectoryPath : "test/.next/standalone /.next/static" ,
176
+ serverFilePath : "test/.next/standalone /server.js" ,
218
177
} ;
219
- assert . deepEqual ( populateOutputBundleOptions ( "test" , "test" ) , expectedOutputBundleOptions ) ;
178
+ assert . deepEqual (
179
+ populateOutputBundleOptions ( "test" , "test" , "test/.next" ) ,
180
+ expectedOutputBundleOptions ,
181
+ ) ;
220
182
} ) ;
221
183
afterEach ( ( ) => {
222
184
fs . rmSync ( tmpDir , { recursive : true , force : true } ) ;
0 commit comments