tdd-guard
Version:
Automated Test-Driven Development enforcement for Claude Code
58 lines (57 loc) • 2.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestResultSchema = exports.TestModuleSchema = exports.TestSchema = exports.UnhandledErrorSchema = exports.TestErrorSchema = void 0;
exports.isTestModule = isTestModule;
exports.isTestCase = isTestCase;
exports.isFailingTest = isFailingTest;
exports.isPassingTest = isPassingTest;
exports.isTestPassing = isTestPassing;
const zod_1 = require("zod");
exports.TestErrorSchema = zod_1.z.object({
message: zod_1.z.string(),
stack: zod_1.z.string().optional(),
});
exports.UnhandledErrorSchema = zod_1.z.object({
name: zod_1.z.string(),
message: zod_1.z.string(),
stack: zod_1.z.string().optional(),
});
exports.TestSchema = zod_1.z.object({
name: zod_1.z.string(),
fullName: zod_1.z.string(),
state: zod_1.z.enum(['passed', 'failed', 'skipped']),
errors: zod_1.z.array(exports.TestErrorSchema).optional(),
});
exports.TestModuleSchema = zod_1.z.object({
moduleId: zod_1.z.string(),
tests: zod_1.z.array(exports.TestSchema),
});
exports.TestResultSchema = zod_1.z.object({
testModules: zod_1.z.array(exports.TestModuleSchema),
unhandledErrors: zod_1.z.array(exports.UnhandledErrorSchema).optional(),
reason: zod_1.z.enum(['passed', 'failed', 'interrupted']).optional(),
});
function isTestModule(value) {
return exports.TestModuleSchema.safeParse(value).success;
}
function isTestCase(value) {
return exports.TestSchema.safeParse(value).success;
}
function isFailingTest(value) {
return isTestCase(value) && value.state === 'failed';
}
function isPassingTest(value) {
return isTestCase(value) && value.state === 'passed';
}
function isTestPassing(testResult) {
// No tests means the test suite is not passing
if (testResult.testModules.length === 0) {
return false;
}
// Check if any tests exist
const hasTests = testResult.testModules.some((module) => module.tests.length > 0);
if (!hasTests) {
return false;
}
return testResult.testModules.every((module) => module.tests.every((test) => test.state !== 'failed'));
}