You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
process.hrtime.bigint() comes back as undefined #43920
Linux XXX 4.15.0-101-generic #102-Ubuntu SMP Mon May 11 10:07:26 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
I have a nestjs app that gets tested using jest. Sometimes when the tests are being run on our build machine process.hrtime.bigint() comes back as undefined. I have not been able to repro this locally.
How often does it reproduce? Is there a required condition?
Randomly on build machine.
What is the expected behavior?
It's never undefined.
What do you see instead?
undefined
exportfunctiongetHrTimeBigInt(): bigint{consthrTimeBigInt=process.hrtime.bigint();if(hrTimeBigInt===undefined){getLogger().error(`Hell has frozen over bigint is undefined`);returnBigInt(0);}returnhrTimeBigInt;}
Only when tests are run on our build machine
console.error [winston] Attempt to write logs with no transports {"message":"Hell has frozen over bigint is undefined","level":"error"}
You can also try to freeze process and process.hrtime before running the tests. It should throw an error and show what is trying to override it.
Only if your code is in strict mode ("use strict" in CJS file, or an ESM file); in sloppy mode it will silently ignore the override (which should make your test pass but won't tell you what is trying to override that method).
Looks like bigintis being overwritten by some module (perhaps webpack or similar is forcing the use of some polyfill or is assuming it doesn't exist so it doesn't check that it exists first).
This:
function () {
return fn.apply(this, arguments);
}
should look more like this:
function hrtimeBigInt() {
binding.hrtimeBigInt();
return hrBigintValues[0];
}
Alright gang, I found the issue. Turns out replacing process.hrtime and putting it back in a separate test file was breaking things for reasons I don't quite understand. Thank you for humoring my OMG NODE IS BROKEN IN WAYS IT CAN'T BE thread.
it('didResolveOperation should record start time', async () => {
const hrtime = process.hrtime;
process.hrtime.bigint = jest.fn().mockReturnValueOnce(BigInt(100000000));
expect(listeners.didResolveOperation).toBeDefined();
if (!listeners.didResolveOperation) {
throw new Error('didResolveOperation undefined');
}
const context = {} as GraphQLRequestContextDidResolveOperationCustomized<GqlContext>;
await listeners.didResolveOperation(context);
expect(context.startTime).toEqual(BigInt(100000000));
process.hrtime = hrtime;
});
Activity
mscdex commentedon Jul 21, 2022
I don't see how it could possibly return
undefined. Perhaps some third party module is overriding that function's implementation?sshevlyagin commentedon Jul 21, 2022
I’m with you. The code runs in 30 tests and ends up failing like that in one or two of them consistently.
Does not fail on my M1 Mac so no local repro.
mscdex commentedon Jul 21, 2022
Perhaps when it returns
undefined, try doingconsole.log(process.hrtime.bigint.toString());to see if it at least matches what's in node core.targos commentedon Jul 21, 2022
You can also try to freeze
processandprocess.hrtimebefore running the tests. It should throw an error and show what is trying to override it.aduh95 commentedon Jul 21, 2022
Only if your code is in strict mode (
"use strict"in CJS file, or an ESM file); in sloppy mode it will silently ignore the override (which should make your test pass but won't tell you what is trying to override that method).sshevlyagin commentedon Jul 21, 2022
I'm using typescript so it's set to strict, I tried logging out
process.hrtimeandprocess.hrtime.bigintand it seems fine...The code
mscdex commentedon Jul 21, 2022
Looks like
bigintis being overwritten by some module (perhaps webpack or similar is forcing the use of some polyfill or is assuming it doesn't exist so it doesn't check that it exists first).This:
should look more like this:
sshevlyagin commentedon Jul 21, 2022
Alright gang, I found the issue. Turns out replacing
process.hrtimeand putting it back in a separate test file was breaking things for reasons I don't quite understand. Thank you for humoring my OMG NODE IS BROKEN IN WAYS IT CAN'T BE thread.