1

I basically copy-pasted the Mocha.js Base reporter to build a custom reporter.
Now for some reason, inside the on "end" callback, Date.now() returns 0,
while new Date() returns a date for Thu Jan 01 1970 01:00:00 GMT+0100 (CET).

And I really don’t get it. This language is driving me nuts.
Hope someone knows what’s going on here.

enter image description here

rubiii
  • 6,903
  • 2
  • 38
  • 51
  • I see new Date; over there, you sure you did new Date()? – Steve Oct 30 '14 at 00:24
  • 2
    What do you see in the console if you just type `Date.now`? It should be `function now() { [native code] }`. If it isn't, then something has overridden it – Phil Oct 30 '14 at 00:25
  • 1
    @Steve doesn't matter. See http://stackoverflow.com/questions/3034941/new-myobject-vs-new-myobject – Phil Oct 30 '14 at 00:26
  • 1
    @Phil nice! `function now() { return target.clock.now; }` looks like something changed the function. `clock` sounds like it may be coming from sinon.js. I’ll look into it. Thanks man! – rubiii Oct 30 '14 at 00:32
  • you might want to add some CSP to this page, with the rule "don't override existing prototypes" at the very least. That should even tell you what's doing the redefining. – Mike 'Pomax' Kamermans Oct 30 '14 at 00:36
  • It’s sinon.js’ fake timer: https://github.com/cjohansen/Sinon.JS/blob/5ea0c84c2d95187da191039fe3923d697a4c09e9/lib/sinon/util/fake_timers.js#L115-L117 – rubiii Oct 30 '14 at 00:40

1 Answers1

1

You might be using sinon's fake timer somewhere in another test

clock = sinon.useFakeTimers()

but forgetting to restore it after the tests finished running:

clock.restore()
syonip
  • 2,762
  • 25
  • 27