From 925b0be2466c5a370cd5c47bab10e3907dd51535 Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Wed, 7 Feb 2024 18:38:11 +0000 Subject: [PATCH] fix tests --- .../wrangler/src/__tests__/deploy.test.ts | 23 +++++++++++-------- .../__tests__/pages/functions-build.test.ts | 23 ++++++++++--------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/packages/wrangler/src/__tests__/deploy.test.ts b/packages/wrangler/src/__tests__/deploy.test.ts index f7a073c3755b..190b962a850f 100644 --- a/packages/wrangler/src/__tests__/deploy.test.ts +++ b/packages/wrangler/src/__tests__/deploy.test.ts @@ -7938,7 +7938,7 @@ export default{ }); describe("`nodejs_compat` compatibility flag", () => { - it('when absent, should error on any "external" `node:*` imports', async () => { + it('when absent, should warn on any "external" `node:*` imports', async () => { writeWranglerToml(); fs.writeFileSync( "index.js", @@ -7948,15 +7948,18 @@ export default{ export default {} ` ); - let err: esbuild.BuildFailure | undefined; - try { - await runWrangler("deploy index.js --dry-run"); // expecting this to throw, as node compatibility isn't enabled - } catch (e) { - err = e as esbuild.BuildFailure; - } - expect( - esbuild.formatMessagesSync(err?.errors ?? [], { kind: "error" }).join() - ).toMatch(/Could not resolve "node:async_hooks"/); + await runWrangler("deploy index.js --dry-run"); + + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] The package \\"node:async_hooks\\" wasn't found on the file system but is built into node. + + Your Worker may throw errors at runtime unless you enable the \\"nodejs_compat\\" compatibility flag. + Refer to https://developers.cloudflare.com/workers/runtime-apis/nodejs/ for more details. Imported + from: + - index.js + + " + `); }); it('when present, should support any "external" `node:*` imports', async () => { diff --git a/packages/wrangler/src/__tests__/pages/functions-build.test.ts b/packages/wrangler/src/__tests__/pages/functions-build.test.ts index 5327ac0a58fe..3e3693189e1c 100644 --- a/packages/wrangler/src/__tests__/pages/functions-build.test.ts +++ b/packages/wrangler/src/__tests__/pages/functions-build.test.ts @@ -413,7 +413,7 @@ export default { ); }); - it("should error at Node.js imports when the `nodejs_compat` compatibility flag is not set", async () => { + it("should warn at Node.js imports when the `nodejs_compat` compatibility flag is not set", async () => { mkdirSync("functions"); writeFileSync( "functions/hello.js", @@ -428,17 +428,18 @@ export default { ); await expect( - runWrangler(`pages functions build --outfile=public/_worker.bundle`) - ).rejects.toThrowErrorMatchingInlineSnapshot(` - "Build failed with 1 error: - hello.js:2:36: ERROR: Could not resolve \\"node:async_hooks\\"" - `); - expect(std.err).toContain( - 'The package "node:async_hooks" wasn\'t found on the file system but is built into node.' - ); - expect(std.err).toContain( - 'Add the "nodejs_compat" compatibility flag to your Pages project and make sure to prefix the module name with "node:" to enable Node.js compatibility.' + await runWrangler(`pages functions build --outfile=public/_worker.bundle`) ); + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] The package \\"node:async_hooks\\" wasn't found on the file system but is built into node. + + Your Worker may throw errors at runtime unless you enable the \\"nodejs_compat\\" compatibility flag. + Refer to https://developers.cloudflare.com/workers/runtime-apis/nodejs/ for more details. Imported + from: + - hello.js + + " + `); }); it("should compile a _worker.js/ directory", async () => {