MCPcopy
hub / github.com/vercel/next.js / setupTests

Function setupTests

test/integration/image-optimizer/test/util.ts:1704–1906  ·  view source on GitHub ↗
(ctx: SetupTestsCtx)

Source from the content-addressed store, hash-verified

1702}
1703
1704export const setupTests = (ctx: SetupTestsCtx) => {
1705 const nextConfig = new File(join(ctx.appDir, 'next.config.js'))
1706
1707 const originalIsNextDev = (global as any).isNextDev
1708 afterAll(() => {
1709 ;(global as any).isNextDev = originalIsNextDev
1710 })
1711
1712 describe('dev support w/o next.config.js', () => {
1713 if (ctx.nextConfigImages) {
1714 // skip this test because it requires next.config.js
1715 return
1716 }
1717
1718 const isDev = true
1719 // Set global.isNextDev for getDistDir()
1720 ;(global as any).isNextDev = isDev
1721 const imagesDir = join(ctx.appDir, getDistDir(), 'cache', 'images')
1722 const size = 384 // defaults defined in server/config.ts
1723 const curCtx: RunTestsCtx = {
1724 ...ctx,
1725 w: size,
1726 q: 75,
1727 isDev,
1728 imagesDir,
1729 }
1730
1731 beforeAll(async () => {
1732 const json = JSON.stringify({
1733 // See https://github.com/vercel/next.js/pull/60972
1734 outputFileTracingRoot: join(__dirname, '../../../..'),
1735 experimental: curCtx.nextConfigExperimental,
1736 } satisfies NextConfig)
1737 nextConfig.replace('{ /* replaceme */ }', json)
1738 curCtx.nextOutput = ''
1739 curCtx.appPort = await findPort()
1740 curCtx.app = await launchApp(curCtx.appDir, curCtx.appPort, {
1741 onStderr(msg) {
1742 curCtx.nextOutput += msg
1743 },
1744 cwd: curCtx.appDir,
1745 })
1746 await cleanImagesDir(imagesDir)
1747 })
1748 afterAll(async () => {
1749 nextConfig.restore()
1750 if (curCtx.app) await killApp(curCtx.app)
1751 })
1752
1753 runTests(curCtx)
1754 })
1755
1756 describe('dev support with next.config.js', () => {
1757 const isDev = true
1758 // Set global.isNextDev for getDistDir()
1759 ;(global as any).isNextDev = isDev
1760 const imagesDir = join(ctx.appDir, getDistDir(), 'cache', 'images')
1761 const size = 400

Calls 13

replaceMethod · 0.95
restoreMethod · 0.95
joinFunction · 0.90
getDistDirFunction · 0.90
findPortFunction · 0.90
launchAppFunction · 0.90
killAppFunction · 0.90
nextBuildFunction · 0.90
nextStartFunction · 0.90
describeFunction · 0.85
cleanImagesDirFunction · 0.85
runTestsFunction · 0.70

Tested by

no test coverage detected