@executablemd/testing 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/LICENSE +21 -0
- package/esm/core/mod.js +55 -0
- package/esm/core/src/api.js +31 -0
- package/esm/core/src/collect.js +24 -0
- package/esm/core/src/component-api.js +47 -0
- package/esm/core/src/content-context.js +23 -0
- package/esm/core/src/deno-compiler.js +51 -0
- package/esm/core/src/errors.js +13 -0
- package/esm/core/src/eval-context.js +13 -0
- package/esm/core/src/eval-handler.js +79 -0
- package/esm/core/src/eval-interpolate.js +63 -0
- package/esm/core/src/eval-transform.js +378 -0
- package/esm/core/src/execute.js +378 -0
- package/esm/core/src/expand.js +988 -0
- package/esm/core/src/frontmatter.js +98 -0
- package/esm/core/src/heal.js +29 -0
- package/esm/core/src/interpolate.js +39 -0
- package/esm/core/src/modifiers/daemon.js +60 -0
- package/esm/core/src/modifiers/persist.js +35 -0
- package/esm/core/src/modifiers/timeout.js +55 -0
- package/esm/core/src/modifiers.js +113 -0
- package/esm/core/src/output/normalize.js +33 -0
- package/esm/core/src/output/terminal.js +20 -0
- package/esm/core/src/render.js +30 -0
- package/esm/core/src/replay-stream.js +58 -0
- package/esm/core/src/sample-api.js +45 -0
- package/esm/core/src/scanner.js +632 -0
- package/esm/core/src/temp-file-compiler.js +68 -0
- package/esm/core/src/types.js +7 -0
- package/esm/core/src/validate.js +82 -0
- package/esm/durable-streams/combinators.js +227 -0
- package/esm/durable-streams/context.js +13 -0
- package/esm/durable-streams/divergence.js +56 -0
- package/esm/durable-streams/each.js +193 -0
- package/esm/durable-streams/effect.js +273 -0
- package/esm/durable-streams/ephemeral.js +80 -0
- package/esm/durable-streams/errors.js +92 -0
- package/esm/durable-streams/http-stream.js +207 -0
- package/esm/durable-streams/mod.js +34 -0
- package/esm/durable-streams/operations.js +88 -0
- package/esm/durable-streams/replay-guard.js +87 -0
- package/esm/durable-streams/replay-index.js +132 -0
- package/esm/durable-streams/run.js +137 -0
- package/esm/durable-streams/serialize.js +65 -0
- package/esm/durable-streams/stream.js +56 -0
- package/esm/durable-streams/types.js +10 -0
- package/esm/package.json +3 -0
- package/esm/runtime/apis.js +237 -0
- package/esm/runtime/find-free-port.js +33 -0
- package/esm/runtime/mod.js +20 -0
- package/esm/testing/npm/src/_dnt.polyfills.js +1 -0
- package/esm/testing/npm/src/_dnt.shims.js +57 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/almost_equals.js +47 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/array_includes.js +65 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/assert.js +23 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/assertion_error.js +30 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/equal.js +194 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/equals.js +61 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/exists.js +27 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/fail.js +20 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/false.js +23 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/greater.js +29 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.js +29 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/instance_of.js +52 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/is_error.js +53 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/less.js +28 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/less_or_equal.js +29 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/match.js +26 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/mod.js +45 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/not_equals.js +39 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/not_instance_of.js +29 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/not_match.js +26 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.js +32 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/object_match.js +177 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/rejects.js +53 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/strict_equals.js +58 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/string_includes.js +26 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/throws.js +44 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/unimplemented.js +20 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/unreachable.js +20 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/internal/1.0.14/build_message.js +116 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/internal/1.0.14/diff.js +277 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/internal/1.0.14/diff_str.js +181 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/internal/1.0.14/format.js +70 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/internal/1.0.14/styles.js +207 -0
- package/esm/testing/npm/src/deps/jsr.io/@std/internal/1.0.14/types.js +3 -0
- package/esm/testing/npm/src/mod.js +27 -0
- package/esm/testing/npm/src/src/assertions.js +250 -0
- package/esm/testing/npm/src/src/handlers.js +245 -0
- package/esm/testing/npm/src/src/journal.js +152 -0
- package/esm/testing/npm/src/src/test-api.js +33 -0
- package/esm/testing/npm/src/src/use-testing.js +79 -0
- package/esm/testing/npm/src/src/vocabulary.js +111 -0
- package/package.json +35 -0
- package/types/_dnt.polyfills.d.ts +6 -0
- package/types/_dnt.shims.d.ts +1 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/almost_equals.d.ts +29 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/array_includes.d.ts +28 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/assert.d.ts +16 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/assertion_error.d.ts +25 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/equal.d.ts +24 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/equals.d.ts +36 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/exists.d.ts +17 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/fail.d.ts +14 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/false.d.ts +18 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/greater.d.ts +19 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.d.ts +19 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/instance_of.d.ts +22 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/is_error.d.ts +24 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/less.d.ts +18 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/less_or_equal.d.ts +19 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/match.d.ts +17 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/mod.d.ts +43 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/not_equals.d.ts +26 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/not_instance_of.d.ts +19 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/not_match.d.ts +17 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.d.ts +22 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/object_match.d.ts +28 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/rejects.d.ts +41 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/strict_equals.d.ts +23 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/string_includes.d.ts +17 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/throws.d.ts +44 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/unimplemented.d.ts +14 -0
- package/types/deps/jsr.io/@std/assert/1.0.19/unreachable.d.ts +14 -0
- package/types/deps/jsr.io/@std/internal/1.0.14/build_message.d.ts +79 -0
- package/types/deps/jsr.io/@std/internal/1.0.14/diff.d.ts +139 -0
- package/types/deps/jsr.io/@std/internal/1.0.14/diff_str.d.ts +98 -0
- package/types/deps/jsr.io/@std/internal/1.0.14/format.d.ts +28 -0
- package/types/deps/jsr.io/@std/internal/1.0.14/styles.d.ts +158 -0
- package/types/deps/jsr.io/@std/internal/1.0.14/types.d.ts +24 -0
- package/types/mod.d.ts +29 -0
- package/types/src/assertions.d.ts +55 -0
- package/types/src/handlers.d.ts +18 -0
- package/types/src/journal.d.ts +29 -0
- package/types/src/test-api.d.ts +54 -0
- package/types/src/use-testing.d.ts +25 -0
- package/types/src/vocabulary.d.ts +34 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use this to stub out methods that will throw when invoked.
|
|
3
|
+
*
|
|
4
|
+
* @example Usage
|
|
5
|
+
* ```ts ignore
|
|
6
|
+
* import { unimplemented } from "@std/assert";
|
|
7
|
+
*
|
|
8
|
+
* unimplemented(); // Throws
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @param msg Optional message to include in the error.
|
|
12
|
+
* @returns Never returns, always throws.
|
|
13
|
+
*/
|
|
14
|
+
export declare function unimplemented(msg?: string): never;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use this to assert unreachable code.
|
|
3
|
+
*
|
|
4
|
+
* @example Usage
|
|
5
|
+
* ```ts ignore
|
|
6
|
+
* import { unreachable } from "@std/assert";
|
|
7
|
+
*
|
|
8
|
+
* unreachable(); // Throws
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @param msg Optional message to include in the error.
|
|
12
|
+
* @returns Never returns, always throws.
|
|
13
|
+
*/
|
|
14
|
+
export declare function unreachable(msg?: string): never;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { DiffResult, DiffType } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Colors the output of assertion diffs.
|
|
4
|
+
*
|
|
5
|
+
* @param diffType Difference type, either added or removed.
|
|
6
|
+
* @param background If true, colors the background instead of the text.
|
|
7
|
+
*
|
|
8
|
+
* @returns A function that colors the input string.
|
|
9
|
+
*
|
|
10
|
+
* @example Usage
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { createColor } from "@std/internal";
|
|
13
|
+
* import { assertEquals } from "@std/assert";
|
|
14
|
+
* import { bold, green, red, white } from "@std/fmt/colors";
|
|
15
|
+
*
|
|
16
|
+
* assertEquals(createColor("added")("foo"), green(bold("foo")));
|
|
17
|
+
* assertEquals(createColor("removed")("foo"), red(bold("foo")));
|
|
18
|
+
* assertEquals(createColor("common")("foo"), white("foo"));
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function createColor(diffType: DiffType,
|
|
22
|
+
/**
|
|
23
|
+
* TODO(@littledivy): Remove this when we can detect true color terminals. See
|
|
24
|
+
* https://github.com/denoland/std/issues/2575.
|
|
25
|
+
*/
|
|
26
|
+
background?: boolean): (s: string) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Prefixes `+` or `-` in diff output.
|
|
29
|
+
*
|
|
30
|
+
* @param diffType Difference type, either added or removed
|
|
31
|
+
*
|
|
32
|
+
* @returns A string representing the sign.
|
|
33
|
+
*
|
|
34
|
+
* @example Usage
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { createSign } from "@std/internal";
|
|
37
|
+
* import { assertEquals } from "@std/assert";
|
|
38
|
+
*
|
|
39
|
+
* assertEquals(createSign("added"), "+ ");
|
|
40
|
+
* assertEquals(createSign("removed"), "- ");
|
|
41
|
+
* assertEquals(createSign("common"), " ");
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function createSign(diffType: DiffType): string;
|
|
45
|
+
/** Options for {@linkcode buildMessage}. */
|
|
46
|
+
export interface BuildMessageOptions {
|
|
47
|
+
/**
|
|
48
|
+
* Whether to output the diff as a single string.
|
|
49
|
+
* @default {false}
|
|
50
|
+
*/
|
|
51
|
+
stringDiff?: boolean;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Builds a message based on the provided diff result.
|
|
55
|
+
*
|
|
56
|
+
* @param diffResult The diff result array.
|
|
57
|
+
* @param options Optional parameters for customizing the message.
|
|
58
|
+
* @param truncateDiff Function to truncate the diff (default is no truncation).
|
|
59
|
+
*
|
|
60
|
+
* @returns An array of strings representing the built message.
|
|
61
|
+
*
|
|
62
|
+
* @example Usage
|
|
63
|
+
* ```ts no-assert
|
|
64
|
+
* import { diffStr, buildMessage } from "@std/internal";
|
|
65
|
+
*
|
|
66
|
+
* diffStr("Hello, world!", "Hello, world");
|
|
67
|
+
* // [
|
|
68
|
+
* // "",
|
|
69
|
+
* // "",
|
|
70
|
+
* // " [Diff] Actual / Expected",
|
|
71
|
+
* // "",
|
|
72
|
+
* // "",
|
|
73
|
+
* // "- Hello, world!",
|
|
74
|
+
* // "+ Hello, world",
|
|
75
|
+
* // "",
|
|
76
|
+
* // ]
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function buildMessage(diffResult: ReadonlyArray<DiffResult<string>>, options?: BuildMessageOptions, truncateDiff?: (diffResult: ReadonlyArray<DiffResult<string>>, stringDiff: boolean, contextLength?: number | null) => ReadonlyArray<DiffResult<string>>): string[];
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { DiffResult, DiffType } from "./types.js";
|
|
2
|
+
/** Represents the farthest point in the diff algorithm. */
|
|
3
|
+
export interface FarthestPoint {
|
|
4
|
+
/** The y-coordinate of the point. */
|
|
5
|
+
y: number;
|
|
6
|
+
/** The id of the point. */
|
|
7
|
+
id: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates an array of common elements between two arrays.
|
|
11
|
+
*
|
|
12
|
+
* @typeParam T The type of elements in the arrays.
|
|
13
|
+
*
|
|
14
|
+
* @param A The first array.
|
|
15
|
+
* @param B The second array.
|
|
16
|
+
*
|
|
17
|
+
* @returns An array containing the common elements between the two arrays.
|
|
18
|
+
*
|
|
19
|
+
* @example Usage
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { createCommon } from "@std/internal/diff";
|
|
22
|
+
* import { assertEquals } from "@std/assert";
|
|
23
|
+
*
|
|
24
|
+
* const a = [1, 2, 3];
|
|
25
|
+
* const b = [1, 2, 4];
|
|
26
|
+
*
|
|
27
|
+
* assertEquals(createCommon(a, b), [1, 2]);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function createCommon<T>(A: T[], B: T[]): T[];
|
|
31
|
+
/**
|
|
32
|
+
* Asserts that the value is a {@linkcode FarthestPoint}.
|
|
33
|
+
* If not, an error is thrown.
|
|
34
|
+
*
|
|
35
|
+
* @param value The value to check.
|
|
36
|
+
*
|
|
37
|
+
* @returns A void value that returns once the assertion completes.
|
|
38
|
+
*
|
|
39
|
+
* @example Usage
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { assertFp } from "@std/internal/diff";
|
|
42
|
+
* import { assertThrows } from "@std/assert";
|
|
43
|
+
*
|
|
44
|
+
* assertFp({ y: 0, id: 0 });
|
|
45
|
+
* assertThrows(() => assertFp({ id: 0 }));
|
|
46
|
+
* assertThrows(() => assertFp({ y: 0 }));
|
|
47
|
+
* assertThrows(() => assertFp(undefined));
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function assertFp(value: unknown): asserts value is FarthestPoint;
|
|
51
|
+
/**
|
|
52
|
+
* Creates an array of backtraced differences.
|
|
53
|
+
*
|
|
54
|
+
* @typeParam T The type of elements in the arrays.
|
|
55
|
+
*
|
|
56
|
+
* @param A The first array.
|
|
57
|
+
* @param B The second array.
|
|
58
|
+
* @param current The current {@linkcode FarthestPoint}.
|
|
59
|
+
* @param swapped Boolean indicating if the arrays are swapped.
|
|
60
|
+
* @param routes The routes array.
|
|
61
|
+
* @param diffTypesPtrOffset The offset of the diff types in the routes array.
|
|
62
|
+
*
|
|
63
|
+
* @returns An array of backtraced differences.
|
|
64
|
+
*
|
|
65
|
+
* @example Usage
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { backTrace } from "@std/internal/diff";
|
|
68
|
+
* import { assertEquals } from "@std/assert";
|
|
69
|
+
*
|
|
70
|
+
* assertEquals(
|
|
71
|
+
* backTrace([], [], { y: 0, id: 0 }, false, new Uint32Array(0), 0),
|
|
72
|
+
* [],
|
|
73
|
+
* );
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function backTrace<T>(A: T[], B: T[], current: FarthestPoint, swapped: boolean, routes: Uint32Array, diffTypesPtrOffset: number): Array<{
|
|
77
|
+
type: DiffType;
|
|
78
|
+
value: T;
|
|
79
|
+
}>;
|
|
80
|
+
/**
|
|
81
|
+
* Creates a {@linkcode FarthestPoint}.
|
|
82
|
+
*
|
|
83
|
+
* @param k The current index.
|
|
84
|
+
* @param M The length of the first array.
|
|
85
|
+
* @param routes The routes array.
|
|
86
|
+
* @param diffTypesPtrOffset The offset of the diff types in the routes array.
|
|
87
|
+
* @param ptr The current pointer.
|
|
88
|
+
* @param slide The slide {@linkcode FarthestPoint}.
|
|
89
|
+
* @param down The down {@linkcode FarthestPoint}.
|
|
90
|
+
*
|
|
91
|
+
* @returns A {@linkcode FarthestPoint}.
|
|
92
|
+
*
|
|
93
|
+
* @example Usage
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { createFp } from "@std/internal/diff";
|
|
96
|
+
* import { assertEquals } from "@std/assert";
|
|
97
|
+
*
|
|
98
|
+
* assertEquals(
|
|
99
|
+
* createFp(
|
|
100
|
+
* 0,
|
|
101
|
+
* 0,
|
|
102
|
+
* new Uint32Array(0),
|
|
103
|
+
* 0,
|
|
104
|
+
* 0,
|
|
105
|
+
* { y: -1, id: 0 },
|
|
106
|
+
* { y: 0, id: 0 },
|
|
107
|
+
* ),
|
|
108
|
+
* { y: -1, id: 1 },
|
|
109
|
+
* );
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare function createFp(k: number, M: number, routes: Uint32Array, diffTypesPtrOffset: number, ptr: number, slide?: FarthestPoint, down?: FarthestPoint): FarthestPoint;
|
|
113
|
+
/**
|
|
114
|
+
* Renders the differences between the actual and expected values.
|
|
115
|
+
*
|
|
116
|
+
* @typeParam T The type of elements in the arrays.
|
|
117
|
+
*
|
|
118
|
+
* @param A Actual value
|
|
119
|
+
* @param B Expected value
|
|
120
|
+
*
|
|
121
|
+
* @returns An array of differences between the actual and expected values.
|
|
122
|
+
*
|
|
123
|
+
* @example Usage
|
|
124
|
+
* ```ts
|
|
125
|
+
* import { diff } from "@std/internal/diff";
|
|
126
|
+
* import { assertEquals } from "@std/assert";
|
|
127
|
+
*
|
|
128
|
+
* const a = [1, 2, 3];
|
|
129
|
+
* const b = [1, 2, 4];
|
|
130
|
+
*
|
|
131
|
+
* assertEquals(diff(a, b), [
|
|
132
|
+
* { type: "common", value: 1 },
|
|
133
|
+
* { type: "common", value: 2 },
|
|
134
|
+
* { type: "removed", value: 3 },
|
|
135
|
+
* { type: "added", value: 4 },
|
|
136
|
+
* ]);
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export declare function diff<T>(A: T[], B: T[]): DiffResult<T>[];
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { DiffResult } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Unescape invisible characters.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#escape_sequences}
|
|
6
|
+
*
|
|
7
|
+
* @param string String to unescape.
|
|
8
|
+
*
|
|
9
|
+
* @returns Unescaped string.
|
|
10
|
+
*
|
|
11
|
+
* @example Usage
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { unescape } from "@std/internal/diff-str";
|
|
14
|
+
* import { assertEquals } from "@std/assert";
|
|
15
|
+
*
|
|
16
|
+
* assertEquals(unescape("Hello\nWorld"), "Hello\\n\nWorld");
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function unescape(string: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Tokenizes a string into an array of tokens.
|
|
22
|
+
*
|
|
23
|
+
* @param string The string to tokenize.
|
|
24
|
+
* @param wordDiff If true, performs word-based tokenization. Default is false.
|
|
25
|
+
*
|
|
26
|
+
* @returns An array of tokens.
|
|
27
|
+
*
|
|
28
|
+
* @example Usage
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { tokenize } from "@std/internal/diff-str";
|
|
31
|
+
* import { assertEquals } from "@std/assert";
|
|
32
|
+
*
|
|
33
|
+
* assertEquals(tokenize("Hello\nWorld"), ["Hello\n", "World"]);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function tokenize(string: string, wordDiff?: boolean): string[];
|
|
37
|
+
/**
|
|
38
|
+
* Create details by filtering relevant word-diff for current line and merge
|
|
39
|
+
* "space-diff" if surrounded by word-diff for cleaner displays.
|
|
40
|
+
*
|
|
41
|
+
* @param line Current line
|
|
42
|
+
* @param tokens Word-diff tokens
|
|
43
|
+
*
|
|
44
|
+
* @returns Array of diff results.
|
|
45
|
+
*
|
|
46
|
+
* @example Usage
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { createDetails } from "@std/internal/diff-str";
|
|
49
|
+
* import { assertEquals } from "@std/assert";
|
|
50
|
+
*
|
|
51
|
+
* const tokens = [
|
|
52
|
+
* { type: "added", value: "a" },
|
|
53
|
+
* { type: "removed", value: "b" },
|
|
54
|
+
* { type: "common", value: "c" },
|
|
55
|
+
* ] as const;
|
|
56
|
+
* assertEquals(
|
|
57
|
+
* createDetails({ type: "added", value: "a" }, [...tokens]),
|
|
58
|
+
* [{ type: "added", value: "a" }, { type: "common", value: "c" }]
|
|
59
|
+
* );
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function createDetails(line: DiffResult<string>, tokens: DiffResult<string>[]): DiffResult<string>[];
|
|
63
|
+
/**
|
|
64
|
+
* Renders the differences between the actual and expected strings. Partially
|
|
65
|
+
* inspired from {@link https://github.com/kpdecker/jsdiff}.
|
|
66
|
+
*
|
|
67
|
+
* @param A Actual string
|
|
68
|
+
* @param B Expected string
|
|
69
|
+
*
|
|
70
|
+
* @returns Array of diff results.
|
|
71
|
+
*
|
|
72
|
+
* @example Usage
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { diffStr } from "@std/internal/diff-str";
|
|
75
|
+
* import { assertEquals } from "@std/assert";
|
|
76
|
+
*
|
|
77
|
+
* assertEquals(diffStr("Hello!", "Hello"), [
|
|
78
|
+
* {
|
|
79
|
+
* type: "removed",
|
|
80
|
+
* value: "Hello!\n",
|
|
81
|
+
* details: [
|
|
82
|
+
* { type: "common", value: "Hello" },
|
|
83
|
+
* { type: "removed", value: "!" },
|
|
84
|
+
* { type: "common", value: "\n" }
|
|
85
|
+
* ]
|
|
86
|
+
* },
|
|
87
|
+
* {
|
|
88
|
+
* type: "added",
|
|
89
|
+
* value: "Hello\n",
|
|
90
|
+
* details: [
|
|
91
|
+
* { type: "common", value: "Hello" },
|
|
92
|
+
* { type: "common", value: "\n" }
|
|
93
|
+
* ]
|
|
94
|
+
* }
|
|
95
|
+
* ]);
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare function diffStr(A: string, B: string): DiffResult<string>[];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type InspectFn = (v: unknown, options: {
|
|
2
|
+
depth: number;
|
|
3
|
+
sorted: boolean;
|
|
4
|
+
trailingComma: boolean;
|
|
5
|
+
compact: boolean;
|
|
6
|
+
iterableLimit: number;
|
|
7
|
+
getters: boolean;
|
|
8
|
+
strAbbreviateSize: number;
|
|
9
|
+
}) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Converts the input into a string. Objects, Sets and Maps are sorted so as to
|
|
12
|
+
* make tests less flaky.
|
|
13
|
+
*
|
|
14
|
+
* @param v Value to be formatted
|
|
15
|
+
*
|
|
16
|
+
* @returns The formatted string
|
|
17
|
+
*
|
|
18
|
+
* @example Usage
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { format } from "@std/internal/format";
|
|
21
|
+
* import { assertEquals } from "@std/assert";
|
|
22
|
+
*
|
|
23
|
+
* assertEquals(format({ a: 1, b: 2 }), "{\n a: 1,\n b: 2,\n}");
|
|
24
|
+
* assertEquals(format(new Set([1, 2])), "Set(2) {\n 1,\n 2,\n}");
|
|
25
|
+
* assertEquals(format(new Map([[1, 2]])), "Map(1) {\n 1 => 2,\n}");
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function format(v: unknown): string;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets the style of text to be printed to bold.
|
|
3
|
+
*
|
|
4
|
+
* Disable by setting the `NO_COLOR` environmental variable.
|
|
5
|
+
*
|
|
6
|
+
* @param str Text to make bold
|
|
7
|
+
*
|
|
8
|
+
* @returns Bold text for printing
|
|
9
|
+
*
|
|
10
|
+
* @example Usage
|
|
11
|
+
* ```ts no-assert
|
|
12
|
+
* import { bold } from "@std/internal/styles";
|
|
13
|
+
*
|
|
14
|
+
* console.log(bold("Hello, world!")); // Prints "Hello, world!" in bold
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function bold(str: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Sets the color of text to be printed to red.
|
|
20
|
+
*
|
|
21
|
+
* Disable by setting the `NO_COLOR` environmental variable.
|
|
22
|
+
*
|
|
23
|
+
* @param str Text to make red
|
|
24
|
+
*
|
|
25
|
+
* @returns Red text for printing
|
|
26
|
+
*
|
|
27
|
+
* @example Usage
|
|
28
|
+
* ```ts no-assert
|
|
29
|
+
* import { red } from "@std/internal/styles";
|
|
30
|
+
*
|
|
31
|
+
* console.log(red("Hello, world!")); // Prints "Hello, world!" in red
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function red(str: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Sets the color of text to be printed to green.
|
|
37
|
+
*
|
|
38
|
+
* Disable by setting the `NO_COLOR` environmental variable.
|
|
39
|
+
*
|
|
40
|
+
* @param str Text to make green
|
|
41
|
+
*
|
|
42
|
+
* @returns Green text for print
|
|
43
|
+
*
|
|
44
|
+
* @example Usage
|
|
45
|
+
* ```ts no-assert
|
|
46
|
+
* import { green } from "@std/internal/styles";
|
|
47
|
+
*
|
|
48
|
+
* console.log(green("Hello, world!")); // Prints "Hello, world!" in green
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function green(str: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* Sets the color of text to be printed to yellow.
|
|
54
|
+
*
|
|
55
|
+
* Disable by setting the `NO_COLOR` environmental variable.
|
|
56
|
+
*
|
|
57
|
+
* @param str Text to make yellow
|
|
58
|
+
*
|
|
59
|
+
* @returns Yellow text for print
|
|
60
|
+
*
|
|
61
|
+
* @example Usage
|
|
62
|
+
* ```ts no-assert
|
|
63
|
+
* import { yellow } from "@std/internal/styles";
|
|
64
|
+
*
|
|
65
|
+
* console.log(yellow("Hello, world!")); // Prints "Hello, world!" in yellow
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function yellow(str: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* Sets the color of text to be printed to white.
|
|
71
|
+
*
|
|
72
|
+
* @param str Text to make white
|
|
73
|
+
*
|
|
74
|
+
* @returns White text for print
|
|
75
|
+
*
|
|
76
|
+
* @example Usage
|
|
77
|
+
* ```ts no-assert
|
|
78
|
+
* import { white } from "@std/internal/styles";
|
|
79
|
+
*
|
|
80
|
+
* console.log(white("Hello, world!")); // Prints "Hello, world!" in white
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function white(str: string): string;
|
|
84
|
+
/**
|
|
85
|
+
* Sets the color of text to be printed to gray.
|
|
86
|
+
*
|
|
87
|
+
* @param str Text to make gray
|
|
88
|
+
*
|
|
89
|
+
* @returns Gray text for print
|
|
90
|
+
*
|
|
91
|
+
* @example Usage
|
|
92
|
+
* ```ts no-assert
|
|
93
|
+
* import { gray } from "@std/internal/styles";
|
|
94
|
+
*
|
|
95
|
+
* console.log(gray("Hello, world!")); // Prints "Hello, world!" in gray
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare function gray(str: string): string;
|
|
99
|
+
/**
|
|
100
|
+
* Sets the color of text to be printed to bright-black.
|
|
101
|
+
*
|
|
102
|
+
* @param str Text to make bright-black
|
|
103
|
+
*
|
|
104
|
+
* @returns Bright-black text for print
|
|
105
|
+
*
|
|
106
|
+
* @example Usage
|
|
107
|
+
* ```ts no-assert
|
|
108
|
+
* import { brightBlack } from "@std/internal/styles";
|
|
109
|
+
*
|
|
110
|
+
* console.log(brightBlack("Hello, world!")); // Prints "Hello, world!" in bright-black
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare function brightBlack(str: string): string;
|
|
114
|
+
/**
|
|
115
|
+
* Sets the background color of text to be printed to red.
|
|
116
|
+
*
|
|
117
|
+
* @param str Text to make its background red
|
|
118
|
+
*
|
|
119
|
+
* @returns Red background text for print
|
|
120
|
+
*
|
|
121
|
+
* @example Usage
|
|
122
|
+
* ```ts no-assert
|
|
123
|
+
* import { bgRed } from "@std/internal/styles";
|
|
124
|
+
*
|
|
125
|
+
* console.log(bgRed("Hello, world!")); // Prints "Hello, world!" with red background
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export declare function bgRed(str: string): string;
|
|
129
|
+
/**
|
|
130
|
+
* Sets the background color of text to be printed to green.
|
|
131
|
+
*
|
|
132
|
+
* @param str Text to make its background green
|
|
133
|
+
*
|
|
134
|
+
* @returns Green background text for print
|
|
135
|
+
*
|
|
136
|
+
* @example Usage
|
|
137
|
+
* ```ts no-assert
|
|
138
|
+
* import { bgGreen } from "@std/internal/styles";
|
|
139
|
+
*
|
|
140
|
+
* console.log(bgGreen("Hello, world!")); // Prints "Hello, world!" with green background
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
export declare function bgGreen(str: string): string;
|
|
144
|
+
/**
|
|
145
|
+
* Remove ANSI escape codes from the string.
|
|
146
|
+
*
|
|
147
|
+
* @param string Text to remove ANSI escape codes from
|
|
148
|
+
*
|
|
149
|
+
* @returns Text without ANSI escape codes
|
|
150
|
+
*
|
|
151
|
+
* @example Usage
|
|
152
|
+
* ```ts no-assert
|
|
153
|
+
* import { red, stripAnsiCode } from "@std/internal/styles";
|
|
154
|
+
*
|
|
155
|
+
* console.log(stripAnsiCode(red("Hello, world!"))); // Prints "Hello, world!"
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export declare function stripAnsiCode(string: string): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Ways that lines in a diff can be different. */
|
|
2
|
+
export type DiffType = DiffResult<unknown>["type"];
|
|
3
|
+
/**
|
|
4
|
+
* Represents the result of a diff operation.
|
|
5
|
+
* @typeParam T The type of the value in the diff result.
|
|
6
|
+
*/
|
|
7
|
+
export type DiffResult<T> = ChangedDiffResult<T> | CommonDiffResult<T>;
|
|
8
|
+
/**
|
|
9
|
+
* Represents the result of a common diff operation.
|
|
10
|
+
* @typeParam T The type of the value in the diff result.
|
|
11
|
+
*/
|
|
12
|
+
export type CommonDiffResult<T> = {
|
|
13
|
+
type: "common" | "truncation";
|
|
14
|
+
value: T;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Represents the result of a changed diff operation.
|
|
18
|
+
* @typeParam T The type of the value in the diff result.
|
|
19
|
+
*/
|
|
20
|
+
export type ChangedDiffResult<T> = {
|
|
21
|
+
type: "removed" | "added";
|
|
22
|
+
value: T;
|
|
23
|
+
details?: DiffResult<T>[];
|
|
24
|
+
};
|
package/types/mod.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Testing vocabulary for executable.md documents (specs/testing-spec.md).
|
|
4
|
+
*
|
|
5
|
+
* `<Testing>` activates testing mode for its expanded subtree, `<Test>`
|
|
6
|
+
* defines an atomic test, and the assertion components map to `@std/assert`.
|
|
7
|
+
*
|
|
8
|
+
* Composition with core execution:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { execute } from "@executablemd/core";
|
|
12
|
+
* import { useTesting } from "@executablemd/testing";
|
|
13
|
+
*
|
|
14
|
+
* const tests = yield* useTesting();
|
|
15
|
+
* const execution = yield* execute(options);
|
|
16
|
+
* const outcome = yield* execution; // Result<string>
|
|
17
|
+
* const results = yield* tests.results;
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Vocabulary registration (`installTestingVocabulary`) is distinct from
|
|
21
|
+
* testing-mode activation (`useTesting()` at the root, or a `<Testing>`
|
|
22
|
+
* element for a subtree).
|
|
23
|
+
*/
|
|
24
|
+
import "./_dnt.polyfills.js";
|
|
25
|
+
export { Test, testing, record, results, TestFailureError } from "./src/test-api.js";
|
|
26
|
+
export type { TestApi, TestResult, BoundaryOutcome } from "./src/test-api.js";
|
|
27
|
+
export { installTestingVocabulary } from "./src/vocabulary.js";
|
|
28
|
+
export { useTesting } from "./src/use-testing.js";
|
|
29
|
+
export type { Testing } from "./src/use-testing.js";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assertion components (specs/testing-spec.md §Assertions).
|
|
3
|
+
*
|
|
4
|
+
* Each component maps to an `@std/assert` export with the same name and
|
|
5
|
+
* parameter names. Expression props evaluate LIVE against the merged binding
|
|
6
|
+
* environment — never through JSON serialization, which would destroy
|
|
7
|
+
* `RegExp`s, `undefined`, and object identity.
|
|
8
|
+
*
|
|
9
|
+
* The assertion runs on the raw values BEFORE any diagnostic formatting, so
|
|
10
|
+
* formatting arbitrary values (mutating or throwing getters/toJSON/toString)
|
|
11
|
+
* can never change the assertion outcome. Diagnostics are built afterwards
|
|
12
|
+
* under guarded fallback.
|
|
13
|
+
*/
|
|
14
|
+
import { AssertionError } from "../deps/jsr.io/@std/assert/1.0.19/mod.js";
|
|
15
|
+
import type { Operation } from "effection";
|
|
16
|
+
import type { ComponentInvocation, InvocationContext, Segment } from "@executablemd/core";
|
|
17
|
+
type AssertionKind = "unary-truthy" | "unary-exists" | "binary-eq" | "string-includes" | "match" | "numeric";
|
|
18
|
+
export interface AssertionEntry {
|
|
19
|
+
name: string;
|
|
20
|
+
kind: AssertionKind;
|
|
21
|
+
/** Runs the underlying @std/assert function on the resolved raw values. */
|
|
22
|
+
run(values: ResolvedValues): void;
|
|
23
|
+
allowsExpectedChildren: boolean;
|
|
24
|
+
}
|
|
25
|
+
interface ResolvedValues {
|
|
26
|
+
expr?: unknown;
|
|
27
|
+
actual?: unknown;
|
|
28
|
+
expected?: unknown;
|
|
29
|
+
msg?: string;
|
|
30
|
+
}
|
|
31
|
+
export declare const ASSERTIONS: Map<string, AssertionEntry>;
|
|
32
|
+
/**
|
|
33
|
+
* An assertion failure enriched with its Markdown diagnostic. Still an
|
|
34
|
+
* `AssertionError`, so containment and classification treat it as the
|
|
35
|
+
* original @std/assert failure.
|
|
36
|
+
*/
|
|
37
|
+
export declare class AssertionDiagnostic extends AssertionError {
|
|
38
|
+
name: string;
|
|
39
|
+
diagnostic: string;
|
|
40
|
+
detail: {
|
|
41
|
+
actual?: string;
|
|
42
|
+
expected?: string;
|
|
43
|
+
};
|
|
44
|
+
constructor(cause: Error, diagnostic: string, detail: {
|
|
45
|
+
actual?: string;
|
|
46
|
+
expected?: string;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Expand one assertion component: validate props, resolve raw values, run the
|
|
51
|
+
* @std/assert function, then build the diagnostic. Returns diagnostic text on
|
|
52
|
+
* a visible pass; throws `AssertionDiagnostic` on failure.
|
|
53
|
+
*/
|
|
54
|
+
export declare function expandAssertion(assertion: AssertionEntry, invocation: ComponentInvocation, ctx: InvocationContext): Operation<Segment[]>;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<Testing>` and `<Test>` handlers (specs/testing-spec.md).
|
|
3
|
+
*
|
|
4
|
+
* `createTestHandlers` is the internal dependency-injection seam for the
|
|
5
|
+
* fixed 20-second test timeout: the public vocabulary always constructs
|
|
6
|
+
* handlers with 20_000; tests construct them directly with a small timeout.
|
|
7
|
+
*/
|
|
8
|
+
import type { Operation } from "effection";
|
|
9
|
+
import type { ComponentInvocation, InvocationContext, Segment } from "@executablemd/core";
|
|
10
|
+
import type { AssertionEntry } from "./assertions.js";
|
|
11
|
+
export interface TestHandlers {
|
|
12
|
+
expandTesting(invocation: ComponentInvocation, ctx: InvocationContext): Operation<Segment[]>;
|
|
13
|
+
expandTest(invocation: ComponentInvocation, ctx: InvocationContext): Operation<Segment[]>;
|
|
14
|
+
expandAssertion(assertion: AssertionEntry, invocation: ComponentInvocation, ctx: InvocationContext): Operation<Segment[]>;
|
|
15
|
+
}
|
|
16
|
+
export declare function createTestHandlers(options: {
|
|
17
|
+
timeoutMs: number;
|
|
18
|
+
}): TestHandlers;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Durable testing records (specs/testing-spec.md §Testing Mode).
|
|
3
|
+
*
|
|
4
|
+
* Completed tests and explicit `<Testing>` boundary outcomes are journaled
|
|
5
|
+
* as testing-owned durable operations while document expansion runs —
|
|
6
|
+
* before the root Close event. On a full replay of a completed journal,
|
|
7
|
+
* `durableRun` returns the stored root result without re-expanding the
|
|
8
|
+
* document, so no test would ever re-record; the stored records are
|
|
9
|
+
* restored from the stream instead. On partial replay the document
|
|
10
|
+
* re-expands and each record replays in place, recording exactly once in
|
|
11
|
+
* discovery order.
|
|
12
|
+
*
|
|
13
|
+
* Record identities are deterministic, derived from source position.
|
|
14
|
+
*/
|
|
15
|
+
import type { DurableStream, Workflow } from "@executablemd/durable-streams";
|
|
16
|
+
import type { Operation } from "effection";
|
|
17
|
+
import type { BoundaryOutcome, TestResult } from "./test-api.js";
|
|
18
|
+
export declare function persistTestResult(result: TestResult): Workflow<TestResult>;
|
|
19
|
+
export declare function persistBoundaryOutcome(outcome: BoundaryOutcome, location: string): Workflow<BoundaryOutcome>;
|
|
20
|
+
export interface CompletedRunRecords {
|
|
21
|
+
results: TestResult[];
|
|
22
|
+
boundaries: BoundaryOutcome[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Read testing records from a journal that already holds a root Close
|
|
26
|
+
* event — the confirmed-full-replay case. Returns undefined for a live or
|
|
27
|
+
* partial journal, where expansion itself (re)records each result.
|
|
28
|
+
*/
|
|
29
|
+
export declare function readCompletedRun(stream: DurableStream): Operation<CompletedRunRecords | undefined>;
|