Skip to content

Commit

Permalink
fixup! polish: improve consistency of warnings and errors
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed Apr 26, 2022
1 parent 28b979d commit b9adbd6
Show file tree
Hide file tree
Showing 12 changed files with 211 additions and 237 deletions.
48 changes: 24 additions & 24 deletions packages/wrangler/src/__tests__/dev.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ describe("wrangler dev", () => {
expect(std.out).toMatchInlineSnapshot(`""`);
expect(std.warn.replaceAll(currentDate, "<current-date>"))
.toMatchInlineSnapshot(`
"⚠ No compatibility_date was specified. Using today's date: <current-date>.
Add one to your wrangler.toml file:
⚠ \`\`\`
compatibility_date = \\"<current-date>\\"
⚠ \`\`\`
or pass it in your terminal:
⚠ \`\`\`
⚠ --compatibility-date=<current-date>
⚠ \`\`\`
See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information."
"[33m[39mNo compatibility_date was specified. Using today's date: <current-date>.
[33m[39mAdd one to your wrangler.toml file:
[33m[39m\`\`\`
[33m[39mcompatibility_date = \\"<current-date>\\"
[33m[39m\`\`\`
[33m[39mor pass it in your terminal:
[33m[39m\`\`\`
[33m[39m--compatibility-date=<current-date>
[33m[39m\`\`\`
[33m[39mSee https://developers.cloudflare.com/workers/platform/compatibility-dates for more information."
`);
expect(std.err).toMatchInlineSnapshot(`""`);
});
Expand Down Expand Up @@ -79,9 +79,9 @@ describe("wrangler dev", () => {

expect(std.out).toMatchInlineSnapshot(`""`);
expect(std.err).toMatchInlineSnapshot(`
"✖ Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler dev path/to/script\`) or the \`main\` config field.
✖ [32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
"[31m[39mMissing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler dev path/to/script\`) or the \`main\` config field.
[31m✖ [39m
[31m[39m[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
`);
});

