Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
penalosa committed Feb 7, 2024
1 parent 47c12fb commit 925b0be
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
23 changes: 13 additions & 10 deletions packages/wrangler/src/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 () => {
Expand Down
23 changes: 12 additions & 11 deletions packages/wrangler/src/__tests__/pages/functions-build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 () => {
Expand Down

0 comments on commit 925b0be

Please sign in to comment.