rsnext/test/e2e/app-dir/app/flying-shuttle.test.ts
JJ Kasper 4e84f696f0
Add experimental trace file field (#65071)
This adds a new field to our `.nft.json` trace files when enabled behind
a feature flag to output the hashes for the traced files.

Closes NEXT-3232
2024-04-26 10:08:02 -07:00

61 lines
1.6 KiB
TypeScript

import fs from 'fs'
import path from 'path'
import { nextTestSetup, isNextStart } from 'e2e-utils'
describe('should output updated trace files', () => {
if (!isNextStart) {
it('should skip for non-next start', () => {})
return
}
const { next } = nextTestSetup({
files: __dirname,
dependencies: {
nanoid: '4.0.1',
},
env: {
FLYING_SHUTTLE: 'true',
},
})
it('should have file hashes in trace files', async () => {
const deploymentsTracePath = path.join(
next.testDir,
'.next/server/app/dashboard/deployments/[id]/page.js.nft.json'
)
const deploymentsTrace = JSON.parse(
await fs.promises.readFile(deploymentsTracePath, 'utf8')
)
const ssgTracePath = path.join(
next.testDir,
'.next/server/pages/ssg.js.nft.json'
)
const ssgTrace = JSON.parse(
await fs.promises.readFile(ssgTracePath, 'utf8')
)
expect(deploymentsTrace.fileHashes).toBeTruthy()
expect(ssgTrace.fileHashes).toBeTruthy()
// ensure all files have corresponding fileHashes
for (const [traceFile, traceFilePath] of [
[deploymentsTrace, deploymentsTracePath],
[ssgTrace, ssgTracePath],
]) {
for (const key of traceFile.files) {
const absoluteKey = path.join(path.dirname(traceFilePath), key)
const stats = await fs.promises.stat(absoluteKey)
if (
stats.isSymbolicLink() ||
stats.isDirectory() ||
absoluteKey.startsWith(path.join(next.testDir, '.next'))
) {
continue
}
expect(typeof traceFile.fileHashes[key]).toBe('string')
}
}
})
})