tauri-kargo-tools 0.3.0 → 0.3.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 +1 -1
- package/src/test.ts +46 -2
- package/src/types.ts +2 -1
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>;
|
|
@@ -339,7 +339,7 @@ export function terminate() {
|
|
|
339
339
|
self.postMessage(t)
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
|
-
function log(...args: (string | number)[]) {
|
|
342
|
+
export function log(...args: (string | number)[]) {
|
|
343
343
|
console.log(...args)
|
|
344
344
|
if (self) {
|
|
345
345
|
const log: Log = { type: "log", message: args.length == 1 ? args[0] : args }
|
|
@@ -349,3 +349,47 @@ 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