Skip to content

Commit

Permalink
More Turbopack fixes (#56299)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
timneutkens committed Oct 2, 2023
1 parent ecd94c1 commit 59bda2d
Show file tree
Hide file tree
Showing 127 changed files with 5,751 additions and 5,302 deletions.
405 changes: 205 additions & 200 deletions test/integration/500-page/test/gsp-gssp.test.js

Large diffs are not rendered by default.

507 changes: 256 additions & 251 deletions test/integration/500-page/test/index.test.js

Large diffs are not rendered by default.

178 changes: 90 additions & 88 deletions test/integration/absolute-assetprefix/test/index.test.js
Expand Up @@ -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`
)
})
})
})
178 changes: 90 additions & 88 deletions test/integration/amp-export-validation/test/index.test.js
Expand Up @@ -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()
}
})
})
})

0 comments on commit 59bda2d

Please sign in to comment.