@plugjs/expect5 0.4.0

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/README.md +7 -0
  2. package/dist/cli.d.mts +2 -0
  3. package/dist/cli.mjs +96 -0
  4. package/dist/cli.mjs.map +6 -0
  5. package/dist/execution/executable.cjs +299 -0
  6. package/dist/execution/executable.cjs.map +6 -0
  7. package/dist/execution/executable.d.ts +87 -0
  8. package/dist/execution/executable.mjs +260 -0
  9. package/dist/execution/executable.mjs.map +6 -0
  10. package/dist/execution/executor.cjs +125 -0
  11. package/dist/execution/executor.cjs.map +6 -0
  12. package/dist/execution/executor.d.ts +35 -0
  13. package/dist/execution/executor.mjs +90 -0
  14. package/dist/execution/executor.mjs.map +6 -0
  15. package/dist/execution/setup.cjs +127 -0
  16. package/dist/execution/setup.cjs.map +6 -0
  17. package/dist/execution/setup.d.ts +31 -0
  18. package/dist/execution/setup.mjs +87 -0
  19. package/dist/execution/setup.mjs.map +6 -0
  20. package/dist/expectation/basic.cjs +216 -0
  21. package/dist/expectation/basic.cjs.map +6 -0
  22. package/dist/expectation/basic.d.ts +47 -0
  23. package/dist/expectation/basic.mjs +177 -0
  24. package/dist/expectation/basic.mjs.map +6 -0
  25. package/dist/expectation/diff.cjs +253 -0
  26. package/dist/expectation/diff.cjs.map +6 -0
  27. package/dist/expectation/diff.d.ts +27 -0
  28. package/dist/expectation/diff.mjs +228 -0
  29. package/dist/expectation/diff.mjs.map +6 -0
  30. package/dist/expectation/expect.cjs +211 -0
  31. package/dist/expectation/expect.cjs.map +6 -0
  32. package/dist/expectation/expect.d.ts +140 -0
  33. package/dist/expectation/expect.mjs +219 -0
  34. package/dist/expectation/expect.mjs.map +6 -0
  35. package/dist/expectation/include.cjs +187 -0
  36. package/dist/expectation/include.cjs.map +6 -0
  37. package/dist/expectation/include.d.ts +10 -0
  38. package/dist/expectation/include.mjs +158 -0
  39. package/dist/expectation/include.mjs.map +6 -0
  40. package/dist/expectation/print.cjs +281 -0
  41. package/dist/expectation/print.cjs.map +6 -0
  42. package/dist/expectation/print.d.ts +4 -0
  43. package/dist/expectation/print.mjs +256 -0
  44. package/dist/expectation/print.mjs.map +6 -0
  45. package/dist/expectation/throwing.cjs +58 -0
  46. package/dist/expectation/throwing.cjs.map +6 -0
  47. package/dist/expectation/throwing.d.ts +8 -0
  48. package/dist/expectation/throwing.mjs +32 -0
  49. package/dist/expectation/throwing.mjs.map +6 -0
  50. package/dist/expectation/types.cjs +212 -0
  51. package/dist/expectation/types.cjs.map +6 -0
  52. package/dist/expectation/types.d.ts +57 -0
  53. package/dist/expectation/types.mjs +178 -0
  54. package/dist/expectation/types.mjs.map +6 -0
  55. package/dist/expectation/void.cjs +111 -0
  56. package/dist/expectation/void.cjs.map +6 -0
  57. package/dist/expectation/void.d.ts +39 -0
  58. package/dist/expectation/void.mjs +77 -0
  59. package/dist/expectation/void.mjs.map +6 -0
  60. package/dist/globals.cjs +2 -0
  61. package/dist/globals.cjs.map +6 -0
  62. package/dist/globals.d.ts +23 -0
  63. package/dist/globals.mjs +1 -0
  64. package/dist/globals.mjs.map +6 -0
  65. package/dist/index.cjs +66 -0
  66. package/dist/index.cjs.map +6 -0
  67. package/dist/index.d.ts +29 -0
  68. package/dist/index.mjs +41 -0
  69. package/dist/index.mjs.map +6 -0
  70. package/dist/test.cjs +229 -0
  71. package/dist/test.cjs.map +6 -0
  72. package/dist/test.d.ts +9 -0
  73. package/dist/test.mjs +194 -0
  74. package/dist/test.mjs.map +6 -0
  75. package/package.json +57 -0
  76. package/src/cli.mts +122 -0
  77. package/src/execution/executable.ts +364 -0
  78. package/src/execution/executor.ts +146 -0
  79. package/src/execution/setup.ts +108 -0
  80. package/src/expectation/basic.ts +209 -0
  81. package/src/expectation/diff.ts +445 -0
  82. package/src/expectation/expect.ts +401 -0
  83. package/src/expectation/include.ts +184 -0
  84. package/src/expectation/print.ts +386 -0
  85. package/src/expectation/throwing.ts +45 -0
  86. package/src/expectation/types.ts +263 -0
  87. package/src/expectation/void.ts +80 -0
  88. package/src/globals.ts +30 -0
  89. package/src/index.ts +54 -0
  90. package/src/test.ts +239 -0
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ Unit Testing for the PlugJS Build System
2
+ ========================================
3
+
4
+ Prototype build system from [Juit GmbH](https://www.juit.com/)
5
+
6
+ * [Copyright Notice](https://github.com/plugjs/plug/blob/main/NOTICE.md)
7
+ * [License](https://github.com/plugjs/plug/blob/main/LICENSE.md)
package/dist/cli.d.mts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.mjs ADDED
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env node
2
+
3
+ // cli.mts
4
+ import { async, find, paths, pipe, logging } from "@plugjs/plug";
5
+ import { main, yargsParser } from "@plugjs/tsrun";
6
+ import { Test } from "./test.mjs";
7
+ var { $blu, $und, $gry, $wht } = logging;
8
+ var $gnd = (s) => $gry($und(s));
9
+ var $bnd = (s) => $blu($und(s));
10
+ var $wnd = (s) => $wht($und(s));
11
+ var version = true ? "0.4.0" : "0.0.0-dev";
12
+ function help() {
13
+ console.log(`${$blu($und("Usage:"))}
14
+
15
+ ${$wht("expect5")} ${$gry("[")}--options${$gry("] [...")}globs${$gry("...]")}
16
+
17
+ ${$bnd("Options:")}
18
+
19
+ ${$wht("-d --directory")} ${$gnd("dir")} Directory where tests are to be found
20
+ ${$wht("-h --help ")} Help! You're reading it now!
21
+ ${$wht(" --version ")} Version! This one: ${version}!
22
+
23
+ ${$bnd("Globs:")}
24
+
25
+ Other arguments will be treated as globs, used to match test files in
26
+ the specified directory (defaults to the current directory).
27
+
28
+ If no globs are specified, the default will be to find all JavaScript
29
+ and TypeScript files in the ${$wnd("./test")} directory, prefixed by the ${$wnd(".test")}
30
+ extension ${$gry("(for example")} ${$und("foobar.test.ts")}${$gry(")")}.
31
+
32
+ ${$bnd("Environment Variables:")}
33
+
34
+ ${$wht("LOG_LEVEL ")} The default ${$wnd("notice")}, or ${$gnd("debug")}, ${$gnd("info")}, ${$gnd("warn")} or ${$gnd("error")}.
35
+ ${$wht("NODE_V8_COVERAGE")} The directory where Node will write coverage data to.
36
+
37
+ ${$bnd("TypeScript module format:")}
38
+
39
+ Normally our TypeScript loader will transpile ${$wnd(".ts")} files to the type
40
+ specified in ${$wnd("package.json")}, either ${$wnd("commonjs")} (the default) or ${$wnd("module")}.
41
+
42
+ To force a specific module format use one of the following flags:
43
+
44
+ ${$wht("--force-esm")} Force transpilation of ${$wnd(".ts")} files to EcmaScript modules
45
+ ${$wht("--force-cjs")} Force transpilation of ${$wnd(".ts")} files to CommonJS modules
46
+ `);
47
+ process.exit(0);
48
+ }
49
+ main(import.meta.url, async (args) => {
50
+ logging.logOptions.spinner = false;
51
+ const filename = paths.requireFilename(import.meta.url);
52
+ const context = new pipe.Context(filename, "");
53
+ let directory = ".";
54
+ const globs = [];
55
+ const parsed = yargsParser(args, {
56
+ configuration: {
57
+ "camel-case-expansion": false,
58
+ "strip-aliased": true,
59
+ "strip-dashed": true
60
+ },
61
+ alias: {
62
+ "directory": ["d"],
63
+ "help": ["h"]
64
+ },
65
+ string: ["directory"],
66
+ boolean: ["help", "version"]
67
+ });
68
+ for (const [key, value] of Object.entries(parsed)) {
69
+ switch (key) {
70
+ case "_":
71
+ globs.push(...value);
72
+ break;
73
+ case "directory":
74
+ directory = context.resolve(value);
75
+ break;
76
+ case "help":
77
+ return help();
78
+ case "version":
79
+ return context.log.notice(`Expect5 ${$gry("ver.")} ${$wnd(version)}`);
80
+ default:
81
+ context.log.error(`Unsupported option ${$wnd(key)} (try ${$wnd("--help")})`);
82
+ process.exit(1);
83
+ }
84
+ }
85
+ const glob = globs.shift() || "test/**/*.test.([cm])?[jt]s";
86
+ try {
87
+ process.exitCode = 0;
88
+ await async.runAsync(context, "", () => {
89
+ return find(glob, ...globs, { directory }).plug(new Test());
90
+ });
91
+ } catch (error) {
92
+ context.log.error(error);
93
+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,MAAM;AACtC,aAAO,KAAK,MAAM,GAAG,OAAO,EAAE,UAAU,CAAC,EAAE,KAAK,IAAI,KAAK,CAAC;AAAA,IAC5D,CAAC;AAAA,EACH,SAAS,OAAP;AACA,YAAQ,IAAI,MAAM,KAAK;AACvB,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF,CAAC;",
5
+ "names": []
6
+ }
@@ -0,0 +1,299 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // execution/executable.ts
31
+ var executable_exports = {};
32
+ __export(executable_exports, {
33
+ Hook: () => Hook,
34
+ Spec: () => Spec,
35
+ Suite: () => Suite,
36
+ getCurrentSuite: () => getCurrentSuite,
37
+ skip: () => skip
38
+ });
39
+ module.exports = __toCommonJS(executable_exports);
40
+ var import_node_assert = __toESM(require("node:assert"), 1);
41
+ var import_node_async_hooks = require("node:async_hooks");
42
+ function execute(call, timeout, notify) {
43
+ return new Promise((resolve) => {
44
+ let resolved = false;
45
+ const abort = new AbortController();
46
+ const handle = setTimeout(() => {
47
+ if (resolved)
48
+ return;
49
+ const error = new Error(`Timeout of ${timeout} ms reached`);
50
+ resolve(error);
51
+ notify?.(error);
52
+ resolved = true;
53
+ }, timeout).unref();
54
+ void Promise.resolve().then(async () => {
55
+ try {
56
+ await call.call(void 0, abort.signal);
57
+ resolve(void 0);
58
+ resolved = true;
59
+ } catch (cause) {
60
+ const error = cause instanceof Error ? cause : new Error(String(cause));
61
+ notify?.(error);
62
+ resolve(error);
63
+ resolved = true;
64
+ } finally {
65
+ abort.abort("Spec finished");
66
+ clearTimeout(handle);
67
+ }
68
+ });
69
+ });
70
+ }
71
+ var suiteKey = Symbol.for("plugjs.expect5.async.suiteStorage");
72
+ var skipKey = Symbol.for("plugjs.expect5.async.skipStorage");
73
+ function getSuiteStorage() {
74
+ let storage = globalThis[suiteKey];
75
+ if (!storage) {
76
+ storage = new import_node_async_hooks.AsyncLocalStorage();
77
+ globalThis[suiteKey] = storage;
78
+ }
79
+ return storage;
80
+ }
81
+ function getSkipStorage() {
82
+ let storage = globalThis[skipKey];
83
+ if (!storage) {
84
+ storage = new import_node_async_hooks.AsyncLocalStorage();
85
+ globalThis[skipKey] = storage;
86
+ }
87
+ return storage;
88
+ }
89
+ var suiteStorage = getSuiteStorage();
90
+ var skipStorage = getSkipStorage();
91
+ function getCurrentSuite() {
92
+ const suite = suiteStorage.getStore();
93
+ (0, import_node_assert.default)(suite, "No suite found");
94
+ return suite;
95
+ }
96
+ function skip() {
97
+ const skipState = skipStorage.getStore();
98
+ (0, import_node_assert.default)(skipState, 'The "skip" function can only be used in specs or hooks');
99
+ skipState.skipped = true;
100
+ }
101
+ var suiteMarker = Symbol.for("plugjs:expect5:marker:Suite");
102
+ var Suite = class {
103
+ constructor(parent, name, call, timeout = 5e3, flag = void 0) {
104
+ this.parent = parent;
105
+ this.name = name;
106
+ this.call = call;
107
+ this.timeout = timeout;
108
+ this.flag = flag;
109
+ }
110
+ _beforeAll = [];
111
+ _beforeEach = [];
112
+ _afterAll = [];
113
+ _afterEach = [];
114
+ _suites = [];
115
+ _specs = [];
116
+ _children = [];
117
+ _setup = false;
118
+ static {
119
+ this.prototype[suiteMarker] = suiteMarker;
120
+ }
121
+ static [Symbol.hasInstance](instance) {
122
+ return instance && instance[suiteMarker] === suiteMarker;
123
+ }
124
+ get specs() {
125
+ return this._suites.reduce((n, s) => n + s.specs, 0) + this._specs.length;
126
+ }
127
+ /** Add a child {@link Suite} to this */
128
+ addSuite(suite) {
129
+ import_node_assert.default.strictEqual(suite.parent, this, "Suite is not a child of this");
130
+ this._children.push(suite);
131
+ this._suites.push(suite);
132
+ }
133
+ /** Add a {@link Spec} to this */
134
+ addSpec(spec) {
135
+ import_node_assert.default.strictEqual(spec.parent, this, "Spec is not a child of this");
136
+ this._children.push(spec);
137
+ this._specs.push(spec);
138
+ }
139
+ /** Add a _before all_ {@link Hook} to this */
140
+ addBeforeAllHook(hook) {
141
+ import_node_assert.default.strictEqual(hook.parent, this, "Hook is not a child of this");
142
+ import_node_assert.default.strictEqual(hook.name, "beforeAll", `Invalid before all hook name "${hook.name}"`);
143
+ this._beforeAll.push(hook);
144
+ }
145
+ /** Add a _before each_ {@link Hook} to this */
146
+ addBeforeEachHook(hook) {
147
+ import_node_assert.default.strictEqual(hook.parent, this, "Hook is not a child of this");
148
+ import_node_assert.default.strictEqual(hook.name, "beforeEach", `Invalid before each hook name "${hook.name}"`);
149
+ this._beforeEach.push(hook);
150
+ }
151
+ /** Add a _after all_ {@link Hook} to this */
152
+ addAfterAllHook(hook) {
153
+ import_node_assert.default.strictEqual(hook.parent, this, "Hook is not a child of this");
154
+ import_node_assert.default.strictEqual(hook.name, "afterAll", `Invalid after all hook name "${hook.name}"`);
155
+ this._afterAll.push(hook);
156
+ }
157
+ /** Add a _after each_ {@link Hook} to this */
158
+ addAfterEachHook(hook) {
159
+ import_node_assert.default.strictEqual(hook.parent, this, "Hook is not a child of this");
160
+ import_node_assert.default.strictEqual(hook.name, "afterEach", `Invalid after each hook name "${hook.name}"`);
161
+ this._afterEach.push(hook);
162
+ }
163
+ /**
164
+ * Setup this {@link Suite} invoking its main function, then initializing all
165
+ * children {@link Suite Suites}, and finally normalizing execution flags.
166
+ */
167
+ async setup() {
168
+ if (this._setup)
169
+ return;
170
+ this._setup = true;
171
+ await suiteStorage.run(this, async () => {
172
+ const error = await execute(this.call, this.timeout);
173
+ if (error)
174
+ throw error;
175
+ });
176
+ if (this.parent) {
177
+ this._beforeEach.unshift(...this.parent._beforeEach.map((h) => h.clone(this)));
178
+ this._afterEach.push(...this.parent._afterEach.map((h) => h.clone(this)));
179
+ }
180
+ for (const suite of this._suites) {
181
+ await suite.setup();
182
+ }
183
+ for (const spec of this._specs) {
184
+ spec.before.push(...this._beforeEach.map((h) => h.clone(spec)));
185
+ spec.after.push(...this._afterEach.map((h) => h.clone(spec)));
186
+ }
187
+ const only = this._children.reduce((o, c) => o || c.flag === "only", false);
188
+ if (only) {
189
+ this._children.forEach((c) => c.flag !== "only" && (c.flag = "skip"));
190
+ this.flag = "only";
191
+ }
192
+ if (this.flag === "only") {
193
+ this._children.forEach((c) => c.flag !== "skip" && (c.flag = "only"));
194
+ }
195
+ for (const child of this._children) {
196
+ if (child.flag !== "skip")
197
+ return;
198
+ }
199
+ this.flag = "skip";
200
+ }
201
+ /**
202
+ * Execute this suite, executing all {@link Hook hooks} and children
203
+ * {@link Spec specs} and {@link Suite suites}
204
+ */
205
+ async execute(executor, skip2 = false) {
206
+ const { done } = executor.start(this);
207
+ if (skip2 || this.flag === "skip") {
208
+ for (const child of this._children)
209
+ await child.execute(executor, true);
210
+ return done();
211
+ }
212
+ for (const hook of this._beforeAll) {
213
+ const failed = await hook.execute(executor);
214
+ if (failed) {
215
+ for (const child of this._children)
216
+ await child.execute(executor, true);
217
+ return done();
218
+ }
219
+ }
220
+ for (const child of this._children)
221
+ await child.execute(executor);
222
+ for (const hook of this._afterAll)
223
+ await hook.execute(executor);
224
+ done();
225
+ }
226
+ };
227
+ var specMarker = Symbol.for("plugjs:expect5:marker:Spec");
228
+ var Spec = class {
229
+ constructor(parent, name, call, timeout = 5e3, flag = void 0) {
230
+ this.parent = parent;
231
+ this.name = name;
232
+ this.call = call;
233
+ this.timeout = timeout;
234
+ this.flag = flag;
235
+ }
236
+ before = [];
237
+ after = [];
238
+ static {
239
+ this.prototype[specMarker] = specMarker;
240
+ }
241
+ static [Symbol.hasInstance](instance) {
242
+ return instance && instance[specMarker] === specMarker;
243
+ }
244
+ /** Execute this spec */
245
+ async execute(executor, skip2 = false) {
246
+ const { done, notify } = executor.start(this);
247
+ if (skip2 || this.flag == "skip")
248
+ return done(true);
249
+ for (const hook of this.before) {
250
+ const failed = await hook.execute(executor);
251
+ if (failed)
252
+ return done(true);
253
+ }
254
+ const skipState = { skipped: false };
255
+ await skipStorage.run(skipState, () => execute(this.call, this.timeout, notify));
256
+ for (const hook of this.after)
257
+ await hook.execute(executor);
258
+ return done(skipState.skipped);
259
+ }
260
+ };
261
+ var hookMarker = Symbol.for("plugjs:expect5:marker:Hook");
262
+ var Hook = class {
263
+ constructor(parent, name, call, timeout = 5e3, flag = void 0) {
264
+ this.parent = parent;
265
+ this.name = name;
266
+ this.call = call;
267
+ this.timeout = timeout;
268
+ this.flag = flag;
269
+ }
270
+ static {
271
+ this.prototype[hookMarker] = hookMarker;
272
+ }
273
+ static [Symbol.hasInstance](instance) {
274
+ return instance && instance[hookMarker] === hookMarker;
275
+ }
276
+ /** Execute this hook */
277
+ async execute(executor) {
278
+ if (this.flag === "skip")
279
+ return false;
280
+ const { done, notify } = executor.start(this);
281
+ const skipState = { skipped: false };
282
+ const error = await skipStorage.run(skipState, () => execute(this.call, this.timeout, notify));
283
+ done(skipState.skipped);
284
+ return !!error;
285
+ }
286
+ /** Clone this associating it with a new {@link Suite} or {@link Spec} */
287
+ clone(parent) {
288
+ return new Hook(parent, this.name, this.call, this.timeout, this.flag);
289
+ }
290
+ };
291
+ // Annotate the CommonJS export names for ESM import in node:
292
+ 0 && (module.exports = {
293
+ Hook,
294
+ Spec,
295
+ Suite,
296
+ getCurrentSuite,
297
+ skip
298
+ });
299
+ //# sourceMappingURL=executable.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/execution/executable.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAmB;AACnB,8BAAkC;AAuBlC,SAAS,QACL,MACA,SACA,QAC0B;AAC5B,SAAO,IAAI,QAA2B,CAAC,YAAY;AACjD,QAAI,WAAW;AAGf,UAAM,QAAQ,IAAI,gBAAgB;AAClC,UAAM,SAAS,WAAW,MAAM;AAE9B,UAAI;AAAU;AAEd,YAAM,QAAQ,IAAI,MAAM,cAAc,oBAAoB;AAC1D,cAAQ,KAAK;AACb,eAAS,KAAK;AACd,iBAAW;AAAA,IACb,GAAG,OAAO,EAAE,MAAM;AAGlB,SAAK,QAAQ,QAAQ,EAAE,KAAK,YAAY;AACtC,UAAI;AACF,cAAM,KAAK,KAAK,QAAW,MAAM,MAAM;AACvC,gBAAQ,MAAS;AACjB,mBAAW;AAAA,MACb,SAAS,OAAP;AACA,cAAM,QAAQ,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AACtE,iBAAS,KAAK;AACd,gBAAQ,KAAK;AACb,mBAAW;AAAA,MACb,UAAE;AACA,cAAM,MAAM,eAAe;AAC3B,qBAAa,MAAM;AAAA,MACrB;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;AAWA,IAAM,WAAW,OAAO,IAAI,mCAAmC;AAC/D,IAA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/E,eAAW,QAAQ,KAAK;AAAO,YAAM,KAAK,QAAQ,QAAQ;AAG1D,WAAO,KAAK,UAAU,OAAO;AAAA,EAC/B;AACF;AAKA,IAAM,aAAa,OAAO,IAAI,4BAA4B;AAGnD,IAAM,OAAN,MAAW;AAAA,EAChB,YACoB,QACA,MACA,MACA,UAAkB,KAClB,OAA8B,QAChD;AALkB;AACA;AACA;AACA;AACA;AAAA,EACjB;AAAA,EAEH,OAAO;AACL,IAAC,KAAK,UAAkB,UAAU,IAAI;AAAA,EACxC;AAAA,EAEA,QAAQ,OAAO,WAAW,EAAE,UAAwB;AAClD,WAAO,YAAY,SAAS,UAAU,MAAM;AAAA,EAC9C;AAAA;AAAA,EAGA,MAAM,QAAQ,UAAsC;AAClD,QAAI,KAAK,SAAS;AAAQ,aAAO;AACjC,UAAM,EAAE,MAAM,OAAO,IAAI,SAAS,MAAM,IAAI;AAE5C,UAAM,YAAY,EAAE,SAAS,MAAM;AACnC,UAAM,QAAQ,MAAM,YAAY,IAAI,WAAW,MAAM,QAAQ,KAAK,MAAM,KAAK,SAAS,MAAM,CAAC;AAC7F,SAAK,UAAU,OAAO;AACtB,WAAO,CAAC,CAAE;AAAA,EACZ;AAAA;AAAA,EAGA,MAAM,QAA4B;AAChC,WAAO,IAAI,KAAK,QAAQ,KAAK,MAAM,KAAK,MAAM,KAAK,SAAS,KAAK,IAAI;AAAA,EACvE;AACF;",
5
+ "names": ["assert", "skip"]
6
+ }
@@ -0,0 +1,87 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * A _callable_ (possibly async) function.
4
+ *
5
+ * When the timeout configured is reached, the passed `signal` will be aborted.
6
+ */
7
+ export type Call = (this: undefined, signal: AbortSignal) => void | Promise<void>;
8
+ /** Flag types for an {@link Executable} */
9
+ export type Flag = 'skip' | 'only' | undefined;
10
+ /** An {@link Executor} notifying lifecycle events for {@link Executable}s */
11
+ export interface Executor {
12
+ start(executable: Suite | Spec | Hook): {
13
+ notify(error: Error): void;
14
+ done(skip?: boolean): void;
15
+ };
16
+ }
17
+ export declare function getCurrentSuite(): Suite;
18
+ export declare function skip(): void;
19
+ /** Our {@link Suite} implementation */
20
+ export declare class Suite {
21
+ readonly parent: Suite | undefined;
22
+ readonly name: string;
23
+ readonly call: Call;
24
+ readonly timeout: number;
25
+ flag: Flag;
26
+ private _beforeAll;
27
+ private _beforeEach;
28
+ private _afterAll;
29
+ private _afterEach;
30
+ private _suites;
31
+ private _specs;
32
+ private _children;
33
+ private _setup;
34
+ constructor(parent: Suite | undefined, name: string, call: Call, timeout?: number, flag?: Flag);
35
+ static [Symbol.hasInstance](instance: any): boolean;
36
+ get specs(): number;
37
+ /** Add a child {@link Suite} to this */
38
+ addSuite(suite: Suite): void;
39
+ /** Add a {@link Spec} to this */
40
+ addSpec(spec: Spec): void;
41
+ /** Add a _before all_ {@link Hook} to this */
42
+ addBeforeAllHook(hook: Hook): void;
43
+ /** Add a _before each_ {@link Hook} to this */
44
+ addBeforeEachHook(hook: Hook): void;
45
+ /** Add a _after all_ {@link Hook} to this */
46
+ addAfterAllHook(hook: Hook): void;
47
+ /** Add a _after each_ {@link Hook} to this */
48
+ addAfterEachHook(hook: Hook): void;
49
+ /**
50
+ * Setup this {@link Suite} invoking its main function, then initializing all
51
+ * children {@link Suite Suites}, and finally normalizing execution flags.
52
+ */
53
+ setup(): Promise<void>;
54
+ /**
55
+ * Execute this suite, executing all {@link Hook hooks} and children
56
+ * {@link Spec specs} and {@link Suite suites}
57
+ */
58
+ execute(executor: Executor, skip?: boolean): Promise<Error | void>;
59
+ }
60
+ /** Our {@link Spec} implementation */
61
+ export declare class Spec {
62
+ readonly parent: Suite;
63
+ readonly name: string;
64
+ readonly call: Call;
65
+ readonly timeout: number;
66
+ flag: Flag;
67
+ before: Hook[];
68
+ after: Hook[];
69
+ constructor(parent: Suite, name: string, call: Call, timeout?: number, flag?: Flag);
70
+ static [Symbol.hasInstance](instance: any): boolean;
71
+ /** Execute this spec */
72
+ execute(executor: Executor, skip?: boolean): Promise<void>;
73
+ }
74
+ /** Our {@link Hook} implementation */
75
+ export declare class Hook {
76
+ readonly parent: Suite | Spec;
77
+ readonly name: 'beforeAll' | 'afterAll' | 'beforeEach' | 'afterEach';
78
+ readonly call: Call;
79
+ readonly timeout: number;
80
+ readonly flag: Exclude<Flag, 'only'>;
81
+ constructor(parent: Suite | Spec, name: 'beforeAll' | 'afterAll' | 'beforeEach' | 'afterEach', call: Call, timeout?: number, flag?: Exclude<Flag, 'only'>);
82
+ static [Symbol.hasInstance](instance: any): boolean;
83
+ /** Execute this hook */
84
+ execute(executor: Executor): Promise<boolean>;
85
+ /** Clone this associating it with a new {@link Suite} or {@link Spec} */
86
+ clone(parent: Suite | Spec): Hook;
87
+ }