track-cli 4.0.3 → 4.1.0-rc1

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.
Files changed (90) hide show
  1. package/esm/_dnt.shims.d.ts +1 -1
  2. package/esm/_dnt.test_shims.d.ts +20 -0
  3. package/esm/_dnt.test_shims.js +77 -0
  4. package/esm/deps/deno.land/std@0.195.0/_util/diff.d.ts +26 -0
  5. package/esm/deps/deno.land/std@0.195.0/_util/diff.js +311 -0
  6. package/esm/deps/deno.land/std@0.195.0/assert/_constants.d.ts +1 -0
  7. package/esm/deps/deno.land/std@0.195.0/assert/_constants.js +2 -0
  8. package/esm/deps/deno.land/std@0.195.0/assert/_format.d.ts +1 -0
  9. package/esm/deps/deno.land/std@0.195.0/assert/_format.js +23 -0
  10. package/esm/deps/deno.land/std@0.195.0/assert/assert_almost_equals.d.ts +18 -0
  11. package/esm/deps/deno.land/std@0.195.0/assert/assert_almost_equals.js +32 -0
  12. package/esm/deps/deno.land/std@0.195.0/assert/assert_array_includes.d.ts +14 -0
  13. package/esm/deps/deno.land/std@0.195.0/assert/assert_array_includes.js +38 -0
  14. package/esm/deps/deno.land/std@0.195.0/assert/assert_equals.d.ts +17 -0
  15. package/esm/deps/deno.land/std@0.195.0/assert/assert_equals.js +45 -0
  16. package/esm/deps/deno.land/std@0.195.0/assert/assert_exists.d.ts +5 -0
  17. package/esm/deps/deno.land/std@0.195.0/assert/assert_exists.js +14 -0
  18. package/esm/deps/deno.land/std@0.195.0/assert/assert_false.d.ts +4 -0
  19. package/esm/deps/deno.land/std@0.195.0/assert/assert_false.js +7 -0
  20. package/esm/deps/deno.land/std@0.195.0/assert/assert_instance_of.d.ts +8 -0
  21. package/esm/deps/deno.land/std@0.195.0/assert/assert_instance_of.js +38 -0
  22. package/esm/deps/deno.land/std@0.195.0/assert/assert_is_error.d.ts +7 -0
  23. package/esm/deps/deno.land/std@0.195.0/assert/assert_is_error.js +26 -0
  24. package/esm/deps/deno.land/std@0.195.0/assert/assert_match.d.ts +5 -0
  25. package/esm/deps/deno.land/std@0.195.0/assert/assert_match.js +13 -0
  26. package/esm/deps/deno.land/std@0.195.0/assert/assert_not_equals.d.ts +14 -0
  27. package/esm/deps/deno.land/std@0.195.0/assert/assert_not_equals.js +37 -0
  28. package/esm/deps/deno.land/std@0.195.0/assert/assert_not_instance_of.d.ts +5 -0
  29. package/esm/deps/deno.land/std@0.195.0/assert/assert_not_instance_of.js +14 -0
  30. package/esm/deps/deno.land/std@0.195.0/assert/assert_not_match.d.ts +5 -0
  31. package/esm/deps/deno.land/std@0.195.0/assert/assert_not_match.js +14 -0
  32. package/esm/deps/deno.land/std@0.195.0/assert/assert_not_strict_equals.d.ts +11 -0
  33. package/esm/deps/deno.land/std@0.195.0/assert/assert_not_strict_equals.js +20 -0
  34. package/esm/deps/deno.land/std@0.195.0/assert/assert_object_match.d.ts +5 -0
  35. package/esm/deps/deno.land/std@0.195.0/assert/assert_object_match.js +78 -0
  36. package/esm/deps/deno.land/std@0.195.0/assert/assert_rejects.d.ts +64 -0
  37. package/esm/deps/deno.land/std@0.195.0/assert/assert_rejects.js +50 -0
  38. package/esm/deps/deno.land/std@0.195.0/assert/assert_strict_equals.d.ts +23 -0
  39. package/esm/deps/deno.land/std@0.195.0/assert/assert_strict_equals.js +60 -0
  40. package/esm/deps/deno.land/std@0.195.0/assert/assert_string_includes.d.ts +5 -0
  41. package/esm/deps/deno.land/std@0.195.0/assert/assert_string_includes.js +13 -0
  42. package/esm/deps/deno.land/std@0.195.0/assert/assert_throws.d.ts +54 -0
  43. package/esm/deps/deno.land/std@0.195.0/assert/assert_throws.js +44 -0
  44. package/esm/deps/deno.land/std@0.195.0/assert/equal.d.ts +6 -0
  45. package/esm/deps/deno.land/std@0.195.0/assert/equal.js +102 -0
  46. package/esm/deps/deno.land/std@0.195.0/assert/fail.d.ts +4 -0
  47. package/esm/deps/deno.land/std@0.195.0/assert/fail.js +9 -0
  48. package/esm/deps/deno.land/std@0.195.0/assert/mod.d.ts +32 -0
  49. package/esm/deps/deno.land/std@0.195.0/assert/mod.js +33 -0
  50. package/esm/deps/deno.land/std@0.195.0/assert/unimplemented.d.ts +2 -0
  51. package/esm/deps/deno.land/std@0.195.0/assert/unimplemented.js +7 -0
  52. package/esm/deps/deno.land/std@0.195.0/assert/unreachable.d.ts +2 -0
  53. package/esm/deps/deno.land/std@0.195.0/assert/unreachable.js +6 -0
  54. package/esm/deps/deno.land/std@0.195.0/testing/_test_suite.d.ts +70 -0
  55. package/esm/deps/deno.land/std@0.195.0/testing/_test_suite.js +321 -0
  56. package/esm/deps/deno.land/std@0.195.0/testing/asserts.d.ts +329 -0
  57. package/esm/deps/deno.land/std@0.195.0/testing/asserts.js +330 -0
  58. package/esm/deps/deno.land/std@0.195.0/testing/bdd.d.ts +440 -0
  59. package/esm/deps/deno.land/std@0.195.0/testing/bdd.js +215 -0
  60. package/esm/deps/deno.land/std@0.195.0/testing/mock.d.ts +110 -0
  61. package/esm/deps/deno.land/std@0.195.0/testing/mock.js +746 -0
  62. package/esm/src/action/clone.js +4 -3
  63. package/esm/src/action/frontend-template-switch.d.ts +1 -0
  64. package/esm/src/action/frontend-template-switch.js +56 -0
  65. package/esm/src/action/frontend-template.d.ts +2 -0
  66. package/esm/src/action/frontend-template.js +12 -0
  67. package/esm/src/main.js +9 -2
  68. package/esm/src/meta.d.ts +1 -1
  69. package/esm/src/meta.js +108 -25
  70. package/esm/src/orca/client.js +1 -1
  71. package/esm/src/shared/config.d.ts +1 -0
  72. package/esm/src/shared/file.d.ts +1 -0
  73. package/esm/src/shared/file.js +32 -0
  74. package/esm/src/shared/mod.d.ts +1 -1
  75. package/esm/src/shared/mod.js +10 -2
  76. package/esm/src/shared/types.d.ts +15 -0
  77. package/esm/src/shared/types.js +1 -0
  78. package/esm/src/track/client.d.ts +4 -1
  79. package/esm/src/track/test.d.ts +5 -2
  80. package/esm/src/track/test.js +18 -2
  81. package/esm/src/track/training.d.ts +4 -1
  82. package/esm/src/track/training.js +9 -0
  83. package/esm/test/shared/config_test.d.ts +1 -0
  84. package/esm/test/shared/config_test.js +57 -0
  85. package/esm/test/shared/file_test.d.ts +1 -0
  86. package/esm/test/shared/file_test.js +265 -0
  87. package/esm/test/shared/mod_test.d.ts +1 -0
  88. package/esm/test/shared/mod_test.js +353 -0
  89. package/package.json +2 -1
  90. package/test_runner.js +186 -0
