@carlonicora/nextjs-jsonapi 4.1.1 → 4.1.2

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": "@carlonicora/nextjs-jsonapi",
3
- "version": "4.1.1",
3
+ "version": "4.1.2",
4
4
  "description": "Next.js JSON:API client with server/client support and caching",
5
5
  "author": "Carlo Nicora",
6
6
  "license": "GPL-3.0-or-later",
@@ -0,0 +1,54 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ DEFAULT_SLOW_TEST_MS,
4
+ formatSlowTests,
5
+ resolveSlowTestThreshold,
6
+ type SlowTestEntry,
7
+ } from "../vitest.slow-tests.reporter";
8
+
9
+ const entry = (name: string, durationMs: number, file = "src/a.spec.ts"): SlowTestEntry => ({ file, name, durationMs });
10
+
11
+ describe("formatSlowTests", () => {
12
+ it("returns nothing when no test exceeds the threshold", () => {
13
+ expect(formatSlowTests([entry("fast", 10), entry("at threshold", 1000)], 1000)).toEqual([]);
14
+ });
15
+
16
+ it("lists only tests above the threshold, slowest first, with file, name and duration", () => {
17
+ const lines = formatSlowTests(
18
+ [entry("a", 1500), entry("fast", 20), entry("b", 4200.6, "src/b.spec.ts"), entry("c", 1001)],
19
+ 1000,
20
+ );
21
+
22
+ expect(lines).toEqual([
23
+ "Slow tests (> 1000 ms): 3",
24
+ " 4201 ms src/b.spec.ts > b",
25
+ " 1500 ms src/a.spec.ts > a",
26
+ " 1001 ms src/a.spec.ts > c",
27
+ ]);
28
+ });
29
+
30
+ it("caps the list and counts the rest", () => {
31
+ const entries = Array.from({ length: 25 }, (_, i) => entry(`t${i}`, 2000 + i));
32
+ const lines = formatSlowTests(entries, 1000, 20);
33
+
34
+ expect(lines[0]).toBe("Slow tests (> 1000 ms): 25");
35
+ expect(lines).toHaveLength(1 + 20 + 1);
36
+ expect(lines[1]).toContain("t24");
37
+ expect(lines[lines.length - 1]).toBe(" ... and 5 more");
38
+ });
39
+ });
40
+
41
+ describe("resolveSlowTestThreshold", () => {
42
+ it("defaults to 1000 ms when unset, empty or invalid", () => {
43
+ expect(DEFAULT_SLOW_TEST_MS).toBe(1000);
44
+ expect(resolveSlowTestThreshold(undefined)).toBe(1000);
45
+ expect(resolveSlowTestThreshold("")).toBe(1000);
46
+ expect(resolveSlowTestThreshold("abc")).toBe(1000);
47
+ expect(resolveSlowTestThreshold("-5")).toBe(1000);
48
+ });
49
+
50
+ it("uses the env value when it is a valid number", () => {
51
+ expect(resolveSlowTestThreshold("250")).toBe(250);
52
+ expect(resolveSlowTestThreshold("0")).toBe(0);
53
+ });
54
+ });