Skip to content

Commit

Permalink
Add 544 + internal changes to the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
omrilotan committed Jan 8, 2025
1 parent b2309ea commit d516f2c
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 203 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/periodic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ jobs:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "22"
- run: node --version
- run: npm i
- run: npm run prepare
- name: Create issue if tests fail
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ jobs:
permissions:
actions: read
contents: write
strategy:
matrix:
node-version:
- "20"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "22"
- run: node --version
- run: npm i
- run: npm t
- run: npm run format
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20
22
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 2.1.2

- Add 544

## 2.1.1

- Add 542, 543
Expand Down
11 changes: 3 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-error-decoder",
"version": "2.1.1",
"version": "2.1.2",
"description": "⚛︎ Decode React minified error message",
"keywords": [
"react",
Expand Down Expand Up @@ -48,17 +48,12 @@
"prepare": "curl https://raw.githubusercontent.com/facebook/react/main/scripts/error-codes/codes.json > src/collection.json",
"build": "./scripts/build.sh",
"format": "prettier --write .",
"lint": "prettier --check .",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --forceExit",
"test": "./scripts/test.sh",
"prepublishOnly": "npm run build"
},
"devDependencies": {
"@babel/plugin-syntax-import-assertions": "^7.18.6",
"@types/jest": "^29.4.0",
"esbuild": "^0.19.5",
"jest": "^29.4.1",
"esbuild": "^0.24.2",
"prettier": "^3.0.3",
"ts-jest": "^29.0.5",
"typescript": "^5.2.2"
}
}
2 changes: 1 addition & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

esbuild src/index.ts --outfile=index.js --bundle --platform=node --format=cjs
esbuild src/index.ts --outfile=index.mjs --bundle --platform=node --format=esm
tsc src/index.ts --declaration --emitDeclarationOnly --resolveJsonModule --esModuleInterop --outDir .
tsc src/index.ts --declaration --emitDeclarationOnly --resolveJsonModule --esModuleInterop --outDir . --module esnext --lib esnext --moduleResolution bundler
9 changes: 9 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

code=0

echo "Run tests. To update snapshots run: npm t -- --test-update-snapshots"
NODE_NO_WARNINGS=1 node --test --experimental-test-coverage --experimental-test-snapshots --experimental-strip-types $@ **/test.ts
code=$((code + $?))

exit $code
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import collection from "./collection.json";
import collection from "./collection.json" with { type: "json" };

type Collection = Record<string, string>;

Expand Down Expand Up @@ -26,6 +26,7 @@ function decodeDetails(message: string): {

try {
const [url] = message.match(pattern) || [];
// @ts-ignore - Use the global URL, which is available in Node, workers and browsers
const { searchParams } = new URL(url);
const args = searchParams.getAll("args[]");
const [invariant] = searchParams.getAll("invariant");
Expand Down
36 changes: 23 additions & 13 deletions src/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { decode } from ".";
import {
afterEach,
before,
beforeEach,
describe,
snapshot,
test,
} from "node:test";
import { deepEqual, equal, ok } from "node:assert/strict";
import { decode } from "./index.ts";

describe("react-error-decoder", (): void => {
test("get all details for error", (): void => {
Expand All @@ -9,9 +18,9 @@ describe("react-error-decoder", (): void => {
const url =
"https://reactjs.org/docs/error-decoder.html?invariant=130&args[]=undefined&args[]=";
const invariant = "130";
expect(decode.details(input)).toEqual({ message, url, invariant });
deepEqual(decode.details(input), { message, url, invariant });
});
test.each([
[
[
"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.",
"Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.",
Expand All @@ -24,29 +33,30 @@ describe("react-error-decoder", (): void => {
"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.",
"Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.",
],
])("decodes messages successfully", (input: string, message: string): void =>
expect(decode(input)).toBe(message),
].forEach(([input, message]: string[]) =>
test("decodes messages successfully", (): void => {
equal(decode(input), message);
}),
);

test("Leave an error not in dictionary as is", (): void => {
const input =
"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.";
expect(decode(input)).toBe(input);
equal(decode(input), input);
});
test("creates an object from regular error messages", (): void => {
expect(decode.details("Something must have gone horribly wrong")).toEqual({
deepEqual(decode.details("Something must have gone horribly wrong"), {
message: "Something must have gone horribly wrong",
url: undefined,
invariant: undefined,
});
});
test.each([
[
"visit https://reactjs.org/docs/error-decoder.html?invariant=130&args[]=undefined&args[]= for the full message",
"Minified React error #1: Something else has gone wrong.",
"Minified React error #1: Something else has gone wrong. https://www.facebook.com",
"Minified React error #1: Something else has gone wrong. https://www.facebook.com?invariant=900",
])("falls back to original message", (message: string): void =>
expect(decode(message)).toBe(message),
);
test("updated snapshot", (): void =>
expect(decode.collection).toMatchSnapshot());
].forEach((message: string): void => equal(decode(message), message));
test("updated snapshot", (context): void =>
context.assert.snapshot(decode.collection));
});
Loading

0 comments on commit d516f2c

Please sign in to comment.