-
Notifications
You must be signed in to change notification settings - Fork 109
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
window.performance.mark becomes undefined after timer install #136
Comments
I had to do some digging, the error on my side was coming from this line: https://github.com/facebook/react/blob/v16.0.0/src/renderers/shared/fiber/ReactDebugFiberPerf.js#L81. |
Verified. Here is the test with a browserified transpiled output that can be copy-pasted directly into Chrome for verification. Tested with |
@oliviertassinari wanna take a shot at a PR at this? Otherwise I can probably take a stab |
@benjamingr I'm already pretty busy with Material-UI. Sorry, it's not a priority for me. |
@oliviertassinari no need to justify or apologize - it's entirely fine if it's not a priority for you - I was merely offering :) |
@fatso83 I still can't assign myself to issues by the way :D I'll take a stab next week hopefully |
Is there anyone working at this issue at the moment? :-) |
sorry, completely forgot about it - can take a look early next week |
Thank you very much! |
Hi guys, news about this issue? thanks |
@risinglf Feel free to have a go. It's a very minor fix that you can probably make a PR for in 30 mins. |
As a temporary solution, I used the following function: function useFakeTimers() {
const timer = sinon.useFakeTimers();
performance.mark = () => void 0;
performance.clearMarks = () => void 0;
performance.measure = () => void 0;
performance.clearMeasures = () => void 0;
}
const timer = useFakeTimers(); It works with: |
This temporary solution did not work for me using: However, @oliviertassinari's workaround did work for me. |
Going to tackle this now |
I added a test case as: describe("issue #136", function () {
if (performancePresent) {
it("should clear performance.mark after uninstall", function () {
var oldMark = performance.mark;
var clock = lolex.install();
assert.same(performance.mark, oldMark);
clock.uninstall();
assert.same(performance.mark, oldMark);
});
}
}); but it passed without any changes - what am I not understanding? |
Hi, any news on this issue? |
This is what I'm seeing: In my test: beforeEach(function() {
console.log('pm0:', performance.mark)
this.clock = sinon.useFakeTimers()
console.log('pm1:', performance.mark)
})
afterEach(function() {
console.log('pm2:', performance.mark)
this.clock.restore()
console.log('pm3:', performance.mark)
}) Output:
So sinon is setting performance.mark to undefined for some reason. |
So sinon is setting performance.mark to undefined for some reason. So maybe the testcase should look like this: describe("issue #136", function () {
if (performancePresent) {
it("should clear performance.mark after uninstall", function () {
var oldMark = performance.mark;
var clock = sinon.useFakeTimers();
assert.same(performance.mark, oldMark);
assert.equals(typeOf performance.mark , 'function'); // I do not know this assert api, but you get the gist
clock.uninstall();
assert.same(performance.mark, oldMark);
});
}
}); |
@tarjei are you able to reproduce it with lolex alone? |
@benjamingr I didn't try as it seemed to me to be related to sinon - esp since your testcase works. How do I run the tests with performancePresent btw? It seems that the performance object is missing when I run npm test. |
I think I know what the cause is. May I have fix this issue? |
@CoderK I suspect that a PR would be most welcome :) 👍 |
Ok, I’m gonna make a patch soon! |
I created pull request, #160. If there is someone who has admin permissions, please review my PR. |
Until #160 is approved, I just did this before starting any tests import lolex from 'lolex'
const org_install = lolex.install
lolex.install = () => {
return org_install({
toFake: ['setTimeout', 'clearTimeout', 'setImmediate', 'clearImmediate', 'setInterval', 'clearInterval', 'Date'],
})
} |
See sinonjs/fake-timers#136 We don't use fake timers, but we do use lolex's clock, which probably causes the same thing. Jumping from 2.x to 4.x looks largely compatible - tests pass.
I have noticed the following behavior in the browser:
window.performance
became a function after callinguseFakeTimers
. I believe that the issue is coming from this line:https://github.com/sinonjs/lolex/blob/c08ff362a47e9786bc62da6c37175838bb7bd21e/src/lolex-src.js#L406-L408
One simple workaround is the following:
The text was updated successfully, but these errors were encountered: