Skip to content

Commit

Permalink
Merge pull request #15 from agrostar/#7_skip-tests
Browse files Browse the repository at this point in the history
display SKIP for tests with skip attribute present in spec
  • Loading branch information
vasan-agrostar authored Jun 8, 2024
2 parents be010f2 + 759c0a2 commit fc916f3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 20 additions & 14 deletions src/getResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ import { displayUndefs, getOutputChannel } from "./utils/outputChannel";
import { getVarStore } from "./variables";
import { getGotRequest } from "./reformatRequest";

function formatTestResults(results: TestResult[], spec: string): string[] {
function formatTestResults(results: TestResult[], spec: string, skip?: boolean): string[] {
const resultLines: string[] = [];
for (const r of results) {
const testContent = `test ${spec}: expected ${r.op}: ${r.expected}`;
let line: string;
if (r.pass) {
line = `\t[INFO] test ${spec}: expected ${r.op}: ${r.expected} OK`;
if (skip) {
line = `\t[SKIP] ${testContent}`;
} else {
line = `\t[FAIL] test ${spec}: expected ${r.op}: ${r.expected} | got ${r.received}`;
if (r.pass) {
line = `\t[INFO] ${testContent} OK`;
} else {
line = `\t[FAIL] ${testContent} | got ${r.received}`;
}
if (r.message) line += `[${r.message}]`;
}
if (r.message) line += `[${r.message}]`;

resultLines.push(line);
}
Expand All @@ -34,22 +39,23 @@ function getFormattedResult(
size: number,
execTime: string | number,
): string {
function getResultData(res: SpecResult): [number, number] {
function getResultData(res: SpecResult): [number, number, boolean] {
const rootResults = res.results;
// console.log(typeof rootResults);
let passed = rootResults.filter((r) => r.pass).length,
all = rootResults.length;
let passed = !res.skipped ? rootResults.filter((r) => r.pass).length : 0,
all = !res.skipped ? rootResults.length : 0;

let hasSkip: boolean = res.skipped ?? false;
for (const s of res.subResults) {
const [subPassed, subAll] = getResultData(s);
const [subPassed, subAll, subSkip] = getResultData(s);
passed += subPassed;
all += subAll;
hasSkip = hasSkip || subSkip;
}

return [passed, all];
return [passed, all, hasSkip];
}

const [passed, all] = getResultData(specRes);
const [passed, all, hasSkip] = getResultData(specRes);

let message = `${new Date().toLocaleString()} `;
message += all === passed ? "[INFO] " : "[ERROR] ";
Expand All @@ -58,15 +64,15 @@ function getFormattedResult(
message += `${method} ${name} status: ${status} size: ${size} B time: ${execTime} ${testString}`;

function getResult(res: SpecResult, preSpec?: string): string {
if (passed === all) return "";
if (passed === all && !hasSkip) return "";

const getFullSpec = (): string => {
if (!res.spec) return "";
return (preSpec ? preSpec + " / " : "") + res.spec;
};

const spec = getFullSpec();
const resultLines = formatTestResults(res.results, spec);
const resultLines = formatTestResults(res.results, spec, res.skipped);
const subResultLines = [];
for (const s of res.subResults) {
const subRes = getResult(s, spec);
Expand Down

0 comments on commit fc916f3

Please sign in to comment.