@@ -17,6 +17,7 @@ import { dirname } from "path"
17
17
import { resolve } from 'pathe'
18
18
import { join } from "pathe"
19
19
import { Rewrites } from "../../packages/runtime/src/helpers/types"
20
+ import { describeCwdTmpDir , moveNextDist } from "../test-utils"
20
21
21
22
const REDIRECTS : Rewrites = [
22
23
{
@@ -187,21 +188,22 @@ describe('files utility functions', () => {
187
188
expect ( matchesRewrite ( path , REWRITES ) ) . toBeTruthy ( )
188
189
} )
189
190
} )
191
+ } )
190
192
191
- test . only ( 'patches Next server files' , async ( ) => {
192
- const root = path . resolve ( dirname ( __dirname ) )
193
- console . log ( { root } )
194
- // await copy(join(root, 'package.json'), path.join(process.cwd(), 'package.json'))
195
- // await ensureDir(path.join(process.cwd(), 'node_modules'))
196
- // await copy(path.join(root, 'node_modules', 'next'), path.join(process.cwd(), 'node_modules', 'next'))
193
+ describeCwdTmpDir ( 'file patching' , ( ) => {
194
+ it ( 'patches Next server files' , async ( ) => {
195
+ const root = path . resolve ( dirname ( resolve ( __dirname , '..' ) ) )
196
+ await copy ( join ( root , 'package.json' ) , path . join ( process . cwd ( ) , 'package.json' ) )
197
+ await ensureDir ( path . join ( process . cwd ( ) , 'node_modules' ) )
198
+ await copy ( path . join ( root , 'node_modules' , 'next' ) , path . join ( process . cwd ( ) , 'node_modules' , 'next' ) )
197
199
198
- // await patchNextFiles(process.cwd())
200
+ await patchNextFiles ( process . cwd ( ) )
199
201
const serverFile = path . resolve ( process . cwd ( ) , 'node_modules' , 'next' , 'dist' , 'server' , 'base-server.js' )
200
202
const patchedData = await readFileSync ( serverFile , 'utf8' )
201
203
expect ( patchedData . includes ( '_REVALIDATE_SSG' ) ) . toBeTruthy ( )
202
204
expect ( patchedData . includes ( 'private: isPreviewMode && cachedData' ) ) . toBeTruthy ( )
203
205
204
- // await unpatchNextFiles(process.cwd())
206
+ await unpatchNextFiles ( process . cwd ( ) )
205
207
206
208
const unPatchedData = await readFileSync ( serverFile , 'utf8' )
207
209
expect ( unPatchedData . includes ( '_REVALIDATE_SSG' ) ) . toBeFalsy ( )
@@ -213,7 +215,7 @@ describe('dependency tracing', () => {
213
215
it ( 'generates dependency list from a source file' , async ( ) => {
214
216
const dependencies = await getDependenciesOfFile ( resolve ( __dirname , '../fixtures/analysis/background.js' ) )
215
217
expect ( dependencies ) . toEqual (
216
- [ 'test/webpack-api-runtime.js' , 'package.json' ] . map ( ( dep ) => resolve ( dirname ( __dirname ) , dep ) ) ,
218
+ [ 'test/webpack-api-runtime.js' , 'package.json' ] . map ( ( dep ) => resolve ( dirname ( resolve ( __dirname , '..' ) ) , dep ) ) ,
217
219
)
218
220
} )
219
221
} )
0 commit comments