Expand Down Expand Up @@ -436,9 +436,9 @@ describe("wrangler dev", () => {
"
`);
expect(std.err).toMatchInlineSnapshot(`
"✖ Could not resolve \\"index.js\\" after running custom build: node -e \\"console.log('custom build');\\"
✖ [32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
"[31m[39mCould not resolve \\"index.js\\" after running custom build: node -e \\"console.log('custom build');\\"
[31m✖ [39m
[31m[39m[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
`);
expect(std.warn).toMatchInlineSnapshot(`""`);
});
Expand Down Expand Up @@ -470,9 +470,9 @@ describe("wrangler dev", () => {
);
expect(std.out).toMatchInlineSnapshot(`""`);
expect(std.warn).toMatchInlineSnapshot(`
"⚠ Setting upstream-protocol to http is not currently implemented.
If this is required in your project, please add your use case to the following issue:
https://github.com/cloudflare/wrangler2/issues/583."
"[33m[39mSetting upstream-protocol to http is not currently implemented.
[33m[39mIf this is required in your project, please add your use case to the following issue:
[33m[39mhttps://github.com/cloudflare/wrangler2/issues/583."
`);
expect(std.err).toMatchInlineSnapshot(`""`);
});
Expand Down Expand Up @@ -596,11 +596,11 @@ describe("wrangler dev", () => {
expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("localhost");
expect(std.out).toMatchInlineSnapshot(`""`);
expect(std.warn).toMatchInlineSnapshot(`
"⚠ WARNING: You have Durable Object bindings that are not defined locally in the worker being developed.
Be aware that changes to the data stored in these Durable Objects will be permanent and affect the live instances.
Remote Durable Objects that are affected:
⚠ - {\\"name\\":\\"NAME_2\\",\\"class_name\\":\\"CLASS_2\\",\\"script_name\\":\\"SCRIPT_A\\"}
⚠ - {\\"name\\":\\"NAME_4\\",\\"class_name\\":\\"CLASS_4\\",\\"script_name\\":\\"SCRIPT_B\\"}"
"[33m[39mWARNING: You have Durable Object bindings that are not defined locally in the worker being developed.
[33m[39mBe aware that changes to the data stored in these Durable Objects will be permanent and affect the live instances.
[33m[39mRemote Durable Objects that are affected:
[33m[39m- {\\"name\\":\\"NAME_2\\",\\"class_name\\":\\"CLASS_2\\",\\"script_name\\":\\"SCRIPT_A\\"}
[33m[39m- {\\"name\\":\\"NAME_4\\",\\"class_name\\":\\"CLASS_4\\",\\"script_name\\":\\"SCRIPT_B\\"}"
`);
expect(std.err).toMatchInlineSnapshot(`""`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("guess worker format", () => {
);
expect(guess).toBe("service-worker");
expect(std.warn).toMatchInlineSnapshot(
`"⚠ The entrypoint index.ts has exports like an ES Module, but hasn't defined a default export like a module worker normally would. Building the worker using \\"service-worker\\" format..."`
`"[33m[39mThe entrypoint index.ts has exports like an ES Module, but hasn't defined a default export like a module worker normally would. Building the worker using \\"service-worker\\" format..."`
);
});
});
4 changes: 2 additions & 2 deletions packages/wrangler/src/__tests__/https-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ describe("getHttpsOptions()", () => {
`"Generating new self-signed certificate..."`
);
expect(std.warn).toMatchInlineSnapshot(`
"⚠ Unable to cache generated self-signed certificate in home/.wrangler/local-cert.
ERROR: Cannot write file"
"[33m[39mUnable to cache generated self-signed certificate in home/.wrangler/local-cert.
[33m[39mERROR: Cannot write file"
`);
expect(std.err).toMatchInlineSnapshot(`""`);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe("wrangler", () => {
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
--legacy-env Use legacy environments [boolean]
Unknown argument: invalid-command"
[31m[39mUnknown argument: invalid-command"
`);
});
});
Expand Down
9 changes: 0 additions & 9 deletions packages/wrangler/src/__tests__/jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@ import {
} from "../cfetch/internal";
import { confirm, prompt } from "../dialogs";
import { mockFetchInternal, mockFetchKVGetValue } from "./helpers/mock-cfetch";
import { useMockIsTTY } from "./helpers/mock-istty";
import { MockWebSocket } from "./helpers/mock-web-socket";

// For tests let's just agree to pretend we are not running in a TTY environment.
// This ensures consistency between running tests:
// - locally with `run test-watch`,
// - locally (in parallel) using `run test`,
// - and also in the CI actions.
// eslint-disable-next-line react-hooks/rules-of-hooks
useMockIsTTY().setIsTTY(false);

jest.mock("ws", () => {
return {
__esModule: true,
Expand Down
60 changes: 30 additions & 30 deletions packages/wrangler/src/__tests__/kv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe("wrangler", () => {
Options:
-e, --env Perform on a specific environment [string]
--preview Interact with a preview namespace [boolean]
Not enough non-option arguments: got 0, need at least 1"
[31m[39mNot enough non-option arguments: got 0, need at least 1"
`);
});

Expand Down Expand Up @@ -91,7 +91,7 @@ describe("wrangler", () => {
Options:
-e, --env Perform on a specific environment [string]
--preview Interact with a preview namespace [boolean]
Unknown arguments: def, ghi"
[31m[39mUnknown arguments: def, ghi"
`);
});

Expand Down Expand Up @@ -120,7 +120,7 @@ describe("wrangler", () => {
Options:
-e, --env Perform on a specific environment [string]
--preview Interact with a preview namespace [boolean]
The namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number."
[31m[39mThe namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number."
`);
});

Expand Down Expand Up @@ -285,8 +285,8 @@ describe("wrangler", () => {
--namespace-id The id of the namespace to delete [string]
-e, --env Perform on a specific environment [string]
--preview Interact with a preview namespace [boolean]
Not able to delete namespace.
A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."
[31m[39mNot able to delete namespace.
[31m[39mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."
`);
});

Expand Down Expand Up @@ -481,7 +481,7 @@ describe("wrangler", () => {
--ttl Time for which the entries should be visible [number]
--expiration Time since the UNIX epoch after which the entry expires [number]
--path Read value from the file at a given path [string]
Not enough non-option arguments: got 0, need at least 1"
[31m[39mNot enough non-option arguments: got 0, need at least 1"
`);
});

Expand Down Expand Up @@ -516,7 +516,7 @@ describe("wrangler", () => {
--ttl Time for which the entries should be visible [number]
--expiration Time since the UNIX epoch after which the entry expires [number]
--path Read value from the file at a given path [string]
Exactly one of the arguments binding and namespace-id is required"
[31m[39mExactly one of the arguments binding and namespace-id is required"
`);
});

Expand Down Expand Up @@ -551,7 +551,7 @@ describe("wrangler", () => {
--ttl Time for which the entries should be visible [number]
--expiration Time since the UNIX epoch after which the entry expires [number]
--path Read value from the file at a given path [string]
Arguments binding and namespace-id are mutually exclusive"
[31m[39mArguments binding and namespace-id are mutually exclusive"
`);
});

Expand Down Expand Up @@ -586,7 +586,7 @@ describe("wrangler", () => {
--ttl Time for which the entries should be visible [number]
--expiration Time since the UNIX epoch after which the entry expires [number]
--path Read value from the file at a given path [string]
Exactly one of the arguments value and path is required"
[31m[39mExactly one of the arguments value and path is required"
`);
});

Expand Down Expand Up @@ -621,7 +621,7 @@ describe("wrangler", () => {
--ttl Time for which the entries should be visible [number]
--expiration Time since the UNIX epoch after which the entry expires [number]
--path Read value from the file at a given path [string]
Arguments value and path are mutually exclusive"
[31m[39mArguments value and path are mutually exclusive"
`);
});

Expand All @@ -635,9 +635,9 @@ describe("wrangler", () => {

expect(std.out).toMatchInlineSnapshot(`""`);
expect(std.err).toMatchInlineSnapshot(`
"✖ A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
✖ [32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
"[31m[39mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
[31m✖ [39m
[31m[39m[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
`);
});

Expand All @@ -654,9 +654,9 @@ describe("wrangler", () => {
);
expect(std.out).toMatchInlineSnapshot(`""`);
expect(std.err).toMatchInlineSnapshot(`
"✖ someBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace.
✖ [32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
"[31m[39msomeBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace.
[31m✖ [39m
[31m[39m[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
`);
expect(requests.count).toEqual(0);
});
Expand Down Expand Up @@ -816,9 +816,9 @@ describe("wrangler", () => {
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
);
expect(std.err).toMatchInlineSnapshot(`
"✖ A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
✖ [32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
"[31m[39mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
[31m✖ [39m
[31m[39m[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
`);
expect(std.out).toMatchInlineSnapshot(`""`);
});
Expand Down Expand Up @@ -910,7 +910,7 @@ describe("wrangler", () => {
--namespace-id The id of the namespace to get from [string]
-e, --env Perform on a specific environment [string]
--preview Interact with a preview namespace [boolean] [default: false]
Not enough non-option arguments: got 0, need at least 1"
[31m[39mNot enough non-option arguments: got 0, need at least 1"
`);
});

Expand Down Expand Up @@ -940,7 +940,7 @@ describe("wrangler", () => {
--namespace-id The id of the namespace to get from [string]
-e, --env Perform on a specific environment [string]
--preview Interact with a preview namespace [boolean] [default: false]
Exactly one of the arguments binding and namespace-id is required"
[31m[39mExactly one of the arguments binding and namespace-id is required"
`);
});

Expand Down Expand Up @@ -971,7 +971,7 @@ describe("wrangler", () => {
--namespace-id The id of the namespace to get from [string]
-e, --env Perform on a specific environment [string]
--preview Interact with a preview namespace [boolean] [default: false]
Arguments binding and namespace-id are mutually exclusive"
[31m[39mArguments binding and namespace-id are mutually exclusive"
`);
});

Expand All @@ -984,9 +984,9 @@ describe("wrangler", () => {
);
expect(std.out).toMatchInlineSnapshot(`""`);
expect(std.err).toMatchInlineSnapshot(`
"✖ A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
✖ [32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
"[31m[39mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
[31m✖ [39m
[31m[39m[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
`);
});
});
Expand Down Expand Up @@ -1046,9 +1046,9 @@ describe("wrangler", () => {
);

expect(std.err).toMatchInlineSnapshot(`
"✖ A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
✖ [32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
"[31m[39mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
[31m✖ [39m
[31m[39m[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
`);
});

Expand Down Expand Up @@ -1187,8 +1187,8 @@ describe("wrangler", () => {

expect(std.out).toMatchInlineSnapshot(`""`);
expect(std.warn).toMatchInlineSnapshot(`
"⚠ Unexpected key-value properties in \\"keys.json\\".
The item at index 4 contains unexpected properties: [\\"invalid\\"]."
"[33m[39mUnexpected key-value properties in \\"keys.json\\".
[33m[39mThe item at index 4 contains unexpected properties: [\\"invalid\\"]."
`);
});
});
Expand Down
Loading

0 comments on commit b9adbd6

Please sign in to comment.