@terpjs/react-core 0.19.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terpjs/react-core",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "type": "module",
5
5
  "description": "Terp React stack core — typed @terpjs/contract client provider, auth session, capability gates, TanStack Router adapter, app shell, page archetypes, DataView and token-styled UI primitives. First frontend stack; see README.md for the component catalog.",
6
6
  "exports": {
@@ -14,24 +14,24 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@tanstack/react-router": "^1.170.32",
17
- "@terpjs/contract": "^0.19.0"
17
+ "@terpjs/contract": "^0.20.0"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "react": "^19.0.0",
21
21
  "react-dom": "^19.0.0"
22
22
  },
23
23
  "devDependencies": {
24
- "@testing-library/jest-dom": "^6.9.1",
24
+ "@testing-library/jest-dom": "^7.0.1",
25
25
  "@testing-library/react": "^16.3.3",
26
26
  "@types/react": "^19.2.18",
27
27
  "@types/react-dom": "^19.2.7",
28
28
  "@vitejs/plugin-react": "^6.1.1",
29
- "jsdom": "^29.1.1",
29
+ "jsdom": "^30.0.1",
30
30
  "react": "^19.2.7",
31
31
  "react-dom": "^19.2.7",
32
32
  "typescript": "^5.9.3",
33
33
  "vite": "^8.2.2",
34
- "vitest": "^4.1.9"
34
+ "vitest": "^5.0.0"
35
35
  },
36
36
  "license": "Apache-2.0",
37
37
  "repository": {
@@ -0,0 +1,24 @@
1
+ import { getConfig } from "@testing-library/dom";
2
+ import { expect, it } from "vitest";
3
+
4
+ // Testing Library's 1000ms default is not enough for this suite, and the way it fails is
5
+ // the problem: intermittently, on whichever test the machine happened to be busy during.
6
+ // Five failures across one day, four different tests, each passing alone and on a re-run —
7
+ // and one of them red in CI on a branch whose own change was fine.
8
+ //
9
+ // What this file holds is that the `configure` call in vitest.setup.ts actually TOOK
10
+ // EFFECT. Reading the number back out of the setup file would pass with the call deleted
11
+ // and the constant left behind, which is the one failure mode a config guard must not
12
+ // have. The bounds it has to sit between — above the default, below a toast's
13
+ // auto-dismiss, below `testTimeout` — span three files, so they are held from the Python
14
+ // side in `test_frontend_async_budget.py`, the way this repository holds its other
15
+ // cross-file config invariants. This package compiles with `types: []`, and reading files
16
+ // here would need node types it deliberately does not have.
17
+
18
+ const _WELL_ABOVE_THE_DEFAULT_MS = 2_000;
19
+
20
+ it("configures an async budget the loaded machine can actually meet", () => {
21
+ // Not a render: `findBy*` in these tests spans a resolved fetch, the state it sets and
22
+ // the re-render that puts the text on screen. One second covers that only when idle.
23
+ expect(getConfig().asyncUtilTimeout).toBeGreaterThanOrEqual(_WELL_ABOVE_THE_DEFAULT_MS);
24
+ });
package/vite.config.ts CHANGED
@@ -10,5 +10,22 @@ export default defineConfig({
10
10
  environment: "node",
11
11
  setupFiles: ["./vitest.setup.ts"],
12
12
  include: ["src/**/*.test.ts", "src/**/*.test.tsx"],
13
+ // Above the `asyncUtilTimeout` the setup file configures, so a matcher that cannot
14
+ // find its element loses first and says which element. Equal budgets would let the
15
+ // test time out mid-wait and report nothing useful about the assertion. The ordering
16
+ // is held from the Python side in `test_frontend_async_budget.py`, which is why this
17
+ // comment names no number: an earlier version said "the 5s asyncUtilTimeout" while
18
+ // the setup file configured 3s, and a comment that misstates the code it explains is
19
+ // worse than none.
20
+ testTimeout: 15_000,
21
+ // These tests contend for the machine rather than with each other, and losing that
22
+ // contention is how they fail: four different fetch-bound assertions across four CI
23
+ // runs, always one file of eighty-one, each passing on its own. Widening the async
24
+ // budget was tried first and did not fix it (1s to 3s to 4s), and it has nowhere left
25
+ // to go -- a toast's 5s lifetime is the ceiling. So remove the cause rather than the
26
+ // tolerance: a jsdom + React + fetch file is heavy, a small runner has four vCPUs, and
27
+ // eighty-one of them at once starve each other's timers. It costs wall clock and buys
28
+ // a green that means something.
29
+ fileParallelism: false,
13
30
  },
14
31
  });
