Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | 1x 1x | import type { TestResult } from "@featurevisor/types";
import {
CLI_COLOR_CYAN,
CLI_FORMAT_BOLD,
CLI_FORMAT_GREEN,
CLI_FORMAT_RED,
colorize,
} from "./cliFormat";
import { prettyDuration } from "./prettyDuration";
export function printTestResult(testResult: TestResult, relativeTestFilePath, rootDirectoryPath) {
console.log("");
const title = `Testing: ${relativeTestFilePath.replace(rootDirectoryPath, "")} (${prettyDuration(
testResult.duration,
)})`;
console.log(colorize(title, CLI_COLOR_CYAN));
if (testResult.notFound) {
console.log(CLI_FORMAT_RED, ` => ${testResult.type} ${testResult.key} not found`);
return;
}
console.log(CLI_FORMAT_BOLD, ` ${testResult.type} "${testResult.key}":`);
testResult.assertions.forEach(function (assertion) {
if (assertion.passed) {
console.log(
CLI_FORMAT_GREEN,
` ✔ ${assertion.description} (${prettyDuration(assertion.duration)})`,
);
} else {
console.log(
CLI_FORMAT_RED,
` ✘ ${assertion.description} (${prettyDuration(assertion.duration)})`,
);
assertion.errors?.forEach(function (error) {
if (error.message) {
console.log(CLI_FORMAT_RED, ` => ${error.message}`);
return;
}
let section: string = error.type;
if (error.type === "flag") {
section = "expectedToBeEnabled";
} else if (error.type === "variation") {
section = "expectedVariation";
} else if (error.type === "variable") {
section = "expectedVariables";
}
if (error.details && error.details.childIndex !== undefined) {
section = `children[${error.details.childIndex}].${section}`;
}
if (error.type === "variable") {
const variableKey = (error.details as any).variableKey;
console.log(CLI_FORMAT_RED, ` => ${section}.${variableKey}:`);
console.log(CLI_FORMAT_RED, ` => expected: ${error.expected}`);
console.log(CLI_FORMAT_RED, ` => received: ${error.actual}`);
} else {
if (error.type === "evaluation") {
if (error.details && error.details.variableKey) {
section = `${section}.variables.${error.details.variableKey}.${error.details.evaluationKey}`;
} else if (error.details && error.details.evaluationType) {
section = `${section}.${error.details.evaluationType}.${error.details.evaluationKey}`;
}
}
console.log(
CLI_FORMAT_RED,
` => ${section}: expected "${error.expected}", received "${error.actual}"`,
);
}
});
}
});
}
|