@logtape/testing-node 2.3.0-dev.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.
@@ -0,0 +1,159 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { ConfigError, configureSync, getConfig } from "@logtape/logtape";
3
+ import nodeTest, { after, afterEach, before, beforeEach, describe, it as it$1, mock, run, suite } from "node:test";
4
+ import { createFailureLogReporter } from "@logtape/testing/reporter";
5
+
6
+ //#region src/mod.ts
7
+ /**
8
+ * Creates a `node:test` test function that reports LogTape records from failed
9
+ * test callbacks.
10
+ *
11
+ * The returned function preserves Node.js test options and shorthand helpers
12
+ * such as `test.only()`, `test.skip()`, and `test.todo()`. Only callback
13
+ * arguments are adapted; options are passed through to `node:test`.
14
+ *
15
+ * @param options Failure log reporter options.
16
+ * @returns A configured `node:test`-compatible test function.
17
+ * @since 2.3.0
18
+ */
19
+ function createTest(options = {}) {
20
+ return createNodeTestFunction(nodeTest, options);
21
+ }
22
+ /**
23
+ * Creates an `it()` alias that reports LogTape records from failed test
24
+ * callbacks.
25
+ *
26
+ * @param options Failure log reporter options.
27
+ * @returns A configured `node:test`-compatible `it()` function.
28
+ * @since 2.3.0
29
+ */
30
+ function createIt(options = {}) {
31
+ return createNodeTestFunction(it$1, options);
32
+ }
33
+ /**
34
+ * A `node:test` test function that reports LogTape records from failed test
35
+ * callbacks using the default reporter options.
36
+ *
37
+ * @since 2.3.0
38
+ */
39
+ const test = createTest();
40
+ /**
41
+ * A `node:test` `it()` alias that reports LogTape records from failed test
42
+ * callbacks using the default reporter options.
43
+ *
44
+ * @since 2.3.0
45
+ */
46
+ const it = createIt();
47
+ /**
48
+ * Shorthand for marking a test as `only`.
49
+ *
50
+ * @since 2.3.0
51
+ */
52
+ const only = test.only;
53
+ /**
54
+ * Shorthand for skipping a test.
55
+ *
56
+ * @since 2.3.0
57
+ */
58
+ const skip = test.skip;
59
+ /**
60
+ * Shorthand for marking a test as TODO.
61
+ *
62
+ * @since 2.3.0
63
+ */
64
+ const todo = test.todo;
65
+ /**
66
+ * Shorthand for expecting a test to fail when supported by the active Node.js
67
+ * runtime.
68
+ *
69
+ * @since 2.3.0
70
+ */
71
+ const expectFailure = test.expectFailure;
72
+ /**
73
+ * Node.js' test assertion tracker when supported by the active runtime.
74
+ *
75
+ * @since 2.3.0
76
+ */
77
+ const assert = test.assert;
78
+ /**
79
+ * Node.js' snapshot helper when supported by the active runtime.
80
+ *
81
+ * @since 2.3.0
82
+ */
83
+ const snapshot = test.snapshot;
84
+ var src_default = test;
85
+ function createNodeTestFunction(baseTest, options, includeExtendedProperties = true) {
86
+ const register = (...args) => Reflect.apply(baseTest, void 0, wrapCallbackArgument(args, options));
87
+ const baseExpectFailure = baseTest.expectFailure;
88
+ const wrapped = Object.assign(register, baseTest, {
89
+ only: (...args) => Reflect.apply(baseTest.only, void 0, wrapCallbackArgument(args, options)),
90
+ skip: (...args) => Reflect.apply(baseTest.skip, void 0, wrapCallbackArgument(args, options)),
91
+ todo: (...args) => Reflect.apply(baseTest.todo, void 0, wrapCallbackArgument(args, options)),
92
+ expectFailure: typeof baseExpectFailure === "function" ? (...args) => Reflect.apply(baseExpectFailure, void 0, wrapCallbackArgument(args, options)) : void 0
93
+ });
94
+ if (includeExtendedProperties) {
95
+ if (typeof baseTest.it === "function") Object.defineProperty(wrapped, "it", {
96
+ configurable: true,
97
+ enumerable: true,
98
+ value: createNodeTestFunction(baseTest.it, options, false),
99
+ writable: true
100
+ });
101
+ if (typeof baseTest.test === "function") Object.defineProperty(wrapped, "test", {
102
+ configurable: true,
103
+ enumerable: true,
104
+ value: wrapped,
105
+ writable: true
106
+ });
107
+ }
108
+ return wrapped;
109
+ }
110
+ function wrapCallbackArgument(args, options) {
111
+ const callback = args.at(-1);
112
+ if (typeof callback !== "function") return [...args];
113
+ const reporter = createFailureLogReporter(options);
114
+ const wrapped = wrapNodeCallback(reporter.wrap.bind(reporter), callback);
115
+ return [...args.slice(0, -1), wrapped];
116
+ }
117
+ function wrapNodeCallback(wrap, callback) {
118
+ if (callback.length >= 2) return function(context, done) {
119
+ const runCallback = (...args) => Reflect.apply(callback, this, args);
120
+ wrap(() => new Promise((resolve, reject) => {
121
+ let settled = false;
122
+ const wrappedDone = (error) => {
123
+ if (settled) return;
124
+ settled = true;
125
+ if (error == null) resolve();
126
+ else reject(error);
127
+ };
128
+ try {
129
+ runCallback(context, wrappedDone);
130
+ } catch (error) {
131
+ reject(error);
132
+ }
133
+ }))().then(() => done(), (error) => done(error));
134
+ };
135
+ if (callback.length === 0) return function() {
136
+ return wrap(() => Reflect.apply(callback, this, []))();
137
+ };
138
+ return function(context) {
139
+ return wrap(() => Reflect.apply(callback, this, [context]))();
140
+ };
141
+ }
142
+
143
+ //#endregion
144
+ //#region src/autoload.ts
145
+ const config = getConfig();
146
+ if (config == null) configureSync({
147
+ contextLocalStorage: new AsyncLocalStorage(),
148
+ sinks: {},
149
+ loggers: [{
150
+ category: ["logtape", "meta"],
151
+ sinks: []
152
+ }]
153
+ });
154
+ else if (config.contextLocalStorage == null) throw new ConfigError("@logtape/testing-node/autoload requires the existing LogTape configuration to provide contextLocalStorage.");
155
+ var autoload_default = src_default;
156
+
157
+ //#endregion
158
+ export { after, afterEach, assert, before, beforeEach, createIt, createTest, autoload_default as default, describe, expectFailure, it, mock, only, run, skip, snapshot, suite, src_default as test, todo };
159
+ //# sourceMappingURL=autoload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autoload.js","names":["options: FailureLogReporterOptions","nodeIt","test: NodeTestFunction","it: NodeTestFunction","only: NodeTestFunction","skip: NodeTestFunction","todo: NodeTestFunction","expectFailure: NodeTestFunction | undefined","assert: unknown","snapshot: unknown","baseTest: BaseNodeTestFunction","args: readonly unknown[]","wrap: ReturnType<typeof createFailureLogReporter>[\"wrap\"]","callback: AnyFunction","context: TestContext","done: NodeDoneCallback","wrappedDone: NodeDoneCallback","error?: unknown","error: unknown","test"],"sources":["../src/mod.ts","../src/autoload.ts"],"sourcesContent":["import nodeTest, { it as nodeIt } from \"node:test\";\nimport type { TestContext } from \"node:test\";\n\nimport {\n createFailureLogReporter,\n type FailureLogReporterOptions,\n} from \"@logtape/testing/reporter\";\n\nexport type {\n FailureLogReporterOptions,\n FailureLogReportMode,\n} from \"@logtape/testing/reporter\";\nexport {\n after,\n afterEach,\n before,\n beforeEach,\n describe,\n mock,\n run,\n suite,\n} from \"node:test\";\n\n/**\n * Options accepted by Node.js `test()` and `it()` functions.\n *\n * The shape intentionally mirrors Node's documented option bag while allowing\n * newer Node.js options to pass through even when a runtime's bundled TypeScript\n * declarations lag behind the current documentation.\n *\n * @since 2.3.0\n */\nexport interface NodeTestOptions {\n readonly concurrency?: number | boolean;\n readonly expectFailure?:\n | boolean\n | string\n | RegExp\n | ((error: unknown) => boolean)\n | object\n | Error;\n readonly only?: boolean;\n readonly signal?: AbortSignal;\n readonly skip?: boolean | string;\n readonly tags?: readonly string[];\n readonly todo?: boolean | string;\n readonly timeout?: number;\n readonly plan?: number;\n}\n\n/**\n * A callback passed to Node.js `test()` or `it()`.\n *\n * @since 2.3.0\n */\nexport type NodeTestCallback = (\n context: TestContext,\n done?: NodeDoneCallback,\n) => unknown;\n\n/**\n * A Node.js `test()`-compatible function.\n *\n * @since 2.3.0\n */\nexport interface NodeTestFunction {\n (name?: string, options?: NodeTestOptions, fn?: NodeTestCallback): Promise<\n void\n >;\n (name?: string, fn?: NodeTestCallback): Promise<void>;\n (options?: NodeTestOptions, fn?: NodeTestCallback): Promise<void>;\n (fn?: NodeTestCallback): Promise<void>;\n readonly only: NodeTestFunction;\n readonly skip: NodeTestFunction;\n readonly todo: NodeTestFunction;\n readonly expectFailure?: NodeTestFunction;\n readonly it?: NodeTestFunction;\n readonly test?: NodeTestFunction;\n}\n\ntype NodeDoneCallback = (error?: unknown) => void;\ntype AnyFunction = (...args: never[]) => unknown;\ntype BaseNodeTestFunction = AnyFunction & {\n readonly only: AnyFunction;\n readonly skip: AnyFunction;\n readonly todo: AnyFunction;\n readonly expectFailure?: AnyFunction;\n readonly it?: AnyFunction;\n readonly test?: AnyFunction;\n};\n\n/**\n * Creates a `node:test` test function that reports LogTape records from failed\n * test callbacks.\n *\n * The returned function preserves Node.js test options and shorthand helpers\n * such as `test.only()`, `test.skip()`, and `test.todo()`. Only callback\n * arguments are adapted; options are passed through to `node:test`.\n *\n * @param options Failure log reporter options.\n * @returns A configured `node:test`-compatible test function.\n * @since 2.3.0\n */\nexport function createTest(\n options: FailureLogReporterOptions = {},\n): NodeTestFunction {\n return createNodeTestFunction(\n nodeTest as unknown as BaseNodeTestFunction,\n options,\n );\n}\n\n/**\n * Creates an `it()` alias that reports LogTape records from failed test\n * callbacks.\n *\n * @param options Failure log reporter options.\n * @returns A configured `node:test`-compatible `it()` function.\n * @since 2.3.0\n */\nexport function createIt(\n options: FailureLogReporterOptions = {},\n): NodeTestFunction {\n return createNodeTestFunction(\n nodeIt as unknown as BaseNodeTestFunction,\n options,\n );\n}\n\n/**\n * A `node:test` test function that reports LogTape records from failed test\n * callbacks using the default reporter options.\n *\n * @since 2.3.0\n */\nexport const test: NodeTestFunction = createTest();\n\n/**\n * A `node:test` `it()` alias that reports LogTape records from failed test\n * callbacks using the default reporter options.\n *\n * @since 2.3.0\n */\nexport const it: NodeTestFunction = createIt();\n\n/**\n * Shorthand for marking a test as `only`.\n *\n * @since 2.3.0\n */\nexport const only: NodeTestFunction = test.only;\n\n/**\n * Shorthand for skipping a test.\n *\n * @since 2.3.0\n */\nexport const skip: NodeTestFunction = test.skip;\n\n/**\n * Shorthand for marking a test as TODO.\n *\n * @since 2.3.0\n */\nexport const todo: NodeTestFunction = test.todo;\n\n/**\n * Shorthand for expecting a test to fail when supported by the active Node.js\n * runtime.\n *\n * @since 2.3.0\n */\nexport const expectFailure: NodeTestFunction | undefined = test.expectFailure;\n\n/**\n * Node.js' test assertion tracker when supported by the active runtime.\n *\n * @since 2.3.0\n */\nexport const assert: unknown = (test as { readonly assert?: unknown }).assert;\n\n/**\n * Node.js' snapshot helper when supported by the active runtime.\n *\n * @since 2.3.0\n */\nexport const snapshot: unknown = (test as { readonly snapshot?: unknown })\n .snapshot;\n\nexport default test;\n\nfunction createNodeTestFunction(\n baseTest: BaseNodeTestFunction,\n options: FailureLogReporterOptions,\n includeExtendedProperties = true,\n): NodeTestFunction {\n const register = ((...args: unknown[]) =>\n Reflect.apply(\n baseTest,\n undefined,\n wrapCallbackArgument(args, options),\n )) as NodeTestFunction;\n\n const baseExpectFailure = baseTest.expectFailure;\n const wrapped = Object.assign(register, baseTest, {\n only: ((...args: unknown[]) =>\n Reflect.apply(\n baseTest.only,\n undefined,\n wrapCallbackArgument(args, options),\n )) as NodeTestFunction[\"only\"],\n skip: ((...args: unknown[]) =>\n Reflect.apply(\n baseTest.skip,\n undefined,\n wrapCallbackArgument(args, options),\n )) as NodeTestFunction[\"skip\"],\n todo: ((...args: unknown[]) =>\n Reflect.apply(\n baseTest.todo,\n undefined,\n wrapCallbackArgument(args, options),\n )) as NodeTestFunction[\"todo\"],\n expectFailure: typeof baseExpectFailure === \"function\"\n ? ((...args: unknown[]) =>\n Reflect.apply(\n baseExpectFailure,\n undefined,\n wrapCallbackArgument(args, options),\n )) as NodeTestFunction[\"expectFailure\"]\n : undefined,\n });\n\n if (includeExtendedProperties) {\n if (typeof baseTest.it === \"function\") {\n Object.defineProperty(wrapped, \"it\", {\n configurable: true,\n enumerable: true,\n value: createNodeTestFunction(\n baseTest.it as BaseNodeTestFunction,\n options,\n false,\n ),\n writable: true,\n });\n }\n if (typeof baseTest.test === \"function\") {\n Object.defineProperty(wrapped, \"test\", {\n configurable: true,\n enumerable: true,\n value: wrapped,\n writable: true,\n });\n }\n }\n\n return wrapped;\n}\n\nfunction wrapCallbackArgument(\n args: readonly unknown[],\n options: FailureLogReporterOptions,\n): unknown[] {\n const callback = args.at(-1);\n if (typeof callback !== \"function\") return [...args];\n\n const reporter = createFailureLogReporter(options);\n const wrapped = wrapNodeCallback(\n reporter.wrap.bind(reporter),\n callback as unknown as AnyFunction,\n );\n return [...args.slice(0, -1), wrapped];\n}\n\nfunction wrapNodeCallback(\n wrap: ReturnType<typeof createFailureLogReporter>[\"wrap\"],\n callback: AnyFunction,\n): AnyFunction {\n if (callback.length >= 2) {\n return function (\n this: unknown,\n context: TestContext,\n done: NodeDoneCallback,\n ): void {\n const runCallback = (...args: readonly unknown[]): unknown =>\n Reflect.apply(callback, this, args);\n void wrap(() =>\n new Promise<void>((resolve, reject) => {\n let settled = false;\n const wrappedDone: NodeDoneCallback = ((error?: unknown) => {\n if (settled) return;\n settled = true;\n if (error == null) resolve();\n else reject(error);\n }) as NodeDoneCallback;\n\n try {\n runCallback(context, wrappedDone);\n } catch (error) {\n reject(error);\n }\n })\n )().then(\n () => done(),\n (error: unknown) => done(error),\n );\n };\n }\n\n if (callback.length === 0) {\n return function (this: unknown): Promise<unknown> {\n return wrap(() => Reflect.apply(callback, this, []))();\n };\n }\n\n return function (this: unknown, context: TestContext): Promise<unknown> {\n return wrap(() => Reflect.apply(callback, this, [context]))();\n };\n}\n\nexport type { TestContext };\n","import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport {\n ConfigError,\n configureSync,\n type ContextLocalStorage,\n getConfig,\n} from \"@logtape/logtape\";\n\nimport {\n after,\n afterEach,\n assert,\n before,\n beforeEach,\n createIt,\n createTest,\n default as test,\n describe,\n expectFailure,\n it,\n mock,\n only,\n run,\n skip,\n snapshot,\n suite,\n todo,\n} from \"./mod.ts\";\n\nexport type {\n FailureLogReporterOptions,\n FailureLogReportMode,\n NodeTestCallback,\n NodeTestFunction,\n NodeTestOptions,\n TestContext,\n} from \"./mod.ts\";\n\nconst config = getConfig();\n\nif (config == null) {\n configureSync({\n contextLocalStorage: new AsyncLocalStorage() as ContextLocalStorage<\n Record<string, unknown>\n >,\n sinks: {},\n loggers: [\n { category: [\"logtape\", \"meta\"], sinks: [] },\n ],\n });\n} else if (config.contextLocalStorage == null) {\n throw new ConfigError(\n \"@logtape/testing-node/autoload requires the existing LogTape \" +\n \"configuration to provide contextLocalStorage.\",\n );\n}\n\nexport {\n after,\n afterEach,\n assert,\n before,\n beforeEach,\n createIt,\n createTest,\n describe,\n expectFailure,\n it,\n mock,\n only,\n run,\n skip,\n snapshot,\n suite,\n test,\n todo,\n};\nexport default test;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuGA,SAAgB,WACdA,UAAqC,CAAE,GACrB;AAClB,QAAO,uBACL,UACA,QACD;AACF;;;;;;;;;AAUD,SAAgB,SACdA,UAAqC,CAAE,GACrB;AAClB,QAAO,uBACLC,MACA,QACD;AACF;;;;;;;AAQD,MAAaC,OAAyB,YAAY;;;;;;;AAQlD,MAAaC,KAAuB,UAAU;;;;;;AAO9C,MAAaC,OAAyB,KAAK;;;;;;AAO3C,MAAaC,OAAyB,KAAK;;;;;;AAO3C,MAAaC,OAAyB,KAAK;;;;;;;AAQ3C,MAAaC,gBAA8C,KAAK;;;;;;AAOhE,MAAaC,SAAmB,KAAuC;;;;;;AAOvE,MAAaC,WAAqB,KAC/B;AAEH,kBAAe;AAEf,SAAS,uBACPC,UACAV,SACA,4BAA4B,MACV;CAClB,MAAM,WAAY,CAAC,GAAG,SACpB,QAAQ,MACN,kBAEA,qBAAqB,MAAM,QAAQ,CACpC;CAEH,MAAM,oBAAoB,SAAS;CACnC,MAAM,UAAU,OAAO,OAAO,UAAU,UAAU;EAChD,MAAO,CAAC,GAAG,SACT,QAAQ,MACN,SAAS,cAET,qBAAqB,MAAM,QAAQ,CACpC;EACH,MAAO,CAAC,GAAG,SACT,QAAQ,MACN,SAAS,cAET,qBAAqB,MAAM,QAAQ,CACpC;EACH,MAAO,CAAC,GAAG,SACT,QAAQ,MACN,SAAS,cAET,qBAAqB,MAAM,QAAQ,CACpC;EACH,sBAAsB,sBAAsB,aACvC,CAAC,GAAG,SACL,QAAQ,MACN,2BAEA,qBAAqB,MAAM,QAAQ,CACpC;CAEN,EAAC;AAEF,KAAI,2BA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UAAU,MAAM,CAAC,OAAQ,EAAC,CAAC,EAAE;CAC9D;AACF;;;;ACvRD,MAAM,SAAS,WAAW;AAE1B,IAAI,UAAU,KACZ,eAAc;CACZ,qBAAqB,IAAI;CAGzB,OAAO,CAAE;CACT,SAAS,CACP;EAAE,UAAU,CAAC,WAAW,MAAO;EAAE,OAAO,CAAE;CAAE,CAC7C;AACF,EAAC;SACO,OAAO,uBAAuB,KACvC,OAAM,IAAI,YACR;AAyBJ,uBAAeK"}
package/dist/mod.cjs ADDED
@@ -0,0 +1,202 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
3
+ const node_test = require_rolldown_runtime.__toESM(require("node:test"));
4
+ const __logtape_testing_reporter = require_rolldown_runtime.__toESM(require("@logtape/testing/reporter"));
5
+
6
+ //#region src/mod.ts
7
+ /**
8
+ * Creates a `node:test` test function that reports LogTape records from failed
9
+ * test callbacks.
10
+ *
11
+ * The returned function preserves Node.js test options and shorthand helpers
12
+ * such as `test.only()`, `test.skip()`, and `test.todo()`. Only callback
13
+ * arguments are adapted; options are passed through to `node:test`.
14
+ *
15
+ * @param options Failure log reporter options.
16
+ * @returns A configured `node:test`-compatible test function.
17
+ * @since 2.3.0
18
+ */
19
+ function createTest(options = {}) {
20
+ return createNodeTestFunction(node_test.default, options);
21
+ }
22
+ /**
23
+ * Creates an `it()` alias that reports LogTape records from failed test
24
+ * callbacks.
25
+ *
26
+ * @param options Failure log reporter options.
27
+ * @returns A configured `node:test`-compatible `it()` function.
28
+ * @since 2.3.0
29
+ */
30
+ function createIt(options = {}) {
31
+ return createNodeTestFunction(node_test.it, options);
32
+ }
33
+ /**
34
+ * A `node:test` test function that reports LogTape records from failed test
35
+ * callbacks using the default reporter options.
36
+ *
37
+ * @since 2.3.0
38
+ */
39
+ const test = createTest();
40
+ /**
41
+ * A `node:test` `it()` alias that reports LogTape records from failed test
42
+ * callbacks using the default reporter options.
43
+ *
44
+ * @since 2.3.0
45
+ */
46
+ const it = createIt();
47
+ /**
48
+ * Shorthand for marking a test as `only`.
49
+ *
50
+ * @since 2.3.0
51
+ */
52
+ const only = test.only;
53
+ /**
54
+ * Shorthand for skipping a test.
55
+ *
56
+ * @since 2.3.0
57
+ */
58
+ const skip = test.skip;
59
+ /**
60
+ * Shorthand for marking a test as TODO.
61
+ *
62
+ * @since 2.3.0
63
+ */
64
+ const todo = test.todo;
65
+ /**
66
+ * Shorthand for expecting a test to fail when supported by the active Node.js
67
+ * runtime.
68
+ *
69
+ * @since 2.3.0
70
+ */
71
+ const expectFailure = test.expectFailure;
72
+ /**
73
+ * Node.js' test assertion tracker when supported by the active runtime.
74
+ *
75
+ * @since 2.3.0
76
+ */
77
+ const assert = test.assert;
78
+ /**
79
+ * Node.js' snapshot helper when supported by the active runtime.
80
+ *
81
+ * @since 2.3.0
82
+ */
83
+ const snapshot = test.snapshot;
84
+ var src_default = test;
85
+ function createNodeTestFunction(baseTest, options, includeExtendedProperties = true) {
86
+ const register = (...args) => Reflect.apply(baseTest, void 0, wrapCallbackArgument(args, options));
87
+ const baseExpectFailure = baseTest.expectFailure;
88
+ const wrapped = Object.assign(register, baseTest, {
89
+ only: (...args) => Reflect.apply(baseTest.only, void 0, wrapCallbackArgument(args, options)),
90
+ skip: (...args) => Reflect.apply(baseTest.skip, void 0, wrapCallbackArgument(args, options)),
91
+ todo: (...args) => Reflect.apply(baseTest.todo, void 0, wrapCallbackArgument(args, options)),
92
+ expectFailure: typeof baseExpectFailure === "function" ? (...args) => Reflect.apply(baseExpectFailure, void 0, wrapCallbackArgument(args, options)) : void 0
93
+ });
94
+ if (includeExtendedProperties) {
95
+ if (typeof baseTest.it === "function") Object.defineProperty(wrapped, "it", {
96
+ configurable: true,
97
+ enumerable: true,
98
+ value: createNodeTestFunction(baseTest.it, options, false),
99
+ writable: true
100
+ });
101
+ if (typeof baseTest.test === "function") Object.defineProperty(wrapped, "test", {
102
+ configurable: true,
103
+ enumerable: true,
104
+ value: wrapped,
105
+ writable: true
106
+ });
107
+ }
108
+ return wrapped;
109
+ }
110
+ function wrapCallbackArgument(args, options) {
111
+ const callback = args.at(-1);
112
+ if (typeof callback !== "function") return [...args];
113
+ const reporter = (0, __logtape_testing_reporter.createFailureLogReporter)(options);
114
+ const wrapped = wrapNodeCallback(reporter.wrap.bind(reporter), callback);
115
+ return [...args.slice(0, -1), wrapped];
116
+ }
117
+ function wrapNodeCallback(wrap, callback) {
118
+ if (callback.length >= 2) return function(context, done) {
119
+ const runCallback = (...args) => Reflect.apply(callback, this, args);
120
+ wrap(() => new Promise((resolve, reject) => {
121
+ let settled = false;
122
+ const wrappedDone = (error) => {
123
+ if (settled) return;
124
+ settled = true;
125
+ if (error == null) resolve();
126
+ else reject(error);
127
+ };
128
+ try {
129
+ runCallback(context, wrappedDone);
130
+ } catch (error) {
131
+ reject(error);
132
+ }
133
+ }))().then(() => done(), (error) => done(error));
134
+ };
135
+ if (callback.length === 0) return function() {
136
+ return wrap(() => Reflect.apply(callback, this, []))();
137
+ };
138
+ return function(context) {
139
+ return wrap(() => Reflect.apply(callback, this, [context]))();
140
+ };
141
+ }
142
+
143
+ //#endregion
144
+ Object.defineProperty(exports, 'after', {
145
+ enumerable: true,
146
+ get: function () {
147
+ return node_test.after;
148
+ }
149
+ });
150
+ Object.defineProperty(exports, 'afterEach', {
151
+ enumerable: true,
152
+ get: function () {
153
+ return node_test.afterEach;
154
+ }
155
+ });
156
+ exports.assert = assert;
157
+ Object.defineProperty(exports, 'before', {
158
+ enumerable: true,
159
+ get: function () {
160
+ return node_test.before;
161
+ }
162
+ });
163
+ Object.defineProperty(exports, 'beforeEach', {
164
+ enumerable: true,
165
+ get: function () {
166
+ return node_test.beforeEach;
167
+ }
168
+ });
169
+ exports.createIt = createIt;
170
+ exports.createTest = createTest;
171
+ exports.default = src_default;
172
+ Object.defineProperty(exports, 'describe', {
173
+ enumerable: true,
174
+ get: function () {
175
+ return node_test.describe;
176
+ }
177
+ });
178
+ exports.expectFailure = expectFailure;
179
+ exports.it = it;
180
+ Object.defineProperty(exports, 'mock', {
181
+ enumerable: true,
182
+ get: function () {
183
+ return node_test.mock;
184
+ }
185
+ });
186
+ exports.only = only;
187
+ Object.defineProperty(exports, 'run', {
188
+ enumerable: true,
189
+ get: function () {
190
+ return node_test.run;
191
+ }
192
+ });
193
+ exports.skip = skip;
194
+ exports.snapshot = snapshot;
195
+ Object.defineProperty(exports, 'suite', {
196
+ enumerable: true,
197
+ get: function () {
198
+ return node_test.suite;
199
+ }
200
+ });
201
+ exports.test = test;
202
+ exports.todo = todo;
package/dist/mod.d.cts ADDED
@@ -0,0 +1,125 @@
1
+ import { TestContext, after, afterEach, before, beforeEach, describe, mock, run, suite } from "node:test";
2
+ import { FailureLogReportMode, FailureLogReporterOptions, FailureLogReporterOptions as FailureLogReporterOptions$1 } from "@logtape/testing/reporter";
3
+
4
+ //#region src/mod.d.ts
5
+
6
+ /**
7
+ * Options accepted by Node.js `test()` and `it()` functions.
8
+ *
9
+ * The shape intentionally mirrors Node's documented option bag while allowing
10
+ * newer Node.js options to pass through even when a runtime's bundled TypeScript
11
+ * declarations lag behind the current documentation.
12
+ *
13
+ * @since 2.3.0
14
+ */
15
+ interface NodeTestOptions {
16
+ readonly concurrency?: number | boolean;
17
+ readonly expectFailure?: boolean | string | RegExp | ((error: unknown) => boolean) | object | Error;
18
+ readonly only?: boolean;
19
+ readonly signal?: AbortSignal;
20
+ readonly skip?: boolean | string;
21
+ readonly tags?: readonly string[];
22
+ readonly todo?: boolean | string;
23
+ readonly timeout?: number;
24
+ readonly plan?: number;
25
+ }
26
+ /**
27
+ * A callback passed to Node.js `test()` or `it()`.
28
+ *
29
+ * @since 2.3.0
30
+ */
31
+ type NodeTestCallback = (context: TestContext, done?: NodeDoneCallback) => unknown;
32
+ /**
33
+ * A Node.js `test()`-compatible function.
34
+ *
35
+ * @since 2.3.0
36
+ */
37
+ interface NodeTestFunction {
38
+ (name?: string, options?: NodeTestOptions, fn?: NodeTestCallback): Promise<void>;
39
+ (name?: string, fn?: NodeTestCallback): Promise<void>;
40
+ (options?: NodeTestOptions, fn?: NodeTestCallback): Promise<void>;
41
+ (fn?: NodeTestCallback): Promise<void>;
42
+ readonly only: NodeTestFunction;
43
+ readonly skip: NodeTestFunction;
44
+ readonly todo: NodeTestFunction;
45
+ readonly expectFailure?: NodeTestFunction;
46
+ readonly it?: NodeTestFunction;
47
+ readonly test?: NodeTestFunction;
48
+ }
49
+ type NodeDoneCallback = (error?: unknown) => void;
50
+ /**
51
+ * Creates a `node:test` test function that reports LogTape records from failed
52
+ * test callbacks.
53
+ *
54
+ * The returned function preserves Node.js test options and shorthand helpers
55
+ * such as `test.only()`, `test.skip()`, and `test.todo()`. Only callback
56
+ * arguments are adapted; options are passed through to `node:test`.
57
+ *
58
+ * @param options Failure log reporter options.
59
+ * @returns A configured `node:test`-compatible test function.
60
+ * @since 2.3.0
61
+ */
62
+ declare function createTest(options?: FailureLogReporterOptions$1): NodeTestFunction;
63
+ /**
64
+ * Creates an `it()` alias that reports LogTape records from failed test
65
+ * callbacks.
66
+ *
67
+ * @param options Failure log reporter options.
68
+ * @returns A configured `node:test`-compatible `it()` function.
69
+ * @since 2.3.0
70
+ */
71
+ declare function createIt(options?: FailureLogReporterOptions$1): NodeTestFunction;
72
+ /**
73
+ * A `node:test` test function that reports LogTape records from failed test
74
+ * callbacks using the default reporter options.
75
+ *
76
+ * @since 2.3.0
77
+ */
78
+ declare const test: NodeTestFunction;
79
+ /**
80
+ * A `node:test` `it()` alias that reports LogTape records from failed test
81
+ * callbacks using the default reporter options.
82
+ *
83
+ * @since 2.3.0
84
+ */
85
+ declare const it: NodeTestFunction;
86
+ /**
87
+ * Shorthand for marking a test as `only`.
88
+ *
89
+ * @since 2.3.0
90
+ */
91
+ declare const only: NodeTestFunction;
92
+ /**
93
+ * Shorthand for skipping a test.
94
+ *
95
+ * @since 2.3.0
96
+ */
97
+ declare const skip: NodeTestFunction;
98
+ /**
99
+ * Shorthand for marking a test as TODO.
100
+ *
101
+ * @since 2.3.0
102
+ */
103
+ declare const todo: NodeTestFunction;
104
+ /**
105
+ * Shorthand for expecting a test to fail when supported by the active Node.js
106
+ * runtime.
107
+ *
108
+ * @since 2.3.0
109
+ */
110
+ declare const expectFailure: NodeTestFunction | undefined;
111
+ /**
112
+ * Node.js' test assertion tracker when supported by the active runtime.
113
+ *
114
+ * @since 2.3.0
115
+ */
116
+ declare const assert: unknown;
117
+ /**
118
+ * Node.js' snapshot helper when supported by the active runtime.
119
+ *
120
+ * @since 2.3.0
121
+ */
122
+ declare const snapshot: unknown;
123
+ //#endregion
124
+ export { FailureLogReportMode, FailureLogReporterOptions, NodeTestCallback, NodeTestFunction, NodeTestOptions, TestContext, after, afterEach, assert, before, beforeEach, createIt, createTest, test as default, test, describe, expectFailure, it, mock, only, run, skip, snapshot, suite, todo };
125
+ //# sourceMappingURL=mod.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.cts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;AAgCA;;;;;AAU+B;AAa/B;;;AAES,UAzBQ,eAAA,CAyBR;EAAgB,SAAA,WAAA,CAAA,EAAA,MAAA,GAAA,OAAA;EAQR,SAAA,aAAgB,CAAA,EAAA,OAAA,GAAA,MAAA,GA5B3B,MA4B2B,GAAA,CAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GAAA,OAAA,CAAA,GAAA,MAAA,GAzB3B,KAyB2B;EAAA,SAAA,IAAA,CAAA,EAAA,OAAA;EAAA,SACL,MAAA,CAAA,EAxBR,WAwBQ;EAAe,SAAO,IAAA,CAAA,EAAA,OAAA,GAAA,MAAA;EAAgB,SAAG,IAAA,CAAA,EAAA,SAAA,MAAA,EAAA;EAAO,SAGrD,IAAA,CAAA,EAAA,OAAA,GAAA,MAAA;EAAgB,SAAG,OAAA,CAAA,EAAA,MAAA;EAAO,SACpC,IAAA,CAAA,EAAA,MAAA;;;;;;;AAII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"node:test";
2
+ import { FailureLogReportMode, FailureLogReporterOptions, FailureLogReporterOptions as FailureLogReporterOptions$1 } from "@logtape/testing/reporter";
3
+
4
+ //#region src/mod.d.ts
5
+
6
+ /**
7
+ * Options accepted by Node.js `test()` and `it()` functions.
8
+ *
9
+ * The shape intentionally mirrors Node's documented option bag while allowing
10
+ * newer Node.js options to pass through even when a runtime's bundled TypeScript
11
+ * declarations lag behind the current documentation.
12
+ *
13
+ * @since 2.3.0
14
+ */
15
+ interface NodeTestOptions {
16
+ readonly concurrency?: number | boolean;
17
+ readonly expectFailure?: boolean | string | RegExp | ((error: unknown) => boolean) | object | Error;
18
+ readonly only?: boolean;
19
+ readonly signal?: AbortSignal;
20
+ readonly skip?: boolean | string;
21
+ readonly tags?: readonly string[];
22
+ readonly todo?: boolean | string;
23
+ readonly timeout?: number;
24
+ readonly plan?: number;
25
+ }
26
+ /**
27
+ * A callback passed to Node.js `test()` or `it()`.
28
+ *
29
+ * @since 2.3.0
30
+ */
31
+ type NodeTestCallback = (context: TestContext, done?: NodeDoneCallback) => unknown;
32
+ /**
33
+ * A Node.js `test()`-compatible function.
34
+ *
35
+ * @since 2.3.0
36
+ */
37
+ interface NodeTestFunction {
38
+ (name?: string, options?: NodeTestOptions, fn?: NodeTestCallback): Promise<void>;
39
+ (name?: string, fn?: NodeTestCallback): Promise<void>;
40
+ (options?: NodeTestOptions, fn?: NodeTestCallback): Promise<void>;
41
+ (fn?: NodeTestCallback): Promise<void>;
42
+ readonly only: NodeTestFunction;
43
+ readonly skip: NodeTestFunction;
44
+ readonly todo: NodeTestFunction;
45
+ readonly expectFailure?: NodeTestFunction;
46
+ readonly it?: NodeTestFunction;
47
+ readonly test?: NodeTestFunction;
48
+ }
49
+ type NodeDoneCallback = (error?: unknown) => void;
50
+ /**
51
+ * Creates a `node:test` test function that reports LogTape records from failed
52
+ * test callbacks.
53
+ *
54
+ * The returned function preserves Node.js test options and shorthand helpers
55
+ * such as `test.only()`, `test.skip()`, and `test.todo()`. Only callback
56
+ * arguments are adapted; options are passed through to `node:test`.
57
+ *
58
+ * @param options Failure log reporter options.
59
+ * @returns A configured `node:test`-compatible test function.
60
+ * @since 2.3.0
61
+ */
62
+ declare function createTest(options?: FailureLogReporterOptions$1): NodeTestFunction;
63
+ /**
64
+ * Creates an `it()` alias that reports LogTape records from failed test
65
+ * callbacks.
66
+ *
67
+ * @param options Failure log reporter options.
68
+ * @returns A configured `node:test`-compatible `it()` function.
69
+ * @since 2.3.0
70
+ */
71
+ declare function createIt(options?: FailureLogReporterOptions$1): NodeTestFunction;
72
+ /**
73
+ * A `node:test` test function that reports LogTape records from failed test
74
+ * callbacks using the default reporter options.
75
+ *
76
+ * @since 2.3.0
77
+ */
78
+ declare const test: NodeTestFunction;
79
+ /**
80
+ * A `node:test` `it()` alias that reports LogTape records from failed test
81
+ * callbacks using the default reporter options.
82
+ *
83
+ * @since 2.3.0
84
+ */
85
+ declare const it: NodeTestFunction;
86
+ /**
87
+ * Shorthand for marking a test as `only`.
88
+ *
89
+ * @since 2.3.0
90
+ */
91
+ declare const only: NodeTestFunction;
92
+ /**
93
+ * Shorthand for skipping a test.
94
+ *
95
+ * @since 2.3.0
96
+ */
97
+ declare const skip: NodeTestFunction;
98
+ /**
99
+ * Shorthand for marking a test as TODO.
100
+ *
101
+ * @since 2.3.0
102
+ */
103
+ declare const todo: NodeTestFunction;
104
+ /**
105
+ * Shorthand for expecting a test to fail when supported by the active Node.js
106
+ * runtime.
107
+ *
108
+ * @since 2.3.0
109
+ */
110
+ declare const expectFailure: NodeTestFunction | undefined;
111
+ /**
112
+ * Node.js' test assertion tracker when supported by the active runtime.
113
+ *
114
+ * @since 2.3.0
115
+ */
116
+ declare const assert: unknown;
117
+ /**
118
+ * Node.js' snapshot helper when supported by the active runtime.
119
+ *
120
+ * @since 2.3.0
121
+ */
122
+ declare const snapshot: unknown;
123
+ //#endregion
124
+ export { FailureLogReportMode, FailureLogReporterOptions, NodeTestCallback, NodeTestFunction, NodeTestOptions, TestContext, after, afterEach, assert, before, beforeEach, createIt, createTest, test as default, test, describe, expectFailure, it, mock, only, run, skip, snapshot, suite, todo };
125
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;AAgCA;;;;;AAU+B;AAa/B;;;AAES,UAzBQ,eAAA,CAyBR;EAAgB,SAAA,WAAA,CAAA,EAAA,MAAA,GAAA,OAAA;EAQR,SAAA,aAAgB,CAAA,EAAA,OAAA,GAAA,MAAA,GA5B3B,MA4B2B,GAAA,CAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GAAA,OAAA,CAAA,GAAA,MAAA,GAzB3B,KAyB2B;EAAA,SAAA,IAAA,CAAA,EAAA,OAAA;EAAA,SACL,MAAA,CAAA,EAxBR,WAwBQ;EAAe,SAAO,IAAA,CAAA,EAAA,OAAA,GAAA,MAAA;EAAgB,SAAG,IAAA,CAAA,EAAA,SAAA,MAAA,EAAA;EAAO,SAGrD,IAAA,CAAA,EAAA,OAAA,GAAA,MAAA;EAAgB,SAAG,OAAA,CAAA,EAAA,MAAA;EAAO,SACpC,IAAA,CAAA,EAAA,MAAA;;;;;;;AAII,KAnBL,gBAAA,GAmBK,CAAA,OAAA,EAlBN,WAkBM,EAAA,IAAA,CAAA,EAjBR,gBAiBQ,EAAA,GAAA,OAAA;;;;AAGiB;AACjC;AAyBe,UAtCC,gBAAA,CAsCS;EAAA,CAAA,IAAA,CAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EArCE,eAqCF,EAAA,EAAA,CAAA,EArCwB,gBAqCxB,CAAA,EArC2C,OAqC3C,CAAA,IAAA,CAAA;EAAA,CAAA,IACf,CAAA,EAAA,MAAA,EAAA,EAAA,CAAA,EAnCY,gBAmCZ,CAAA,EAnC+B,OAmC/B,CAAA,IAAA,CAAA;EAA8B,CAAA,OACtC,CAAA,EAnCU,eAmCV,EAAA,EAAA,CAAA,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