@@ -13,13 +13,28 @@ import { copyStaticAssets, copyStaticContent } from './static.js'
13
13
14
14
type Context = FixtureTestContext & {
15
15
pluginContext : PluginContext
16
+ publishDir : string
17
+ }
18
+ const createFsFixtureWithBasePath = (
19
+ fixture : Record < string , string > ,
20
+ ctx : Omit < Context , 'pluginContext' > ,
21
+ basePath = '' ,
22
+ ) => {
23
+ return createFsFixture (
24
+ {
25
+ ...fixture ,
26
+ [ join ( ctx . publishDir , 'routes-manifest.json' ) ] : JSON . stringify ( { basePath } ) ,
27
+ } ,
28
+ ctx ,
29
+ )
16
30
}
17
31
18
32
describe ( 'Regular Repository layout' , ( ) => {
19
33
beforeEach < Context > ( ( ctx ) => {
34
+ ctx . publishDir = '.next'
20
35
ctx . pluginContext = new PluginContext ( {
21
36
constants : {
22
- PUBLISH_DIR : '.next' ,
37
+ PUBLISH_DIR : ctx . publishDir ,
23
38
} ,
24
39
utils : { build : { failBuild : vi . fn ( ) } as unknown } ,
25
40
} as NetlifyPluginOptions )
@@ -35,11 +50,11 @@ describe('Regular Repository layout', () => {
35
50
)
36
51
} )
37
52
38
- test < Context > ( 'should link static content from the publish directory to the static directory' , async ( {
53
+ test < Context > ( 'should link static content from the publish directory to the static directory (no basePath) ' , async ( {
39
54
pluginContext,
40
55
...ctx
41
56
} ) => {
42
- const { cwd } = await createFsFixture (
57
+ const { cwd } = await createFsFixtureWithBasePath (
43
58
{
44
59
'.next/static/test.js' : '' ,
45
60
'.next/static/sub-dir/test2.js' : '' ,
@@ -58,11 +73,35 @@ describe('Regular Repository layout', () => {
58
73
)
59
74
} )
60
75
61
- test < Context > ( 'should link static content from the public directory to the static directory' , async ( {
76
+ test < Context > ( 'should link static content from the publish directory to the static directory (with basePath)' , async ( {
77
+ pluginContext,
78
+ ...ctx
79
+ } ) => {
80
+ const { cwd } = await createFsFixtureWithBasePath (
81
+ {
82
+ '.next/static/test.js' : '' ,
83
+ '.next/static/sub-dir/test2.js' : '' ,
84
+ } ,
85
+ ctx ,
86
+ '/base/path' ,
87
+ )
88
+
89
+ await copyStaticAssets ( pluginContext )
90
+ expect ( await glob ( '**/*' , { cwd, dot : true , absolute : true } ) ) . toEqual (
91
+ expect . arrayContaining ( [
92
+ join ( cwd , '.next/static/test.js' ) ,
93
+ join ( cwd , '.next/static/sub-dir/test2.js' ) ,
94
+ join ( pluginContext . staticDir , 'base/path/_next/static/test.js' ) ,
95
+ join ( pluginContext . staticDir , 'base/path/_next/static/sub-dir/test2.js' ) ,
96
+ ] ) ,
97
+ )
98
+ } )
99
+
100
+ test < Context > ( 'should link static content from the public directory to the static directory (no basePath)' , async ( {
62
101
pluginContext,
63
102
...ctx
64
103
} ) => {
65
- const { cwd } = await createFsFixture (
104
+ const { cwd } = await createFsFixtureWithBasePath (
66
105
{
67
106
'public/fake-image.svg' : '' ,
68
107
'public/another-asset.json' : '' ,
@@ -81,11 +120,35 @@ describe('Regular Repository layout', () => {
81
120
)
82
121
} )
83
122
123
+ test < Context > ( 'should link static content from the public directory to the static directory (with basePath)' , async ( {
124
+ pluginContext,
125
+ ...ctx
126
+ } ) => {
127
+ const { cwd } = await createFsFixtureWithBasePath (
128
+ {
129
+ 'public/fake-image.svg' : '' ,
130
+ 'public/another-asset.json' : '' ,
131
+ } ,
132
+ ctx ,
133
+ '/base/path' ,
134
+ )
135
+
136
+ await copyStaticAssets ( pluginContext )
137
+ expect ( await glob ( '**/*' , { cwd, dot : true , absolute : true } ) ) . toEqual (
138
+ expect . arrayContaining ( [
139
+ join ( cwd , 'public/another-asset.json' ) ,
140
+ join ( cwd , 'public/fake-image.svg' ) ,
141
+ join ( pluginContext . staticDir , '/base/path/another-asset.json' ) ,
142
+ join ( pluginContext . staticDir , '/base/path/fake-image.svg' ) ,
143
+ ] ) ,
144
+ )
145
+ } )
146
+
84
147
test < Context > ( 'should copy the static pages to the publish directory if there are no corresponding JSON files' , async ( {
85
148
pluginContext,
86
149
...ctx
87
150
} ) => {
88
- await createFsFixture (
151
+ await createFsFixtureWithBasePath (
89
152
{
90
153
'.next/server/pages/test.html' : '' ,
91
154
'.next/server/pages/test2.html' : '' ,
@@ -107,7 +170,7 @@ describe('Regular Repository layout', () => {
107
170
pluginContext,
108
171
...ctx
109
172
} ) => {
110
- await createFsFixture (
173
+ await createFsFixtureWithBasePath (
111
174
{
112
175
'.next/server/pages/test.html' : '' ,
113
176
'.next/server/pages/test.json' : '' ,
@@ -124,20 +187,21 @@ describe('Regular Repository layout', () => {
124
187
125
188
describe ( 'Mono Repository' , ( ) => {
126
189
beforeEach < Context > ( ( ctx ) => {
190
+ ctx . publishDir = 'apps/app-1/.next'
127
191
ctx . pluginContext = new PluginContext ( {
128
192
constants : {
129
- PUBLISH_DIR : 'apps/app-1/.next' ,
193
+ PUBLISH_DIR : ctx . publishDir ,
130
194
PACKAGE_PATH : 'apps/app-1' ,
131
195
} ,
132
196
utils : { build : { failBuild : vi . fn ( ) } as unknown } ,
133
197
} as NetlifyPluginOptions )
134
198
} )
135
199
136
- test < Context > ( 'should link static content from the publish directory to the static directory' , async ( {
200
+ test < Context > ( 'should link static content from the publish directory to the static directory (no basePath) ' , async ( {
137
201
pluginContext,
138
202
...ctx
139
203
} ) => {
140
- const { cwd } = await createFsFixture (
204
+ const { cwd } = await createFsFixtureWithBasePath (
141
205
{
142
206
'apps/app-1/.next/static/test.js' : '' ,
143
207
'apps/app-1/.next/static/sub-dir/test2.js' : '' ,
@@ -156,11 +220,35 @@ describe('Mono Repository', () => {
156
220
)
157
221
} )
158
222
159
- test < Context > ( 'should link static content from the public directory to the static directory' , async ( {
223
+ test < Context > ( 'should link static content from the publish directory to the static directory (with basePath) ' , async ( {
160
224
pluginContext,
161
225
...ctx
162
226
} ) => {
163
- const { cwd } = await createFsFixture (
227
+ const { cwd } = await createFsFixtureWithBasePath (
228
+ {
229
+ 'apps/app-1/.next/static/test.js' : '' ,
230
+ 'apps/app-1/.next/static/sub-dir/test2.js' : '' ,
231
+ } ,
232
+ ctx ,
233
+ '/base/path' ,
234
+ )
235
+
236
+ await copyStaticAssets ( pluginContext )
237
+ expect ( await glob ( '**/*' , { cwd, dot : true , absolute : true } ) ) . toEqual (
238
+ expect . arrayContaining ( [
239
+ join ( cwd , 'apps/app-1/.next/static/test.js' ) ,
240
+ join ( cwd , 'apps/app-1/.next/static/sub-dir/test2.js' ) ,
241
+ join ( pluginContext . staticDir , '/base/path/_next/static/test.js' ) ,
242
+ join ( pluginContext . staticDir , '/base/path/_next/static/sub-dir/test2.js' ) ,
243
+ ] ) ,
244
+ )
245
+ } )
246
+
247
+ test < Context > ( 'should link static content from the public directory to the static directory (no basePath)' , async ( {
248
+ pluginContext,
249
+ ...ctx
250
+ } ) => {
251
+ const { cwd } = await createFsFixtureWithBasePath (
164
252
{
165
253
'apps/app-1/public/fake-image.svg' : '' ,
166
254
'apps/app-1/public/another-asset.json' : '' ,
@@ -179,11 +267,35 @@ describe('Mono Repository', () => {
179
267
)
180
268
} )
181
269
270
+ test < Context > ( 'should link static content from the public directory to the static directory (with basePath)' , async ( {
271
+ pluginContext,
272
+ ...ctx
273
+ } ) => {
274
+ const { cwd } = await createFsFixtureWithBasePath (
275
+ {
276
+ 'apps/app-1/public/fake-image.svg' : '' ,
277
+ 'apps/app-1/public/another-asset.json' : '' ,
278
+ } ,
279
+ ctx ,
280
+ '/base/path' ,
281
+ )
282
+
283
+ await copyStaticAssets ( pluginContext )
284
+ expect ( await glob ( '**/*' , { cwd, dot : true , absolute : true } ) ) . toEqual (
285
+ expect . arrayContaining ( [
286
+ join ( cwd , 'apps/app-1/public/another-asset.json' ) ,
287
+ join ( cwd , 'apps/app-1/public/fake-image.svg' ) ,
288
+ join ( pluginContext . staticDir , '/base/path/another-asset.json' ) ,
289
+ join ( pluginContext . staticDir , '/base/path/fake-image.svg' ) ,
290
+ ] ) ,
291
+ )
292
+ } )
293
+
182
294
test < Context > ( 'should copy the static pages to the publish directory if there are no corresponding JSON files' , async ( {
183
295
pluginContext,
184
296
...ctx
185
297
} ) => {
186
- await createFsFixture (
298
+ await createFsFixtureWithBasePath (
187
299
{
188
300
'apps/app-1/.next/server/pages/test.html' : '' ,
189
301
'apps/app-1/.next/server/pages/test2.html' : '' ,
@@ -205,7 +317,7 @@ describe('Mono Repository', () => {
205
317
pluginContext,
206
318
...ctx
207
319
} ) => {
208
- await createFsFixture (
320
+ await createFsFixtureWithBasePath (
209
321
{
210
322
'apps/app-1/.next/server/pages/test.html' : '' ,
211
323
'apps/app-1/.next/server/pages/test.json' : '' ,
0 commit comments