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