Unverified Commit 59bda2d8 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

More Turbopack fixes (#56299)

Skips additional production-only tests.

Follow-up to #56089.

In this PR I went through all of `test/integration` looking for `nextBuild(` and added the skipping logic.
parent ecd94c1a
...@@ -19,103 +19,105 @@ let cdnAccessLog = [] ...@@ -19,103 +19,105 @@ let cdnAccessLog = []
const nextConfig = new File(path.resolve(__dirname, '../next.config.js')) const nextConfig = new File(path.resolve(__dirname, '../next.config.js'))
describe('absolute assetPrefix with path prefix', () => { describe('absolute assetPrefix with path prefix', () => {
beforeAll(async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
cdnPort = await findPort() beforeAll(async () => {
// lightweight http proxy cdnPort = await findPort()
cdn = http.createServer((clientReq, clientRes) => { // lightweight http proxy
const proxyPath = clientReq.url.slice('/path-prefix'.length) cdn = http.createServer((clientReq, clientRes) => {
cdnAccessLog.push(proxyPath) const proxyPath = clientReq.url.slice('/path-prefix'.length)
const proxyReq = http.request( cdnAccessLog.push(proxyPath)
{ const proxyReq = http.request(
hostname: 'localhost', {
port: appPort, hostname: 'localhost',
path: proxyPath, port: appPort,
method: clientReq.method, path: proxyPath,
headers: clientReq.headers, method: clientReq.method,
}, headers: clientReq.headers,
(proxyRes) => { },
// cdn must be configured to allow requests from this origin (proxyRes) => {
proxyRes.headers[ // cdn must be configured to allow requests from this origin
'Access-Control-Allow-Origin' proxyRes.headers[
] = `http://localhost:${appPort}` 'Access-Control-Allow-Origin'
clientRes.writeHead(proxyRes.statusCode, proxyRes.headers) ] = `http://localhost:${appPort}`
proxyRes.pipe(clientRes, { end: true }) clientRes.writeHead(proxyRes.statusCode, proxyRes.headers)
} proxyRes.pipe(clientRes, { end: true })
}
)
clientReq.pipe(proxyReq, { end: true })
})
await new Promise((resolve) => cdn.listen(cdnPort, resolve))
nextConfig.replace('__CDN_PORT__', cdnPort)
await nextBuild(appDir)
buildId = await fs.readFile(
path.resolve(__dirname, '../.next/BUILD_ID'),
'utf8'
) )
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
clientReq.pipe(proxyReq, { end: true }) afterEach(() => {
cdnAccessLog = []
}) })
await new Promise((resolve) => cdn.listen(cdnPort, resolve))
nextConfig.replace('__CDN_PORT__', cdnPort)
await nextBuild(appDir)
buildId = await fs.readFile(
path.resolve(__dirname, '../.next/BUILD_ID'),
'utf8'
)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterEach(() => { afterAll(() => killApp(app))
cdnAccessLog = [] afterAll(() => cdn.close())
}) afterAll(() => nextConfig.restore())
afterAll(() => killApp(app)) it('should not fetch static data from a CDN', async () => {
afterAll(() => cdn.close()) const browser = await webdriver(appPort, '/')
afterAll(() => nextConfig.restore()) await browser.waitForElementByCss('#about-link').click()
const prop = await browser.waitForElementByCss('#prop').text()
expect(prop).toBe('hello')
expect(cdnAccessLog).not.toContain(`/_next/data/${buildId}/about.json`)
})
it('should not fetch static data from a CDN', async () => { it('should fetch from cache correctly', async () => {
const browser = await webdriver(appPort, '/') const browser = await webdriver(appPort, '/')
await browser.waitForElementByCss('#about-link').click() await browser.eval('window.clientSideNavigated = true')
const prop = await browser.waitForElementByCss('#prop').text() await browser.waitForElementByCss('#about-link').click()
expect(prop).toBe('hello') await browser.waitForElementByCss('#prop')
expect(cdnAccessLog).not.toContain(`/_next/data/${buildId}/about.json`) await browser.back()
}) await browser.waitForElementByCss('#about-link').click()
const prop = await browser.waitForElementByCss('#prop').text()
expect(prop).toBe('hello')
expect(await browser.eval('window.clientSideNavigated')).toBe(true)
expect(
cdnAccessLog.filter(
(path) => path === `/_next/data/${buildId}/about.json`
)
).toHaveLength(0)
})
it('should fetch from cache correctly', async () => { it('should work with getStaticPaths prerendered', async () => {
const browser = await webdriver(appPort, '/') const browser = await webdriver(appPort, '/')
await browser.eval('window.clientSideNavigated = true') await browser.waitForElementByCss('#gsp-prerender-link').click()
await browser.waitForElementByCss('#about-link').click() const prop = await browser.waitForElementByCss('#prop').text()
await browser.waitForElementByCss('#prop') expect(prop).toBe('prerendered')
await browser.back() expect(cdnAccessLog).not.toContain(
await browser.waitForElementByCss('#about-link').click() `/_next/data/${buildId}/gsp-fallback/prerendered.json`
const prop = await browser.waitForElementByCss('#prop').text()
expect(prop).toBe('hello')
expect(await browser.eval('window.clientSideNavigated')).toBe(true)
expect(
cdnAccessLog.filter(
(path) => path === `/_next/data/${buildId}/about.json`
) )
).toHaveLength(0) })
})
it('should work with getStaticPaths prerendered', async () => {
const browser = await webdriver(appPort, '/')
await browser.waitForElementByCss('#gsp-prerender-link').click()
const prop = await browser.waitForElementByCss('#prop').text()
expect(prop).toBe('prerendered')
expect(cdnAccessLog).not.toContain(
`/_next/data/${buildId}/gsp-fallback/prerendered.json`
)
})
it('should work with getStaticPaths fallback', async () => { it('should work with getStaticPaths fallback', async () => {
const browser = await webdriver(appPort, '/') const browser = await webdriver(appPort, '/')
await browser.waitForElementByCss('#gsp-fallback-link').click() await browser.waitForElementByCss('#gsp-fallback-link').click()
const prop = await browser.waitForElementByCss('#prop').text() const prop = await browser.waitForElementByCss('#prop').text()
expect(prop).toBe('fallback') expect(prop).toBe('fallback')
expect(cdnAccessLog).not.toContain( expect(cdnAccessLog).not.toContain(
`/_next/data/${buildId}/gsp-fallback/fallback.json` `/_next/data/${buildId}/gsp-fallback/fallback.json`
) )
}) })
it('should work with getServerSideProps', async () => { it('should work with getServerSideProps', async () => {
const browser = await webdriver(appPort, '/') const browser = await webdriver(appPort, '/')
await browser.waitForElementByCss('#gssp-link').click() await browser.waitForElementByCss('#gssp-link').click()
const prop = await browser.waitForElementByCss('#prop').text() const prop = await browser.waitForElementByCss('#prop').text()
expect(prop).toBe('foo') expect(prop).toBe('foo')
expect(cdnAccessLog).not.toContain( expect(cdnAccessLog).not.toContain(
`/_next/data/${buildId}/gssp.json?prop=foo` `/_next/data/${buildId}/gssp.json?prop=foo`
) )
})
}) })
}) })
...@@ -13,114 +13,116 @@ const nextConfig = new File(join(appDir, 'next.config.js')) ...@@ -13,114 +13,116 @@ const nextConfig = new File(join(appDir, 'next.config.js'))
let buildOutput let buildOutput
describe('AMP Validation on Export', () => { describe('AMP Validation on Export', () => {
beforeAll(async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const { stdout = '', stderr = '' } = await nextBuild(appDir, [], { beforeAll(async () => {
stdout: true, const { stdout = '', stderr = '' } = await nextBuild(appDir, [], {
stderr: true, stdout: true,
stderr: true,
})
await nextExport(appDir, { outdir: outDir }, { ignoreFail: true })
buildOutput = stdout + stderr
}) })
await nextExport(appDir, { outdir: outDir }, { ignoreFail: true })
buildOutput = stdout + stderr
})
it('should have shown errors during build', async () => { it('should have shown errors during build', async () => {
expect(buildOutput).toMatch( expect(buildOutput).toMatch(
/error.*The mandatory attribute 'height' is missing in tag 'amp-video'\./ /error.*The mandatory attribute 'height' is missing in tag 'amp-video'\./
) )
}) })
it('should export AMP pages', async () => { it('should export AMP pages', async () => {
const toCheck = ['first', 'second', 'third.amp'] const toCheck = ['first', 'second', 'third.amp']
await Promise.all( await Promise.all(
toCheck.map(async (page) => { toCheck.map(async (page) => {
const content = await readFile(join(outDir, `${page}.html`)) const content = await readFile(join(outDir, `${page}.html`))
await validateAMP(content.toString()) await validateAMP(content.toString())
}) })
) )
}) })
// this is now an error instead of a warning // this is now an error instead of a warning
it.skip('shows AMP warning without throwing error', async () => { it.skip('shows AMP warning without throwing error', async () => {
nextConfig.replace( nextConfig.replace(
'// exportPathMap', '// exportPathMap',
`exportPathMap: function(defaultMap) { `exportPathMap: function(defaultMap) {
return { return {
'/cat': { page: '/cat' }, '/cat': { page: '/cat' },
} }
},` },`
)
try {
const { stdout, stderr } = await runNextCommand(['export', appDir], {
stdout: true,
stderr: true,
})
expect(stdout).toMatch(
/error.*The mandatory attribute 'height' is missing in tag 'amp-video'\./
)
await expect(access(join(outDir, 'cat.html'))).resolves.toBe(undefined)
await expect(stderr).not.toMatch(
/Found conflicting amp tag "meta" with conflicting prop name="viewport"/
) )
} finally {
nextConfig.restore()
}
})
// img instead of amp-img no longer shows a warning try {
it.skip('throws error on AMP error', async () => { const { stdout, stderr } = await runNextCommand(['export', appDir], {
nextConfig.replace( stdout: true,
'// exportPathMap', stderr: true,
`exportPathMap: function(defaultMap) { })
expect(stdout).toMatch(
/error.*The mandatory attribute 'height' is missing in tag 'amp-video'\./
)
await expect(access(join(outDir, 'cat.html'))).resolves.toBe(undefined)
await expect(stderr).not.toMatch(
/Found conflicting amp tag "meta" with conflicting prop name="viewport"/
)
} finally {
nextConfig.restore()
}
})
// img instead of amp-img no longer shows a warning
it.skip('throws error on AMP error', async () => {
nextConfig.replace(
'// exportPathMap',
`exportPathMap: function(defaultMap) {
return { return {
'/dog': { page: '/dog' }, '/dog': { page: '/dog' },
} }
},` },`
)
try {
const { stdout, stderr } = await runNextCommand(['export', appDir], {
stdout: true,
stderr: true,
})
expect(stdout).toMatch(
/error.*The parent tag of tag 'img' is 'div', but it can only be 'i-amphtml-sizer-intrinsic'\./
)
await expect(access(join(outDir, 'dog.html'))).resolves.toBe(undefined)
await expect(stderr).not.toMatch(
/Found conflicting amp tag "meta" with conflicting prop name="viewport"/
) )
} finally {
nextConfig.restore()
}
})
// img instead of amp-img no longer shows a warning try {
it.skip('shows warning and error when throwing error', async () => { const { stdout, stderr } = await runNextCommand(['export', appDir], {
nextConfig.replace( stdout: true,
'// exportPathMap', stderr: true,
`exportPathMap: function(defaultMap) { })
expect(stdout).toMatch(
/error.*The parent tag of tag 'img' is 'div', but it can only be 'i-amphtml-sizer-intrinsic'\./
)
await expect(access(join(outDir, 'dog.html'))).resolves.toBe(undefined)
await expect(stderr).not.toMatch(
/Found conflicting amp tag "meta" with conflicting prop name="viewport"/
)
} finally {
nextConfig.restore()
}
})
// img instead of amp-img no longer shows a warning
it.skip('shows warning and error when throwing error', async () => {
nextConfig.replace(
'// exportPathMap',
`exportPathMap: function(defaultMap) {
return { return {
'/dog-cat': { page: '/dog-cat' }, '/dog-cat': { page: '/dog-cat' },
} }
},` },`
)
try {
const { stdout, stderr } = await runNextCommand(['export', appDir], {
stdout: true,
stderr: true,
})
expect(stdout).toMatch(
/error.*The parent tag of tag 'img' is 'div', but it can only be 'i-amphtml-sizer-intrinsic'\./
) )
await expect(access(join(outDir, 'dog-cat.html'))).resolves.toBe(
undefined try {
) const { stdout, stderr } = await runNextCommand(['export', appDir], {
await expect(stderr).not.toMatch( stdout: true,
/Found conflicting amp tag "meta" with conflicting prop name="viewport"/ stderr: true,
) })
} finally { expect(stdout).toMatch(
nextConfig.restore() /error.*The parent tag of tag 'img' is 'div', but it can only be 'i-amphtml-sizer-intrinsic'\./
} )
await expect(access(join(outDir, 'dog-cat.html'))).resolves.toBe(
undefined
)
await expect(stderr).not.toMatch(
/Found conflicting amp tag "meta" with conflicting prop name="viewport"/
)
} finally {
nextConfig.restore()
}
})
}) })
}) })
...@@ -14,41 +14,43 @@ let appPort ...@@ -14,41 +14,43 @@ let appPort
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
describe('AMP Custom Optimizer', () => { describe('AMP Custom Optimizer', () => {
it('should build and start for static page', async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const { code } = await nextBuild(appDir) it('should build and start for static page', async () => {
expect(code).toBe(0) const { code } = await nextBuild(appDir)
expect(code).toBe(0)
appPort = await findPort()
app = await nextStart(appDir, appPort) appPort = await findPort()
app = await nextStart(appDir, appPort)
const html = await renderViaHTTP(appPort, '/')
await killApp(app) const html = await renderViaHTTP(appPort, '/')
await killApp(app)
expect(html).toContain(
'amp-twitter width="500" height="500" layout="responsive" data-tweetid="1159145442896166912"' expect(html).toContain(
) 'amp-twitter width="500" height="500" layout="responsive" data-tweetid="1159145442896166912"'
expect(html).toContain('i-amphtml-version="001515617716922"') )
expect(html).toContain( expect(html).toContain('i-amphtml-version="001515617716922"')
'script async src="https://cdn.ampproject.org/rtv/001515617716922/v0.mjs"' expect(html).toContain(
) 'script async src="https://cdn.ampproject.org/rtv/001515617716922/v0.mjs"'
}) )
})
it('should build and start for dynamic page', async () => {
const { code } = await nextBuild(appDir) it('should build and start for dynamic page', async () => {
expect(code).toBe(0) const { code } = await nextBuild(appDir)
expect(code).toBe(0)
appPort = await findPort()
app = await nextStart(appDir, appPort) appPort = await findPort()
app = await nextStart(appDir, appPort)
const html = await renderViaHTTP(appPort, '/dynamic')
await killApp(app) const html = await renderViaHTTP(appPort, '/dynamic')
await killApp(app)
expect(html).toContain(
'amp-img width="500" height="500" layout="responsive" src="https://amp.dev/static/samples/img/story_dog2_portrait.jpg"' expect(html).toContain(
) 'amp-img width="500" height="500" layout="responsive" src="https://amp.dev/static/samples/img/story_dog2_portrait.jpg"'
expect(html).toContain('i-amphtml-version="001515617716922"') )
expect(html).toContain( expect(html).toContain('i-amphtml-version="001515617716922"')
'script async src="https://cdn.ampproject.org/rtv/001515617716922/v0.mjs"' expect(html).toContain(
) 'script async src="https://cdn.ampproject.org/rtv/001515617716922/v0.mjs"'
)
})
}) })
}) })
...@@ -15,33 +15,37 @@ let appPort ...@@ -15,33 +15,37 @@ let appPort
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
describe('AMP Custom Validator', () => { describe('AMP Custom Validator', () => {
it('should build and start successfully', async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const { code } = await nextBuild(appDir) it('should build and start successfully', async () => {
expect(code).toBe(0) const { code } = await nextBuild(appDir)
expect(code).toBe(0)
appPort = await findPort() appPort = await findPort()
app = await nextStart(appDir, appPort) app = await nextStart(appDir, appPort)
const html = await renderViaHTTP(appPort, '/') const html = await renderViaHTTP(appPort, '/')
await killApp(app) await killApp(app)
expect(html).toContain('Hello from AMP') expect(html).toContain('Hello from AMP')
})
}) })
it('should run in dev mode successfully', async () => { describe('development mode', () => {
let stderr = '' it('should run in dev mode successfully', async () => {
let stderr = ''
appPort = await findPort() appPort = await findPort()
app = await launchApp(appDir, appPort, { app = await launchApp(appDir, appPort, {
onStderr(msg) { onStderr(msg) {
stderr += msg || '' stderr += msg || ''
}, },
}) })
const html = await renderViaHTTP(appPort, '/') const html = await renderViaHTTP(appPort, '/')
await killApp(app) await killApp(app)
expect(stderr).not.toContain('error') expect(stderr).not.toContain('error')
expect(html).toContain('Hello from AMP') expect(html).toContain('Hello from AMP')
})
}) })
}) })
...@@ -16,19 +16,21 @@ let appPort ...@@ -16,19 +16,21 @@ let appPort
let app let app
describe('AMP Fragment Styles', () => { describe('AMP Fragment Styles', () => {
beforeAll(async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
await nextBuild(appDir, []) beforeAll(async () => {
appPort = await findPort() await nextBuild(appDir, [])
app = await nextStart(appDir, appPort) appPort = await findPort()
}) app = await nextStart(appDir, appPort)
afterAll(() => killApp(app)) })
afterAll(() => killApp(app))
it('adds styles from fragment in AMP mode correctly', async () => { it('adds styles from fragment in AMP mode correctly', async () => {
const html = await renderViaHTTP(appPort, '/', { amp: 1 }) const html = await renderViaHTTP(appPort, '/', { amp: 1 })
await validateAMP(html) await validateAMP(html)
const $ = cheerio.load(html) const $ = cheerio.load(html)
const styles = $('style[amp-custom]').text() const styles = $('style[amp-custom]').text()
expect(styles).toMatch(/background:(.*|)hotpink/) expect(styles).toMatch(/background:(.*|)hotpink/)
expect(styles).toMatch(/font-size:(.*|)16\.4px/) expect(styles).toMatch(/font-size:(.*|)16\.4px/)
})
}) })
}) })
...@@ -118,32 +118,37 @@ describe('AMP SSG Support', () => { ...@@ -118,32 +118,37 @@ describe('AMP SSG Support', () => {
runTests(true) runTests(true)
}) })
describe('export mode', () => { describe('export mode', () => {
let buildId ;(process.env.TURBOPACK ? describe.skip : describe)(
'production mode',
beforeAll(async () => { () => {
await nextBuild(appDir) let buildId
await nextExport(appDir, { outdir: join(appDir, 'out') })
buildId = await fs.readFile(join(appDir, '.next/BUILD_ID'), 'utf8') beforeAll(async () => {
}) await nextBuild(appDir)
await nextExport(appDir, { outdir: join(appDir, 'out') })
it('should have copied SSG files correctly', async () => { buildId = await fs.readFile(join(appDir, '.next/BUILD_ID'), 'utf8')
const outFile = (file) => join(appDir, 'out', file) })
expect(await fsExists(outFile('amp.html'))).toBe(true) it('should have copied SSG files correctly', async () => {
expect(await fsExists(outFile('index.html'))).toBe(true) const outFile = (file) => join(appDir, 'out', file)
expect(await fsExists(outFile('hybrid.html'))).toBe(true)
expect(await fsExists(outFile('amp.amp.html'))).toBe(false) expect(await fsExists(outFile('amp.html'))).toBe(true)
expect(await fsExists(outFile('hybrid.amp.html'))).toBe(true) expect(await fsExists(outFile('index.html'))).toBe(true)
expect(await fsExists(outFile('blog/post-1.html'))).toBe(true) expect(await fsExists(outFile('hybrid.html'))).toBe(true)
expect(await fsExists(outFile('blog/post-1.amp.html'))).toBe(true) expect(await fsExists(outFile('amp.amp.html'))).toBe(false)
expect(await fsExists(outFile('hybrid.amp.html'))).toBe(true)
expect( expect(await fsExists(outFile('blog/post-1.html'))).toBe(true)
await fsExists(outFile(join('_next/data', buildId, 'amp.json'))) expect(await fsExists(outFile('blog/post-1.amp.html'))).toBe(true)
).toBe(true)
expect(
expect( await fsExists(outFile(join('_next/data', buildId, 'amp.json')))
await fsExists(outFile(join('_next/data', buildId, 'hybrid.json'))) ).toBe(true)
).toBe(true)
}) expect(
await fsExists(outFile(join('_next/data', buildId, 'hybrid.json')))
).toBe(true)
})
}
)
}) })
}) })
...@@ -59,8 +59,7 @@ describe('API routes', () => { ...@@ -59,8 +59,7 @@ describe('API routes', () => {
runTests() runTests()
}) })
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
describe('Server support', () => {
beforeAll(async () => { beforeAll(async () => {
await nextBuild(appDir) await nextBuild(appDir)
appPort = await findPort() appPort = await findPort()
......
...@@ -643,8 +643,7 @@ describe('API routes', () => { ...@@ -643,8 +643,7 @@ describe('API routes', () => {
runTests(true) runTests(true)
}) })
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
describe('Server support', () => {
beforeAll(async () => { beforeAll(async () => {
await nextBuild(appDir) await nextBuild(appDir)
mode = 'server' mode = 'server'
......
...@@ -11,85 +11,54 @@ import { ...@@ -11,85 +11,54 @@ import {
} from './utils' } from './utils'
describe('app dir with output export (next dev / next build)', () => { describe('app dir with output export (next dev / next build)', () => {
it('should throw when exportPathMap configured', async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
nextConfig.replace( it('should throw when exportPathMap configured', async () => {
'trailingSlash: true,', nextConfig.replace(
`trailingSlash: true, 'trailingSlash: true,',
`trailingSlash: true,
exportPathMap: async function (map) { exportPathMap: async function (map) {
return map return map
},` },`
) )
await fs.remove(distDir) await fs.remove(distDir)
await fs.remove(exportDir) await fs.remove(exportDir)
let result = { code: 0, stderr: '' } let result = { code: 0, stderr: '' }
try { try {
result = await nextBuild(appDir, [], { stderr: true }) result = await nextBuild(appDir, [], { stderr: true })
} finally { } finally {
nextConfig.restore() nextConfig.restore()
} }
expect(result.code).toBe(1) expect(result.code).toBe(1)
expect(result.stderr).toContain( expect(result.stderr).toContain(
'The "exportPathMap" configuration cannot be used with the "app" directory. Please use generateStaticParams() instead.' 'The "exportPathMap" configuration cannot be used with the "app" directory. Please use generateStaticParams() instead.'
) )
})
it('should warn about "next export" is no longer needed with config', async () => {
await fs.remove(distDir)
await fs.remove(exportDir)
await nextBuild(appDir)
expect(await getFiles()).toEqual(expectedWhenTrailingSlashTrue)
let stdout = ''
let stderr = ''
await nextExportDefault(appDir, {
onStdout(msg) {
stdout += msg
},
onStderr(msg) {
stderr += msg
},
}) })
expect(stderr).toContain( it('should warn about "next export" is no longer needed with config', async () => {
'"next export" is no longer needed when "output: export" is configured in next.config.js' await fs.remove(distDir)
) await fs.remove(exportDir)
expect(stdout).toContain('Export successful. Files written to') await nextBuild(appDir)
expect(await getFiles()).toEqual(expectedWhenTrailingSlashTrue) expect(await getFiles()).toEqual(expectedWhenTrailingSlashTrue)
}) let stdout = ''
it('should error when "next export -o <dir>" is used with config', async () => { let stderr = ''
await fs.remove(distDir) await nextExportDefault(appDir, {
await fs.remove(exportDir) onStdout(msg) {
await nextBuild(appDir) stdout += msg
expect(await getFiles()).toEqual(expectedWhenTrailingSlashTrue) },
let stdout = '' onStderr(msg) {
let stderr = '' stderr += msg
let error = undefined },
try { })
await nextExport( expect(stderr).toContain(
appDir, '"next export" is no longer needed when "output: export" is configured in next.config.js'
{ outdir: exportDir },
{
onStdout(msg) {
stdout += msg
},
onStderr(msg) {
stderr += msg
},
}
) )
} catch (e) { expect(stdout).toContain('Export successful. Files written to')
error = e expect(await getFiles()).toEqual(expectedWhenTrailingSlashTrue)
} })
expect(error).toBeDefined() it('should error when "next export -o <dir>" is used with config', async () => {
expect(stderr).toContain( await fs.remove(distDir)
'"next export -o <dir>" cannot be used when "output: export" is configured in next.config.js. Instead add "distDir" in next.config.js' await fs.remove(exportDir)
)
expect(stdout).not.toContain('Export successful. Files written to')
})
it('should error when no config.output detected for next export', async () => {
await fs.remove(distDir)
await fs.remove(exportDir)
nextConfig.replace(`output: 'export',`, '')
try {
await nextBuild(appDir) await nextBuild(appDir)
expect(await getFiles()).toEqual([]) expect(await getFiles()).toEqual(expectedWhenTrailingSlashTrue)
let stdout = '' let stdout = ''
let stderr = '' let stderr = ''
let error = undefined let error = undefined
...@@ -111,32 +80,65 @@ describe('app dir with output export (next dev / next build)', () => { ...@@ -111,32 +80,65 @@ describe('app dir with output export (next dev / next build)', () => {
} }
expect(error).toBeDefined() expect(error).toBeDefined()
expect(stderr).toContain( expect(stderr).toContain(
'"next export" does not work with App Router. Please use "output: export" in next.config.js' '"next export -o <dir>" cannot be used when "output: export" is configured in next.config.js. Instead add "distDir" in next.config.js'
) )
expect(stdout).not.toContain('Export successful. Files written to') expect(stdout).not.toContain('Export successful. Files written to')
expect(await getFiles()).toEqual([]) })
} finally { it('should error when no config.output detected for next export', async () => {
nextConfig.restore()
await fs.remove(distDir) await fs.remove(distDir)
await fs.remove(exportDir) await fs.remove(exportDir)
} nextConfig.replace(`output: 'export',`, '')
}) try {
it('should correctly emit exported assets to config.distDir', async () => { await nextBuild(appDir)
const outputDir = join(appDir, 'output') expect(await getFiles()).toEqual([])
await fs.remove(distDir) let stdout = ''
await fs.remove(outputDir) let stderr = ''
nextConfig.replace( let error = undefined
'trailingSlash: true,', try {
`trailingSlash: true, await nextExport(
distDir: 'output',` appDir,
) { outdir: exportDir },
try { {
await nextBuild(appDir) onStdout(msg) {
expect(await getFiles(outputDir)).toEqual(expectedWhenTrailingSlashTrue) stdout += msg
} finally { },
nextConfig.restore() onStderr(msg) {
stderr += msg
},
}
)
} catch (e) {
error = e
}
expect(error).toBeDefined()
expect(stderr).toContain(
'"next export" does not work with App Router. Please use "output: export" in next.config.js'
)
expect(stdout).not.toContain('Export successful. Files written to')
expect(await getFiles()).toEqual([])
} finally {
nextConfig.restore()
await fs.remove(distDir)
await fs.remove(exportDir)
}
})
it('should correctly emit exported assets to config.distDir', async () => {
const outputDir = join(appDir, 'output')
await fs.remove(distDir) await fs.remove(distDir)
await fs.remove(outputDir) await fs.remove(outputDir)
} nextConfig.replace(
'trailingSlash: true,',
`trailingSlash: true,
distDir: 'output',`
)
try {
await nextBuild(appDir)
expect(await getFiles(outputDir)).toEqual(expectedWhenTrailingSlashTrue)
} finally {
nextConfig.restore()
await fs.remove(distDir)
await fs.remove(outputDir)
}
})
}) })
}) })
...@@ -18,43 +18,45 @@ const nextConfig = new File(join(appDir, 'next.config.js')) ...@@ -18,43 +18,45 @@ const nextConfig = new File(join(appDir, 'next.config.js'))
let app let app
describe('app dir with output export (next start)', () => { describe('app dir with output export (next start)', () => {
afterEach(async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
await killApp(app) afterEach(async () => {
nextConfig.restore() await killApp(app)
await fs.remove(distDir) nextConfig.restore()
await fs.remove(exportDir) await fs.remove(distDir)
}) await fs.remove(exportDir)
})
it('should error during next start with output export', async () => { it('should error during next start with output export', async () => {
const { code } = await nextBuild(appDir) const { code } = await nextBuild(appDir)
expect(code).toBe(0) expect(code).toBe(0)
const port = await findPort() const port = await findPort()
let stderr = '' let stderr = ''
app = await nextStart(appDir, port, { app = await nextStart(appDir, port, {
onStderr(msg: string) { onStderr(msg: string) {
stderr += msg || '' stderr += msg || ''
}, },
})
await check(() => stderr, /error/i)
expect(stderr).toContain(
'"next start" does not work with "output: export" configuration. Use "npx serve@latest out" instead.'
)
}) })
await check(() => stderr, /error/i)
expect(stderr).toContain(
'"next start" does not work with "output: export" configuration. Use "npx serve@latest out" instead.'
)
})
it('should warn during next start with output standalone', async () => { it('should warn during next start with output standalone', async () => {
nextConfig.replace(`output: 'export'`, `output: 'standalone'`) nextConfig.replace(`output: 'export'`, `output: 'standalone'`)
const { code } = await nextBuild(appDir) const { code } = await nextBuild(appDir)
expect(code).toBe(0) expect(code).toBe(0)
const port = await findPort() const port = await findPort()
let stderr = '' let stderr = ''
app = await nextStart(appDir, port, { app = await nextStart(appDir, port, {
onStderr(msg: string) { onStderr(msg: string) {
stderr += msg || '' stderr += msg || ''
}, },
})
await check(() => stderr, /⚠/i)
expect(stderr).toContain(
`"next start" does not work with "output: standalone" configuration. Use "node .next/standalone/server.js" instead.`
)
}) })
await check(() => stderr, /⚠/i)
expect(stderr).toContain(
`"next start" does not work with "output: standalone" configuration. Use "node .next/standalone/server.js" instead.`
)
}) })
}) })
...@@ -51,24 +51,26 @@ const respectsChunkAttachmentOrder = async () => { ...@@ -51,24 +51,26 @@ const respectsChunkAttachmentOrder = async () => {
} }
describe('Root components import order', () => { describe('Root components import order', () => {
beforeAll(async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
await nextBuild(appDir) beforeAll(async () => {
appPort = await findPort() await nextBuild(appDir)
app = await nextStart(appDir, appPort) appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
it(
'_app chunks should be attached to de dom before page chunks',
respectsChunkAttachmentOrder
)
it(
'root components should be imported in this order _document > _app > page in order to respect side effects',
respectsSideEffects
)
}) })
afterAll(() => killApp(app))
it(
'_app chunks should be attached to de dom before page chunks',
respectsChunkAttachmentOrder
)
it(
'root components should be imported in this order _document > _app > page in order to respect side effects',
respectsSideEffects
)
}) })
describe('on dev server', () => { describe('development mode', () => {
beforeAll(async () => { beforeAll(async () => {
appPort = await findPort() appPort = await findPort()
app = await launchApp(join(__dirname, '../'), appPort) app = await launchApp(join(__dirname, '../'), appPort)
......
...@@ -16,25 +16,27 @@ let server ...@@ -16,25 +16,27 @@ let server
let app let app
describe('Custom Document Fragment Styles', () => { describe('Custom Document Fragment Styles', () => {
beforeAll(async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
await nextBuild(appDir) beforeAll(async () => {
app = nextServer({ await nextBuild(appDir)
dir: join(__dirname, '../'), app = nextServer({
dev: false, dir: join(__dirname, '../'),
quiet: true, dev: false,
}) quiet: true,
})
server = await startApp(app) server = await startApp(app)
appPort = server.address().port appPort = server.address().port
}) })
afterAll(() => stopApp(server)) afterAll(() => stopApp(server))
it('correctly adds styles from fragment styles key', async () => { it('correctly adds styles from fragment styles key', async () => {
const html = await renderViaHTTP(appPort, '/') const html = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(html) const $ = cheerio.load(html)
const styles = $('style').text() const styles = $('style').text()
expect(styles).toMatch(/background:(.*|)hotpink/) expect(styles).toMatch(/background:(.*|)hotpink/)
expect(styles).toMatch(/font-size:(.*|)16\.4px/) expect(styles).toMatch(/font-size:(.*|)16\.4px/)
})
}) })
}) })
import { nextBuild } from 'next-test-utils' import { nextBuild } from 'next-test-utils'
import { join } from 'path' import { join } from 'path'
describe('app-dynamic-error', () => {
it('throws an error when prerendering a page with config dynamic error', async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const appDir = join(__dirname, '../../app-dynamic-error') it('throws an error when prerendering a page with config dynamic error', async () => {
const { stderr, code } = await nextBuild(appDir, [], { const appDir = join(__dirname, '../../app-dynamic-error')
stderr: true, const { stderr, code } = await nextBuild(appDir, [], {
stdout: true, stderr: true,
stdout: true,
})
expect(stderr).toContain(
'Error occurred prerendering page "/dynamic-error"'
)
expect(code).toBe(1)
})
}) })
expect(stderr).toContain('Error occurred prerendering page "/dynamic-error"')
expect(code).toBe(1)
}) })
...@@ -27,8 +27,10 @@ const runTests = () => { ...@@ -27,8 +27,10 @@ const runTests = () => {
}) })
} }
describe('dev mode', () => { // Skip as it runs `next build`, seems that is a bug.
;(process.env.TURBOPACK ? describe.skip : describe)('dev mode', () => {
beforeAll(async () => { beforeAll(async () => {
// TODO: This look like a bug, `nextBuild` shouldn't be required here.
await nextBuild(appDir) await nextBuild(appDir)
appPort = await findPort() appPort = await findPort()
buildId = 'development' buildId = 'development'
......
...@@ -7,67 +7,71 @@ import { nextBuild } from 'next-test-utils' ...@@ -7,67 +7,71 @@ import { nextBuild } from 'next-test-utils'
const appDir = join(__dirname, '../app') const appDir = join(__dirname, '../app')
describe('build trace with extra entries', () => { describe('build trace with extra entries', () => {
it('should build and trace correctly', async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const result = await nextBuild(appDir, undefined, { it('should build and trace correctly', async () => {
cwd: appDir, const result = await nextBuild(appDir, undefined, {
stderr: true, cwd: appDir,
stdout: true, stderr: true,
}) stdout: true,
console.log(result) })
expect(result.code).toBe(0) console.log(result)
expect(result.code).toBe(0)
const appTrace = await fs.readJSON(
join(appDir, '.next/server/pages/_app.js.nft.json')
)
const indexTrace = await fs.readJSON(
join(appDir, '.next/server/pages/index.js.nft.json')
)
const anotherTrace = await fs.readJSON(
join(appDir, '.next/server/pages/another.js.nft.json')
)
const imageTrace = await fs.readJSON(
join(appDir, '.next/server/pages/image-import.js.nft.json')
)
const tracedFiles = [ const appTrace = await fs.readJSON(
...appTrace.files, join(appDir, '.next/server/pages/_app.js.nft.json')
...indexTrace.files, )
...anotherTrace.files, const indexTrace = await fs.readJSON(
...imageTrace.files, join(appDir, '.next/server/pages/index.js.nft.json')
] )
const anotherTrace = await fs.readJSON(
join(appDir, '.next/server/pages/another.js.nft.json')
)
const imageTrace = await fs.readJSON(
join(appDir, '.next/server/pages/image-import.js.nft.json')
)
expect(tracedFiles.some((file) => file.endsWith('hello.json'))).toBe(true) const tracedFiles = [
expect(tracedFiles.some((file) => file.includes('some-cms/index.js'))).toBe( ...appTrace.files,
true ...indexTrace.files,
) ...anotherTrace.files,
expect( ...imageTrace.files,
tracedFiles.some((file) => file === '../../../include-me/hello.txt') ]
).toBe(true)
expect(
tracedFiles.some((file) => file === '../../../include-me/second.txt')
).toBe(true)
expect(indexTrace.files.some((file) => file.includes('exclude-me'))).toBe(
false
)
expect( expect(tracedFiles.some((file) => file.endsWith('hello.json'))).toBe(true)
tracedFiles.some((file) => expect(
file.includes('nested-structure/constants/package.json') tracedFiles.some((file) => file.includes('some-cms/index.js'))
).toBe(true)
expect(
tracedFiles.some((file) => file === '../../../include-me/hello.txt')
).toBe(true)
expect(
tracedFiles.some((file) => file === '../../../include-me/second.txt')
).toBe(true)
expect(indexTrace.files.some((file) => file.includes('exclude-me'))).toBe(
false
) )
).toBe(true)
expect( expect(
tracedFiles.some((file) => file.includes('nested-structure/package.json')) tracedFiles.some((file) =>
).toBe(true) file.includes('nested-structure/constants/package.json')
expect( )
tracedFiles.some((file) => ).toBe(true)
file.includes('nested-structure/dist/constants.js') expect(
tracedFiles.some((file) =>
file.includes('nested-structure/package.json')
)
).toBe(true)
expect(
tracedFiles.some((file) =>
file.includes('nested-structure/dist/constants.js')
)
).toBe(true)
expect(
tracedFiles.some((file) => file.includes('public/another.jpg'))
).toBe(true)
expect(tracedFiles.some((file) => file.includes('public/test.jpg'))).toBe(
false
) )
).toBe(true) })
expect(
tracedFiles.some((file) => file.includes('public/another.jpg'))
).toBe(true)
expect(tracedFiles.some((file) => file.includes('public/test.jpg'))).toBe(
false
)
}) })
}) })
...@@ -7,81 +7,87 @@ import { nextBuild } from 'next-test-utils' ...@@ -7,81 +7,87 @@ import { nextBuild } from 'next-test-utils'
const appDir = join(__dirname, '../app') const appDir = join(__dirname, '../app')
describe('build trace with extra entries', () => { describe('build trace with extra entries', () => {
it('should build and trace correctly', async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const result = await nextBuild(appDir, undefined, { it('should build and trace correctly', async () => {
cwd: appDir, const result = await nextBuild(appDir, undefined, {
stderr: true, cwd: appDir,
stdout: true, stderr: true,
}) stdout: true,
console.log(result) })
expect(result.code).toBe(0) console.log(result)
expect(result.code).toBe(0)
const appTrace = await fs.readJSON(
join(appDir, '.next/server/pages/_app.js.nft.json')
)
const indexTrace = await fs.readJSON(
join(appDir, '.next/server/pages/index.js.nft.json')
)
const anotherTrace = await fs.readJSON(
join(appDir, '.next/server/pages/another.js.nft.json')
)
const imageTrace = await fs.readJSON(
join(appDir, '.next/server/pages/image-import.js.nft.json')
)
expect(appTrace.files.some((file) => file.endsWith('hello.json'))).toBe( const appTrace = await fs.readJSON(
true join(appDir, '.next/server/pages/_app.js.nft.json')
)
expect(
appTrace.files.some((file) => file.endsWith('lib/get-data.js'))
).toBe(true)
expect(
indexTrace.files.some((file) => file.endsWith('hello.json'))
).toBeFalsy()
expect(
indexTrace.files.some((file) => file.endsWith('some-dir'))
).toBeFalsy()
expect(
indexTrace.files.some((file) =>
file.endsWith('.dot-folder/another-file.txt')
) )
).toBe(true) const indexTrace = await fs.readJSON(
expect( join(appDir, '.next/server/pages/index.js.nft.json')
indexTrace.files.some((file) => file.endsWith('some-dir/file.txt')) )
).toBe(true) const anotherTrace = await fs.readJSON(
expect( join(appDir, '.next/server/pages/another.js.nft.json')
indexTrace.files.some((file) => file.includes('some-cms/index.js'))
).toBe(true)
expect(
indexTrace.files.some((file) => file === '../../../include-me/hello.txt')
).toBe(true)
expect(
indexTrace.files.some((file) => file === '../../../include-me/second.txt')
).toBe(true)
expect(indexTrace.files.some((file) => file.includes('exclude-me'))).toBe(
false
)
expect(
anotherTrace.files.some((file) =>
file.includes('nested-structure/constants/package.json')
) )
).toBe(true) const imageTrace = await fs.readJSON(
expect( join(appDir, '.next/server/pages/image-import.js.nft.json')
anotherTrace.files.some((file) =>
file.includes('nested-structure/package.json')
) )
).toBe(true)
expect( expect(appTrace.files.some((file) => file.endsWith('hello.json'))).toBe(
anotherTrace.files.some((file) => true
file.includes('nested-structure/dist/constants.js') )
expect(
appTrace.files.some((file) => file.endsWith('lib/get-data.js'))
).toBe(true)
expect(
indexTrace.files.some((file) => file.endsWith('hello.json'))
).toBeFalsy()
expect(
indexTrace.files.some((file) => file.endsWith('some-dir'))
).toBeFalsy()
expect(
indexTrace.files.some((file) =>
file.endsWith('.dot-folder/another-file.txt')
)
).toBe(true)
expect(
indexTrace.files.some((file) => file.endsWith('some-dir/file.txt'))
).toBe(true)
expect(
indexTrace.files.some((file) => file.includes('some-cms/index.js'))
).toBe(true)
expect(
indexTrace.files.some(
(file) => file === '../../../include-me/hello.txt'
)
).toBe(true)
expect(
indexTrace.files.some(
(file) => file === '../../../include-me/second.txt'
)
).toBe(true)
expect(indexTrace.files.some((file) => file.includes('exclude-me'))).toBe(
false
) )
).toBe(true)
expect( expect(
imageTrace.files.some((file) => file.includes('public/another.jpg')) anotherTrace.files.some((file) =>
).toBe(true) file.includes('nested-structure/constants/package.json')
expect( )
imageTrace.files.some((file) => file.includes('public/test.jpg')) ).toBe(true)
).toBe(false) expect(
anotherTrace.files.some((file) =>
file.includes('nested-structure/package.json')
)
).toBe(true)
expect(
anotherTrace.files.some((file) =>
file.includes('nested-structure/dist/constants.js')
)
).toBe(true)
expect(
imageTrace.files.some((file) => file.includes('public/another.jpg'))
).toBe(true)
expect(
imageTrace.files.some((file) => file.includes('public/test.jpg'))
).toBe(false)
})
}) })
}) })
...@@ -7,83 +7,85 @@ import { join } from 'path' ...@@ -7,83 +7,85 @@ import { join } from 'path'
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
describe('Build warnings', () => { describe('Build warnings', () => {
it('should not shown warning about minification withou any modification', async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const { stderr } = await nextBuild(appDir, undefined, { stderr: true }) it('should not shown warning about minification without any modification', async () => {
expect(stderr).not.toContain('optimization has been disabled') const { stderr } = await nextBuild(appDir, undefined, { stderr: true })
}) expect(stderr).not.toContain('optimization has been disabled')
})
it('should shown warning about minification for minimize', async () => { it('should shown warning about minification for minimize', async () => {
const nextConfig = new File(join(appDir, 'next.config.js')) const nextConfig = new File(join(appDir, 'next.config.js'))
await waitFor(500) await waitFor(500)
nextConfig.replace('true', 'false') nextConfig.replace('true', 'false')
const { stderr } = await nextBuild(appDir, undefined, { stderr: true }) const { stderr } = await nextBuild(appDir, undefined, { stderr: true })
expect(stderr).toContain('optimization has been disabled') expect(stderr).toContain('optimization has been disabled')
nextConfig.restore() nextConfig.restore()
}) })
it('should shown warning about minification for minimizer', async () => { it('should shown warning about minification for minimizer', async () => {
const nextConfig = new File(join(appDir, 'next.config.js')) const nextConfig = new File(join(appDir, 'next.config.js'))
await waitFor(500) await waitFor(500)
nextConfig.replace( nextConfig.replace(
'config.optimization.minimize = true', 'config.optimization.minimize = true',
'config.optimization.minimizer = []' 'config.optimization.minimizer = []'
) )
const { stderr } = await nextBuild(appDir, undefined, { stderr: true }) const { stderr } = await nextBuild(appDir, undefined, { stderr: true })
expect(stderr).toContain('optimization has been disabled') expect(stderr).toContain('optimization has been disabled')
nextConfig.restore() nextConfig.restore()
}) })
it('should not warn about missing cache in non-CI', async () => { it('should not warn about missing cache in non-CI', async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
const { stdout } = await nextBuild(appDir, undefined, { const { stdout } = await nextBuild(appDir, undefined, {
stdout: true, stdout: true,
env: { env: {
CI: '', CI: '',
CIRCLECI: '', CIRCLECI: '',
TRAVIS: '', TRAVIS: '',
SYSTEM_TEAMFOUNDATIONCOLLECTIONURI: '', SYSTEM_TEAMFOUNDATIONCOLLECTIONURI: '',
GITHUB_ACTIONS: '', GITHUB_ACTIONS: '',
GITHUB_EVENT_NAME: '', GITHUB_EVENT_NAME: '',
}, },
})
expect(stdout).not.toContain('no-cache')
}) })
expect(stdout).not.toContain('no-cache')
})
it('should not warn about missing cache on supported platforms', async () => { it('should not warn about missing cache on supported platforms', async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
const { stdout } = await nextBuild(appDir, undefined, { const { stdout } = await nextBuild(appDir, undefined, {
stdout: true, stdout: true,
env: { CI: '1', NOW_BUILDER: '1' }, env: { CI: '1', NOW_BUILDER: '1' },
})
expect(stdout).not.toContain('no-cache')
}) })
expect(stdout).not.toContain('no-cache')
})
it('should warn about missing cache in CI', async () => {
await remove(join(appDir, '.next'))
let { stdout } = await nextBuild(appDir, undefined, { it('should warn about missing cache in CI', async () => {
stdout: true, await remove(join(appDir, '.next'))
env: { CI: '1' },
let { stdout } = await nextBuild(appDir, undefined, {
stdout: true,
env: { CI: '1' },
})
expect(stdout).toContain('no-cache')
// Do not warn after cache is present
;({ stdout } = await nextBuild(appDir, undefined, {
stdout: true,
env: { CI: '1' },
}))
expect(stdout).not.toContain('no-cache')
}) })
expect(stdout).toContain('no-cache')
// Do not warn after cache is present
;({ stdout } = await nextBuild(appDir, undefined, {
stdout: true,
env: { CI: '1' },
}))
expect(stdout).not.toContain('no-cache')
}) })
}) })
...@@ -13,19 +13,22 @@ const appDir = join(__dirname, '../') ...@@ -13,19 +13,22 @@ const appDir = join(__dirname, '../')
const errorRegex = /getStaticPaths was added without a getStaticProps in/ const errorRegex = /getStaticPaths was added without a getStaticProps in/
describe('Catches Missing getStaticProps', () => { describe('Catches Missing getStaticProps', () => {
it('should catch it in dev mode', async () => { describe('development mode', () => {
const appPort = await findPort() it('should catch it in dev mode', async () => {
const app = await launchApp(appDir, appPort) const appPort = await findPort()
const html = await renderViaHTTP(appPort, '/hello') const app = await launchApp(appDir, appPort)
await killApp(app) const html = await renderViaHTTP(appPort, '/hello')
await killApp(app)
expect(html).toMatch(errorRegex) expect(html).toMatch(errorRegex)
})
}) })
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
it('should catch it in server build mode', async () => { it('should catch it in server build mode', async () => {
const { stderr } = await nextBuild(appDir, [], { const { stderr } = await nextBuild(appDir, [], {
stderr: true, stderr: true,
})
expect(stderr).toMatch(errorRegex)
}) })
expect(stderr).toMatch(errorRegex)
}) })
}) })
This diff is collapsed.
...@@ -7,12 +7,13 @@ import { nextBuild } from 'next-test-utils' ...@@ -7,12 +7,13 @@ import { nextBuild } from 'next-test-utils'
const appDir = join(__dirname, '..') const appDir = join(__dirname, '..')
describe('Promise in next config', () => { describe('Promise in next config', () => {
afterEach(() => fs.remove(join(appDir, 'next.config.js'))) ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
afterEach(() => fs.remove(join(appDir, 'next.config.js')))
it('should warn when a promise is returned on webpack', async () => { it('should warn when a promise is returned on webpack', async () => {
fs.writeFile( fs.writeFile(
join(appDir, 'next.config.js'), join(appDir, 'next.config.js'),
` `
module.exports = (phase, { isServer }) => { module.exports = (phase, { isServer }) => {
return { return {
webpack: async (config) => { webpack: async (config) => {
...@@ -21,14 +22,15 @@ describe('Promise in next config', () => { ...@@ -21,14 +22,15 @@ describe('Promise in next config', () => {
} }
} }
` `
) )
const { stderr, stdout } = await nextBuild(appDir, undefined, { const { stderr, stdout } = await nextBuild(appDir, undefined, {
stderr: true, stderr: true,
stdout: true, stdout: true,
})
expect(stderr + stdout).toMatch(
/> Promise returned in next config\. https:\/\//
)
}) })
expect(stderr + stdout).toMatch(
/> Promise returned in next config\. https:\/\//
)
}) })
}) })
...@@ -8,44 +8,46 @@ const nextConfigJS = join(appDir, 'next.config.js') ...@@ -8,44 +8,46 @@ const nextConfigJS = join(appDir, 'next.config.js')
const nextConfigMJS = join(appDir, 'next.config.mjs') const nextConfigMJS = join(appDir, 'next.config.mjs')
describe('Invalid config syntax', () => { describe('Invalid config syntax', () => {
it('should error when next.config.js contains syntax error', async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
await fs.writeFile( it('should error when next.config.js contains syntax error', async () => {
nextConfigJS, await fs.writeFile(
` nextConfigJS,
`
module.exports = { module.exports = {
reactStrictMode: true,, reactStrictMode: true,,
} }
` `
) )
const { stderr } = await nextBuild(appDir, undefined, { const { stderr } = await nextBuild(appDir, undefined, {
stderr: true, stderr: true,
}) })
await fs.remove(nextConfigJS) await fs.remove(nextConfigJS)
expect(stderr).toContain( expect(stderr).toContain(
'Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error' 'Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error'
) )
expect(stderr).toContain('SyntaxError') expect(stderr).toContain('SyntaxError')
}) })
it('should error when next.config.mjs contains syntax error', async () => { it('should error when next.config.mjs contains syntax error', async () => {
await fs.writeFile( await fs.writeFile(
nextConfigMJS, nextConfigMJS,
` `
const config = { const config = {
reactStrictMode: true,, reactStrictMode: true,,
} }
export default config export default config
` `
) )
const { stderr } = await nextBuild(appDir, undefined, { const { stderr } = await nextBuild(appDir, undefined, {
stderr: true, stderr: true,
}) })
await fs.remove(nextConfigMJS) await fs.remove(nextConfigMJS)
expect(stderr).toContain( expect(stderr).toContain(
'Failed to load next.config.mjs, see more info here https://nextjs.org/docs/messages/next-config-error' 'Failed to load next.config.mjs, see more info here https://nextjs.org/docs/messages/next-config-error'
) )
expect(stderr).toContain('SyntaxError') expect(stderr).toContain('SyntaxError')
})
}) })
}) })
...@@ -5,10 +5,11 @@ import fs from 'fs-extra' ...@@ -5,10 +5,11 @@ import fs from 'fs-extra'
const nextConfigPath = path.join(__dirname, '../next.config.js') const nextConfigPath = path.join(__dirname, '../next.config.js')
describe('next.config.js validation', () => { describe('next.config.js validation', () => {
it.each([ ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
{ it.each([
name: 'invalid config types', {
configContent: ` name: 'invalid config types',
configContent: `
module.exports = { module.exports = {
swcMinify: 'hello', swcMinify: 'hello',
rewrites: true, rewrites: true,
...@@ -17,15 +18,15 @@ describe('next.config.js validation', () => { ...@@ -17,15 +18,15 @@ describe('next.config.js validation', () => {
} }
} }
`, `,
outputs: [ outputs: [
'The value at .images.loader must be one of', 'The value at .images.loader must be one of',
'The value at .rewrites must be a function that returns a Promise', 'The value at .rewrites must be a function that returns a Promise',
'The value at .swcMinify must be a boolean but it was a string', 'The value at .swcMinify must be a boolean but it was a string',
], ],
}, },
{ {
name: 'unexpected config fields', name: 'unexpected config fields',
configContent: ` configContent: `
module.exports = { module.exports = {
nonExistent: true, nonExistent: true,
experimental: { experimental: {
...@@ -33,24 +34,25 @@ describe('next.config.js validation', () => { ...@@ -33,24 +34,25 @@ describe('next.config.js validation', () => {
} }
} }
`, `,
outputs: [ outputs: [
'The root value has an unexpected property, nonExistent,', 'The root value has an unexpected property, nonExistent,',
'The value at .experimental has an unexpected property, anotherNonExistent', 'The value at .experimental has an unexpected property, anotherNonExistent',
], ],
}, },
])( ])(
'it should validate correctly for $name', 'it should validate correctly for $name',
async ({ outputs, configContent }) => { async ({ outputs, configContent }) => {
await fs.writeFile(nextConfigPath, configContent) await fs.writeFile(nextConfigPath, configContent)
const result = await nextBuild(path.join(__dirname, '../'), undefined, { const result = await nextBuild(path.join(__dirname, '../'), undefined, {
stderr: true, stderr: true,
stdout: true, stdout: true,
}) })
await fs.remove(nextConfigPath) await fs.remove(nextConfigPath)
for (const output of outputs) { for (const output of outputs) {
expect(result.stdout + result.stderr).toContain(output) expect(result.stdout + result.stderr).toContain(output)
}
} }
} )
) })
}) })
...@@ -12,28 +12,34 @@ import { ...@@ -12,28 +12,34 @@ import {
const appDir = path.join(__dirname, '..') const appDir = path.join(__dirname, '..')
describe('Errors on conflict between public file and page file', () => { describe('Errors on conflict between public file and page file', () => {
it('Throws error during development', async () => { describe('development mode', () => {
const appPort = await findPort() it('Throws error during development', async () => {
const app = await launchApp(appDir, appPort) const appPort = await findPort()
const conflicts = ['/another/conflict', '/hello'] const app = await launchApp(appDir, appPort)
const conflicts = ['/another/conflict', '/hello']
for (const conflict of conflicts) { for (const conflict of conflicts) {
const html = await renderViaHTTP(appPort, conflict) const html = await renderViaHTTP(appPort, conflict)
expect(html).toMatch( expect(html).toMatch(
/A conflicting public file and page file was found for path/ /A conflicting public file and page file was found for path/
) )
} }
await killApp(app) await killApp(app)
})
}) })
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
it('Throws error during build', async () => {
const conflicts = ['/another/conflict', '/another', '/hello']
const results = await nextBuild(appDir, [], {
stdout: true,
stderr: true,
})
const output = results.stdout + results.stderr
expect(output).toMatch(/Conflicting public and page files were found/)
it('Throws error during build', async () => { for (const conflict of conflicts) {
const conflicts = ['/another/conflict', '/another', '/hello'] expect(output.indexOf(conflict) > 0).toBe(true)
const results = await nextBuild(appDir, [], { stdout: true, stderr: true }) }
const output = results.stdout + results.stderr })
expect(output).toMatch(/Conflicting public and page files were found/)
for (const conflict of conflicts) {
expect(output.indexOf(conflict) > 0).toBe(true)
}
}) })
}) })
...@@ -8,13 +8,14 @@ const appDir = join(__dirname, '../') ...@@ -8,13 +8,14 @@ const appDir = join(__dirname, '../')
const pagesDir = join(appDir, 'pages') const pagesDir = join(appDir, 'pages')
describe('Conflicting SSG paths', () => { describe('Conflicting SSG paths', () => {
afterEach(() => fs.remove(pagesDir)) ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
afterEach(() => fs.remove(pagesDir))
it('should show proper error when two dynamic SSG routes have conflicting paths', async () => {
await fs.ensureDir(join(pagesDir, 'blog')) it('should show proper error when two dynamic SSG routes have conflicting paths', async () => {
await fs.writeFile( await fs.ensureDir(join(pagesDir, 'blog'))
join(pagesDir, 'blog/[slug].js'), await fs.writeFile(
` join(pagesDir, 'blog/[slug].js'),
`
export const getStaticProps = () => { export const getStaticProps = () => {
return { return {
props: {} props: {}
...@@ -35,11 +36,11 @@ describe('Conflicting SSG paths', () => { ...@@ -35,11 +36,11 @@ describe('Conflicting SSG paths', () => {
return '/blog/[slug]' return '/blog/[slug]'
} }
` `
) )
await fs.writeFile( await fs.writeFile(
join(pagesDir, '[...catchAll].js'), join(pagesDir, '[...catchAll].js'),
` `
export const getStaticProps = () => { export const getStaticProps = () => {
return { return {
props: {} props: {}
...@@ -60,39 +61,39 @@ describe('Conflicting SSG paths', () => { ...@@ -60,39 +61,39 @@ describe('Conflicting SSG paths', () => {
return '/[catchAll]' return '/[catchAll]'
} }
` `
) )
const result = await nextBuild(appDir, undefined, { const result = await nextBuild(appDir, undefined, {
stdout: true, stdout: true,
stderr: true, stderr: true,
})
const output = result.stdout + result.stderr
expect(output).toContain(
'Conflicting paths returned from getStaticPaths, paths must be unique per page'
)
expect(output).toContain(
'https://nextjs.org/docs/messages/conflicting-ssg-paths'
)
expect(output).toContain(
`path: "/blog/conflicting" from page: "/[...catchAll]"`
)
expect(output).toContain(`conflicts with path: "/blog/conflicting"`)
}) })
const output = result.stdout + result.stderr
expect(output).toContain(
'Conflicting paths returned from getStaticPaths, paths must be unique per page'
)
expect(output).toContain(
'https://nextjs.org/docs/messages/conflicting-ssg-paths'
)
expect(output).toContain(
`path: "/blog/conflicting" from page: "/[...catchAll]"`
)
expect(output).toContain(`conflicts with path: "/blog/conflicting"`)
})
it('should show proper error when a dynamic SSG route conflicts with normal route', async () => { it('should show proper error when a dynamic SSG route conflicts with normal route', async () => {
await fs.ensureDir(join(pagesDir, 'hello')) await fs.ensureDir(join(pagesDir, 'hello'))
await fs.writeFile( await fs.writeFile(
join(pagesDir, 'hello/world.js'), join(pagesDir, 'hello/world.js'),
` `
export default function Page() { export default function Page() {
return '/hello/world' return '/hello/world'
} }
` `
) )
await fs.writeFile( await fs.writeFile(
join(pagesDir, '[...catchAll].js'), join(pagesDir, '[...catchAll].js'),
` `
export const getStaticProps = () => { export const getStaticProps = () => {
return { return {
props: {} props: {}
...@@ -113,40 +114,40 @@ describe('Conflicting SSG paths', () => { ...@@ -113,40 +114,40 @@ describe('Conflicting SSG paths', () => {
return '/[catchAll]' return '/[catchAll]'
} }
` `
) )
const result = await nextBuild(appDir, undefined, { const result = await nextBuild(appDir, undefined, {
stdout: true, stdout: true,
stderr: true, stderr: true,
})
const output = result.stdout + result.stderr
expect(output).toContain(
'Conflicting paths returned from getStaticPaths, paths must be unique per page'
)
expect(output).toContain(
'https://nextjs.org/docs/messages/conflicting-ssg-paths'
)
expect(output).toContain(
`path: "/hellO/world" from page: "/[...catchAll]" conflicts with path: "/hello/world"`
)
}) })
const output = result.stdout + result.stderr
expect(output).toContain(
'Conflicting paths returned from getStaticPaths, paths must be unique per page'
)
expect(output).toContain(
'https://nextjs.org/docs/messages/conflicting-ssg-paths'
)
expect(output).toContain(
`path: "/hellO/world" from page: "/[...catchAll]" conflicts with path: "/hello/world"`
)
})
it('should show proper error when a dynamic SSG route conflicts with SSR route', async () => { it('should show proper error when a dynamic SSG route conflicts with SSR route', async () => {
await fs.ensureDir(join(pagesDir, 'hello')) await fs.ensureDir(join(pagesDir, 'hello'))
await fs.writeFile( await fs.writeFile(
join(pagesDir, 'hello/world.js'), join(pagesDir, 'hello/world.js'),
` `
export const getServerSideProps = () => ({ props: {} }) export const getServerSideProps = () => ({ props: {} })
export default function Page() { export default function Page() {
return '/hello/world' return '/hello/world'
} }
` `
) )
await fs.writeFile( await fs.writeFile(
join(pagesDir, '[...catchAll].js'), join(pagesDir, '[...catchAll].js'),
` `
export const getStaticProps = () => { export const getStaticProps = () => {
return { return {
props: {} props: {}
...@@ -167,21 +168,22 @@ describe('Conflicting SSG paths', () => { ...@@ -167,21 +168,22 @@ describe('Conflicting SSG paths', () => {
return '/[catchAll]' return '/[catchAll]'
} }
` `
) )
const result = await nextBuild(appDir, undefined, { const result = await nextBuild(appDir, undefined, {
stdout: true, stdout: true,
stderr: true, stderr: true,
})
const output = result.stdout + result.stderr
expect(output).toContain(
'Conflicting paths returned from getStaticPaths, paths must be unique per page'
)
expect(output).toContain(
'https://nextjs.org/docs/messages/conflicting-ssg-paths'
)
expect(output).toContain(
`path: "/hellO/world" from page: "/[...catchAll]" conflicts with path: "/hello/world"`
)
}) })
const output = result.stdout + result.stderr
expect(output).toContain(
'Conflicting paths returned from getStaticPaths, paths must be unique per page'
)
expect(output).toContain(
'https://nextjs.org/docs/messages/conflicting-ssg-paths'
)
expect(output).toContain(
`path: "/hellO/world" from page: "/[...catchAll]" conflicts with path: "/hello/world"`
)
}) })
}) })
...@@ -57,23 +57,25 @@ function runTests() { ...@@ -57,23 +57,25 @@ function runTests() {
} }
describe('CSS optimization for SSR apps', () => { describe('CSS optimization for SSR apps', () => {
beforeAll(async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
await fs.writeFile( beforeAll(async () => {
nextConfig, await fs.writeFile(
`module.exports = { experimental: {optimizeCss: true} }`, nextConfig,
'utf8' `module.exports = { experimental: {optimizeCss: true} }`,
) 'utf8'
)
if (fs.pathExistsSync(join(appDir, '.next'))) { if (fs.pathExistsSync(join(appDir, '.next'))) {
await fs.remove(join(appDir, '.next')) await fs.remove(join(appDir, '.next'))
} }
await nextBuild(appDir) await nextBuild(appDir)
appPort = await findPort() appPort = await findPort()
app = await nextStart(appDir, appPort) app = await nextStart(appDir, appPort)
}) })
afterAll(async () => { afterAll(async () => {
await killApp(app) await killApp(app)
await fs.remove(nextConfig) await fs.remove(nextConfig)
})
runTests()
}) })
runTests()
}) })
...@@ -28,13 +28,15 @@ function runTests() { ...@@ -28,13 +28,15 @@ function runTests() {
} }
describe('css-minify', () => { describe('css-minify', () => {
beforeAll(async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
await nextBuild(appDir) beforeAll(async () => {
appPort = await findPort() await nextBuild(appDir)
app = await nextStart(appDir, appPort) appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
runTests()
}) })
afterAll(async () => {
await killApp(app)
})
runTests()
}) })
...@@ -243,44 +243,52 @@ describe('Can hot reload CSS Module without losing state', () => { ...@@ -243,44 +243,52 @@ describe('Can hot reload CSS Module without losing state', () => {
}) })
describe.skip('Invalid CSS Module Usage in node_modules', () => { describe.skip('Invalid CSS Module Usage in node_modules', () => {
const appDir = join(fixturesDir, 'invalid-module') ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const appDir = join(fixturesDir, 'invalid-module')
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
}) })
it('should fail to build', async () => { it('should fail to build', async () => {
const { code, stderr } = await nextBuild(appDir, [], { const { code, stderr } = await nextBuild(appDir, [], {
stderr: true, stderr: true,
})
expect(code).not.toBe(0)
expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('node_modules/example/index.module.css')
expect(stderr).toMatch(
/CSS Modules.*cannot.*be imported from within.*node_modules/
)
expect(stderr).toMatch(
/Location:.*node_modules[\\/]example[\\/]index\.mjs/
)
}) })
expect(code).not.toBe(0)
expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('node_modules/example/index.module.css')
expect(stderr).toMatch(
/CSS Modules.*cannot.*be imported from within.*node_modules/
)
expect(stderr).toMatch(/Location:.*node_modules[\\/]example[\\/]index\.mjs/)
}) })
}) })
describe.skip('Invalid Global CSS Module Usage in node_modules', () => { describe.skip('Invalid Global CSS Module Usage in node_modules', () => {
const appDir = join(fixturesDir, 'invalid-global-module') ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const appDir = join(fixturesDir, 'invalid-global-module')
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
}) })
it('should fail to build', async () => { it('should fail to build', async () => {
const { code, stderr } = await nextBuild(appDir, [], { const { code, stderr } = await nextBuild(appDir, [], {
stderr: true, stderr: true,
})
expect(code).not.toBe(0)
expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('node_modules/example/index.css')
expect(stderr).toMatch(
/Global CSS.*cannot.*be imported from within.*node_modules/
)
expect(stderr).toMatch(
/Location:.*node_modules[\\/]example[\\/]index\.mjs/
)
}) })
expect(code).not.toBe(0)
expect(stderr).toContain('Failed to compile')
expect(stderr).toContain('node_modules/example/index.css')
expect(stderr).toMatch(
/Global CSS.*cannot.*be imported from within.*node_modules/
)
expect(stderr).toMatch(/Location:.*node_modules[\\/]example[\\/]index\.mjs/)
}) })
}) })
......
...@@ -38,35 +38,37 @@ describe('Ordering with styled-jsx (dev)', () => { ...@@ -38,35 +38,37 @@ describe('Ordering with styled-jsx (dev)', () => {
}) })
describe('Ordering with styled-jsx (prod)', () => { describe('Ordering with styled-jsx (prod)', () => {
const appDir = join(fixturesDir, 'with-styled-jsx') ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const appDir = join(fixturesDir, 'with-styled-jsx')
let appPort let appPort
let app let app
let stdout let stdout
let code let code
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
;({ code, stdout } = await nextBuild(appDir, [], { ;({ code, stdout } = await nextBuild(appDir, [], {
stdout: true, stdout: true,
})) }))
appPort = await findPort() appPort = await findPort()
app = await nextStart(appDir, appPort) app = await nextStart(appDir, appPort)
}) })
afterAll(async () => { afterAll(async () => {
await killApp(app) await killApp(app)
}) })
it('should have compiled successfully', () => { it('should have compiled successfully', () => {
expect(code).toBe(0) expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/) expect(stdout).toMatch(/Compiled successfully/)
}) })
it('should have the correct color (css ordering)', async () => { it('should have the correct color (css ordering)', async () => {
const browser = await webdriver(appPort, '/') const browser = await webdriver(appPort, '/')
const currentColor = await browser.eval( const currentColor = await browser.eval(
`window.getComputedStyle(document.querySelector('.my-text')).color` `window.getComputedStyle(document.querySelector('.my-text')).color`
) )
expect(currentColor).toMatchInlineSnapshot(`"rgb(0, 128, 0)"`) expect(currentColor).toMatchInlineSnapshot(`"rgb(0, 128, 0)"`)
})
}) })
}) })
...@@ -15,19 +15,21 @@ import { join } from 'path' ...@@ -15,19 +15,21 @@ import { join } from 'path'
const fixturesDir = join(__dirname, '../..', 'css-fixtures') const fixturesDir = join(__dirname, '../..', 'css-fixtures')
describe('CSS Support', () => { describe('CSS Support', () => {
describe('CSS Import from node_modules', () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
const appDir = join(fixturesDir, 'npm-import-bad') describe('CSS Import from node_modules', () => {
const appDir = join(fixturesDir, 'npm-import-bad')
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
}) })
it('should fail the build', async () => { it('should fail the build', async () => {
const { code, stderr } = await nextBuild(appDir, [], { stderr: true }) const { code, stderr } = await nextBuild(appDir, [], { stderr: true })
expect(code).toBe(0) expect(code).toBe(0)
expect(stderr).not.toMatch(/Can't resolve '[^']*?nprogress[^']*?'/) expect(stderr).not.toMatch(/Can't resolve '[^']*?nprogress[^']*?'/)
expect(stderr).not.toMatch(/Build error occurred/) expect(stderr).not.toMatch(/Build error occurred/)
})
}) })
}) })
......
...@@ -11,24 +11,26 @@ let app ...@@ -11,24 +11,26 @@ let app
// TODO: re-enable with React 18 // TODO: re-enable with React 18
describe.skip('Custom error page exception', () => { describe.skip('Custom error page exception', () => {
beforeAll(async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
await nextBuild(appDir, undefined, { beforeAll(async () => {
nodeArgs, await nextBuild(appDir, undefined, {
nodeArgs,
})
appPort = await findPort()
app = await nextStart(appDir, appPort, {
nodeArgs,
})
}) })
appPort = await findPort() afterAll(() => killApp(app))
app = await nextStart(appDir, appPort, { it('should handle errors from _error render', async () => {
nodeArgs, const navSel = '#nav'
}) const browser = await webdriver(appPort, '/')
}) await browser.waitForElementByCss(navSel).elementByCss(navSel).click()
afterAll(() => killApp(app))
it('should handle errors from _error render', async () => {
const navSel = '#nav'
const browser = await webdriver(appPort, '/')
await browser.waitForElementByCss(navSel).elementByCss(navSel).click()
await check( await check(
() => browser.eval('document.documentElement.innerHTML'), () => browser.eval('document.documentElement.innerHTML'),
/Application error: a client-side exception has occurred/ /Application error: a client-side exception has occurred/
) )
})
}) })
}) })
...@@ -143,16 +143,23 @@ describe.skip.each([ ...@@ -143,16 +143,23 @@ describe.skip.each([
}) })
describe('with generateEtags enabled', () => { describe('with generateEtags enabled', () => {
beforeAll(async () => { ;(process.env.TURBOPACK ? describe.skip : describe)(
await nextBuild(appDir) 'production mode',
await startServer({ GENERATE_ETAGS: 'true', NODE_ENV: 'production' }) () => {
}) beforeAll(async () => {
afterAll(() => killApp(server)) await nextBuild(appDir)
await startServer({ GENERATE_ETAGS: 'true', NODE_ENV: 'production' })
})
afterAll(() => killApp(server))
it('response includes etag header', async () => { it('response includes etag header', async () => {
const response = await fetchViaHTTP(nextUrl, '/', undefined, { agent }) const response = await fetchViaHTTP(nextUrl, '/', undefined, {
expect(response.headers.get('etag')).toBeTruthy() agent,
}) })
expect(response.headers.get('etag')).toBeTruthy()
})
}
)
}) })
describe('with generateEtags disabled', () => { describe('with generateEtags disabled', () => {
...@@ -222,28 +229,32 @@ describe.skip.each([ ...@@ -222,28 +229,32 @@ describe.skip.each([
expect(html).toContain('made it to dashboard') expect(html).toContain('made it to dashboard')
expect(stderr).toContain('Cannot render page with path "dashboard"') expect(stderr).toContain('Cannot render page with path "dashboard"')
}) })
;(process.env.TURBOPACK ? describe.skip : describe)(
it('should warn in production mode', async () => { 'production mode',
const { code } = await nextBuild(appDir) () => {
expect(code).toBe(0) it('should warn in production mode', async () => {
const { code } = await nextBuild(appDir)
let stderr = '' expect(code).toBe(0)
await startServer( let stderr = ''
{ NODE_ENV: 'production' },
{ await startServer(
onStderr(msg) { { NODE_ENV: 'production' },
stderr += msg || '' {
}, onStderr(msg) {
} stderr += msg || ''
) },
}
const html = await renderViaHTTP(nextUrl, '/no-slash', undefined, { )
agent,
}) const html = await renderViaHTTP(nextUrl, '/no-slash', undefined, {
expect(html).toContain('made it to dashboard') agent,
expect(stderr).toContain('Cannot render page with path "dashboard"') })
}) expect(html).toContain('made it to dashboard')
expect(stderr).toContain('Cannot render page with path "dashboard"')
})
}
)
}) })
describe('compression handling', function () { describe('compression handling', function () {
......
...@@ -132,12 +132,9 @@ describe('GS(S)P Page Errors', () => { ...@@ -132,12 +132,9 @@ describe('GS(S)P Page Errors', () => {
describe('dev mode', () => { describe('dev mode', () => {
runTests(true) runTests(true)
}) })
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
describe('build mode', () => {
runTests() runTests()
})
describe('start mode', () => {
it('Error stack printed to stderr', async () => { it('Error stack printed to stderr', async () => {
try { try {
await fs.writeFile( await fs.writeFile(
......
...@@ -15,28 +15,30 @@ let appPort ...@@ -15,28 +15,30 @@ let appPort
let app let app
describe('De-dedupes scripts in _document', () => { describe('De-dedupes scripts in _document', () => {
beforeAll(async () => { ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
appPort = await findPort() beforeAll(async () => {
await nextBuild(appDir) appPort = await findPort()
app = await nextStart(appDir, appPort) await nextBuild(appDir)
}) app = await nextStart(appDir, appPort)
afterAll(() => killApp(app)) })
afterAll(() => killApp(app))
it('Does not have duplicate script references', async () => { it('Does not have duplicate script references', async () => {
const html = await renderViaHTTP(appPort, '/') const html = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(html) const $ = cheerio.load(html)
let foundDuplicate = false let foundDuplicate = false
const srcs = new Set() const srcs = new Set()
for (const script of $('script').toArray()) { for (const script of $('script').toArray()) {
const { src } = script.attribs const { src } = script.attribs
if (!src || !src.startsWith('/_next/static')) continue if (!src || !src.startsWith('/_next/static')) continue
if (srcs.has(src)) { if (srcs.has(src)) {
console.error(`Found duplicate script ${src}`) console.error(`Found duplicate script ${src}`)
foundDuplicate = true foundDuplicate = true
}
srcs.add(src)
} }
srcs.add(src) expect(foundDuplicate).toBe(false)
} })
expect(foundDuplicate).toBe(false)
}) })
}) })
...@@ -19,28 +19,33 @@ let app ...@@ -19,28 +19,33 @@ let app
describe('distDir', () => { describe('distDir', () => {
describe('With basic usage', () => { describe('With basic usage', () => {
beforeAll(async () => { ;(process.env.TURBOPACK ? describe.skip : describe)(
await fs.remove(join(appDir, '.next')) 'production mode',
await fs.remove(join(appDir, 'dist')) () => {
await nextBuild(appDir) beforeAll(async () => {
appPort = await findPort() await fs.remove(join(appDir, '.next'))
app = await nextStart(appDir, appPort) await fs.remove(join(appDir, 'dist'))
}) await nextBuild(appDir)
afterAll(() => killApp(app)) appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
it('should render the page', async () => { it('should render the page', async () => {
const html = await renderViaHTTP(appPort, '/') const html = await renderViaHTTP(appPort, '/')
expect(html).toMatch(/Hello World/) expect(html).toMatch(/Hello World/)
}) })
it('should build the app within the given `dist` directory', async () => { it('should build the app within the given `dist` directory', async () => {
expect( expect(
await fs.exists(join(__dirname, `/../dist/${BUILD_ID_FILE}`)) await fs.exists(join(__dirname, `/../dist/${BUILD_ID_FILE}`))
).toBeTruthy() ).toBeTruthy()
}) })
it('should not build the app within the default `.next` directory', async () => { it('should not build the app within the default `.next` directory', async () => {
expect(await fs.exists(join(__dirname, '/../.next'))).toBeFalsy() expect(await fs.exists(join(__dirname, '/../.next'))).toBeFalsy()
}) })
}
)
}) })
describe('dev mode', () => { describe('dev mode', () => {
...@@ -66,27 +71,28 @@ describe('distDir', () => { ...@@ -66,27 +71,28 @@ describe('distDir', () => {
expect(await fs.exists(join(__dirname, '/../.next'))).toBeFalsy() expect(await fs.exists(join(__dirname, '/../.next'))).toBeFalsy()
}) })
}) })
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
it('should throw error with invalid distDir', async () => {
const origNextConfig = await fs.readFile(nextConfig, 'utf8')
await fs.writeFile(nextConfig, `module.exports = { distDir: '' }`)
const { stderr } = await nextBuild(appDir, [], { stderr: true })
await fs.writeFile(nextConfig, origNextConfig)
it('should throw error with invalid distDir', async () => { expect(stderr).toContain(
const origNextConfig = await fs.readFile(nextConfig, 'utf8') 'Invalid distDir provided, distDir can not be an empty string. Please remove this config or set it to undefined'
await fs.writeFile(nextConfig, `module.exports = { distDir: '' }`) )
const { stderr } = await nextBuild(appDir, [], { stderr: true }) })
await fs.writeFile(nextConfig, origNextConfig)
expect(stderr).toContain(
'Invalid distDir provided, distDir can not be an empty string. Please remove this config or set it to undefined'
)
})
it('should handle null/undefined distDir', async () => { it('should handle null/undefined distDir', async () => {
const origNextConfig = await fs.readFile(nextConfig, 'utf8') const origNextConfig = await fs.readFile(nextConfig, 'utf8')
await fs.writeFile( await fs.writeFile(
nextConfig, nextConfig,
`module.exports = { distDir: null, eslint: { ignoreDuringBuilds: true } }` `module.exports = { distDir: null, eslint: { ignoreDuringBuilds: true } }`
) )
const { stderr } = await nextBuild(appDir, [], { stderr: true }) const { stderr } = await nextBuild(appDir, [], { stderr: true })
await fs.writeFile(nextConfig, origNextConfig) await fs.writeFile(nextConfig, origNextConfig)
expect(stderr.length).toBe(0) expect(stderr.length).toBe(0)
})
}) })
}) })
...@@ -95,17 +95,25 @@ describe('Edge runtime code with imports', () => { ...@@ -95,17 +95,25 @@ describe('Edge runtime code with imports', () => {
return 'success' return 'success'
}, 'success') }, 'success')
}) })
;(process.env.TURBOPACK ? describe.skip : describe)(
it('throws unsupported module error in production at runtime and prints error on logs', async () => { 'production mode',
const { stderr } = await nextBuild(context.appDir, undefined, { () => {
stderr: true, it('throws unsupported module error in production at runtime and prints error on logs', async () => {
}) const { stderr } = await nextBuild(context.appDir, undefined, {
expect(stderr).toContain(getUnsupportedModuleWarning(moduleName)) stderr: true,
context.app = await nextStart(context.appDir, context.appPort, appOption) })
const res = await fetchViaHTTP(context.appPort, url) expect(stderr).toContain(getUnsupportedModuleWarning(moduleName))
expect(res.status).toBe(500) context.app = await nextStart(
expectUnsupportedModuleProdError(moduleName) context.appDir,
}) context.appPort,
appOption
)
const res = await fetchViaHTTP(context.appPort, url)
expect(res.status).toBe(500)
expectUnsupportedModuleProdError(moduleName)
})
}
)
}) })
describe.each([ describe.each([
...@@ -157,16 +165,20 @@ describe('Edge runtime code with imports', () => { ...@@ -157,16 +165,20 @@ describe('Edge runtime code with imports', () => {
return 'success' return 'success'
}, 'success') }, 'success')
}) })
;(process.env.TURBOPACK ? describe.skip : describe)(
it('does not build and reports module not found error', async () => { 'production mode',
const { code, stderr } = await nextBuild(context.appDir, undefined, { () => {
ignoreFail: true, it('does not build and reports module not found error', async () => {
stdout: true, const { code, stderr } = await nextBuild(context.appDir, undefined, {
stderr: true, ignoreFail: true,
}) stdout: true,
expect(code).toEqual(1) stderr: true,
expectModuleNotFoundProdError(moduleName, stderr) })
}) expect(code).toEqual(1)
expectModuleNotFoundProdError(moduleName, stderr)
})
}
)
}) })
describe.each([ describe.each([
...@@ -221,17 +233,21 @@ describe('Edge runtime code with imports', () => { ...@@ -221,17 +233,21 @@ describe('Edge runtime code with imports', () => {
return 'success' return 'success'
}, 'success') }, 'success')
}) })
;(process.env.TURBOPACK ? describe.skip : describe)(
'production mode',
() => {
it('does not build and reports module not found error', async () => {
const { code, stderr } = await nextBuild(context.appDir, undefined, {
ignoreFail: true,
stdout: true,
stderr: true,
})
expect(code).toEqual(1)
it('does not build and reports module not found error', async () => { expectModuleNotFoundProdError(moduleName, stderr)
const { code, stderr } = await nextBuild(context.appDir, undefined, { })
ignoreFail: true, }
stdout: true, )
stderr: true,
})
expect(code).toEqual(1)
expectModuleNotFoundProdError(moduleName, stderr)
})
}) })
describe.each([ describe.each([
...@@ -279,16 +295,24 @@ describe('Edge runtime code with imports', () => { ...@@ -279,16 +295,24 @@ describe('Edge runtime code with imports', () => {
expect(res.status).toBe(200) expect(res.status).toBe(200)
expectNoError(moduleName) expectNoError(moduleName)
}) })
;(process.env.TURBOPACK ? describe.skip : describe)(
it('does not throw in production at runtime', async () => { 'production mode',
const { stderr } = await nextBuild(context.appDir, undefined, { () => {
stderr: true, it('does not throw in production at runtime', async () => {
}) const { stderr } = await nextBuild(context.appDir, undefined, {
expect(stderr).toContain(getUnsupportedModuleWarning(moduleName)) stderr: true,
context.app = await nextStart(context.appDir, context.appPort, appOption) })
const res = await fetchViaHTTP(context.appPort, url) expect(stderr).toContain(getUnsupportedModuleWarning(moduleName))
expect(res.status).toBe(200) context.app = await nextStart(
expectNoError(moduleName) context.appDir,
}) context.appPort,
appOption
)
const res = await fetchViaHTTP(context.appPort, url)
expect(res.status).toBe(200)
expectNoError(moduleName)
})
}
)
}) })
}) })
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment