@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/dist/test.cjs ADDED
@@ -0,0 +1,229 @@
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
+ // test.ts
31
+ var test_exports = {};
32
+ __export(test_exports, {
33
+ Test: () => Test
34
+ });
35
+ module.exports = __toCommonJS(test_exports);
36
+ var import_node_assert = require("node:assert");
37
+ var import_plug = require("@plugjs/plug");
38
+ var import_logging = require("@plugjs/plug/logging");
39
+ var import_asserts = require("@plugjs/plug/asserts");
40
+ var import_executable = require("./execution/executable.cjs");
41
+ var import_executor = require("./execution/executor.cjs");
42
+ var import_expect = require("./expectation/expect.cjs");
43
+ var import_types = require("./expectation/types.cjs");
44
+ var import_print = require("./expectation/print.cjs");
45
+ var import_diff = require("./expectation/diff.cjs");
46
+ var setup = __toESM(require("./execution/setup.cjs"), 1);
47
+ var _pending = "\u22EF";
48
+ var _success = "\u2714";
49
+ var _failure = "\u2718";
50
+ var _details = "\u2192";
51
+ var Test = class {
52
+ constructor(_options = {}) {
53
+ this._options = _options;
54
+ }
55
+ async pipe(files, context) {
56
+ (0, import_asserts.assert)(files.length, "No files available for running tests");
57
+ const {
58
+ globals = true,
59
+ genericErrorDiffs = true,
60
+ maxFailures = Number.POSITIVE_INFINITY
61
+ } = this._options;
62
+ if (globals) {
63
+ const anyGlobal = globalThis;
64
+ anyGlobal["describe"] = setup.describe;
65
+ anyGlobal["fdescribe"] = setup.fdescribe;
66
+ anyGlobal["xdescribe"] = setup.xdescribe;
67
+ anyGlobal["it"] = setup.it;
68
+ anyGlobal["fit"] = setup.fit;
69
+ anyGlobal["xit"] = setup.xit;
70
+ anyGlobal["afterAll"] = setup.afterAll;
71
+ anyGlobal["afterEach"] = setup.afterEach;
72
+ anyGlobal["beforeAll"] = setup.beforeAll;
73
+ anyGlobal["beforeEach"] = setup.beforeEach;
74
+ anyGlobal["xafterAll"] = setup.xafterAll;
75
+ anyGlobal["xafterEach"] = setup.xafterEach;
76
+ anyGlobal["xbeforeAll"] = setup.xbeforeAll;
77
+ anyGlobal["xbeforeEach"] = setup.xbeforeEach;
78
+ anyGlobal["skip"] = import_executable.skip;
79
+ anyGlobal["expect"] = import_expect.expect;
80
+ anyGlobal["log"] = import_logging.log;
81
+ }
82
+ const suite = new import_executable.Suite(void 0, "", async () => {
83
+ for (const file of files.absolutePaths())
84
+ await import(file);
85
+ });
86
+ await suite.setup();
87
+ const snum = suite.specs;
88
+ const fnum = files.length;
89
+ const smsg = snum === 1 ? "spec" : "specs";
90
+ const fmsg = fnum === 1 ? "file" : "files";
91
+ (0, import_asserts.assert)(snum, "No specs configured by test files");
92
+ const execution = (0, import_executor.runSuite)(suite);
93
+ execution.on("suite:start", (current) => {
94
+ if (current.parent === suite) {
95
+ if (suite.flag !== "only")
96
+ context.log.notice("");
97
+ context.log.enter(import_logging.NOTICE, `${(0, import_logging.$wht)(current.name)}`);
98
+ context.log.notice("");
99
+ } else if (current.parent) {
100
+ context.log.enter(import_logging.NOTICE, `${(0, import_logging.$blu)(_details)} ${(0, import_logging.$wht)(current.name)}`);
101
+ } else {
102
+ context.log.notice(`Running ${(0, import_logging.$ylw)(snum)} ${smsg} from ${(0, import_logging.$ylw)(fnum)} ${fmsg}`);
103
+ if (suite.flag === "only")
104
+ context.log.notice("");
105
+ }
106
+ });
107
+ execution.on("suite:done", (current) => {
108
+ if (current.parent)
109
+ context.log.leave();
110
+ });
111
+ execution.on("spec:start", (spec) => {
112
+ context.log.enter(import_logging.NOTICE, `${(0, import_logging.$blu)(_pending)} ${spec.name}`);
113
+ });
114
+ execution.on("spec:skip", (spec, ms) => {
115
+ if (suite.flag === "only")
116
+ return context.log.leave();
117
+ context.log.leave(import_logging.WARN, `${(0, import_logging.$ylw)(_pending)} ${spec.name} ${(0, import_logging.$ms)(ms)} ${(0, import_logging.$gry)("[")}${(0, import_logging.$ylw)("skipped")}${(0, import_logging.$gry)("]")}`);
118
+ });
119
+ execution.on("spec:pass", (spec, ms) => {
120
+ context.log.leave(import_logging.NOTICE, `${(0, import_logging.$grn)(_success)} ${spec.name} ${(0, import_logging.$ms)(ms)}`);
121
+ });
122
+ execution.on("spec:fail", (spec, ms, { number }) => {
123
+ context.log.leave(
124
+ import_logging.ERROR,
125
+ `${(0, import_logging.$red)(_failure)} ${spec.name} ${(0, import_logging.$ms)(ms)} ${(0, import_logging.$gry)("[")}${(0, import_logging.$red)("failed")}${(0, import_logging.$gry)("|")}${(0, import_logging.$red)(`${number}`)}${(0, import_logging.$gry)("]")}`
126
+ );
127
+ });
128
+ execution.on("hook:fail", (hook, ms, { number }) => {
129
+ context.log.error(`${(0, import_logging.$red)(_failure)} Hook "${hook.name}" ${(0, import_logging.$ms)(ms)} ${(0, import_logging.$gry)("[")}${(0, import_logging.$red)("failed")}${(0, import_logging.$gry)("|")}${(0, import_logging.$red)(`${number}`)}${(0, import_logging.$gry)("]")}`);
130
+ });
131
+ const { failed, passed, skipped, failures, time } = await execution.result;
132
+ const limit = Math.min(failures.length, maxFailures);
133
+ for (let i = 0; i < limit; i++) {
134
+ if (i === 0)
135
+ context.log.error("");
136
+ const { source, error, number } = failures[i];
137
+ const names = [""];
138
+ for (let p = source.parent; p?.parent; p = p.parent) {
139
+ if (p)
140
+ names.unshift(p.name);
141
+ }
142
+ const details = names.join(` ${(0, import_logging.$gry)(_details)} `) + (0, import_logging.$wht)(source.name);
143
+ context.log.enter(import_logging.ERROR, `${(0, import_logging.$gry)("[")}${(0, import_logging.$red)(number)}${(0, import_logging.$gry)("]:")} ${details}`);
144
+ dumpError(context.log, error, genericErrorDiffs);
145
+ context.log.leave();
146
+ }
147
+ const summary = [`${passed} ${(0, import_logging.$gry)("passed")}`];
148
+ if (skipped)
149
+ summary.push(`${skipped} ${(0, import_logging.$gry)("skipped")}`);
150
+ if (failed)
151
+ summary.push(`${failed} ${(0, import_logging.$gry)("failed")}`);
152
+ if (failures.length)
153
+ summary.push(`${failures.length} ${(0, import_logging.$gry)("total failures")}`);
154
+ const epilogue = ` ${(0, import_logging.$gry)("(")}${summary.join((0, import_logging.$gry)(", "))}${(0, import_logging.$gry)(")")}`;
155
+ const message = `Ran ${(0, import_logging.$ylw)(snum)} ${smsg} from ${(0, import_logging.$ylw)(fnum)} ${fmsg}${epilogue} ${(0, import_logging.$ms)(time)}`;
156
+ if (failures.length) {
157
+ context.log.error(message);
158
+ throw new import_plug.BuildFailure();
159
+ } else if (suite.flag === "only") {
160
+ context.log.error("");
161
+ context.log.error(message);
162
+ throw new import_plug.BuildFailure('Suite running in focus ("only") mode');
163
+ } else if (skipped) {
164
+ context.log.warn("");
165
+ context.log.warn(message);
166
+ } else {
167
+ context.log.notice("");
168
+ context.log.notice(message);
169
+ }
170
+ }
171
+ };
172
+ function dumpError(log2, error, genericErrorDiffs) {
173
+ if (error instanceof import_types.ExpectationError) {
174
+ log2.enter(import_logging.ERROR, `${(0, import_logging.$gry)("Expectation Error:")} ${(0, import_logging.$red)(error.message)}`);
175
+ try {
176
+ dumpStack(log2, error);
177
+ if (error.diff)
178
+ (0, import_print.printDiff)(log2, error.diff);
179
+ } finally {
180
+ log2.error("");
181
+ log2.leave();
182
+ }
183
+ } else if (error instanceof import_node_assert.AssertionError) {
184
+ const [message = "Unknown Error", ...lines] = error.message.split("\n");
185
+ log2.enter(import_logging.ERROR, `${(0, import_logging.$gry)("Assertion Error:")} ${(0, import_logging.$red)(message)}`);
186
+ try {
187
+ dumpStack(log2, error);
188
+ if (genericErrorDiffs) {
189
+ if (!error.generatedMessage)
190
+ for (const line of lines)
191
+ log2.error(" ", line);
192
+ (0, import_print.printDiff)(log2, (0, import_diff.diff)(error.actual, error.expected));
193
+ } else {
194
+ while (lines.length && !lines[0])
195
+ lines.shift();
196
+ for (const line of lines)
197
+ log2.error(" ", line);
198
+ }
199
+ } finally {
200
+ log2.error("");
201
+ log2.leave();
202
+ }
203
+ } else if (error instanceof Error) {
204
+ const message = error.message || "Unknown Error";
205
+ const type = (0, import_types.stringifyObjectType)(error);
206
+ log2.enter(import_logging.ERROR, `${(0, import_logging.$gry)(type)}: ${(0, import_logging.$red)(message)}`);
207
+ try {
208
+ dumpStack(log2, error);
209
+ if (genericErrorDiffs && ("actual" in error || "expected" in error)) {
210
+ (0, import_print.printDiff)(log2, (0, import_diff.diff)(error.actual, error.expected));
211
+ }
212
+ } finally {
213
+ log2.error("");
214
+ log2.leave();
215
+ }
216
+ } else {
217
+ log2.error((0, import_logging.$gry)("Uknown error:"), error);
218
+ }
219
+ }
220
+ function dumpStack(log2, error) {
221
+ if (!error.stack)
222
+ return log2.error("<no stack trace>");
223
+ error.stack.split("\n").filter((line) => line.match(/^\s+at\s+/)).map((line) => line.trim()).forEach((line) => log2.error(line));
224
+ }
225
+ // Annotate the CommonJS export names for ESM import in node:
226
+ 0 && (module.exports = {
227
+ Test
228
+ });
229
+ //# sourceMappingURL=test.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/test.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAA+B;AAE/B,kBAA6B;AAC7B,qBAAkF;AAClF,qBAAuB;AAEvB,wBAA4B;AAC5B,sBAAyB;AACzB,oBAAuB;AACvB,mBAAsD;AACtD,mBAA0B;AAC1B,kBAAqB;AACrB,YAAuB;AAOvB,IAAM,WAAW;AACjB,IAAM,WAAW;AACjB,IAAM,WAAW;AACjB,IAAM,WAAW;AAGV,IAAM,OAAN,MAAiC;AAAA,EAEtC,YAA6B,WAAwB,CAAC,GAAG;AAA5B;AAAA,EAA6B;AAAA,EAE1D,MAAM,KAAK,OAAc,SAAiC;AACxD,+BAAO,MAAM,QAAQ,sCAAsC;AAE3D,UAAM;AAAA,MACJ,UAAU;AAAA,MACV,oBAAoB;AAAA,MACpB,cAAc,OAAO;AAAA,IACvB,IAAI,KAAK;AAGT,QAAI,SAAS;AACX,YAAM,YAAY;AAElB,gBAAU,UAAU,IAAU;AAC9B,gBAAU,WAAW,IAAU;AAC/B,gBAAU,WAAW,IAAU;AAC/B,gBAAU,IAAI,IAAU;AACxB,gBAAU,KAAK,IAAU;AACzB,gBAAU,KAAK,IAAU;AACzB,gBAAU,UAAU,IAAU;AAC9B,gBAAU,WAAW,IAAU;AAC/B,gBAAU,WAAW,IAAU;AAC/B,gBAAU,YAAY,IAAU;AAChC,gBAAU,WAAW,IAAU;AAC/B,gBAAU,YAAY,IAAU;AAChC,gBAAU,YAAY,IAAU;AAChC,gBAAU,aAAa,IAAU;AACjC,gBAAU,MAAM,IAAI;AACpB,gBAA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MAAc,QAAQ,CAAC;AAAA,MACrE;AAAA,IACF,UAAE;AACA,MAAAA,KAAI,MAAM,EAAE;AACZ,MAAAA,KAAI,MAAM;AAAA,IACZ;AAAA,EAGF,OAAkC;AAEhC,IAAAA,KAAI,UAAM,qBAAK,eAAe,GAAG,KAAK;AAAA,EACxC;AACF;AAEA,SAAS,UAAUA,MAAa,OAAoB;AAClD,MAAI,CAAE,MAAM;AAAO,WAAOA,KAAI,MAAM,kBAAkB;AACtD,QAAM,MACD,MAAM,IAAI,EACV,OAAO,CAAC,SAAS,KAAK,MAAM,WAAW,CAAC,EACxC,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC,EACzB,QAAQ,CAAC,SAASA,KAAI,MAAM,IAAI,CAAC;AACxC;",
5
+ "names": ["log"]
6
+ }
package/dist/test.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /// <reference path="index.d.ts" />
2
+ import type { Files } from '@plugjs/plug/files';
3
+ import type { Context, PipeParameters, Plug } from '@plugjs/plug/pipe';
4
+ /** Writes some info about the current {@link Files} being passed around. */
5
+ export declare class Test implements Plug<void> {
6
+ private readonly _options;
7
+ constructor(...args: PipeParameters<'test'>);
8
+ pipe(files: Files, context: Context): Promise<void>;
9
+ }
package/dist/test.mjs ADDED
@@ -0,0 +1,194 @@
1
+ // test.ts
2
+ import { AssertionError } from "node:assert";
3
+ import { BuildFailure } from "@plugjs/plug";
4
+ import { $blu, $grn, $gry, $ms, $red, $wht, $ylw, log, ERROR, NOTICE, WARN } from "@plugjs/plug/logging";
5
+ import { assert } from "@plugjs/plug/asserts";
6
+ import { skip, Suite } from "./execution/executable.mjs";
7
+ import { runSuite } from "./execution/executor.mjs";
8
+ import { expect } from "./expectation/expect.mjs";
9
+ import { ExpectationError, stringifyObjectType } from "./expectation/types.mjs";
10
+ import { printDiff } from "./expectation/print.mjs";
11
+ import { diff } from "./expectation/diff.mjs";
12
+ import * as setup from "./execution/setup.mjs";
13
+ var _pending = "\u22EF";
14
+ var _success = "\u2714";
15
+ var _failure = "\u2718";
16
+ var _details = "\u2192";
17
+ var Test = class {
18
+ constructor(_options = {}) {
19
+ this._options = _options;
20
+ }
21
+ async pipe(files, context) {
22
+ assert(files.length, "No files available for running tests");
23
+ const {
24
+ globals = true,
25
+ genericErrorDiffs = true,
26
+ maxFailures = Number.POSITIVE_INFINITY
27
+ } = this._options;
28
+ if (globals) {
29
+ const anyGlobal = globalThis;
30
+ anyGlobal["describe"] = setup.describe;
31
+ anyGlobal["fdescribe"] = setup.fdescribe;
32
+ anyGlobal["xdescribe"] = setup.xdescribe;
33
+ anyGlobal["it"] = setup.it;
34
+ anyGlobal["fit"] = setup.fit;
35
+ anyGlobal["xit"] = setup.xit;
36
+ anyGlobal["afterAll"] = setup.afterAll;
37
+ anyGlobal["afterEach"] = setup.afterEach;
38
+ anyGlobal["beforeAll"] = setup.beforeAll;
39
+ anyGlobal["beforeEach"] = setup.beforeEach;
40
+ anyGlobal["xafterAll"] = setup.xafterAll;
41
+ anyGlobal["xafterEach"] = setup.xafterEach;
42
+ anyGlobal["xbeforeAll"] = setup.xbeforeAll;
43
+ anyGlobal["xbeforeEach"] = setup.xbeforeEach;
44
+ anyGlobal["skip"] = skip;
45
+ anyGlobal["expect"] = expect;
46
+ anyGlobal["log"] = log;
47
+ }
48
+ const suite = new Suite(void 0, "", async () => {
49
+ for (const file of files.absolutePaths())
50
+ await import(file);
51
+ });
52
+ await suite.setup();
53
+ const snum = suite.specs;
54
+ const fnum = files.length;
55
+ const smsg = snum === 1 ? "spec" : "specs";
56
+ const fmsg = fnum === 1 ? "file" : "files";
57
+ assert(snum, "No specs configured by test files");
58
+ const execution = runSuite(suite);
59
+ execution.on("suite:start", (current) => {
60
+ if (current.parent === suite) {
61
+ if (suite.flag !== "only")
62
+ context.log.notice("");
63
+ context.log.enter(NOTICE, `${$wht(current.name)}`);
64
+ context.log.notice("");
65
+ } else if (current.parent) {
66
+ context.log.enter(NOTICE, `${$blu(_details)} ${$wht(current.name)}`);
67
+ } else {
68
+ context.log.notice(`Running ${$ylw(snum)} ${smsg} from ${$ylw(fnum)} ${fmsg}`);
69
+ if (suite.flag === "only")
70
+ context.log.notice("");
71
+ }
72
+ });
73
+ execution.on("suite:done", (current) => {
74
+ if (current.parent)
75
+ context.log.leave();
76
+ });
77
+ execution.on("spec:start", (spec) => {
78
+ context.log.enter(NOTICE, `${$blu(_pending)} ${spec.name}`);
79
+ });
80
+ execution.on("spec:skip", (spec, ms) => {
81
+ if (suite.flag === "only")
82
+ return context.log.leave();
83
+ context.log.leave(WARN, `${$ylw(_pending)} ${spec.name} ${$ms(ms)} ${$gry("[")}${$ylw("skipped")}${$gry("]")}`);
84
+ });
85
+ execution.on("spec:pass", (spec, ms) => {
86
+ context.log.leave(NOTICE, `${$grn(_success)} ${spec.name} ${$ms(ms)}`);
87
+ });
88
+ execution.on("spec:fail", (spec, ms, { number }) => {
89
+ context.log.leave(
90
+ ERROR,
91
+ `${$red(_failure)} ${spec.name} ${$ms(ms)} ${$gry("[")}${$red("failed")}${$gry("|")}${$red(`${number}`)}${$gry("]")}`
92
+ );
93
+ });
94
+ execution.on("hook:fail", (hook, ms, { number }) => {
95
+ context.log.error(`${$red(_failure)} Hook "${hook.name}" ${$ms(ms)} ${$gry("[")}${$red("failed")}${$gry("|")}${$red(`${number}`)}${$gry("]")}`);
96
+ });
97
+ const { failed, passed, skipped, failures, time } = await execution.result;
98
+ const limit = Math.min(failures.length, maxFailures);
99
+ for (let i = 0; i < limit; i++) {
100
+ if (i === 0)
101
+ context.log.error("");
102
+ const { source, error, number } = failures[i];
103
+ const names = [""];
104
+ for (let p = source.parent; p?.parent; p = p.parent) {
105
+ if (p)
106
+ names.unshift(p.name);
107
+ }
108
+ const details = names.join(` ${$gry(_details)} `) + $wht(source.name);
109
+ context.log.enter(ERROR, `${$gry("[")}${$red(number)}${$gry("]:")} ${details}`);
110
+ dumpError(context.log, error, genericErrorDiffs);
111
+ context.log.leave();
112
+ }
113
+ const summary = [`${passed} ${$gry("passed")}`];
114
+ if (skipped)
115
+ summary.push(`${skipped} ${$gry("skipped")}`);
116
+ if (failed)
117
+ summary.push(`${failed} ${$gry("failed")}`);
118
+ if (failures.length)
119
+ summary.push(`${failures.length} ${$gry("total failures")}`);
120
+ const epilogue = ` ${$gry("(")}${summary.join($gry(", "))}${$gry(")")}`;
121
+ const message = `Ran ${$ylw(snum)} ${smsg} from ${$ylw(fnum)} ${fmsg}${epilogue} ${$ms(time)}`;
122
+ if (failures.length) {
123
+ context.log.error(message);
124
+ throw new BuildFailure();
125
+ } else if (suite.flag === "only") {
126
+ context.log.error("");
127
+ context.log.error(message);
128
+ throw new BuildFailure('Suite running in focus ("only") mode');
129
+ } else if (skipped) {
130
+ context.log.warn("");
131
+ context.log.warn(message);
132
+ } else {
133
+ context.log.notice("");
134
+ context.log.notice(message);
135
+ }
136
+ }
137
+ };
138
+ function dumpError(log2, error, genericErrorDiffs) {
139
+ if (error instanceof ExpectationError) {
140
+ log2.enter(ERROR, `${$gry("Expectation Error:")} ${$red(error.message)}`);
141
+ try {
142
+ dumpStack(log2, error);
143
+ if (error.diff)
144
+ printDiff(log2, error.diff);
145
+ } finally {
146
+ log2.error("");
147
+ log2.leave();
148
+ }
149
+ } else if (error instanceof AssertionError) {
150
+ const [message = "Unknown Error", ...lines] = error.message.split("\n");
151
+ log2.enter(ERROR, `${$gry("Assertion Error:")} ${$red(message)}`);
152
+ try {
153
+ dumpStack(log2, error);
154
+ if (genericErrorDiffs) {
155
+ if (!error.generatedMessage)
156
+ for (const line of lines)
157
+ log2.error(" ", line);
158
+ printDiff(log2, diff(error.actual, error.expected));
159
+ } else {
160
+ while (lines.length && !lines[0])
161
+ lines.shift();
162
+ for (const line of lines)
163
+ log2.error(" ", line);
164
+ }
165
+ } finally {
166
+ log2.error("");
167
+ log2.leave();
168
+ }
169
+ } else if (error instanceof Error) {
170
+ const message = error.message || "Unknown Error";
171
+ const type = stringifyObjectType(error);
172
+ log2.enter(ERROR, `${$gry(type)}: ${$red(message)}`);
173
+ try {
174
+ dumpStack(log2, error);
175
+ if (genericErrorDiffs && ("actual" in error || "expected" in error)) {
176
+ printDiff(log2, diff(error.actual, error.expected));
177
+ }
178
+ } finally {
179
+ log2.error("");
180
+ log2.leave();
181
+ }
182
+ } else {
183
+ log2.error($gry("Uknown error:"), error);
184
+ }
185
+ }
186
+ function dumpStack(log2, error) {
187
+ if (!error.stack)
188
+ return log2.error("<no stack trace>");
189
+ error.stack.split("\n").filter((line) => line.match(/^\s+at\s+/)).map((line) => line.trim()).forEach((line) => log2.error(line));
190
+ }
191
+ export {
192
+ Test
193
+ };
194
+ //# sourceMappingURL=test.mjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/test.ts"],
4
+ "mappings": ";AAGA,SAAS,sBAAsB;AAE/B,SAAS,oBAAoB;AAC7B,SAAS,MAAM,MAAM,MAAM,KAAK,MAAM,MAAM,MAAM,KAAK,OAAO,QAAQ,YAAY;AAClF,SAAS,cAAc;AAEvB,SAAS,MAAM,aAAa;AAC5B,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,kBAAkB,2BAA2B;AACtD,SAAS,iBAAiB;AAC1B,SAAS,YAAY;AACrB,YAAY,WAAW;AAOvB,IAAM,WAAW;AACjB,IAAM,WAAW;AACjB,IAAM,WAAW;AACjB,IAAM,WAAW;AAGV,IAAM,OAAN,MAAiC;AAAA,EAEtC,YAA6B,WAAwB,CAAC,GAAG;AAA5B;AAAA,EAA6B;AAAA,EAE1D,MAAM,KAAK,OAAc,SAAiC;AACxD,WAAO,MAAM,QAAQ,sCAAsC;AAE3D,UAAM;AAAA,MACJ,UAAU;AAAA,MACV,oBAAoB;AAAA,MACpB,cAAc,OAAO;AAAA,IACvB,IAAI,KAAK;AAGT,QAAI,SAAS;AACX,YAAM,YAAY;AAElB,gBAAU,UAAU,IAAU;AAC9B,gBAAU,WAAW,IAAU;AAC/B,gBAAU,WAAW,IAAU;AAC/B,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AW;AACjC,UAAM,OAAO,oBAAoB,KAAK;AACtC,IAAAA,KAAI,MAAM,OAAO,GAAG,KAAK,IAAI,MAAM,KAAK,OAAO,GAAG;AAClD,QAAI;AACF,gBAAUA,MAAK,KAAK;AAGpB,UAAI,sBAAuB,YAAY,SAAW,cAAc,QAAS;AACvE,kBAAUA,MAAK,KAAM,MAAc,QAAS,MAAc,QAAQ,CAAC;AAAA,MACrE;AAAA,IACF,UAAE;AACA,MAAAA,KAAI,MAAM,EAAE;AACZ,MAAAA,KAAI,MAAM;AAAA,IACZ;AAAA,EAGF,OAAkC;AAEhC,IAAAA,KAAI,MAAM,KAAK,eAAe,GAAG,KAAK;AAAA,EACxC;AACF;AAEA,SAAS,UAAUA,MAAa,OAAoB;AAClD,MAAI,CAAE,MAAM;AAAO,WAAOA,KAAI,MAAM,kBAAkB;AACtD,QAAM,MACD,MAAM,IAAI,EACV,OAAO,CAAC,SAAS,KAAK,MAAM,WAAW,CAAC,EACxC,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC,EACzB,QAAQ,CAAC,SAASA,KAAI,MAAM,IAAI,CAAC;AACxC;",
5
+ "names": ["log"]
6
+ }
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@plugjs/expect5",
3
+ "version": "0.4.0",
4
+ "type": "module",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "bin": {
9
+ "expect5": "./dist/cli.mjs"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "require": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.cjs"
16
+ },
17
+ "import": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.mjs"
20
+ }
21
+ },
22
+ "./globals": {
23
+ "require": {
24
+ "types": "./dist/globals.d.ts",
25
+ "default": "./dist/globals.cjs"
26
+ },
27
+ "import": {
28
+ "types": "./dist/globals.d.ts",
29
+ "default": "./dist/globals.mjs"
30
+ }
31
+ },
32
+ "./test": {
33
+ "require": {
34
+ "types": "./dist/test.d.ts",
35
+ "default": "./dist/test.cjs"
36
+ },
37
+ "import": {
38
+ "types": "./dist/test.d.ts",
39
+ "default": "./dist/test.mjs"
40
+ }
41
+ }
42
+ },
43
+ "author": "Juit Developers <developers@juit.com>",
44
+ "license": "Apache-2.0",
45
+ "devDependencies": {
46
+ "@types/chai": "^4.3.4",
47
+ "chai": "^4.3.7"
48
+ },
49
+ "peerDependencies": {
50
+ "@plugjs/plug": "0.4.0"
51
+ },
52
+ "files": [
53
+ "*.md",
54
+ "dist/",
55
+ "src/"
56
+ ]
57
+ }
package/src/cli.mts ADDED
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { async, find, paths, pipe, logging } from '@plugjs/plug'
4
+ import { main, yargsParser } from '@plugjs/tsrun'
5
+
6
+ import { Test } from './test'
7
+
8
+ const { $blu, $und, $gry, $wht } = logging
9
+ const $gnd = (s: string): string => $gry($und(s))
10
+ const $bnd = (s: string): string => $blu($und(s))
11
+ const $wnd = (s: string): string => $wht($und(s))
12
+
13
+
14
+ /** Version injected by esbuild, defaulted in case of dynamic transpilation */
15
+ const version = typeof __version === 'string' ? __version : '0.0.0-dev'
16
+ declare const __version: string | undefined
17
+
18
+ /* ========================================================================== *
19
+ * HELP SCREEN *
20
+ * ========================================================================== */
21
+
22
+ /** Show help screen */
23
+ function help(): void {
24
+ // eslint-disable-next-line no-console
25
+ console.log(`${$blu($und('Usage:'))}
26
+
27
+ ${$wht('expect5')} ${$gry('[')}--options${$gry('] [...')}globs${$gry('...]')}
28
+
29
+ ${$bnd('Options:')}
30
+
31
+ ${$wht('-d --directory')} ${$gnd('dir')} Directory where tests are to be found
32
+ ${$wht('-h --help ')} Help! You're reading it now!
33
+ ${$wht(' --version ')} Version! This one: ${version}!
34
+
35
+ ${$bnd('Globs:')}
36
+
37
+ Other arguments will be treated as globs, used to match test files in
38
+ the specified directory (defaults to the current directory).
39
+
40
+ If no globs are specified, the default will be to find all JavaScript
41
+ and TypeScript files in the ${$wnd('./test')} directory, prefixed by the ${$wnd('.test')}
42
+ extension ${$gry('(for example')} ${$und('foobar.test.ts')}${$gry(')')}.
43
+
44
+ ${$bnd('Environment Variables:')}
45
+
46
+ ${$wht('LOG_LEVEL ')} The default ${$wnd('notice')}, or ${$gnd('debug')}, ${$gnd('info')}, ${$gnd('warn')} or ${$gnd('error')}.
47
+ ${$wht('NODE_V8_COVERAGE')} The directory where Node will write coverage data to.
48
+
49
+ ${$bnd('TypeScript module format:')}
50
+
51
+ Normally our TypeScript loader will transpile ${$wnd('.ts')} files to the type
52
+ specified in ${$wnd('package.json')}, either ${$wnd('commonjs')} (the default) or ${$wnd('module')}.
53
+
54
+ To force a specific module format use one of the following flags:
55
+
56
+ ${$wht('--force-esm')} Force transpilation of ${$wnd('.ts')} files to EcmaScript modules
57
+ ${$wht('--force-cjs')} Force transpilation of ${$wnd('.ts')} files to CommonJS modules
58
+ `)
59
+ process.exit(0)
60
+ }
61
+
62
+ /* ========================================================================== *
63
+ * MAIN TEST RUNNER *
64
+ * ========================================================================== */
65
+
66
+ /** Parse command line and run tests */
67
+ main(import.meta.url, async (args): Promise<void> => {
68
+ logging.logOptions.spinner = false
69
+
70
+ const filename = paths.requireFilename(import.meta.url) // self, for context
71
+ const context = new pipe.Context(filename, '') // context for pipes
72
+ let directory = '.' // default directory to CWD
73
+ const globs: string[] = [] // empty globs list
74
+
75
+ const parsed = yargsParser(args, {
76
+ configuration: {
77
+ 'camel-case-expansion': false,
78
+ 'strip-aliased': true,
79
+ 'strip-dashed': true,
80
+ },
81
+
82
+ alias: {
83
+ 'directory': [ 'd' ],
84
+ 'help': [ 'h' ],
85
+ },
86
+
87
+ string: [ 'directory' ],
88
+ boolean: [ 'help', 'version' ],
89
+ })
90
+
91
+ for (const [ key, value ] of Object.entries(parsed)) {
92
+ switch (key) {
93
+ case '_': // globs as args
94
+ globs.push(...value)
95
+ break
96
+ case 'directory':
97
+ directory = context.resolve(value)
98
+ break
99
+ case 'help':
100
+ return help()
101
+ case 'version':
102
+ return context.log.notice(`Expect5 ${$gry('ver.')} ${$wnd(version)}`)
103
+ default:
104
+ context.log.error(`Unsupported option ${$wnd(key)} (try ${$wnd('--help')})`)
105
+ process.exit(1)
106
+ }
107
+ }
108
+
109
+ // Default glob (all .test.xx files in the test directory)
110
+ const glob = globs.shift() || 'test/**/*.test.([cm])?[jt]s'
111
+
112
+ // Simply create the Test plug and pass everything to it
113
+ try {
114
+ process.exitCode = 0
115
+ await async.runAsync(context, '', () => {
116
+ return find(glob, ...globs, { directory }).plug(new Test())
117
+ })
118
+ } catch (error) {
119
+ context.log.error(error)
120
+ process.exit(1)
121
+ }
122
+ })