Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patchFile awaits compilation #72267

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions test/development/middleware-errors/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('middleware - development errors', () => {
const browser = await next.browser('/')
await assertHasRedbox(browser)
await next.patchFile('middleware.js', `export default function () {}`)
await assertHasRedbox(browser)
huozhi marked this conversation as resolved.
Show resolved Hide resolved
await assertNoRedbox(browser)
})
})

Expand Down Expand Up @@ -160,7 +160,7 @@ describe('middleware - development errors', () => {
await assertHasRedbox(browser)
expect(await getRedboxSource(browser)).toContain(`eval('test')`)
await next.patchFile('middleware.js', `export default function () {}`)
await assertHasRedbox(browser)
await assertNoRedbox(browser)
})
})

Expand Down Expand Up @@ -207,7 +207,7 @@ describe('middleware - development errors', () => {
expect(source).toContain('middleware.js')
expect(source).not.toContain('//middleware.js')
await next.patchFile('middleware.js', `export default function () {}`)
await assertHasRedbox(browser)
await assertNoRedbox(browser)
})
})

Expand Down Expand Up @@ -311,7 +311,7 @@ describe('middleware - development errors', () => {
await browser.elementByCss('#nextjs__container_errors_desc').text()
).toEqual('Failed to compile')
await next.patchFile('middleware.js', `export default function () {}`)
await assertHasRedbox(browser)
await assertNoRedbox(browser)
expect(await browser.elementByCss('#page-title')).toBeTruthy()
})
})
Expand Down
7 changes: 1 addition & 6 deletions test/e2e/prerender.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1133,13 +1133,8 @@ describe('Prerender', () => {

await next.patchFile(
'pages/index.js',
(content) =>
content
.replace('// throw new', 'throw new')
.replace('{/* <div', '<div')
.replace('</div> */}', '</div>'),
(content) => content.replace('// throw new', 'throw new'),
async () => {
await browser.waitForElementByCss('#after-change')
// we need to reload the page to trigger getStaticProps
await browser.refresh()

Expand Down
1 change: 0 additions & 1 deletion test/e2e/prerender/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export async function getStaticProps() {
const Page = ({ world, time }) => {
return (
<>
{/* <div id='after-change'>idk</div> */}
<p>hello {world}</p>
<span>time: {time}</span>
<Link href="/non-json/[p]" as="/non-json/1" id="non-json">
Expand Down
1 change: 1 addition & 0 deletions test/lib/next-modes/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class NextInstance {
public forcedPort?: string
public dirSuffix: string = ''
public serverReadyPattern?: RegExp = / ✓ Ready in /
public serverCompiledPattern?: RegExp = / ✓ Compiled /

constructor(opts: NextInstanceOpts) {
this.env = {}
Expand Down
12 changes: 12 additions & 0 deletions test/lib/next-modes/next-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ export class NextDevInstance extends NextInstance {
throw new Error('Server has not finished restarting.')
}
})
} else {
try {
await retry(async () => {
const cliOutput = this.cliOutput.slice(cliOutputLength)

if (!this.serverCompiledPattern.test(cliOutput)) {
throw new Error('Server has not finished restarting.')
}
}, 5000)
} catch (e) {
/** Fail silently because not all change will be reflected in the server output */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a bug then? This means that every test where a patch file doesn't result in the CLI output will now wait idly for 5s.
Can we instead always throw if retry times out and then add an option instead where the patchFile callsites can control this behavior so that we know which tests don't actually need to wait for the server to reflect the changes?

Copy link
Contributor Author

@gaojude gaojude Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the control of it to callsites: #72439

}
}
}
}
Expand Down
Loading