@tapjs/node-serialize
Advanced tools
Comparing version 1.1.10 to 1.2.0
@@ -5,3 +5,3 @@ /// <reference types="node" /> | ||
import { TestMap } from './test-map.js'; | ||
export declare const printMessagesFn: (tap: TAP, stream: TestStreamSerialize, subsMap: TestMap<Base[]>, diagsMap: TestMap<DiagnosticData[]>) => (t: Base) => void; | ||
export declare const printMessagesFn: (tap: TAP, stream: TestStreamSerialize, subsMap: TestMap<Base[]>, diagsMap: TestMap<DiagnosticData[]>) => (t: Base, testNumber?: number) => void; | ||
//# sourceMappingURL=print-messages.d.ts.map |
@@ -6,2 +6,4 @@ "use strict"; | ||
const test_nested_location_js_1 = require("./test-nested-location.js"); | ||
const test_point_message_data_js_1 = require("./test-point-message-data.js"); | ||
const test_point_results_js_1 = require("./test-point-results.js"); | ||
const test_results_js_1 = require("./test-results.js"); | ||
@@ -11,3 +13,3 @@ const isPass = (pf) => !!pf?.details && !pf.details.error; | ||
const printMessagesFn = (tap, stream, subsMap, diagsMap) => { | ||
const printMessages = (t) => { | ||
const printMessages = (t, testNumber = 0) => { | ||
// enqueue all my subs, then dequeue each one and print them | ||
@@ -19,15 +21,45 @@ const subs = subsMap.get(t); | ||
} | ||
let count = 0; | ||
// print all the test points emitted directly on this test | ||
const results = t.results; | ||
/* c8 ignore start */ | ||
if (!results) | ||
throw new Error('printing results before test completion'); | ||
/* c8 ignore stop */ | ||
for (const type of [ | ||
'passes', | ||
'skips', | ||
'todos', | ||
'failures', | ||
]) { | ||
for (const res of results[type] ?? []) { | ||
if (res.closingTestPoint) | ||
continue; | ||
stream.enqueue((0, test_point_message_data_js_1.testPointMessageData)(res, t)); | ||
stream.dequeue((0, test_point_message_data_js_1.testPointMessageData)(res, t)); | ||
stream.start((0, test_point_message_data_js_1.testPointMessageData)(res, t)); | ||
const passFail = (0, test_point_results_js_1.testPointResults)(res, t, ++count); | ||
if (isPass(passFail)) { | ||
stream.pass(passFail); | ||
} | ||
else { | ||
stream.fail(passFail); | ||
} | ||
} | ||
} | ||
// recurse to all subtests | ||
if (subs) { | ||
// determine whether a suite or assertion based on subs.length | ||
for (const t of subs) { | ||
// console.error(t.parser) | ||
stream.enqueue((0, test_message_data_js_1.testMessageData)(t)); | ||
} | ||
for (const t of subs) { | ||
printMessages(t); | ||
printMessages(t, ++count); | ||
} | ||
if (subs.length && t !== tap) { | ||
stream.plan({ ...(0, test_nested_location_js_1.testNestedLocation)(t), count: subs.length }); | ||
} | ||
} | ||
const passFail = (0, test_results_js_1.testResults)(t, subsMap); | ||
if (count && t !== tap) { | ||
stream.plan({ ...(0, test_nested_location_js_1.testNestedLocation)(t), count }); | ||
} | ||
const passFail = (0, test_results_js_1.testResults)(t, count, testNumber); | ||
if (isPass(passFail)) { | ||
@@ -34,0 +66,0 @@ stream.pass(passFail); |
@@ -11,3 +11,3 @@ "use strict"; | ||
const resultToError = (result, test) => { | ||
const { stack: diagStack, diff: rawDiff, source, ...diag } = result.diag || {}; | ||
const { stack: diagStack, diff: rawDiff, source, passes: _, ...diag } = result.diag || {}; | ||
const at = diag.at ?? test?.options.at; | ||
@@ -14,0 +14,0 @@ const lfa = !!at ? (0, loc_from_callsite_js_1.locFromCallSite)(at) : undefined; |
@@ -8,2 +8,3 @@ "use strict"; | ||
const core_1 = require("@tapjs/core"); | ||
const node_util_1 = require("node:util"); | ||
const comment_js_1 = require("./comment.js"); | ||
@@ -23,9 +24,20 @@ const on_add_js_1 = require("./on-add.js"); | ||
tap.register?.(); | ||
tap.options.passes = true; | ||
const subsMap = new test_map_js_1.TestMap(); | ||
const diagsMap = new test_map_js_1.TestMap([[tap, []]]); | ||
const stream = new error_serdes_1.TestStreamSerialize(); | ||
// stream | ||
// .pipe(new TestStreamDeserialize()) | ||
// .on('data', c => stdout.write(format(c))) | ||
stream.pipe(stdout); | ||
// just for inspecting in dev. | ||
/* c8 ignore start */ | ||
if (process.env.TAP_SERIALIZE_DEBUG === '1') { | ||
stream | ||
.pipe(new error_serdes_1.TestStreamDeserialize()) | ||
.on('data', c => stdout.write((0, node_util_1.inspect)(JSON.parse(JSON.stringify(c)), { | ||
colors: true, | ||
depth: Infinity, | ||
}) + '\n')); | ||
} | ||
else { | ||
/* c8 ignore stop */ | ||
stream.pipe(stdout); | ||
} | ||
const comment = (0, comment_js_1.commentMethod)(stream, diagsMap); | ||
@@ -38,4 +50,6 @@ // unpossible, we already checked on module load | ||
/* c8 ignore stop */ | ||
(0, stdio_js_1.serializeStdio)(stream, core_1.proc, 'stderr'); | ||
(0, stdio_js_1.serializeStdio)(stream, core_1.proc, 'stdout'); | ||
if (process.env.TAP_SERIALIZE_DEBUG !== '1') { | ||
(0, stdio_js_1.serializeStdio)(stream, core_1.proc, 'stderr'); | ||
(0, stdio_js_1.serializeStdio)(stream, core_1.proc, 'stdout'); | ||
} | ||
const onAdd = (0, on_add_js_1.onAddFn)(comment, diagsMap, subsMap); | ||
@@ -42,0 +56,0 @@ const printMessages = (0, print_messages_js_1.printMessagesFn)(tap, stream, subsMap, diagsMap); |
import { Base } from '@tapjs/core'; | ||
import { FailData, PassData } from '@tapjs/error-serdes'; | ||
import { TestMap } from './test-map.js'; | ||
export declare const testResults: (t: Base, subsMap: TestMap<Base[]>) => PassData | FailData | undefined; | ||
export declare const testResults: (t: Base, count: number, testNumber: number) => PassData | FailData | undefined; | ||
//# sourceMappingURL=test-results.d.ts.map |
@@ -7,19 +7,7 @@ "use strict"; | ||
const test_message_data_js_1 = require("./test-message-data.js"); | ||
const testResults = (t, subsMap) => { | ||
const testResults = (t, count, testNumber) => { | ||
if (!t.parent) | ||
return; | ||
const results = t.results; | ||
const psubs = subsMap.get(t.parent); | ||
/* c8 ignore start */ | ||
if (!psubs) { | ||
throw new Error('ending subtest when parent has no subtests'); | ||
} | ||
const n = psubs.indexOf(t); | ||
const tn = n === -1 ? psubs.indexOf(t.t) : n; | ||
if (tn === -1) { | ||
throw new Error('subtest not found in parent subtests list'); | ||
} | ||
/* c8 ignore stop */ | ||
const testNumber = tn + 1; | ||
/* c8 ignore start */ | ||
if (!results) { | ||
@@ -29,4 +17,3 @@ throw new Error('printing messages before results available'); | ||
/* c8 ignore stop */ | ||
const subs = subsMap.get(t); | ||
const suite = !!subs?.length; | ||
const suite = count > 0; | ||
const p = { | ||
@@ -39,8 +26,10 @@ ...(0, test_message_data_js_1.testMessageData)(t), | ||
}; | ||
if (results.ok && !!results.todo) | ||
p.todo = true; | ||
if ((results.plan.skipAll && results.plan.skipReason) || | ||
(results.ok && !!results.skip)) { | ||
p.skip = true; | ||
} | ||
const skip = results.plan.skipAll | ||
? results.plan.skipReason || true | ||
: t.options.skip; | ||
if (skip) | ||
p.skip = skip; | ||
const todo = t.options.todo; | ||
if (todo) | ||
p.todo = todo; | ||
if (suite) | ||
@@ -51,3 +40,3 @@ p.details.type = 'suite'; | ||
if (suite) { | ||
const nf = subs.filter(s => !s.results?.ok).length; | ||
const nf = results.failures.length; | ||
const m = `${nf} subtest${nf === 1 ? '' : 's'} failed`; | ||
@@ -72,11 +61,10 @@ return { | ||
} | ||
// just report the first failure | ||
const fe = (0, result_to_error_js_1.resultToError)(t.lists.fail[0] /* c8 ignore start */ || | ||
results.failures[0] || { | ||
// a failure here indicates a strange test that had no failing test points, | ||
// but then was marked as not ok. | ||
const fe = (0, result_to_error_js_1.resultToError)(t.lists.fail[0] ?? | ||
results.failures[0] ?? { | ||
ok: false, | ||
name: 'Unknown test failure', | ||
diag: {}, | ||
}, | ||
/* c8 ignore stop */ | ||
t); | ||
}, t); | ||
return { | ||
@@ -83,0 +71,0 @@ ...p, |
@@ -5,3 +5,3 @@ /// <reference types="node" resolution-mode="require"/> | ||
import { TestMap } from './test-map.js'; | ||
export declare const printMessagesFn: (tap: TAP, stream: TestStreamSerialize, subsMap: TestMap<Base[]>, diagsMap: TestMap<DiagnosticData[]>) => (t: Base) => void; | ||
export declare const printMessagesFn: (tap: TAP, stream: TestStreamSerialize, subsMap: TestMap<Base[]>, diagsMap: TestMap<DiagnosticData[]>) => (t: Base, testNumber?: number) => void; | ||
//# sourceMappingURL=print-messages.d.ts.map |
import { testMessageData } from './test-message-data.js'; | ||
import { testNestedLocation } from './test-nested-location.js'; | ||
import { testPointMessageData } from './test-point-message-data.js'; | ||
import { testPointResults } from './test-point-results.js'; | ||
import { testResults } from './test-results.js'; | ||
@@ -7,3 +9,3 @@ const isPass = (pf) => !!pf?.details && !pf.details.error; | ||
export const printMessagesFn = (tap, stream, subsMap, diagsMap) => { | ||
const printMessages = (t) => { | ||
const printMessages = (t, testNumber = 0) => { | ||
// enqueue all my subs, then dequeue each one and print them | ||
@@ -15,15 +17,45 @@ const subs = subsMap.get(t); | ||
} | ||
let count = 0; | ||
// print all the test points emitted directly on this test | ||
const results = t.results; | ||
/* c8 ignore start */ | ||
if (!results) | ||
throw new Error('printing results before test completion'); | ||
/* c8 ignore stop */ | ||
for (const type of [ | ||
'passes', | ||
'skips', | ||
'todos', | ||
'failures', | ||
]) { | ||
for (const res of results[type] ?? []) { | ||
if (res.closingTestPoint) | ||
continue; | ||
stream.enqueue(testPointMessageData(res, t)); | ||
stream.dequeue(testPointMessageData(res, t)); | ||
stream.start(testPointMessageData(res, t)); | ||
const passFail = testPointResults(res, t, ++count); | ||
if (isPass(passFail)) { | ||
stream.pass(passFail); | ||
} | ||
else { | ||
stream.fail(passFail); | ||
} | ||
} | ||
} | ||
// recurse to all subtests | ||
if (subs) { | ||
// determine whether a suite or assertion based on subs.length | ||
for (const t of subs) { | ||
// console.error(t.parser) | ||
stream.enqueue(testMessageData(t)); | ||
} | ||
for (const t of subs) { | ||
printMessages(t); | ||
printMessages(t, ++count); | ||
} | ||
if (subs.length && t !== tap) { | ||
stream.plan({ ...testNestedLocation(t), count: subs.length }); | ||
} | ||
} | ||
const passFail = testResults(t, subsMap); | ||
if (count && t !== tap) { | ||
stream.plan({ ...testNestedLocation(t), count }); | ||
} | ||
const passFail = testResults(t, count, testNumber); | ||
if (isPass(passFail)) { | ||
@@ -30,0 +62,0 @@ stream.pass(passFail); |
@@ -8,3 +8,3 @@ // turn a tap-parser Result object into an Error | ||
export const resultToError = (result, test) => { | ||
const { stack: diagStack, diff: rawDiff, source, ...diag } = result.diag || {}; | ||
const { stack: diagStack, diff: rawDiff, source, passes: _, ...diag } = result.diag || {}; | ||
const at = diag.at ?? test?.options.at; | ||
@@ -11,0 +11,0 @@ const lfa = !!at ? locFromCallSite(at) : undefined; |
// Serialize the root TAP object, and output a node:test style | ||
// serialized message stream. | ||
import { TestStreamSerialize } from '@tapjs/error-serdes'; | ||
import { TestStreamDeserialize, TestStreamSerialize, } from '@tapjs/error-serdes'; | ||
import { proc } from '@tapjs/core'; | ||
import { inspect } from 'node:util'; | ||
import { commentMethod } from './comment.js'; | ||
@@ -19,9 +20,20 @@ import { onAddFn } from './on-add.js'; | ||
tap.register?.(); | ||
tap.options.passes = true; | ||
const subsMap = new TestMap(); | ||
const diagsMap = new TestMap([[tap, []]]); | ||
const stream = new TestStreamSerialize(); | ||
// stream | ||
// .pipe(new TestStreamDeserialize()) | ||
// .on('data', c => stdout.write(format(c))) | ||
stream.pipe(stdout); | ||
// just for inspecting in dev. | ||
/* c8 ignore start */ | ||
if (process.env.TAP_SERIALIZE_DEBUG === '1') { | ||
stream | ||
.pipe(new TestStreamDeserialize()) | ||
.on('data', c => stdout.write(inspect(JSON.parse(JSON.stringify(c)), { | ||
colors: true, | ||
depth: Infinity, | ||
}) + '\n')); | ||
} | ||
else { | ||
/* c8 ignore stop */ | ||
stream.pipe(stdout); | ||
} | ||
const comment = commentMethod(stream, diagsMap); | ||
@@ -34,4 +46,6 @@ // unpossible, we already checked on module load | ||
/* c8 ignore stop */ | ||
serializeStdio(stream, proc, 'stderr'); | ||
serializeStdio(stream, proc, 'stdout'); | ||
if (process.env.TAP_SERIALIZE_DEBUG !== '1') { | ||
serializeStdio(stream, proc, 'stderr'); | ||
serializeStdio(stream, proc, 'stdout'); | ||
} | ||
const onAdd = onAddFn(comment, diagsMap, subsMap); | ||
@@ -38,0 +52,0 @@ const printMessages = printMessagesFn(tap, stream, subsMap, diagsMap); |
import { Base } from '@tapjs/core'; | ||
import { FailData, PassData } from '@tapjs/error-serdes'; | ||
import { TestMap } from './test-map.js'; | ||
export declare const testResults: (t: Base, subsMap: TestMap<Base[]>) => PassData | FailData | undefined; | ||
export declare const testResults: (t: Base, count: number, testNumber: number) => PassData | FailData | undefined; | ||
//# sourceMappingURL=test-results.d.ts.map |
import { expandStack } from '@tapjs/stack'; | ||
import { resultToError } from './result-to-error.js'; | ||
import { testMessageData } from './test-message-data.js'; | ||
export const testResults = (t, subsMap) => { | ||
export const testResults = (t, count, testNumber) => { | ||
if (!t.parent) | ||
return; | ||
const results = t.results; | ||
const psubs = subsMap.get(t.parent); | ||
/* c8 ignore start */ | ||
if (!psubs) { | ||
throw new Error('ending subtest when parent has no subtests'); | ||
} | ||
const n = psubs.indexOf(t); | ||
const tn = n === -1 ? psubs.indexOf(t.t) : n; | ||
if (tn === -1) { | ||
throw new Error('subtest not found in parent subtests list'); | ||
} | ||
/* c8 ignore stop */ | ||
const testNumber = tn + 1; | ||
/* c8 ignore start */ | ||
if (!results) { | ||
@@ -25,4 +13,3 @@ throw new Error('printing messages before results available'); | ||
/* c8 ignore stop */ | ||
const subs = subsMap.get(t); | ||
const suite = !!subs?.length; | ||
const suite = count > 0; | ||
const p = { | ||
@@ -35,8 +22,10 @@ ...testMessageData(t), | ||
}; | ||
if (results.ok && !!results.todo) | ||
p.todo = true; | ||
if ((results.plan.skipAll && results.plan.skipReason) || | ||
(results.ok && !!results.skip)) { | ||
p.skip = true; | ||
} | ||
const skip = results.plan.skipAll | ||
? results.plan.skipReason || true | ||
: t.options.skip; | ||
if (skip) | ||
p.skip = skip; | ||
const todo = t.options.todo; | ||
if (todo) | ||
p.todo = todo; | ||
if (suite) | ||
@@ -47,3 +36,3 @@ p.details.type = 'suite'; | ||
if (suite) { | ||
const nf = subs.filter(s => !s.results?.ok).length; | ||
const nf = results.failures.length; | ||
const m = `${nf} subtest${nf === 1 ? '' : 's'} failed`; | ||
@@ -68,11 +57,10 @@ return { | ||
} | ||
// just report the first failure | ||
const fe = resultToError(t.lists.fail[0] /* c8 ignore start */ || | ||
results.failures[0] || { | ||
// a failure here indicates a strange test that had no failing test points, | ||
// but then was marked as not ok. | ||
const fe = resultToError(t.lists.fail[0] ?? | ||
results.failures[0] ?? { | ||
ok: false, | ||
name: 'Unknown test failure', | ||
diag: {}, | ||
}, | ||
/* c8 ignore stop */ | ||
t); | ||
}, t); | ||
return { | ||
@@ -79,0 +67,0 @@ ...p, |
{ | ||
"name": "@tapjs/node-serialize", | ||
"version": "1.1.10", | ||
"version": "1.2.0", | ||
"description": "Stream TAP test data as a serialized node:test stream", | ||
@@ -43,8 +43,8 @@ "tshy": { | ||
"dependencies": { | ||
"@tapjs/error-serdes": "1.1.0", | ||
"@tapjs/error-serdes": "1.2.0", | ||
"@tapjs/stack": "1.2.5", | ||
"tap-parser": "15.2.1" | ||
"tap-parser": "15.3.0" | ||
}, | ||
"peerDependencies": { | ||
"@tapjs/core": "1.3.10" | ||
"@tapjs/core": "1.4.0" | ||
}, | ||
@@ -51,0 +51,0 @@ "tap": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
126149
133
1088
4
+ Added@tapjs/after@1.1.11(transitive)
+ Added@tapjs/after-each@1.1.11(transitive)
+ Added@tapjs/asserts@1.1.11(transitive)
+ Added@tapjs/before@1.1.11(transitive)
+ Added@tapjs/before-each@1.1.11(transitive)
+ Added@tapjs/core@1.4.0(transitive)
+ Added@tapjs/error-serdes@1.2.0(transitive)
+ Added@tapjs/filter@1.2.11(transitive)
+ Added@tapjs/fixture@1.2.11(transitive)
+ Added@tapjs/intercept@1.2.11(transitive)
+ Added@tapjs/mock@1.2.9(transitive)
+ Added@tapjs/snapshot@1.2.11(transitive)
+ Added@tapjs/spawn@1.1.11(transitive)
+ Added@tapjs/stdin@1.1.11(transitive)
+ Added@tapjs/test@1.3.11(transitive)
+ Added@tapjs/typescript@1.3.0(transitive)
+ Added@tapjs/worker@1.1.11(transitive)
+ Addedtap-parser@15.3.0(transitive)
- Removed@tapjs/after@1.1.10(transitive)
- Removed@tapjs/after-each@1.1.10(transitive)
- Removed@tapjs/asserts@1.1.10(transitive)
- Removed@tapjs/before@1.1.10(transitive)
- Removed@tapjs/before-each@1.1.10(transitive)
- Removed@tapjs/core@1.3.10(transitive)
- Removed@tapjs/error-serdes@1.1.0(transitive)
- Removed@tapjs/filter@1.2.10(transitive)
- Removed@tapjs/fixture@1.2.10(transitive)
- Removed@tapjs/intercept@1.2.10(transitive)
- Removed@tapjs/mock@1.2.8(transitive)
- Removed@tapjs/snapshot@1.2.10(transitive)
- Removed@tapjs/spawn@1.1.10(transitive)
- Removed@tapjs/stdin@1.1.10(transitive)
- Removed@tapjs/test@1.3.10(transitive)
- Removed@tapjs/typescript@1.2.10(transitive)
- Removed@tapjs/worker@1.1.10(transitive)
- Removedtap-parser@15.2.1(transitive)
Updated@tapjs/error-serdes@1.2.0
Updatedtap-parser@15.3.0