未验证 提交 7782ba6f 编写于 作者: J JJ Kasper 提交者: GitHub

Ensure export progress handles less pages than segments (#19281)

This updates the export progress to make sure we log out the final progress update when less pages than number of progress updates (segments). This also adds tests to ensure we are logging the progress out as expected. 

Fixes: https://github.com/vercel/next.js/issues/19122
Closes: https://github.com/vercel/next.js/pull/19123
上级 5959f184
......@@ -51,7 +51,9 @@ const exists = promisify(existsOrig)
function divideSegments(number: number, segments: number): number[] {
const result = []
while (number > 0 && segments > 0) {
const dividedNumber = Math.floor(number / segments)
const dividedNumber =
number < segments ? number : Math.floor(number / segments)
number -= dividedNumber
segments--
result.push(dividedNumber)
......
......@@ -12,11 +12,14 @@ let appPort
let app
describe('Polyfills', () => {
let output = ''
beforeAll(async () => {
const { stdout, stderr } = await nextBuild(appDir, [], {
stdout: true,
stderr: true,
})
output = (stderr || '') + (stdout + '')
console.log(stdout)
console.error(stderr)
appPort = await findPort()
......@@ -34,4 +37,11 @@ describe('Polyfills', () => {
await browser.close()
})
it('should contain generated page count in output', async () => {
expect(output).toContain('Generating static pages (0/3)')
expect(output).toContain('Generating static pages (3/3)')
// we should only have 1 segment and the initial message logged out
expect(output.match(/Generating static pages/g).length).toBe(2)
})
})
......@@ -32,20 +32,37 @@ jest.setTimeout(1000 * 60 * 5)
const context = {}
describe('Production Usage', () => {
let output = ''
beforeAll(async () => {
await runNextCommand(['build', appDir])
const result = await runNextCommand(['build', appDir], {
stderr: true,
stdout: true,
})
app = nextServer({
dir: join(__dirname, '../'),
dev: false,
quiet: true,
})
output = (result.stderr || '') + (result.stdout || '')
console.log(output)
if (result.code !== 0) {
throw new Error(`Failed to build, exited with code ${result.code}`)
}
server = await startApp(app)
context.appPort = appPort = server.address().port
})
afterAll(() => stopApp(server))
it('should contain generated page count in output', async () => {
expect(output).toContain('Generating static pages (0/36)')
expect(output).toContain('Generating static pages (36/36)')
// we should only have 4 segments and the initial message logged out
expect(output.match(/Generating static pages/g).length).toBe(5)
})
describe('With basic usage', () => {
it('should render the page', async () => {
const html = await renderViaHTTP(appPort, '/')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册