Unverified Commit b925a1bf authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub
parent 01e7c373
...@@ -235,12 +235,13 @@ describe('app-dir - logging', () => { ...@@ -235,12 +235,13 @@ describe('app-dir - logging', () => {
await next.patchFile( await next.patchFile(
'app/default-cache/page.js', 'app/default-cache/page.js',
(content) => content.replace('Default Cache', 'Hello!'), (content) => content.replace('Default Cache', 'Hello!'),
async () => { async () =>
headline = await browser.waitForElementByCss('h1').text() retry(async () => {
expect(headline).toBe('Hello!') headline = await browser.waitForElementByCss('h1').text()
const logs = stripAnsi(next.cliOutput.slice(outputIndex)) expect(headline).toBe('Hello!')
expect(logs).not.toInclude(` │ GET `) const logs = stripAnsi(next.cliOutput.slice(outputIndex))
} expect(logs).not.toInclude(` │ GET `)
})
) )
}) })
} }
......
This diff is collapsed.
...@@ -8,7 +8,7 @@ import { ChildProcess } from 'child_process' ...@@ -8,7 +8,7 @@ import { ChildProcess } from 'child_process'
import { createNextInstall } from '../create-next-install' import { createNextInstall } from '../create-next-install'
import { Span } from 'next/dist/trace' import { Span } from 'next/dist/trace'
import webdriver from '../next-webdriver' import webdriver from '../next-webdriver'
import { renderViaHTTP, fetchViaHTTP, findPort, retry } from 'next-test-utils' import { renderViaHTTP, fetchViaHTTP, findPort } from 'next-test-utils'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { once } from 'events' import { once } from 'events'
import { BrowserInterface } from '../browsers/base' import { BrowserInterface } from '../browsers/base'
...@@ -69,7 +69,7 @@ export class NextInstance { ...@@ -69,7 +69,7 @@ export class NextInstance {
public env: Record<string, string> public env: Record<string, string>
public forcedPort?: string public forcedPort?: string
public dirSuffix: string = '' public dirSuffix: string = ''
public serverReadyPattern?: RegExp = /^\s* ✓ Ready in / public serverReadyPattern?: RegExp = / ✓ Ready in /
constructor(opts: NextInstanceOpts) { constructor(opts: NextInstanceOpts) {
this.env = {} this.env = {}
...@@ -491,7 +491,7 @@ export class NextInstance { ...@@ -491,7 +491,7 @@ export class NextInstance {
public async patchFile( public async patchFile(
filename: string, filename: string,
content: string | ((content: string) => string), content: string | ((content: string) => string),
retryWithTempContent?: (context: { newFile: boolean }) => Promise<void> runWithTempContent?: (context: { newFile: boolean }) => Promise<void>
): Promise<{ newFile: boolean }> { ): Promise<{ newFile: boolean }> {
const outputPath = path.join(this.testDir, filename) const outputPath = path.join(this.testDir, filename)
const newFile = !existsSync(outputPath) const newFile = !existsSync(outputPath)
...@@ -503,9 +503,9 @@ export class NextInstance { ...@@ -503,9 +503,9 @@ export class NextInstance {
typeof content === 'function' ? content(previousContent) : content typeof content === 'function' ? content(previousContent) : content
) )
if (retryWithTempContent) { if (runWithTempContent) {
try { try {
await retry(() => retryWithTempContent({ newFile })) await runWithTempContent({ newFile })
} finally { } finally {
if (previousContent === undefined) { if (previousContent === undefined) {
await fs.rm(outputPath) await fs.rm(outputPath)
......
...@@ -153,7 +153,7 @@ export class NextDevInstance extends NextInstance { ...@@ -153,7 +153,7 @@ export class NextDevInstance extends NextInstance {
public override async patchFile( public override async patchFile(
filename: string, filename: string,
content: string | ((contents: string) => string), content: string | ((contents: string) => string),
retryWithTempContent?: (context: { newFile: boolean }) => Promise<void> runWithTempContent?: (context: { newFile: boolean }) => Promise<void>
) { ) {
const isServerRunning = this.childProcess && !this.isStopping const isServerRunning = this.childProcess && !this.isStopping
const cliOutputLength = this.cliOutput.length const cliOutputLength = this.cliOutput.length
...@@ -167,17 +167,21 @@ export class NextDevInstance extends NextInstance { ...@@ -167,17 +167,21 @@ export class NextDevInstance extends NextInstance {
if (newFile) { if (newFile) {
await this.handleDevWatchDelayAfterChange(filename) await this.handleDevWatchDelayAfterChange(filename)
} else if (filename.startsWith('next.config')) { } else if (filename.startsWith('next.config')) {
if (!this.cliOutput.slice(cliOutputLength).includes('Ready in')) { await retry(async () => {
throw new Error('Server has not finished restarting.') const cliOutput = this.cliOutput.slice(cliOutputLength)
}
if (!this.serverReadyPattern.test(cliOutput)) {
throw new Error('Server has not finished restarting.')
}
})
} }
} }
} }
if (retryWithTempContent) { if (runWithTempContent) {
return super.patchFile(filename, content, async ({ newFile }) => { return super.patchFile(filename, content, async ({ newFile }) => {
await waitForChanges({ newFile }) await waitForChanges({ newFile })
await retryWithTempContent({ newFile }) await runWithTempContent({ newFile })
}) })
} }
......
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