package/vitest.setup.ts CHANGED
@@ -3,6 +3,37 @@
3
3
  // the jsdom component tests.
4
4
  import "@testing-library/jest-dom/vitest";
5
5
 
6
+ import { configure } from "@testing-library/dom";
7
+
8
+ // `findBy*` and `waitFor` default to a 1000ms budget, and the component tests spend it on
9
+ // a path that is not a render: a mocked fetch resolving, then the state it sets, then the
10
+ // re-render that finally puts the text on screen. One second is enough on an idle machine
11
+ // and not on a loaded one, so the suite failed intermittently — five times across one day,
12
+ // four different tests, every one passing alone and on a re-run, and one of them red in CI
13
+ // on a branch whose own change was fine.
14
+ //
15
+ // The budget is raised rather than the tests retried. A retry would hide a genuinely
16
+ // intermittent product bug, and these assertions are not flaky in what they claim: the
17
+ // text does appear, and a matcher that waits longer asserts exactly the same thing. What
18
+ // it costs is that a test which SHOULD fail now takes longer to say so, which is why
19
+ // `testTimeout` moves too — the matcher must lose before the test does, or the failure
20
+ // arrives as an unhelpful "test timed out" instead of naming the element it could not find.
21
+ //
22
+ // It has a CEILING, and the first attempt at this walked straight into it. A toast
23
+ // auto-dismisses after `DEFAULT_DURATION_MS` (5s, toast.tsx), and several admin tests wait
24
+ // for a field error and then assert the toast SYNCHRONOUSLY. Set the budget to 5s and a
25
+ // wait that takes long enough outlives the toast the next line is about to look for — one
26
+ // flake traded for another, and a worse one, because it looks like a product bug. So the
27
+ // budget sits between the two: comfortably past a fetch and a re-render, comfortably short
28
+ // of a toast's life. `async-budget.test.ts` holds both ends.
29
+ //
30
+ // Raised from 3s to 4s on 2026-09-08: 3s was still not enough under CI load. Two
31
+ // consecutive runs failed on two different fetch-bound tests, and main failed a third
32
+ // time in the same window -- always "unable to find element", always one file of
33
+ // eighty-one. 4s keeps a full second below the toast, which is the last of the
34
+ // headroom this lever has: the next move is less contention, not a longer wait.
35
+ configure({ asyncUtilTimeout: 4_000 });
36
+
6
37
  // jsdom's File / Blob / FormData are structurally incompatible with Node's built-in
7
38
  // (undici) fetch: a jsdom File inside a FormData body serializes as an empty, nameless
8
39
  // part, and on Node >= 24 `Request.formData()` brand-checks reject jsdom instances
@@ -27,6 +58,25 @@ if (typeof window !== "undefined") {
27
58
  ).constructor as typeof FormData;
28
59
  globalThis.FormData = NativeFormData;
29
60
  window.FormData = NativeFormData;
61
+
62
+ // Vitest's jsdom environment installs a `Request` SUBCLASS whose constructor
63
+ // pre-processes `init.body` for jsdom's Blob internals (it reads `_buffer`).
64
+ // With the swap above that body is a Node FormData holding a Node File, so the
65
+ // shim throws on the one thing these tests exist to check — and handed a jsdom
66
+ // FormData instead it does not recognise it as form data at all and serialises
67
+ // the body as a string, so the request goes out as `text/plain` and the
68
+ // multipart assertion fails for a second, quieter reason. Unwrapping to the
69
+ // class it extends restores Node's own constructor, which serialises a Node
70
+ // FormData as multipart with a boundary.
71
+ //
72
+ // Guarded on the shim actually being there: a real `Request` is a base class,
73
+ // so its prototype is `Function.prototype`. If a later Vitest stops wrapping,
74
+ // this becomes a no-op rather than reaching for something that is not a class.
75
+ const RequestBase = Object.getPrototypeOf(globalThis.Request) as typeof Request;
76
+ if (typeof RequestBase === "function" && (RequestBase as unknown) !== Function.prototype) {
77
+ globalThis.Request = RequestBase;
78
+ window.Request = RequestBase;
79
+ }
30
80
  }
31
81
 
32
82
  // jsdom does not implement scrollTo, which TanStack Router calls on navigation; stub it so