Skip to content

Commit

Permalink
sleep after running a spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajaneeshkumar committed May 17, 2024
1 parent ea9686d commit bd7534b
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 4 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.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pactum",
"version": "3.6.8",
"version": "3.6.9",
"description": "REST API Testing Tool for all levels in a Test Pyramid",
"main": "./src/index.js",
"types": "./src/index.d.ts",
Expand All @@ -10,7 +10,7 @@
"scripts": {
"test": "npm run test:unit && npm run test:component",
"test:unit": "mocha --timeout 10000 ./test/unit/",
"test:component": "mocha --timeout 10000 ./test/component/",
"test:component:tag": "mocha --timeout 10000 ./test/component/ --grep '@tag'",
"coverage": "nyc --reporter=lcov --reporter=text npm run test",
"lint": "eslint src/**/*.js"
},
Expand Down
6 changes: 6 additions & 0 deletions src/models/Spec.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,12 @@ declare class Spec {
* @see https://pactumjs.github.io/api/requests/end.html
*/
end(): Spec;

/**
* sleep after spec execution
* @see https://pactumjs.github.io/api/utils/sleep.html
*/
sleep(ms: number): Promise<void>;
}

declare namespace Spec { }
6 changes: 6 additions & 0 deletions src/models/Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ class Spec {
this._save = null;
this._data_maps = [];
this._specHandlerData = data;
this._sleep = '';
hr.spec(name, data, this);
this._opts = opts || {};
this._opts.handler_name = name;
this._expect.setDefaultResponseExpectations();
}

sleep(ms) {
this._sleep = ms;
return this;
}

name(value) {
this._name = value;
Expand Down
2 changes: 2 additions & 0 deletions src/models/Tosser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Tosser {
this.request = spec._request;
this.state = spec._state;
this.expect = spec._expect;
this.sleep = spec._sleep;
this.interactions = spec.interactions;
this.previousLogLevel = spec.previousLogLevel;
this.response = {};
Expand Down Expand Up @@ -50,6 +51,7 @@ class Tosser {
}
return th.getOutput(this.spec, this.spec._returns);
} finally {
this.sleep !== "" && await helper.sleep(this.sleep);
await this.removeInteractionsFromServer();
this.setPreviousLogLevel();
}
Expand Down
4 changes: 4 additions & 0 deletions test/component/bdd.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ describe('BDD', () => {
ce(err).not.undefined;
});

it('Should sleep after spec', async () => {
await spec.get('http://localhost:9393/api/users').expectStatus(200).sleep(3000);
});

});

describe('BDD - AutoReportRunner Disabled', () => {
Expand Down
14 changes: 14 additions & 0 deletions test/component/spec.handler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,18 @@ describe('Spec Handler', () => {
});
});

it('sleep in spec handler', async () => {
await pactum
.spec('get users')
.expectStatus(200)
.expectJson([
{
id: 1
},
{
id: 2
}
])
.sleep(3000);
});
});

0 comments on commit bd7534b

Please sign in to comment.