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

No report generated and failures are ignored if Date.now is stubed to return an invalid value #160

Open
Flarna opened this issue Dec 30, 2021 · 1 comment

Comments

@Flarna
Copy link

Flarna commented Dec 30, 2021

If Date.now is stubbed to return an invalid value an exception happens in reporter causing that no report is generated and exit code from mocha is 0 even a test failed.

Reproducer:

const assert = require("assert");
const sinon = require("sinon");

describe("suite", () => {
  const stub = sinon.stub(Date, "now");
  stub.returns(9000000000000000);

  it("test", () => {
    assert.strictEqual(1, 2);
  });
});

I know that stubbing Date.now like this is not the best idea but I think an exception in reporter should not result in swallowing failed tests.

The exception happens at line _suiteAttr.timestamp = new Date(_suiteAttr.timestamp).toISOString().slice(0, -5); in MochaJUnitReporter.prototype.getXml() because _suiteAttr.timestamp is 9000000000000000 which is to high for new Date().

@calipee
Copy link

calipee commented Jun 24, 2022

I'm experiencing a similar problem when stubbing Date.now(), but in my case the process just doesn't finish and no report is generated.

In my Case adding Date.now.restore(); before the test ends solved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants