tauri-kargo-tools 0.2.9 → 0.3.1
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 +29 -2
- package/src/types.ts +14 -1
package/package.json
CHANGED
package/src/test.ts
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
// }
|
|
13
13
|
// });
|
|
14
14
|
|
|
15
|
+
import { Assert, Log, Terminate } from "./types";
|
|
16
|
+
|
|
15
17
|
type StepFn = () => void | Promise<void>;
|
|
16
18
|
type TestFn = (t: { step: (name: string, fn: StepFn) => Promise<void> }) => void | Promise<void>;
|
|
17
19
|
|
|
@@ -184,7 +186,7 @@ export function deepEqual(a: unknown, b: unknown, seen = new Map<any, any>()): b
|
|
|
184
186
|
// RegExp
|
|
185
187
|
if (a instanceof RegExp || b instanceof RegExp) {
|
|
186
188
|
return a instanceof RegExp && b instanceof RegExp &&
|
|
187
|
-
|
|
189
|
+
a.source === b.source && a.flags === b.flags;
|
|
188
190
|
}
|
|
189
191
|
|
|
190
192
|
// Typed arrays
|
|
@@ -315,10 +317,35 @@ function safeStringify(v: unknown, maxDepth = 10): string {
|
|
|
315
317
|
|
|
316
318
|
// ————— Public assert —————
|
|
317
319
|
export function assertEquals(actual: unknown, expected: unknown, msg?: string): void {
|
|
318
|
-
if (deepEqual(actual, expected))
|
|
320
|
+
if (deepEqual(actual, expected)) {
|
|
321
|
+
const a: Assert = { type: "assert", message: msg ?? "", value: true }
|
|
322
|
+
if (self) {
|
|
323
|
+
self.postMessage(a)
|
|
324
|
+
}
|
|
325
|
+
return;
|
|
326
|
+
};
|
|
319
327
|
const aStr = safeStringify(actual);
|
|
320
328
|
const eStr = safeStringify(expected);
|
|
321
329
|
const defaultMsg = `assertEquals failed:\nExpected:\n${eStr}\nActual:\n${aStr}`;
|
|
330
|
+
const a: Assert = { type: "assert", message: msg ? `${msg}\n${defaultMsg}` : defaultMsg, value: false }
|
|
331
|
+
if (self) {
|
|
332
|
+
self.postMessage(a)
|
|
333
|
+
}
|
|
322
334
|
throw new Error(msg ? `${msg}\n${defaultMsg}` : defaultMsg);
|
|
323
335
|
}
|
|
336
|
+
export function terminate() {
|
|
337
|
+
if (self) {
|
|
338
|
+
const t: Terminate = { type: "terminate" }
|
|
339
|
+
self.postMessage(t)
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
export function log(...args: (string | number)[]) {
|
|
343
|
+
console.log(...args)
|
|
344
|
+
if (self) {
|
|
345
|
+
const log: Log = { type: "log", message: args.length == 1 ? args[0] : args }
|
|
346
|
+
self.postMessage(log)
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
}
|
|
324
351
|
|
package/src/types.ts
CHANGED
|
@@ -262,4 +262,17 @@ export type TypescriptAstResp = TypescriptAstOk | TypescriptAstKo;
|
|
|
262
262
|
export interface ApiTypescriptAstRequest {
|
|
263
263
|
/** Chemin relatif à `state.root` (ex: "src/main.ts") */
|
|
264
264
|
path: string;
|
|
265
|
-
}
|
|
265
|
+
}
|
|
266
|
+
export interface Assert {
|
|
267
|
+
type:'assert'
|
|
268
|
+
value:boolean
|
|
269
|
+
message:string
|
|
270
|
+
}
|
|
271
|
+
export interface Log {
|
|
272
|
+
type:'log'
|
|
273
|
+
message:(string|number)[]|string|number
|
|
274
|
+
}
|
|
275
|
+
export interface Terminate {
|
|
276
|
+
type:'terminate'
|
|
277
|
+
}
|
|
278
|
+
export type TestEvent = Assert|Log|Terminate
|