Skip to content

Commit

Permalink
chore: disable inspection of spec (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
ASaiAnudeep authored Oct 20, 2024
1 parent 7a692c0 commit eeb8cb5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pactum",
"version": "3.7.1",
"version": "3.7.2",
"description": "REST API Testing Tool for all levels in a Test Pyramid",
"main": "./src/index.js",
"types": "./src/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion src/models/Spec.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ declare class Spec {
* @see https://pactumjs.github.io/api/requests/inspect.html
*/
inspect(): Spec;
inspect(enable: boolean): Spec;
inspect(path: string): Spec;

/**
Expand Down Expand Up @@ -457,7 +458,7 @@ declare class Spec {
*/
end(): Spec;

/**
/**
* sleep after spec execution
* @see https://pactumjs.github.io/api/utils/sleep.html
*/
Expand Down
14 changes: 6 additions & 8 deletions src/models/Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class Spec {
return this;
}
this._request.followRedirects = follow;
return this;
return this;
}

withCompression() {
Expand Down Expand Up @@ -516,17 +516,15 @@ class Spec {
}

inspect(inspect_path) {
if (this._inspect) {
if (typeof this._inspect === 'boolean') {
if (typeof inspect_path === 'string') {
if (!Array.isArray(this._inspect)) {
this._inspect = [];
}
this._inspect.push(inspect_path);
} else if (typeof inspect_path === 'boolean') {
this._inspect = inspect_path;
} else {
if (inspect_path) {
this._inspect = [inspect_path];
} else {
this._inspect = true;
}
this._inspect = true;
}
return this;
}
Expand Down
12 changes: 9 additions & 3 deletions src/models/Tosser.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Tosser {
if (this.spec._inspect) {
log.warn('Inspecting Request & Response');
if (typeof this.spec._inspect === 'boolean') {
utils.printReqAndRes(this.request, this.response);
this.printRequestAndResponse();
} else {
for (let i = 0; i < this.spec._inspect.length; i++) {
const inspect_path = this.spec._inspect[i];
Expand Down Expand Up @@ -214,7 +214,7 @@ class Tosser {
this.spec.status = 'FAILED';
this.spec.failure = error.toString();
this.runReport();
utils.printReqAndRes(this.request, this.response);
this.printRequestAndResponse();
throw error;
}
}
Expand All @@ -224,7 +224,7 @@ class Tosser {
this.spec.status = 'ERROR';
this.spec.failure = this.response.toString();
this.runReport();
utils.printReqAndRes(this.request, this.response);
this.printRequestAndResponse();
this.expect.fail(this.response);
}
}
Expand All @@ -249,6 +249,12 @@ class Tosser {
}
}

printRequestAndResponse() {
if (this.spec._inspect !== false) {
utils.printReqAndRes(this.request, this.response);
}
}

}

async function getResponse(tosser) {
Expand Down
12 changes: 12 additions & 0 deletions test/component/inspect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,16 @@ describe('Inspect', () => {
.inspect('people[country=AU]');
});

it('do not inspect on failure', async () => {
try {
await spec()
.useInteraction('get people')
.get('http://localhost:9393/api/people')
.expectStatus(400)
.inspect(false);
} catch {

}
});

});

0 comments on commit eeb8cb5

Please sign in to comment.