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

Change Date.now() to performance.now() to fix shaky test #392

Merged
merged 1 commit into from
Aug 5, 2024
Merged
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
18 changes: 9 additions & 9 deletions test/basics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ describe("MockAdapter basics", function () {

it("allows delay in millsecond per request (legacy non-chaining)", function () {
mock = new MockAdapter(instance);
var start = Date.now();
var start = performance.now();
var firstDelay = 100;
var secondDelay = 500;
var success = 200;
Expand All @@ -576,14 +576,14 @@ describe("MockAdapter basics", function () {

return Promise.all([
instance.get("/foo").then(function (response) {
var end = Date.now();
var end = performance.now();
var totalTime = end - start;

expect(response.status).to.equal(success);
expect(totalTime).greaterThanOrEqual(firstDelay);
}),
instance.get("/bar").then(function (response) {
var end = Date.now();
var end = performance.now();
var totalTime = end - start;

expect(response.status).to.equal(success);
Expand All @@ -594,7 +594,7 @@ describe("MockAdapter basics", function () {

it("allows delay in millsecond per request", function () {
mock = new MockAdapter(instance);
var start = Date.now();
var start = performance.now();
var firstDelay = 100;
var secondDelay = 500;
var success = 200;
Expand All @@ -609,14 +609,14 @@ describe("MockAdapter basics", function () {

return Promise.all([
instance.get("/foo").then(function (response) {
var end = Date.now();
var end = performance.now();
var totalTime = end - start;

expect(response.status).to.equal(success);
expect(totalTime).greaterThanOrEqual(firstDelay);
}),
instance.get("/bar").then(function (response) {
var end = Date.now();
var end = performance.now();
var totalTime = end - start;

expect(response.status).to.equal(success);
Expand All @@ -626,7 +626,7 @@ describe("MockAdapter basics", function () {
});

it("overrides global delay if request per delay is provided and respects global delay if otherwise", function () {
var start = Date.now();
var start = performance.now();
var requestDelay = 100;
var globalDelay = 500;
var success = 200;
Expand All @@ -638,7 +638,7 @@ describe("MockAdapter basics", function () {

return Promise.all([
instance.get("/foo").then(function (response) {
var end = Date.now();
var end = performance.now();
var totalTime = end - start;

expect(response.status).to.equal(success);
Expand All @@ -647,7 +647,7 @@ describe("MockAdapter basics", function () {
expect(totalTime).lessThan(globalDelay);
}),
instance.get("/bar").then(function (response) {
var end = Date.now();
var end = performance.now();
var totalTime = end - start;

expect(response.status).to.equal(success);
Expand Down
Loading