rask-ui 0.24.1 → 0.25.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/dist/asyncState.d.ts +16 -0
- package/dist/asyncState.d.ts.map +1 -0
- package/dist/asyncState.js +24 -0
- package/dist/compiler.d.ts +1 -3
- package/dist/compiler.d.ts.map +1 -1
- package/dist/compiler.js +1 -7
- package/dist/context.d.ts +5 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +29 -0
- package/dist/createAsync.test.d.ts +2 -0
- package/dist/createAsync.test.d.ts.map +1 -0
- package/dist/createAsync.test.js +110 -0
- package/dist/createContext.d.ts +1 -1
- package/dist/createContext.d.ts.map +1 -1
- package/dist/createMutation.test.d.ts +2 -0
- package/dist/createMutation.test.d.ts.map +1 -0
- package/dist/createMutation.test.js +168 -0
- package/dist/createQuery.test.d.ts +2 -0
- package/dist/createQuery.test.d.ts.map +1 -0
- package/dist/createQuery.test.js +156 -0
- package/dist/createRef.d.ts +6 -0
- package/dist/createRef.d.ts.map +1 -0
- package/dist/createRef.js +8 -0
- package/dist/createState.d.ts +0 -2
- package/dist/createState.d.ts.map +1 -1
- package/dist/createState.js +5 -40
- package/dist/createState.test.d.ts.map +1 -0
- package/dist/createState.test.js +111 -0
- package/dist/createView.d.ts +44 -18
- package/dist/createView.d.ts.map +1 -1
- package/dist/createView.js +48 -57
- package/dist/createView.test.d.ts.map +1 -0
- package/dist/{tests/createView.test.js → createView.test.js} +40 -40
- package/dist/error.d.ts +14 -3
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +15 -14
- package/dist/jsx.d.ts +256 -10
- package/dist/observation.test.d.ts.map +1 -0
- package/dist/observation.test.js +150 -0
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.js +3 -3
- package/dist/suspense.d.ts +25 -0
- package/dist/suspense.d.ts.map +1 -0
- package/dist/suspense.js +97 -0
- package/dist/test-setup.d.ts +16 -0
- package/dist/test-setup.d.ts.map +1 -0
- package/dist/test-setup.js +40 -0
- package/dist/test.d.ts +2 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +24 -0
- package/dist/transformer.d.ts +4 -0
- package/dist/transformer.d.ts.map +1 -0
- package/dist/transformer.js +7 -0
- package/dist/useCatchError.d.ts +1 -1
- package/dist/useCatchError.d.ts.map +1 -1
- package/package.json +5 -5
- package/swc-plugin/target/wasm32-wasip1/release/swc_plugin_rask_component.wasm +0 -0
- package/dist/createComputed.d.ts +0 -4
- package/dist/createComputed.d.ts.map +0 -1
- package/dist/createComputed.js +0 -69
- package/dist/createEffect.d.ts +0 -2
- package/dist/createEffect.d.ts.map +0 -1
- package/dist/createEffect.js +0 -29
- package/dist/createRouter.d.ts +0 -8
- package/dist/createRouter.d.ts.map +0 -1
- package/dist/createRouter.js +0 -27
- package/dist/createTask.d.ts +0 -31
- package/dist/createTask.d.ts.map +0 -1
- package/dist/createTask.js +0 -79
- package/dist/patchInferno.d.ts +0 -6
- package/dist/patchInferno.d.ts.map +0 -1
- package/dist/patchInferno.js +0 -53
- package/dist/scheduler.d.ts +0 -4
- package/dist/scheduler.d.ts.map +0 -1
- package/dist/scheduler.js +0 -107
- package/dist/tests/batch.test.d.ts +0 -2
- package/dist/tests/batch.test.d.ts.map +0 -1
- package/dist/tests/batch.test.js +0 -244
- package/dist/tests/createComputed.test.d.ts +0 -2
- package/dist/tests/createComputed.test.d.ts.map +0 -1
- package/dist/tests/createComputed.test.js +0 -257
- package/dist/tests/createContext.test.d.ts +0 -2
- package/dist/tests/createContext.test.d.ts.map +0 -1
- package/dist/tests/createContext.test.js +0 -136
- package/dist/tests/createEffect.test.d.ts +0 -2
- package/dist/tests/createEffect.test.d.ts.map +0 -1
- package/dist/tests/createEffect.test.js +0 -467
- package/dist/tests/createState.test.d.ts.map +0 -1
- package/dist/tests/createState.test.js +0 -144
- package/dist/tests/createTask.test.d.ts +0 -2
- package/dist/tests/createTask.test.d.ts.map +0 -1
- package/dist/tests/createTask.test.js +0 -322
- package/dist/tests/createView.test.d.ts.map +0 -1
- package/dist/tests/error.test.d.ts +0 -2
- package/dist/tests/error.test.d.ts.map +0 -1
- package/dist/tests/error.test.js +0 -168
- package/dist/tests/observation.test.d.ts.map +0 -1
- package/dist/tests/observation.test.js +0 -341
- package/dist/useComputed.d.ts +0 -5
- package/dist/useComputed.d.ts.map +0 -1
- package/dist/useComputed.js +0 -69
- package/dist/useQuery.d.ts +0 -25
- package/dist/useQuery.d.ts.map +0 -1
- package/dist/useQuery.js +0 -25
- package/dist/useSuspendAsync.d.ts +0 -18
- package/dist/useSuspendAsync.d.ts.map +0 -1
- package/dist/useSuspendAsync.js +0 -37
- package/dist/useTask.d.ts +0 -25
- package/dist/useTask.d.ts.map +0 -1
- package/dist/useTask.js +0 -70
- /package/dist/{tests/createState.test.d.ts → createState.test.d.ts} +0 -0
- /package/dist/{tests/createView.test.d.ts → createView.test.d.ts} +0 -0
- /package/dist/{tests/observation.test.d.ts → observation.test.d.ts} +0 -0
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
2
|
-
import { createTask } from "../createTask";
|
|
3
|
-
describe("createTask", () => {
|
|
4
|
-
describe("without parameters", () => {
|
|
5
|
-
it("should auto-run on creation and start in idle state", () => {
|
|
6
|
-
const promise = new Promise(() => { });
|
|
7
|
-
const task = createTask(() => promise);
|
|
8
|
-
// Initial fetch() doesn't set isRunning, only run()/rerun() do
|
|
9
|
-
expect(task.isRunning).toBe(false);
|
|
10
|
-
expect(task.result).toBeNull();
|
|
11
|
-
expect(task.error).toBeNull();
|
|
12
|
-
expect(task.params).toBeNull();
|
|
13
|
-
});
|
|
14
|
-
it("should resolve to result state on success", async () => {
|
|
15
|
-
const task = createTask(() => Promise.resolve("success"));
|
|
16
|
-
// Task doesn't auto-run anymore
|
|
17
|
-
expect(task.isRunning).toBe(false);
|
|
18
|
-
task.run();
|
|
19
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
20
|
-
expect(task.isRunning).toBe(false);
|
|
21
|
-
expect(task.result).toBe("success");
|
|
22
|
-
expect(task.error).toBeNull();
|
|
23
|
-
expect(task.params).toBeNull();
|
|
24
|
-
});
|
|
25
|
-
it("should resolve to error state on rejection", async () => {
|
|
26
|
-
const task = createTask(() => Promise.reject(new Error("failed")));
|
|
27
|
-
task.run();
|
|
28
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
29
|
-
expect(task.isRunning).toBe(false);
|
|
30
|
-
expect(task.result).toBeNull();
|
|
31
|
-
expect(task.error).toContain("failed");
|
|
32
|
-
expect(task.params).toBeNull();
|
|
33
|
-
});
|
|
34
|
-
it("should handle run() method", async () => {
|
|
35
|
-
const fetcher = vi.fn(() => Promise.resolve("data"));
|
|
36
|
-
const task = createTask(fetcher);
|
|
37
|
-
// Tasks no longer auto-run, so fetcher hasn't been called yet
|
|
38
|
-
expect(fetcher).toHaveBeenCalledTimes(0);
|
|
39
|
-
task.run();
|
|
40
|
-
expect(task.isRunning).toBe(true);
|
|
41
|
-
expect(task.result).toBeNull(); // Cleared on run
|
|
42
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
43
|
-
expect(fetcher).toHaveBeenCalledTimes(1);
|
|
44
|
-
expect(task.result).toBe("data");
|
|
45
|
-
});
|
|
46
|
-
it("should handle rerun() method", async () => {
|
|
47
|
-
const fetcher = vi
|
|
48
|
-
.fn()
|
|
49
|
-
.mockResolvedValueOnce("data1")
|
|
50
|
-
.mockResolvedValueOnce("data2");
|
|
51
|
-
const task = createTask(fetcher);
|
|
52
|
-
// First run
|
|
53
|
-
task.run();
|
|
54
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
55
|
-
expect(task.result).toBe("data1");
|
|
56
|
-
task.rerun();
|
|
57
|
-
expect(task.isRunning).toBe(true);
|
|
58
|
-
expect(task.result).toBe("data1"); // Kept during rerun
|
|
59
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
60
|
-
expect(task.result).toBe("data2");
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
describe("with parameters", () => {
|
|
64
|
-
it("should not auto-run on creation", () => {
|
|
65
|
-
const fetcher = vi.fn((page) => Promise.resolve(`page-${page}`));
|
|
66
|
-
const task = createTask(fetcher);
|
|
67
|
-
// Tasks no longer auto-run
|
|
68
|
-
expect(task.isRunning).toBe(false);
|
|
69
|
-
expect(task.result).toBeNull();
|
|
70
|
-
expect(task.error).toBeNull();
|
|
71
|
-
expect(task.params).toBeNull();
|
|
72
|
-
expect(fetcher).toHaveBeenCalledTimes(0);
|
|
73
|
-
});
|
|
74
|
-
it("should run when run() is called with params", async () => {
|
|
75
|
-
const fetcher = vi.fn((page) => Promise.resolve(`page-${page}`));
|
|
76
|
-
const task = createTask(fetcher);
|
|
77
|
-
task.run(1);
|
|
78
|
-
expect(task.isRunning).toBe(true);
|
|
79
|
-
expect(task.params).toBe(1);
|
|
80
|
-
expect(task.result).toBeNull();
|
|
81
|
-
expect(fetcher).toHaveBeenCalledWith(1);
|
|
82
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
83
|
-
expect(task.isRunning).toBe(false);
|
|
84
|
-
expect(task.result).toBe("page-1");
|
|
85
|
-
expect(task.params).toBeNull();
|
|
86
|
-
});
|
|
87
|
-
it("should handle error state with params", async () => {
|
|
88
|
-
const task = createTask((id) => Promise.reject(new Error(`failed-${id}`)));
|
|
89
|
-
task.run(42);
|
|
90
|
-
expect(task.isRunning).toBe(true);
|
|
91
|
-
expect(task.params).toBe(42);
|
|
92
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
93
|
-
expect(task.isRunning).toBe(false);
|
|
94
|
-
expect(task.result).toBeNull();
|
|
95
|
-
expect(task.error).toContain("failed-42");
|
|
96
|
-
expect(task.params).toBeNull();
|
|
97
|
-
});
|
|
98
|
-
it("should handle rerun with params", async () => {
|
|
99
|
-
const fetcher = vi
|
|
100
|
-
.fn()
|
|
101
|
-
.mockResolvedValueOnce("data1")
|
|
102
|
-
.mockResolvedValueOnce("data2");
|
|
103
|
-
const task = createTask((page) => fetcher());
|
|
104
|
-
// First run
|
|
105
|
-
task.run(1);
|
|
106
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
107
|
-
expect(task.result).toBe("data1");
|
|
108
|
-
task.rerun(1);
|
|
109
|
-
expect(task.isRunning).toBe(true);
|
|
110
|
-
expect(task.result).toBe("data1"); // Kept during rerun
|
|
111
|
-
expect(task.params).toBe(1);
|
|
112
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
113
|
-
expect(task.result).toBe("data2");
|
|
114
|
-
});
|
|
115
|
-
it("should update params when running with different values", async () => {
|
|
116
|
-
const task = createTask((page) => Promise.resolve(`page-${page}`));
|
|
117
|
-
task.run(1);
|
|
118
|
-
expect(task.params).toBe(1);
|
|
119
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
120
|
-
task.run(2);
|
|
121
|
-
expect(task.params).toBe(2);
|
|
122
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
123
|
-
expect(task.result).toBe("page-2");
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
describe("cancellation", () => {
|
|
127
|
-
it("should cancel previous request when run again", async () => {
|
|
128
|
-
let resolveFirst;
|
|
129
|
-
let resolveSecond;
|
|
130
|
-
const firstPromise = new Promise((resolve) => {
|
|
131
|
-
resolveFirst = resolve;
|
|
132
|
-
});
|
|
133
|
-
const secondPromise = new Promise((resolve) => {
|
|
134
|
-
resolveSecond = resolve;
|
|
135
|
-
});
|
|
136
|
-
const fetcher = vi
|
|
137
|
-
.fn()
|
|
138
|
-
.mockReturnValueOnce(firstPromise)
|
|
139
|
-
.mockReturnValueOnce(secondPromise);
|
|
140
|
-
const task = createTask(fetcher);
|
|
141
|
-
// First run
|
|
142
|
-
task.run();
|
|
143
|
-
expect(task.isRunning).toBe(true);
|
|
144
|
-
// Trigger second run before first completes - this cancels the first run
|
|
145
|
-
task.run();
|
|
146
|
-
expect(task.isRunning).toBe(true);
|
|
147
|
-
// Resolve first (should be ignored due to cancellation)
|
|
148
|
-
resolveFirst("first");
|
|
149
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
150
|
-
expect(task.result).toBeNull(); // First result ignored
|
|
151
|
-
// Resolve second
|
|
152
|
-
resolveSecond("second");
|
|
153
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
154
|
-
expect(task.result).toBe("second");
|
|
155
|
-
});
|
|
156
|
-
it("should cancel previous request with params", async () => {
|
|
157
|
-
let resolveFirst;
|
|
158
|
-
let resolveSecond;
|
|
159
|
-
const firstPromise = new Promise((resolve) => {
|
|
160
|
-
resolveFirst = resolve;
|
|
161
|
-
});
|
|
162
|
-
const secondPromise = new Promise((resolve) => {
|
|
163
|
-
resolveSecond = resolve;
|
|
164
|
-
});
|
|
165
|
-
const fetcher = vi
|
|
166
|
-
.fn()
|
|
167
|
-
.mockReturnValueOnce(firstPromise)
|
|
168
|
-
.mockReturnValueOnce(secondPromise);
|
|
169
|
-
const task = createTask((page) => fetcher());
|
|
170
|
-
task.run(1);
|
|
171
|
-
expect(task.params).toBe(1);
|
|
172
|
-
// Trigger second run before first completes
|
|
173
|
-
task.run(2);
|
|
174
|
-
expect(task.params).toBe(2);
|
|
175
|
-
// Resolve first (should be ignored due to cancellation)
|
|
176
|
-
resolveFirst("first");
|
|
177
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
178
|
-
expect(task.result).toBeNull(); // First result ignored
|
|
179
|
-
// Resolve second
|
|
180
|
-
resolveSecond("second");
|
|
181
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
182
|
-
expect(task.result).toBe("second");
|
|
183
|
-
});
|
|
184
|
-
it("should handle rapid successive runs", async () => {
|
|
185
|
-
let counter = 0;
|
|
186
|
-
const fetcher = vi.fn(() => Promise.resolve(`data-${++counter}`));
|
|
187
|
-
const task = createTask(fetcher);
|
|
188
|
-
// Rapid runs
|
|
189
|
-
task.run();
|
|
190
|
-
task.run();
|
|
191
|
-
task.run();
|
|
192
|
-
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
193
|
-
// Only the last run should complete
|
|
194
|
-
expect(fetcher).toHaveBeenCalledTimes(3); // 3 runs
|
|
195
|
-
expect(task.result).toBe("data-3");
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
describe("type handling", () => {
|
|
199
|
-
it("should handle numeric values", async () => {
|
|
200
|
-
const task = createTask(() => Promise.resolve(42));
|
|
201
|
-
task.run();
|
|
202
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
203
|
-
expect(task.result).toBe(42);
|
|
204
|
-
});
|
|
205
|
-
it("should handle object values", async () => {
|
|
206
|
-
const data = { id: 1, name: "Test" };
|
|
207
|
-
const task = createTask(() => Promise.resolve(data));
|
|
208
|
-
task.run();
|
|
209
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
210
|
-
expect(task.result).toEqual(data);
|
|
211
|
-
});
|
|
212
|
-
it("should handle array values", async () => {
|
|
213
|
-
const data = [1, 2, 3, 4, 5];
|
|
214
|
-
const task = createTask(() => Promise.resolve(data));
|
|
215
|
-
task.run();
|
|
216
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
217
|
-
expect(task.result).toEqual(data);
|
|
218
|
-
});
|
|
219
|
-
it("should convert error to string", async () => {
|
|
220
|
-
const task = createTask(() => Promise.reject("string error"));
|
|
221
|
-
task.run();
|
|
222
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
223
|
-
expect(typeof task.error).toBe("string");
|
|
224
|
-
expect(task.error).toBe("string error");
|
|
225
|
-
});
|
|
226
|
-
it("should handle error objects", async () => {
|
|
227
|
-
const error = new Error("Something went wrong");
|
|
228
|
-
const task = createTask(() => Promise.reject(error));
|
|
229
|
-
task.run();
|
|
230
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
231
|
-
expect(task.error).toContain("Something went wrong");
|
|
232
|
-
});
|
|
233
|
-
it("should handle different parameter types", async () => {
|
|
234
|
-
const fetcher = vi.fn((params) => Promise.resolve(params));
|
|
235
|
-
// Object params
|
|
236
|
-
const task1 = createTask(fetcher);
|
|
237
|
-
task1.run({ id: 1, name: "test" });
|
|
238
|
-
expect(task1.params).toEqual({ id: 1, name: "test" });
|
|
239
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
240
|
-
// Array params
|
|
241
|
-
const task2 = createTask(fetcher);
|
|
242
|
-
task2.run([1, 2, 3]);
|
|
243
|
-
expect(task2.params).toEqual([1, 2, 3]);
|
|
244
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
245
|
-
// String params
|
|
246
|
-
const task3 = createTask((str) => Promise.resolve(str));
|
|
247
|
-
task3.run("test");
|
|
248
|
-
expect(task3.params).toBe("test");
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
describe("edge cases", () => {
|
|
252
|
-
it("should handle immediate resolution", async () => {
|
|
253
|
-
const task = createTask(() => Promise.resolve("immediate"));
|
|
254
|
-
task.run();
|
|
255
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
256
|
-
expect(task.isRunning).toBe(false);
|
|
257
|
-
expect(task.result).toBe("immediate");
|
|
258
|
-
});
|
|
259
|
-
it("should handle immediate rejection", async () => {
|
|
260
|
-
const task = createTask(() => Promise.reject("immediate error"));
|
|
261
|
-
task.run();
|
|
262
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
263
|
-
expect(task.isRunning).toBe(false);
|
|
264
|
-
expect(task.error).toBe("immediate error");
|
|
265
|
-
});
|
|
266
|
-
it("should handle delayed resolution", async () => {
|
|
267
|
-
const task = createTask(() => new Promise((resolve) => {
|
|
268
|
-
setTimeout(() => resolve("delayed"), 10);
|
|
269
|
-
}));
|
|
270
|
-
task.run();
|
|
271
|
-
expect(task.isRunning).toBe(true);
|
|
272
|
-
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
273
|
-
expect(task.isRunning).toBe(false);
|
|
274
|
-
expect(task.result).toBe("delayed");
|
|
275
|
-
});
|
|
276
|
-
it("should clear error on successful retry", async () => {
|
|
277
|
-
const fetcher = vi
|
|
278
|
-
.fn()
|
|
279
|
-
.mockRejectedValueOnce(new Error("First error"))
|
|
280
|
-
.mockResolvedValueOnce("success");
|
|
281
|
-
const task = createTask(fetcher);
|
|
282
|
-
task.run();
|
|
283
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
284
|
-
expect(task.error).toContain("First error");
|
|
285
|
-
expect(task.result).toBeNull();
|
|
286
|
-
task.run();
|
|
287
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
288
|
-
expect(task.error).toBeNull();
|
|
289
|
-
expect(task.result).toBe("success");
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
describe("reactive getters", () => {
|
|
293
|
-
it("should expose reactive getters", async () => {
|
|
294
|
-
const task = createTask(() => Promise.resolve("data"));
|
|
295
|
-
task.run();
|
|
296
|
-
// Access getters before completion
|
|
297
|
-
const running1 = task.isRunning;
|
|
298
|
-
const result1 = task.result;
|
|
299
|
-
const error1 = task.error;
|
|
300
|
-
const params1 = task.params;
|
|
301
|
-
expect(running1).toBe(true);
|
|
302
|
-
expect(result1).toBeNull();
|
|
303
|
-
expect(error1).toBeNull();
|
|
304
|
-
expect(params1).toBeNull();
|
|
305
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
306
|
-
// Access getters after completion
|
|
307
|
-
expect(task.isRunning).toBe(false);
|
|
308
|
-
expect(task.result).toBe("data");
|
|
309
|
-
expect(task.error).toBeNull();
|
|
310
|
-
expect(task.params).toBeNull();
|
|
311
|
-
});
|
|
312
|
-
it("should track params during execution", async () => {
|
|
313
|
-
const task = createTask((id) => new Promise((resolve) => setTimeout(() => resolve(`result-${id}`), 20)));
|
|
314
|
-
task.run(123);
|
|
315
|
-
expect(task.isRunning).toBe(true);
|
|
316
|
-
expect(task.params).toBe(123);
|
|
317
|
-
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
318
|
-
expect(task.isRunning).toBe(false);
|
|
319
|
-
expect(task.params).toBeNull();
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createView.test.d.ts","sourceRoot":"","sources":["../../src/tests/createView.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error.test.d.ts","sourceRoot":"","sources":["../../src/tests/error.test.tsx"],"names":[],"mappings":""}
|
package/dist/tests/error.test.js
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "./jsx-runtime";
|
|
2
|
-
import { describe, it, expect } from "vitest";
|
|
3
|
-
import { ErrorBoundary } from "../error";
|
|
4
|
-
import { render } from "../";
|
|
5
|
-
describe("ErrorBoundary", () => {
|
|
6
|
-
it("should render children when no error occurs", async () => {
|
|
7
|
-
function SafeChild() {
|
|
8
|
-
return () => _jsx("div", { children: "Safe content" });
|
|
9
|
-
}
|
|
10
|
-
function TestComponent() {
|
|
11
|
-
return () => (_jsx(ErrorBoundary, { error: (error) => _jsxs("div", { children: ["Error: ", String(error)] }), children: _jsx(SafeChild, {}) }));
|
|
12
|
-
}
|
|
13
|
-
const container = document.createElement("div");
|
|
14
|
-
document.body.appendChild(container);
|
|
15
|
-
render(_jsx(TestComponent, {}), container);
|
|
16
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
17
|
-
expect(container.textContent).toContain("Safe content");
|
|
18
|
-
expect(container.textContent).not.toContain("Error:");
|
|
19
|
-
document.body.removeChild(container);
|
|
20
|
-
});
|
|
21
|
-
it("should catch errors thrown in child components", async () => {
|
|
22
|
-
function ThrowingChild() {
|
|
23
|
-
return () => {
|
|
24
|
-
throw new Error("Child component error");
|
|
25
|
-
return _jsx("div", {});
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function TestComponent() {
|
|
29
|
-
return () => (_jsx(ErrorBoundary, { error: (error) => _jsxs("div", { children: ["Error: ", String(error)] }), children: _jsx(ThrowingChild, {}) }));
|
|
30
|
-
}
|
|
31
|
-
const container = document.createElement("div");
|
|
32
|
-
document.body.appendChild(container);
|
|
33
|
-
render(_jsx(TestComponent, {}), container);
|
|
34
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
35
|
-
expect(container.textContent).toContain("Error:");
|
|
36
|
-
expect(container.textContent).toContain("Child component error");
|
|
37
|
-
document.body.removeChild(container);
|
|
38
|
-
});
|
|
39
|
-
it("should render custom error UI", async () => {
|
|
40
|
-
function ThrowingChild() {
|
|
41
|
-
return () => {
|
|
42
|
-
throw new Error("Something went wrong");
|
|
43
|
-
return _jsx("div", {});
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function TestComponent() {
|
|
47
|
-
return () => (_jsx(ErrorBoundary, { error: (error) => (_jsxs("div", { class: "error-ui", children: [_jsx("h1", { children: "Oops!" }), _jsx("p", { children: String(error) })] })), children: _jsx(ThrowingChild, {}) }));
|
|
48
|
-
}
|
|
49
|
-
const container = document.createElement("div");
|
|
50
|
-
document.body.appendChild(container);
|
|
51
|
-
render(_jsx(TestComponent, {}), container);
|
|
52
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
53
|
-
const errorUI = document.querySelector(".error-ui");
|
|
54
|
-
expect(errorUI).not.toBeNull();
|
|
55
|
-
expect(errorUI?.querySelector("h1")?.textContent).toBe("Oops!");
|
|
56
|
-
expect(errorUI?.textContent).toContain("Something went wrong");
|
|
57
|
-
document.body.removeChild(container);
|
|
58
|
-
});
|
|
59
|
-
it("should handle multiple children", async () => {
|
|
60
|
-
function SafeChild1() {
|
|
61
|
-
return () => _jsx("div", { children: "Child 1" });
|
|
62
|
-
}
|
|
63
|
-
function SafeChild2() {
|
|
64
|
-
return () => _jsx("div", { children: "Child 2" });
|
|
65
|
-
}
|
|
66
|
-
function TestComponent() {
|
|
67
|
-
return () => (_jsxs(ErrorBoundary, { error: (error) => _jsxs("div", { children: ["Error: ", String(error)] }), children: [_jsx(SafeChild1, {}), _jsx(SafeChild2, {})] }));
|
|
68
|
-
}
|
|
69
|
-
const container = document.createElement("div");
|
|
70
|
-
document.body.appendChild(container);
|
|
71
|
-
render(_jsx(TestComponent, {}), container);
|
|
72
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
73
|
-
expect(container.textContent).toContain("Child 1");
|
|
74
|
-
expect(container.textContent).toContain("Child 2");
|
|
75
|
-
document.body.removeChild(container);
|
|
76
|
-
});
|
|
77
|
-
it("should catch errors from nested children", async () => {
|
|
78
|
-
function DeepChild() {
|
|
79
|
-
return () => {
|
|
80
|
-
throw new Error("Deep error");
|
|
81
|
-
return _jsx("div", {});
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
function MiddleChild() {
|
|
85
|
-
return () => _jsx(DeepChild, {});
|
|
86
|
-
}
|
|
87
|
-
function TestComponent() {
|
|
88
|
-
return () => (_jsx(ErrorBoundary, { error: (error) => _jsxs("div", { children: ["Caught: ", String(error)] }), children: _jsx(MiddleChild, {}) }));
|
|
89
|
-
}
|
|
90
|
-
const container = document.createElement("div");
|
|
91
|
-
document.body.appendChild(container);
|
|
92
|
-
render(_jsx(TestComponent, {}), container);
|
|
93
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
94
|
-
expect(container.textContent).toContain("Caught:");
|
|
95
|
-
expect(container.textContent).toContain("Deep error");
|
|
96
|
-
document.body.removeChild(container);
|
|
97
|
-
});
|
|
98
|
-
it("should allow nested error boundaries", async () => {
|
|
99
|
-
function ThrowingChild() {
|
|
100
|
-
return () => {
|
|
101
|
-
throw new Error("Inner error");
|
|
102
|
-
return _jsx("div", {});
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
function TestComponent() {
|
|
106
|
-
return () => (_jsx(ErrorBoundary, { error: (error) => _jsxs("div", { children: ["Outer: ", String(error)] }), children: _jsx(ErrorBoundary, { error: (error) => _jsxs("div", { children: ["Inner: ", String(error)] }), children: _jsx(ThrowingChild, {}) }) }));
|
|
107
|
-
}
|
|
108
|
-
const container = document.createElement("div");
|
|
109
|
-
document.body.appendChild(container);
|
|
110
|
-
render(_jsx(TestComponent, {}), container);
|
|
111
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
112
|
-
// Inner boundary should catch the error
|
|
113
|
-
expect(container.textContent).toContain("Inner:");
|
|
114
|
-
expect(container.textContent).not.toContain("Outer:");
|
|
115
|
-
document.body.removeChild(container);
|
|
116
|
-
});
|
|
117
|
-
it("should handle string errors", async () => {
|
|
118
|
-
function ThrowingChild() {
|
|
119
|
-
return () => {
|
|
120
|
-
throw "String error";
|
|
121
|
-
return _jsx("div", {});
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
function TestComponent() {
|
|
125
|
-
return () => (_jsx(ErrorBoundary, { error: (error) => _jsxs("div", { children: ["Error: ", String(error)] }), children: _jsx(ThrowingChild, {}) }));
|
|
126
|
-
}
|
|
127
|
-
const container = document.createElement("div");
|
|
128
|
-
document.body.appendChild(container);
|
|
129
|
-
render(_jsx(TestComponent, {}), container);
|
|
130
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
131
|
-
expect(container.textContent).toContain("String error");
|
|
132
|
-
document.body.removeChild(container);
|
|
133
|
-
});
|
|
134
|
-
it("should handle object errors", async () => {
|
|
135
|
-
function ThrowingChild() {
|
|
136
|
-
return () => {
|
|
137
|
-
throw { message: "Custom error object", code: 500 };
|
|
138
|
-
return _jsx("div", {});
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
function TestComponent() {
|
|
142
|
-
return () => (_jsx(ErrorBoundary, { error: (error) => (_jsxs("div", { children: ["Error: ", error.message, " (Code: ", error.code, ")"] })), children: _jsx(ThrowingChild, {}) }));
|
|
143
|
-
}
|
|
144
|
-
const container = document.createElement("div");
|
|
145
|
-
document.body.appendChild(container);
|
|
146
|
-
render(_jsx(TestComponent, {}), container);
|
|
147
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
148
|
-
expect(container.textContent).toContain("Custom error object");
|
|
149
|
-
expect(container.textContent).toContain("500");
|
|
150
|
-
document.body.removeChild(container);
|
|
151
|
-
});
|
|
152
|
-
it("should switch back to children if error is cleared", async () => {
|
|
153
|
-
// Note: This test demonstrates the current behavior
|
|
154
|
-
// In practice, error clearing would require additional implementation
|
|
155
|
-
function SafeChild() {
|
|
156
|
-
return () => _jsx("div", { children: "Safe content" });
|
|
157
|
-
}
|
|
158
|
-
function TestComponent() {
|
|
159
|
-
return () => (_jsx(ErrorBoundary, { error: (error) => _jsxs("div", { children: ["Error: ", String(error)] }), children: _jsx(SafeChild, {}) }));
|
|
160
|
-
}
|
|
161
|
-
const container = document.createElement("div");
|
|
162
|
-
document.body.appendChild(container);
|
|
163
|
-
render(_jsx(TestComponent, {}), container);
|
|
164
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
165
|
-
expect(container.textContent).toContain("Safe content");
|
|
166
|
-
document.body.removeChild(container);
|
|
167
|
-
});
|
|
168
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"observation.test.d.ts","sourceRoot":"","sources":["../../src/tests/observation.test.ts"],"names":[],"mappings":""}
|