@@ -0,0 +1,4 @@
1
+ /** Make an assertion, error will be thrown if `expr` have truthy value. */
2
+ type Falsy = false | 0 | 0n | "" | null | undefined;
3
+ export declare function assertFalse(expr: unknown, msg?: string): asserts expr is Falsy;
4
+ export {};
@@ -0,0 +1,7 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { AssertionError } from "./assertion_error.js";
3
+ export function assertFalse(expr, msg = "") {
4
+ if (expr) {
5
+ throw new AssertionError(msg);
6
+ }
7
+ }
@@ -0,0 +1,8 @@
1
+ type AnyConstructor = new (...args: any[]) => any;
2
+ type GetConstructorType<T extends AnyConstructor> = T extends new (...args: any) => infer C ? C : never;
3
+ /**
4
+ * Make an assertion that `obj` is an instance of `type`.
5
+ * If not then throw.
6
+ */
7
+ export declare function assertInstanceOf<T extends AnyConstructor>(actual: unknown, expectedType: T, msg?: string): asserts actual is GetConstructorType<T>;
8
+ export {};
@@ -0,0 +1,38 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { AssertionError } from "./assertion_error.js";
3
+ /**
4
+ * Make an assertion that `obj` is an instance of `type`.
5
+ * If not then throw.
6
+ */
7
+ export function assertInstanceOf(actual, expectedType, msg = "") {
8
+ if (actual instanceof expectedType)
9
+ return;
10
+ const msgSuffix = msg ? `: ${msg}` : ".";
11
+ const expectedTypeStr = expectedType.name;
12
+ let actualTypeStr = "";
13
+ if (actual === null) {
14
+ actualTypeStr = "null";
15
+ }
16
+ else if (actual === undefined) {
17
+ actualTypeStr = "undefined";
18
+ }
19
+ else if (typeof actual === "object") {
20
+ actualTypeStr = actual.constructor?.name ?? "Object";
21
+ }
22
+ else {
23
+ actualTypeStr = typeof actual;
24
+ }
25
+ if (expectedTypeStr == actualTypeStr) {
26
+ msg =
27
+ `Expected object to be an instance of "${expectedTypeStr}"${msgSuffix}`;
28
+ }
29
+ else if (actualTypeStr == "function") {
30
+ msg =
31
+ `Expected object to be an instance of "${expectedTypeStr}" but was not an instanced object${msgSuffix}`;
32
+ }
33
+ else {
34
+ msg =
35
+ `Expected object to be an instance of "${expectedTypeStr}" but was "${actualTypeStr}"${msgSuffix}`;
36
+ }
37
+ throw new AssertionError(msg);
38
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Make an assertion that `error` is an `Error`.
3
+ * If not then an error will be thrown.
4
+ * An error class and a string that should be included in the
5
+ * error message can also be asserted.
6
+ */
7
+ export declare function assertIsError<E extends Error = Error>(error: unknown, ErrorClass?: new (...args: any[]) => E, msgIncludes?: string, msg?: string): asserts error is E;
@@ -0,0 +1,26 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { AssertionError } from "./assertion_error.js";
3
+ import { stripColor } from "../fmt/colors.js";
4
+ /**
5
+ * Make an assertion that `error` is an `Error`.
6
+ * If not then an error will be thrown.
7
+ * An error class and a string that should be included in the
8
+ * error message can also be asserted.
9
+ */
10
+ export function assertIsError(error,
11
+ // deno-lint-ignore no-explicit-any
12
+ ErrorClass, msgIncludes, msg) {
13
+ const msgSuffix = msg ? `: ${msg}` : ".";
14
+ if (error instanceof Error === false) {
15
+ throw new AssertionError(`Expected "error" to be an Error object${msgSuffix}}`);
16
+ }
17
+ if (ErrorClass && !(error instanceof ErrorClass)) {
18
+ msg = `Expected error to be instance of "${ErrorClass.name}", but was "${typeof error === "object" ? error?.constructor?.name : "[not an object]"}"${msgSuffix}`;
19
+ throw new AssertionError(msg);
20
+ }
21
+ if (msgIncludes && (!(error instanceof Error) ||
22
+ !stripColor(error.message).includes(stripColor(msgIncludes)))) {
23
+ msg = `Expected error message to include "${msgIncludes}", but got "${error instanceof Error ? error.message : "[not an Error]"}"${msgSuffix}`;
24
+ throw new AssertionError(msg);
25
+ }
26
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Make an assertion that `actual` match RegExp `expected`. If not
3
+ * then throw.
4
+ */
5
+ export declare function assertMatch(actual: string, expected: RegExp, msg?: string): void;
@@ -0,0 +1,13 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { AssertionError } from "./assertion_error.js";
3
+ /**
4
+ * Make an assertion that `actual` match RegExp `expected`. If not
5
+ * then throw.
6
+ */
7
+ export function assertMatch(actual, expected, msg) {
8
+ if (!expected.test(actual)) {
9
+ const msgSuffix = msg ? `: ${msg}` : ".";
10
+ msg = `Expected actual: "${actual}" to match: "${expected}"${msgSuffix}`;
11
+ throw new AssertionError(msg);
12
+ }
13
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Make an assertion that `actual` and `expected` are not equal, deeply.
3
+ * If not then throw.
4
+ *
5
+ * Type parameter can be specified to ensure values under comparison have the same type.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { assertNotEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_not_equals.ts";
10
+ *
11
+ * assertNotEquals<number>(1, 2)
12
+ * ```
13
+ */
14
+ export declare function assertNotEquals<T>(actual: T, expected: T, msg?: string): void;
@@ -0,0 +1,37 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { equal } from "./equal.js";
3
+ import { AssertionError } from "./assertion_error.js";
4
+ /**
5
+ * Make an assertion that `actual` and `expected` are not equal, deeply.
6
+ * If not then throw.
7
+ *
8
+ * Type parameter can be specified to ensure values under comparison have the same type.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { assertNotEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_not_equals.ts";
13
+ *
14
+ * assertNotEquals<number>(1, 2)
15
+ * ```
16
+ */
17
+ export function assertNotEquals(actual, expected, msg) {
18
+ if (!equal(actual, expected)) {
19
+ return;
20
+ }
21
+ let actualString;
22
+ let expectedString;
23
+ try {
24
+ actualString = String(actual);
25
+ }
26
+ catch {
27
+ actualString = "[Cannot display]";
28
+ }
29
+ try {
30
+ expectedString = String(expected);
31
+ }
32
+ catch {
33
+ expectedString = "[Cannot display]";
34
+ }
35
+ const msgSuffix = msg ? `: ${msg}` : ".";
36
+ throw new AssertionError(`Expected actual: ${actualString} not to be: ${expectedString}${msgSuffix}`);
37
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Make an assertion that `obj` is not an instance of `type`.
3
+ * If so, then throw.
4
+ */
5
+ export declare function assertNotInstanceOf<A, T>(actual: A, unexpectedType: new (...args: any[]) => T, msg?: string): asserts actual is Exclude<A, T>;
@@ -0,0 +1,14 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { assertFalse } from "./assert_false.js";
3
+ /**
4
+ * Make an assertion that `obj` is not an instance of `type`.
5
+ * If so, then throw.
6
+ */
7
+ export function assertNotInstanceOf(actual,
8
+ // deno-lint-ignore no-explicit-any
9
+ unexpectedType, msg) {
10
+ const msgSuffix = msg ? `: ${msg}` : ".";
11
+ msg =
12
+ `Expected object to not be an instance of "${typeof unexpectedType}"${msgSuffix}`;
13
+ assertFalse(actual instanceof unexpectedType, msg);
14
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Make an assertion that `actual` not match RegExp `expected`. If match
3
+ * then throw.
4
+ */
5
+ export declare function assertNotMatch(actual: string, expected: RegExp, msg?: string): void;
@@ -0,0 +1,14 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { AssertionError } from "./assertion_error.js";
3
+ /**
4
+ * Make an assertion that `actual` not match RegExp `expected`. If match
5
+ * then throw.
6
+ */
7
+ export function assertNotMatch(actual, expected, msg) {
8
+ if (expected.test(actual)) {
9
+ const msgSuffix = msg ? `: ${msg}` : ".";
10
+ msg =
11
+ `Expected actual: "${actual}" to not match: "${expected}"${msgSuffix}`;
12
+ throw new AssertionError(msg);
13
+ }
14
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Make an assertion that `actual` and `expected` are not strictly equal.
3
+ * If the values are strictly equal then throw.
4
+ *
5
+ * ```ts
6
+ * import { assertNotStrictEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_not_strict_equals.ts";
7
+ *
8
+ * assertNotStrictEquals(1, 1)
9
+ * ```
10
+ */
11
+ export declare function assertNotStrictEquals<T>(actual: T, expected: T, msg?: string): void;
@@ -0,0 +1,20 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { AssertionError } from "./assertion_error.js";
3
+ import { format } from "./_format.js";
4
+ /**
5
+ * Make an assertion that `actual` and `expected` are not strictly equal.
6
+ * If the values are strictly equal then throw.
7
+ *
8
+ * ```ts
9
+ * import { assertNotStrictEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_not_strict_equals.ts";
10
+ *
11
+ * assertNotStrictEquals(1, 1)
12
+ * ```
13
+ */
14
+ export function assertNotStrictEquals(actual, expected, msg) {
15
+ if (!Object.is(actual, expected)) {
16
+ return;
17
+ }
18
+ const msgSuffix = msg ? `: ${msg}` : ".";
19
+ throw new AssertionError(`Expected "actual" to be strictly unequal to: ${format(actual)}${msgSuffix}\n`);
20
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Make an assertion that `actual` object is a subset of `expected` object, deeply.
3
+ * If not, then throw.
4
+ */
5
+ export declare function assertObjectMatch(actual: Record<PropertyKey, any>, expected: Record<PropertyKey, unknown>, msg?: string): void;
@@ -0,0 +1,78 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { assertEquals } from "./assert_equals.js";
3
+ /**
4
+ * Make an assertion that `actual` object is a subset of `expected` object, deeply.
5
+ * If not, then throw.
6
+ */
7
+ export function assertObjectMatch(
8
+ // deno-lint-ignore no-explicit-any
9
+ actual, expected, msg) {
10
+ function filter(a, b) {
11
+ const seen = new WeakMap();
12
+ return fn(a, b);
13
+ function fn(a, b) {
14
+ // Prevent infinite loop with circular references with same filter
15
+ if ((seen.has(a)) && (seen.get(a) === b)) {
16
+ return a;
17
+ }
18
+ try {
19
+ seen.set(a, b);
20
+ }
21
+ catch (err) {
22
+ if (err instanceof TypeError) {
23
+ throw new TypeError(`Cannot assertObjectMatch ${a === null ? null : `type ${typeof a}`}`);
24
+ }
25
+ else
26
+ throw err;
27
+ }
28
+ // Filter keys and symbols which are present in both actual and expected
29
+ const filtered = {};
30
+ const entries = [
31
+ ...Object.getOwnPropertyNames(a),
32
+ ...Object.getOwnPropertySymbols(a),
33
+ ]
34
+ .filter((key) => key in b)
35
+ .map((key) => [key, a[key]]);
36
+ for (const [key, value] of entries) {
37
+ // On array references, build a filtered array and filter nested objects inside
38
+ if (Array.isArray(value)) {
39
+ const subset = b[key];
40
+ if (Array.isArray(subset)) {
41
+ filtered[key] = fn({ ...value }, { ...subset });
42
+ continue;
43
+ }
44
+ } // On regexp references, keep value as it to avoid loosing pattern and flags
45
+ else if (value instanceof RegExp) {
46
+ filtered[key] = value;
47
+ continue;
48
+ } // On nested objects references, build a filtered object recursively
49
+ else if (typeof value === "object" && value !== null) {
50
+ const subset = b[key];
51
+ if ((typeof subset === "object") && (subset)) {
52
+ // When both operands are maps, build a filtered map with common keys and filter nested objects inside
53
+ if ((value instanceof Map) && (subset instanceof Map)) {
54
+ filtered[key] = new Map([...value].filter(([k]) => subset.has(k)).map(([k, v]) => [k, typeof v === "object" ? fn(v, subset.get(k)) : v]));
55
+ continue;
56
+ }
57
+ // When both operands are set, build a filtered set with common values
58
+ if ((value instanceof Set) && (subset instanceof Set)) {
59
+ filtered[key] = new Set([...value].filter((v) => subset.has(v)));
60
+ continue;
61
+ }
62
+ filtered[key] = fn(value, subset);
63
+ continue;
64
+ }
65
+ }
66
+ filtered[key] = value;
67
+ }
68
+ return filtered;
69
+ }
70
+ }
71
+ return assertEquals(
72
+ // get the intersection of "actual" and "expected"
73
+ // side effect: all the instances' constructor field is "Object" now.
74
+ filter(actual, expected),
75
+ // set (nested) instances' constructor field to be "Object" without changing expected value.
76
+ // see https://github.com/denoland/deno_std/pull/1419
77
+ filter(expected, expected), msg);
78
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Executes a function which returns a promise, expecting it to reject.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { assertRejects } from "https://deno.land/std@$STD_VERSION/assert/assert_rejects.ts";
7
+ *
8
+ * Deno.test("doesThrow", async function () {
9
+ * await assertRejects(
10
+ * async () => {
11
+ * throw new TypeError("hello world!");
12
+ * },
13
+ * );
14
+ * await assertRejects(
15
+ * async () => {
16
+ * return Promise.reject(new Error());
17
+ * },
18
+ * );
19
+ * });
20
+ *
21
+ * // This test will not pass.
22
+ * Deno.test("fails", async function () {
23
+ * await assertRejects(
24
+ * async () => {
25
+ * console.log("Hello world");
26
+ * },
27
+ * );
28
+ * });
29
+ * ```
30
+ */
31
+ export declare function assertRejects(fn: () => PromiseLike<unknown>, msg?: string): Promise<unknown>;
32
+ /**
33
+ * Executes a function which returns a promise, expecting it to reject.
34
+ * If it does not, then it throws. An error class and a string that should be
35
+ * included in the error message can also be asserted.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * import { assertRejects } from "https://deno.land/std@$STD_VERSION/assert/assert_rejects.ts";
40
+ *
41
+ * Deno.test("doesThrow", async function () {
42
+ * await assertRejects(async () => {
43
+ * throw new TypeError("hello world!");
44
+ * }, TypeError);
45
+ * await assertRejects(
46
+ * async () => {
47
+ * throw new TypeError("hello world!");
48
+ * },
49
+ * TypeError,
50
+ * "hello",
51
+ * );
52
+ * });
53
+ *
54
+ * // This test will not pass.
55
+ * Deno.test("fails", async function () {
56
+ * await assertRejects(
57
+ * async () => {
58
+ * console.log("Hello world");
59
+ * },
60
+ * );
61
+ * });
62
+ * ```
63
+ */
64
+ export declare function assertRejects<E extends Error = Error>(fn: () => PromiseLike<unknown>, ErrorClass: new (...args: any[]) => E, msgIncludes?: string, msg?: string): Promise<E>;
@@ -0,0 +1,50 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { AssertionError } from "./assertion_error.js";
3
+ import { assertIsError } from "./assert_is_error.js";
4
+ export async function assertRejects(fn, errorClassOrMsg, msgIncludesOrMsg, msg) {
5
+ // deno-lint-ignore no-explicit-any
6
+ let ErrorClass = undefined;
7
+ let msgIncludes = undefined;
8
+ let err;
9
+ if (typeof errorClassOrMsg !== "string") {
10
+ if (errorClassOrMsg === undefined ||
11
+ errorClassOrMsg.prototype instanceof Error ||
12
+ errorClassOrMsg.prototype === Error.prototype) {
13
+ // deno-lint-ignore no-explicit-any
14
+ ErrorClass = errorClassOrMsg;
15
+ msgIncludes = msgIncludesOrMsg;
16
+ }
17
+ }
18
+ else {
19
+ msg = errorClassOrMsg;
20
+ }
21
+ let doesThrow = false;
22
+ let isPromiseReturned = false;
23
+ const msgSuffix = msg ? `: ${msg}` : ".";
24
+ try {
25
+ const possiblePromise = fn();
26
+ if (possiblePromise &&
27
+ typeof possiblePromise === "object" &&
28
+ typeof possiblePromise.then === "function") {
29
+ isPromiseReturned = true;
30
+ await possiblePromise;
31
+ }
32
+ }
33
+ catch (error) {
34
+ if (!isPromiseReturned) {
35
+ throw new AssertionError(`Function throws when expected to reject${msgSuffix}`);
36
+ }
37
+ if (ErrorClass) {
38
+ if (error instanceof Error === false) {
39
+ throw new AssertionError(`A non-Error object was rejected${msgSuffix}`);
40
+ }
41
+ assertIsError(error, ErrorClass, msgIncludes, msg);
42
+ }
43
+ err = error;
44
+ doesThrow = true;
45
+ }
46
+ if (!doesThrow) {
47
+ throw new AssertionError(`Expected function to reject${msgSuffix}`);
48
+ }
49
+ return err;
50
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Make an assertion that `actual` and `expected` are strictly equal. If
3
+ * not then throw.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { assertStrictEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_strict_equals.ts";
8
+ *
9
+ * Deno.test("isStrictlyEqual", function (): void {
10
+ * const a = {};
11
+ * const b = a;
12
+ * assertStrictEquals(a, b);
13
+ * });
14
+ *
15
+ * // This test fails
16
+ * Deno.test("isNotStrictlyEqual", function (): void {
17
+ * const a = {};
18
+ * const b = {};
19
+ * assertStrictEquals(a, b);
20
+ * });
21
+ * ```
22
+ */
23
+ export declare function assertStrictEquals<T>(actual: unknown, expected: T, msg?: string): asserts actual is T;
@@ -0,0 +1,60 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { format } from "./_format.js";
3
+ import { AssertionError } from "./assertion_error.js";
4
+ import { buildMessage, diff, diffstr } from "../_util/diff.js";
5
+ import { CAN_NOT_DISPLAY } from "./_constants.js";
6
+ import { red } from "../fmt/colors.js";
7
+ /**
8
+ * Make an assertion that `actual` and `expected` are strictly equal. If
9
+ * not then throw.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { assertStrictEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_strict_equals.ts";
14
+ *
15
+ * Deno.test("isStrictlyEqual", function (): void {
16
+ * const a = {};
17
+ * const b = a;
18
+ * assertStrictEquals(a, b);
19
+ * });
20
+ *
21
+ * // This test fails
22
+ * Deno.test("isNotStrictlyEqual", function (): void {
23
+ * const a = {};
24
+ * const b = {};
25
+ * assertStrictEquals(a, b);
26
+ * });
27
+ * ```
28
+ */
29
+ export function assertStrictEquals(actual, expected, msg) {
30
+ if (Object.is(actual, expected)) {
31
+ return;
32
+ }
33
+ const msgSuffix = msg ? `: ${msg}` : ".";
34
+ let message;
35
+ const actualString = format(actual);
36
+ const expectedString = format(expected);
37
+ if (actualString === expectedString) {
38
+ const withOffset = actualString
39
+ .split("\n")
40
+ .map((l) => ` ${l}`)
41
+ .join("\n");
42
+ message =
43
+ `Values have the same structure but are not reference-equal${msgSuffix}\n\n${red(withOffset)}\n`;
44
+ }
45
+ else {
46
+ try {
47
+ const stringDiff = (typeof actual === "string") &&
48
+ (typeof expected === "string");
49
+ const diffResult = stringDiff
50
+ ? diffstr(actual, expected)
51
+ : diff(actualString.split("\n"), expectedString.split("\n"));
52
+ const diffMsg = buildMessage(diffResult, { stringDiff }).join("\n");
53
+ message = `Values are not strictly equal${msgSuffix}\n${diffMsg}`;
54
+ }
55
+ catch {
56
+ message = `\n${red(CAN_NOT_DISPLAY)} + \n\n`;
57
+ }
58
+ }
59
+ throw new AssertionError(message);
60
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Make an assertion that actual includes expected. If not
3
+ * then throw.
4
+ */
5
+ export declare function assertStringIncludes(actual: string, expected: string, msg?: string): void;
@@ -0,0 +1,13 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { AssertionError } from "./assertion_error.js";
3
+ /**
4
+ * Make an assertion that actual includes expected. If not
5
+ * then throw.
6
+ */
7
+ export function assertStringIncludes(actual, expected, msg) {
8
+ if (!actual.includes(expected)) {
9
+ const msgSuffix = msg ? `: ${msg}` : ".";
10
+ msg = `Expected actual: "${actual}" to contain: "${expected}"${msgSuffix}`;
11
+ throw new AssertionError(msg);
12
+ }
13
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Executes a function, expecting it to throw. If it does not, then it
3
+ * throws.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { assertThrows } from "https://deno.land/std@$STD_VERSION/assert/assert_throws.ts";
8
+ *
9
+ * Deno.test("doesThrow", function (): void {
10
+ * assertThrows((): void => {
11
+ * throw new TypeError("hello world!");
12
+ * });
13
+ * });
14
+ *
15
+ * // This test will not pass.
16
+ * Deno.test("fails", function (): void {
17
+ * assertThrows((): void => {
18
+ * console.log("Hello world");
19
+ * });
20
+ * });
21
+ * ```
22
+ */
23
+ export declare function assertThrows(fn: () => unknown, msg?: string): unknown;
24
+ /**
25
+ * Executes a function, expecting it to throw. If it does not, then it
26
+ * throws. An error class and a string that should be included in the
27
+ * error message can also be asserted.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { assertThrows } from "https://deno.land/std@$STD_VERSION/assert/assert_throws.ts";
32
+ *
33
+ * Deno.test("doesThrow", function (): void {
34
+ * assertThrows((): void => {
35
+ * throw new TypeError("hello world!");
36
+ * }, TypeError);
37
+ * assertThrows(
38
+ * (): void => {
39
+ * throw new TypeError("hello world!");
40
+ * },
41
+ * TypeError,
42
+ * "hello",
43
+ * );
44
+ * });
45
+ *
46
+ * // This test will not pass.
47
+ * Deno.test("fails", function (): void {
48
+ * assertThrows((): void => {
49
+ * console.log("Hello world");
50
+ * });
51
+ * });
52
+ * ```
53
+ */
54
+ export declare function assertThrows<E extends Error = Error>(fn: () => unknown, ErrorClass: new (...args: any[]) => E, msgIncludes?: string, msg?: string): E;
@@ -0,0 +1,44 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ import { assertIsError } from "./assert_is_error.js";
3
+ import { AssertionError } from "./assertion_error.js";
4
+ export function assertThrows(fn, errorClassOrMsg, msgIncludesOrMsg, msg) {
5
+ // deno-lint-ignore no-explicit-any
6
+ let ErrorClass = undefined;
7
+ let msgIncludes = undefined;
8
+ let err;
9
+ if (typeof errorClassOrMsg !== "string") {
10
+ if (errorClassOrMsg === undefined ||
11
+ errorClassOrMsg.prototype instanceof Error ||
12
+ errorClassOrMsg.prototype === Error.prototype) {
13
+ // deno-lint-ignore no-explicit-any
14
+ ErrorClass = errorClassOrMsg;
15
+ msgIncludes = msgIncludesOrMsg;
16
+ }
17
+ else {
18
+ msg = msgIncludesOrMsg;
19
+ }
20
+ }
21
+ else {
22
+ msg = errorClassOrMsg;
23
+ }
24
+ let doesThrow = false;
25
+ const msgSuffix = msg ? `: ${msg}` : ".";
26
+ try {
27
+ fn();
28
+ }
29
+ catch (error) {
30
+ if (ErrorClass) {
31
+ if (error instanceof Error === false) {
32
+ throw new AssertionError(`A non-Error object was thrown${msgSuffix}`);
33
+ }
34
+ assertIsError(error, ErrorClass, msgIncludes, msg);
35
+ }
36
+ err = error;
37
+ doesThrow = true;
38
+ }
39
+ if (!doesThrow) {
40
+ msg = `Expected function to throw${msgSuffix}`;
41
+ throw new AssertionError(msg);
42
+ }
43
+ return err;
44
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Deep equality comparison used in assertions
3
+ * @param c actual value
4
+ * @param d expected value
5
+ */
6
+ export declare function equal(c: unknown, d: unknown): boolean;