Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addresses issue 5 in zzapi-vscode #2

Merged
merged 4 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/mergeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ function getMergedOptions(cOptions: RawOptions = {}, rOptions: RawOptions = {}):
const keepRawJSON = options.keepRawJSON == true;
const showHeaders = options.showHeaders == true;
const rawParams = options.rawParams == true;
const stopOnFailure = options.stopOnFailure == true;

return { follow, verifySSL, keepRawJSON, showHeaders, rawParams };
return { follow, verifySSL, keepRawJSON, showHeaders, rawParams, stopOnFailure };
}

function getMergedSetVars(
Expand Down
2 changes: 2 additions & 0 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface Options {
keepRawJSON: boolean;
showHeaders: boolean;
rawParams: boolean;
stopOnFailure: boolean;
}

export type Assertion = number | boolean | string | null | { [op: string]: any };
Expand Down Expand Up @@ -50,6 +51,7 @@ export interface RawOptions {
keepRawJSON?: boolean;
showHeaders?: boolean;
rawParams?: boolean;
stopOnFailure?: boolean;
}

export interface RawTests {
Expand Down
33 changes: 20 additions & 13 deletions src/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ import { getStringIfNotScalar } from "./utils/typeUtils";

import { Tests, ResponseData, TestResult, Assertion } from "./models";

export function runAllTests(tests: Tests, responseData: ResponseData): TestResult[] {
export function runAllTests(
tests: Tests,
responseData: ResponseData,
stopOnFailure: boolean,
): TestResult[] {
const results: TestResult[] = [];
if (!tests) return results;

for (const spec in tests.json) {
const expected = tests.json[spec];
const received = getValueForJSONTests(responseData.json, spec);
const jsonResults = runTest(spec, expected, received);
results.push(...jsonResults);
let statusFail = false;
if (tests.status) {
const expected = tests.status;
const received = responseData.status;
const statusResults = runTest("status", expected, received);
results.push(...statusResults);
statusFail = statusResults.some((r) => !r.pass);
}
if (stopOnFailure && statusFail) return results;

for (const spec in tests.headers) {
const expected = tests.headers[spec];
Expand All @@ -22,20 +29,20 @@ export function runAllTests(tests: Tests, responseData: ResponseData): TestResul
results.push(...headerResults);
}

for (const spec in tests.json) {
const expected = tests.json[spec];
const received = getValueForJSONTests(responseData.json, spec);
const jsonResults = runTest(spec, expected, received);
results.push(...jsonResults);
}

if (tests.body) {
const expected = tests.body;
const received = responseData.body;
const bodyResults = runTest("body", expected, received);
results.push(...bodyResults);
}

if (tests.status) {
const expected = tests.status;
const received = responseData.status;
const statusResults = runTest("status", expected, received);
results.push(...statusResults);
}

return results;
}

Expand Down
Loading