From fa05f115532c3fc6b5cdb4b14d08e037ee303edb Mon Sep 17 00:00:00 2001 From: Zack Tanner <1939140+ztanner@users.noreply.github.com> Date: Mon, 10 Jun 2024 16:29:49 -0700 Subject: [PATCH] tweak flaky module-imports test (#66728) This test flakes a _lot_ ([ref](https://github.com/vercel/next.js/actions/runs/9456072960/job/26048162244), [ref](https://github.com/vercel/next.js/actions/runs/9456072960/attempts/2), [ref](https://github.com/vercel/next.js/actions/runs/9456076941/job/26048598801)) likely due to all of the `context` mutation and sharing between tests. This updates the test that fails the most with locally scoped context to flakes introduced by other tests. --- .../test/module-imports.test.js | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/test/integration/edge-runtime-module-errors/test/module-imports.test.js b/test/integration/edge-runtime-module-errors/test/module-imports.test.js index ec253989ccf1e..136cf33fd629e 100644 --- a/test/integration/edge-runtime-module-errors/test/module-imports.test.js +++ b/test/integration/edge-runtime-module-errors/test/module-imports.test.js @@ -21,6 +21,7 @@ import { expectUnsupportedModuleDevError, expectUnsupportedModuleProdError, getUnsupportedModuleWarning, + getModuleNotFound, } from './utils' jest.setTimeout(1000 * 60 * 2) @@ -296,14 +297,29 @@ describe('Edge runtime code with imports', () => { stderr: true, }) expect(stderr).toContain(getUnsupportedModuleWarning(moduleName)) - context.app = await nextStart( - context.appDir, - context.appPort, - appOption - ) - const res = await fetchViaHTTP(context.appPort, url) + + let logs = { stdout: '', stderr: '' } + const port = await findPort() + + const options = { + onStdout(msg) { + logs.output += msg + logs.stdout += msg + }, + onStderr(msg) { + logs.output += msg + logs.stderr += msg + }, + } + + await nextStart(context.appDir, port, options) + const res = await fetchViaHTTP(port, url) expect(res.status).toBe(200) - expectNoError(moduleName) + + expect(logs.output).not.toContain( + getUnsupportedModuleWarning(moduleName) + ) + expect(logs.output).not.toContain(getModuleNotFound(moduleName)) }) } )