e7738de6d2
CI / Deep Native Runtime Cases (1/6) (push) Has been skipped
CI / Native Preflight (push) Failing after 1s
CI / Native Runtime Cases (1/2) (push) Failing after 0s
CI / Native Runtime Cases (2/2) (push) Failing after 1s
CI / Native Metadata Reports (push) Failing after 0s
CI / Native Direct Backend Artifacts (push) Failing after 0s
CI / Native Sanitizer Smoke (push) Failing after 1s
CI / Command Contract Snapshots (push) Failing after 1s
CI / Deep Conformance Suite (push) Has been skipped
CI / Graph Build Perf (push) Failing after 1s
CI / Deep Native Preflight (push) Has been skipped
CI / Deep Native Runtime Cases (2/6) (push) Has been skipped
CI / Deep Native Runtime Cases (3/6) (push) Has been skipped
CI / Conformance Suite (push) Failing after 1s
CI / Workspace Checks (push) Failing after 0s
CI / Deep Native Runtime Cases (5/6) (push) Has been skipped
CI / Deep Native Runtime Cases (6/6) (push) Has been skipped
CI / Deep Native Runtime Cases (4/6) (push) Has been skipped
CI / Deep Graph Build Perf (push) Has been skipped
83 lines
2.2 KiB
JavaScript
83 lines
2.2 KiB
JavaScript
import nodeAssert from "node:assert/strict";
|
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
import { dirname } from "node:path";
|
|
|
|
const methods = ["deepEqual", "doesNotMatch", "equal", "match", "notEqual", "ok"];
|
|
|
|
function formatError(error) {
|
|
if (!(error instanceof Error)) return String(error);
|
|
return error.stack || error.message;
|
|
}
|
|
|
|
function formatFailure(failure, index) {
|
|
const header = `${index + 1}. ${failure.method}: ${failure.message}`;
|
|
return failure.stack ? `${header}\n${failure.stack}` : header;
|
|
}
|
|
|
|
export function createAggregateAssert(options = {}) {
|
|
const failFast = process.env.ZERO_VALIDATION_FAIL_FAST === "1" ||
|
|
process.env.ZERO_ASSERT_FAIL_FAST === "1" ||
|
|
options.failFast === true;
|
|
const failures = [];
|
|
|
|
function record(method, error) {
|
|
if (failFast) throw error;
|
|
failures.push({
|
|
method,
|
|
message: error instanceof Error ? error.message : String(error),
|
|
stack: error instanceof Error ? error.stack : "",
|
|
});
|
|
}
|
|
|
|
function aggregateAssert(value, message) {
|
|
try {
|
|
nodeAssert(value, message);
|
|
} catch (error) {
|
|
record("assert", error);
|
|
}
|
|
}
|
|
|
|
for (const method of methods) {
|
|
aggregateAssert[method] = (...args) => {
|
|
try {
|
|
nodeAssert[method](...args);
|
|
} catch (error) {
|
|
record(method, error);
|
|
}
|
|
};
|
|
}
|
|
|
|
aggregateAssert.fail = (...args) => {
|
|
try {
|
|
nodeAssert.fail(...args);
|
|
} catch (error) {
|
|
record("fail", error);
|
|
}
|
|
};
|
|
|
|
aggregateAssert.failures = failures;
|
|
return aggregateAssert;
|
|
}
|
|
|
|
export function finishAggregateAssert(assert, options = {}) {
|
|
const failures = assert?.failures ?? [];
|
|
if (failures.length === 0) return;
|
|
|
|
const suite = options.suite || "validation";
|
|
const reportPath = options.reportPath;
|
|
const summary = failures.map(formatFailure).join("\n\n");
|
|
const text = `${suite} collected ${failures.length} assertion failure(s):\n\n${summary}\n`;
|
|
|
|
if (reportPath) {
|
|
mkdirSync(dirname(reportPath), { recursive: true });
|
|
writeFileSync(reportPath, `${JSON.stringify({ suite, ok: false, failures }, null, 2)}\n`);
|
|
}
|
|
|
|
process.stderr.write(text);
|
|
process.exit(1);
|
|
}
|
|
|
|
export function describeFailure(error) {
|
|
return formatError(error);
|
|
}
|