Skip to content

Commit d516f2c

Browse files
committed
Add 544 + internal changes to the repo
1 parent b2309ea commit d516f2c

File tree

11 files changed

+182
-203
lines changed

11 files changed

+182
-203
lines changed

.github/workflows/periodic.yml

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ jobs:
1010
contents: write
1111
steps:
1212
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: "22"
16+
- run: node --version
1317
- run: npm i
1418
- run: npm run prepare
1519
- name: Create issue if tests fail

.github/workflows/release.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ jobs:
77
permissions:
88
actions: read
99
contents: write
10-
strategy:
11-
matrix:
12-
node-version:
13-
- "20"
1410
steps:
1511
- uses: actions/checkout@v4
12+
- uses: actions/setup-node@v4
13+
with:
14+
node-version: "22"
15+
- run: node --version
1616
- run: npm i
1717
- run: npm t
1818
- run: npm run format

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20
1+
22

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 2.1.2
4+
5+
- Add 544
6+
37
## 2.1.1
48

59
- Add 542, 543

package.json

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-error-decoder",
3-
"version": "2.1.1",
3+
"version": "2.1.2",
44
"description": "⚛︎ Decode React minified error message",
55
"keywords": [
66
"react",
@@ -48,17 +48,12 @@
4848
"prepare": "curl https://raw.githubusercontent.com/facebook/react/main/scripts/error-codes/codes.json > src/collection.json",
4949
"build": "./scripts/build.sh",
5050
"format": "prettier --write .",
51-
"lint": "prettier --check .",
52-
"test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --forceExit",
51+
"test": "./scripts/test.sh",
5352
"prepublishOnly": "npm run build"
5453
},
5554
"devDependencies": {
56-
"@babel/plugin-syntax-import-assertions": "^7.18.6",
57-
"@types/jest": "^29.4.0",
58-
"esbuild": "^0.19.5",
59-
"jest": "^29.4.1",
55+
"esbuild": "^0.24.2",
6056
"prettier": "^3.0.3",
61-
"ts-jest": "^29.0.5",
6257
"typescript": "^5.2.2"
6358
}
6459
}

scripts/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
esbuild src/index.ts --outfile=index.js --bundle --platform=node --format=cjs
44
esbuild src/index.ts --outfile=index.mjs --bundle --platform=node --format=esm
5-
tsc src/index.ts --declaration --emitDeclarationOnly --resolveJsonModule --esModuleInterop --outDir .
5+
tsc src/index.ts --declaration --emitDeclarationOnly --resolveJsonModule --esModuleInterop --outDir . --module esnext --lib esnext --moduleResolution bundler

scripts/test.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
code=0
4+
5+
echo "Run tests. To update snapshots run: npm t -- --test-update-snapshots"
6+
NODE_NO_WARNINGS=1 node --test --experimental-test-coverage --experimental-test-snapshots --experimental-strip-types $@ **/test.ts
7+
code=$((code + $?))
8+
9+
exit $code

src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import collection from "./collection.json";
1+
import collection from "./collection.json" with { type: "json" };
22

33
type Collection = Record<string, string>;
44

@@ -26,6 +26,7 @@ function decodeDetails(message: string): {
2626

2727
try {
2828
const [url] = message.match(pattern) || [];
29+
// @ts-ignore - Use the global URL, which is available in Node, workers and browsers
2930
const { searchParams } = new URL(url);
3031
const args = searchParams.getAll("args[]");
3132
const [invariant] = searchParams.getAll("invariant");

src/test.ts

+23-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import { decode } from ".";
1+
import {
2+
afterEach,
3+
before,
4+
beforeEach,
5+
describe,
6+
snapshot,
7+
test,
8+
} from "node:test";
9+
import { deepEqual, equal, ok } from "node:assert/strict";
10+
import { decode } from "./index.ts";
211

312
describe("react-error-decoder", (): void => {
413
test("get all details for error", (): void => {
@@ -9,9 +18,9 @@ describe("react-error-decoder", (): void => {
918
const url =
1019
"https://reactjs.org/docs/error-decoder.html?invariant=130&args[]=undefined&args[]=";
1120
const invariant = "130";
12-
expect(decode.details(input)).toEqual({ message, url, invariant });
21+
deepEqual(decode.details(input), { message, url, invariant });
1322
});
14-
test.each([
23+
[
1524
[
1625
"Minified React error #130; visit https://reactjs.org/docs/error-decoder.html?invariant=130&args[]=undefined&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings.",
1726
"Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.",
@@ -24,29 +33,30 @@ describe("react-error-decoder", (): void => {
2433
"Minified React error #152; visit https://legacy.reactjs.org/docs/error-decoder.html?invariant=152&args[]=NGABuilder for the full message or use the non-minified dev environment for full errors and additional helpful warnings.",
2534
"Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.",
2635
],
27-
])("decodes messages successfully", (input: string, message: string): void =>
28-
expect(decode(input)).toBe(message),
36+
].forEach(([input, message]: string[]) =>
37+
test("decodes messages successfully", (): void => {
38+
equal(decode(input), message);
39+
}),
2940
);
41+
3042
test("Leave an error not in dictionary as is", (): void => {
3143
const input =
3244
"Minified React error #223; visit https://reactjs.org/docs/error-decoder.html?invariant=223&args[]=undefined&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings.";
33-
expect(decode(input)).toBe(input);
45+
equal(decode(input), input);
3446
});
3547
test("creates an object from regular error messages", (): void => {
36-
expect(decode.details("Something must have gone horribly wrong")).toEqual({
48+
deepEqual(decode.details("Something must have gone horribly wrong"), {
3749
message: "Something must have gone horribly wrong",
3850
url: undefined,
3951
invariant: undefined,
4052
});
4153
});
42-
test.each([
54+
[
4355
"visit https://reactjs.org/docs/error-decoder.html?invariant=130&args[]=undefined&args[]= for the full message",
4456
"Minified React error #1: Something else has gone wrong.",
4557
"Minified React error #1: Something else has gone wrong. https://www.facebook.com",
4658
"Minified React error #1: Something else has gone wrong. https://www.facebook.com?invariant=900",
47-
])("falls back to original message", (message: string): void =>
48-
expect(decode(message)).toBe(message),
49-
);
50-
test("updated snapshot", (): void =>
51-
expect(decode.collection).toMatchSnapshot());
59+
].forEach((message: string): void => equal(decode(message), message));
60+
test("updated snapshot", (context): void =>
61+
context.assert.snapshot(decode.collection));
5262
});

0 commit comments

Comments
 (0)