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