tauri-kargo-tools 0.3.1 → 0.3.3
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 +1 -1
- package/src/test.ts +45 -1
- package/src/types.ts +36 -32
package/package.json
CHANGED
package/src/test.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// }
|
|
13
13
|
// });
|
|
14
14
|
|
|
15
|
-
import { Assert, Log, Terminate } from "./types";
|
|
15
|
+
import { Assert, Log, Terminate, UpdateSnapshot } from "./types";
|
|
16
16
|
|
|
17
17
|
type StepFn = () => void | Promise<void>;
|
|
18
18
|
type TestFn = (t: { step: (name: string, fn: StepFn) => Promise<void> }) => void | Promise<void>;
|
|
@@ -349,3 +349,47 @@ export function log(...args: (string | number)[]) {
|
|
|
349
349
|
|
|
350
350
|
}
|
|
351
351
|
|
|
352
|
+
|
|
353
|
+
export async function assertEqualsSnapshot(actual: unknown, name: string, msg?: string) {
|
|
354
|
+
let postMessage = true
|
|
355
|
+
try {
|
|
356
|
+
const response = await fetch(`/test/snapshot/${name}.json`)
|
|
357
|
+
if (response.status === 404) {
|
|
358
|
+
const updateSnapshot: UpdateSnapshot = { type: "snapshot", value: actual }
|
|
359
|
+
if (self) {
|
|
360
|
+
self.postMessage(updateSnapshot)
|
|
361
|
+
return
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (response.ok) {
|
|
365
|
+
const value = await response.json()
|
|
366
|
+
if (deepEqual(actual, value)) {
|
|
367
|
+
const a: Assert = { type: "assert", message: msg ?? "", value: true }
|
|
368
|
+
if (self) {
|
|
369
|
+
self.postMessage(a)
|
|
370
|
+
}
|
|
371
|
+
return;
|
|
372
|
+
};
|
|
373
|
+
const aStr = safeStringify(actual);
|
|
374
|
+
|
|
375
|
+
const defaultMsg = `assertEquals failed:\nExpected:\nvalue of ${name}\nActual:\n${aStr}`;
|
|
376
|
+
const a: Assert = { type: "assert", message: msg ? `${msg}\n${defaultMsg}` : defaultMsg, value: false }
|
|
377
|
+
if (self) {
|
|
378
|
+
self.postMessage(a)
|
|
379
|
+
}
|
|
380
|
+
postMessage = false
|
|
381
|
+
}
|
|
382
|
+
} catch (e) {
|
|
383
|
+
|
|
384
|
+
}
|
|
385
|
+
if (postMessage) {
|
|
386
|
+
const a: Assert = { type: "assert", message: msg ? `${msg} error ` : "error ", value: false }
|
|
387
|
+
if (self) {
|
|
388
|
+
self.postMessage(a)
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
throw new Error()
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
}
|
|
395
|
+
|
package/src/types.ts
CHANGED
|
@@ -111,7 +111,7 @@ export type TypeScriptTranspileSuccess = { ok: true; src: string };
|
|
|
111
111
|
export type TypeScriptTranspileError = { ok: false; message: string };
|
|
112
112
|
|
|
113
113
|
export type TypeScriptTranspileResponse = TypeScriptTranspileSuccess | TypeScriptTranspileError;
|
|
114
|
-
|
|
114
|
+
|
|
115
115
|
export interface ExplorerReq {
|
|
116
116
|
path?: string;
|
|
117
117
|
}
|
|
@@ -153,7 +153,7 @@ export type ExplorerFileResponse = {
|
|
|
153
153
|
};
|
|
154
154
|
|
|
155
155
|
export type ExplorerArrayFileItem = {
|
|
156
|
-
type:'file'
|
|
156
|
+
type: 'file'
|
|
157
157
|
name: string;
|
|
158
158
|
/** chemin absolu du fichier */
|
|
159
159
|
path: string;
|
|
@@ -161,33 +161,33 @@ export type ExplorerArrayFileItem = {
|
|
|
161
161
|
|
|
162
162
|
export type ExplorerTreeItem =
|
|
163
163
|
| {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
164
|
+
type: "file";
|
|
165
|
+
name: string;
|
|
166
|
+
path: string; // absolu
|
|
167
|
+
}
|
|
168
168
|
| {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
169
|
+
type: "directory";
|
|
170
|
+
name: string;
|
|
171
|
+
path: string; // absolu
|
|
172
|
+
/** peut être absent si maxDeep empêche d'expand */
|
|
173
|
+
content?: ExplorerTreeItem[];
|
|
174
|
+
};
|
|
175
175
|
|
|
176
176
|
export type ExplorerDirectoryResponse =
|
|
177
177
|
| {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
178
|
+
type: "directory";
|
|
179
|
+
path: string; // absolu
|
|
180
|
+
parent: string | null;
|
|
181
|
+
/** si request.type === "array" */
|
|
182
|
+
content: ExplorerArrayFileItem[];
|
|
183
|
+
}
|
|
184
184
|
| {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
185
|
+
type: "directory";
|
|
186
|
+
path: string; // absolu
|
|
187
|
+
parent: string | null;
|
|
188
|
+
/** si request.type === "tree" (ou mode absent côté compat) */
|
|
189
|
+
content: ExplorerTreeItem[];
|
|
190
|
+
};
|
|
191
191
|
|
|
192
192
|
export type ExplorerResponse =
|
|
193
193
|
| ExplorerErrorResponse
|
|
@@ -264,15 +264,19 @@ export interface ApiTypescriptAstRequest {
|
|
|
264
264
|
path: string;
|
|
265
265
|
}
|
|
266
266
|
export interface Assert {
|
|
267
|
-
type:'assert'
|
|
268
|
-
value:boolean
|
|
269
|
-
message:string
|
|
270
|
-
|
|
267
|
+
type: 'assert'
|
|
268
|
+
value: boolean
|
|
269
|
+
message: string
|
|
270
|
+
}
|
|
271
271
|
export interface Log {
|
|
272
|
-
type:'log'
|
|
273
|
-
message:(string|number)[]|string|number
|
|
272
|
+
type: 'log'
|
|
273
|
+
message: (string | number)[] | string | number
|
|
274
274
|
}
|
|
275
275
|
export interface Terminate {
|
|
276
|
-
type:'terminate'
|
|
276
|
+
type: 'terminate'
|
|
277
277
|
}
|
|
278
|
-
export type TestEvent = Assert|Log|Terminate
|
|
278
|
+
export type TestEvent = Assert | Log | Terminate
|
|
279
|
+
export type UpdateSnapshot = {
|
|
280
|
+
type: "snapshot",
|
|
281
|
+
value: any
|
|
282
|
+
}
|