Usage with Jest
Attempting to run benchmark within Jest errors with:
TypeError: Cannot read property 'parentNode' of undefined
at runScript (node_modules/benchmark/benchmark.js:664:27)
It appears that Benchmark believes it's inside a browser environment via supports.browser. If I hack that boolean to false everything runs happily.
Is there a way to force supports.browser to false in a config?
Or is there a recommended approach for use within Jest tests?
I'll treat this as a feature request for a more robust supports.browser check 😄
Not entirely Benchmark's fault since Jest defaults to a jsdom environment :smile:
Benchmark works as expected when the environment is set to node at the top of a test file.
/**
* @jest-environment node
*/
I have the same error on repl.it: https://repl.it/Kh98/1
I have the same error as well in Jest.
Same error in CodeSandbox: https://codesandbox.io/s/30l42zjjv1
I could get it to work if I set the testEnvironment to node in the jest.config.js. Therefore, we wouldn't need to set the @jest-environment node comment in every file.
Maybe someone can confirm :innocent:?
module.exports = {
testEnvironment: 'node',
...
};
What if I have code that needs to run in jsdom - is there a way to hack support.browser to be false? :)
There's a jest reporter now, https://github.com/pckhoi/jest-bench - just wondering how to use it to create a baseline...