Unverified Commit b9ee1db2 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

[test] Improve deployment skew test for Pages Router data routes (#89038)

Actually test the behavior by switching between two builds, as opposed
to selectively blocking some routes.
parent f2aa053c
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
distDir: process.env.DIST_DIR && '.next.' + process.env.DIST_DIR,
}
module.exports = nextConfig
...@@ -14,20 +14,17 @@ import { ...@@ -14,20 +14,17 @@ import {
const appDir = join(__dirname, '..') const appDir = join(__dirname, '..')
let app
let appPort
let proxyServer
let proxyPort let proxyPort
let should404Data = false
const runTests = () => { const runTests = (switchDeployment: (bool) => void) => {
it('should hard navigate when a new deployment occurs', async () => { it('index to gsp', async () => {
switchDeployment(false)
const browser = await webdriver(proxyPort, '/') const browser = await webdriver(proxyPort, '/')
await browser.eval('window.beforeNav = 1') await browser.eval('window.beforeNav = 1')
expect(await browser.elementByCss('#index').text()).toBe('Index page') await browser.waitForElementByCss('#index')
should404Data = true switchDeployment(true)
await browser.eval(`(function() { await browser.eval(`(function() {
window.next.router.push('/gsp') window.next.router.push('/gsp')
...@@ -35,8 +32,17 @@ const runTests = () => { ...@@ -35,8 +32,17 @@ const runTests = () => {
await browser.waitForElementByCss('#gsp') await browser.waitForElementByCss('#gsp')
expect(await browser.eval('window.beforeNav')).toBeFalsy() expect(await browser.eval('window.beforeNav')).toBeFalsy()
})
it('gsp to gssp', async () => {
switchDeployment(false)
const browser = await webdriver(proxyPort, '/gsp')
await browser.eval('window.beforeNav = 1') await browser.eval('window.beforeNav = 1')
await browser.waitForElementByCss('#gsp')
switchDeployment(true)
await browser.eval(`(function() { await browser.eval(`(function() {
window.next.router.push('/gssp') window.next.router.push('/gssp')
})()`) })()`)
...@@ -46,18 +52,20 @@ const runTests = () => { ...@@ -46,18 +52,20 @@ const runTests = () => {
}) })
} }
describe('SSG data 404', () => { describe('SSG data 404 - hard navigate when a new deployment occurs', () => {
if (process.platform === 'win32') { if (process.platform === 'win32') {
it('should skip this suite on Windows', () => {}) it('should skip this suite on Windows', () => {})
return return
} }
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)( describe('development mode', () => {
'development mode', let should404Data = false
() => { let apps = []
let proxyServer
beforeAll(async () => { beforeAll(async () => {
appPort = await findPort() const appPort = await findPort()
app = await launchApp(appDir, appPort) apps.push(await launchApp(appDir, appPort))
const proxy = httpProxy.createProxyServer({ const proxy = httpProxy.createProxyServer({
target: `http://localhost:${appPort}`, target: `http://localhost:${appPort}`,
...@@ -83,24 +91,69 @@ describe('SSG data 404', () => { ...@@ -83,24 +91,69 @@ describe('SSG data 404', () => {
}) })
}) })
afterAll(async () => { afterAll(async () => {
for (const app of apps) {
await killApp(app) await killApp(app)
}
proxyServer.close() proxyServer.close()
}) })
runTests() runTests((v) => {
} should404Data = v
) })
;(process.env.TURBOPACK_DEV ? describe.skip : describe)( })
'production mode',
() => { describe.each([
{ name: 'with build id' },
{
name: 'with deployment id',
NEXT_DEPLOYMENT_ID1: 'deployment-id-1',
NEXT_DEPLOYMENT_ID2: 'deployment-id-2',
},
])(
'production mode $name',
({ NEXT_DEPLOYMENT_ID1, NEXT_DEPLOYMENT_ID2 }) => {
let shouldSwitchDeployment = false
let apps = []
let proxyServer
beforeAll(async () => { beforeAll(async () => {
await nextBuild(appDir) await nextBuild(appDir, [], {
env: {
DIST_DIR: '1',
NEXT_DEPLOYMENT_ID: NEXT_DEPLOYMENT_ID1,
},
})
let appPort1 = await findPort()
apps.push(
await nextStart(appDir, appPort1, {
env: {
DIST_DIR: '1',
NEXT_DEPLOYMENT_ID: NEXT_DEPLOYMENT_ID1,
},
})
)
appPort = await findPort() await nextBuild(appDir, [], {
app = await nextStart(appDir, appPort) env: {
DIST_DIR: '2',
NEXT_DEPLOYMENT_ID: NEXT_DEPLOYMENT_ID2,
},
})
let appPort2 = await findPort()
apps.push(
await nextStart(appDir, appPort2, {
env: {
DIST_DIR: '2',
NEXT_DEPLOYMENT_ID: NEXT_DEPLOYMENT_ID2,
},
})
)
const proxy = httpProxy.createProxyServer({ const proxy1 = httpProxy.createProxyServer({
target: `http://localhost:${appPort}`, target: `http://localhost:${appPort1}`,
})
const proxy2 = httpProxy.createProxyServer({
target: `http://localhost:${appPort2}`,
}) })
proxyPort = await findPort() proxyPort = await findPort()
...@@ -111,11 +164,15 @@ describe('SSG data 404', () => { ...@@ -111,11 +164,15 @@ describe('SSG data 404', () => {
res.on('error', (e) => { res.on('error', (e) => {
require('console').error(e) require('console').error(e)
}) })
if (should404Data && req.url.match(/\/_next\/data/)) {
res.statusCode = 404 if (shouldSwitchDeployment) {
return res.end('not found') proxy2.web(req, res, undefined, (e) => {
require('console').error(e)
})
return
} }
proxy.web(req, res, undefined, (e) => {
proxy1.web(req, res, undefined, (e) => {
require('console').error(e) require('console').error(e)
}) })
}) })
...@@ -125,11 +182,15 @@ describe('SSG data 404', () => { ...@@ -125,11 +182,15 @@ describe('SSG data 404', () => {
}) })
}) })
afterAll(async () => { afterAll(async () => {
for (const app of apps) {
await killApp(app) await killApp(app)
}
proxyServer.close() proxyServer.close()
}) })
runTests() runTests((v) => {
shouldSwitchDeployment = v
})
} }
) )
}) })
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