Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Usage with Jest #191

Open
DJTB opened this issue Jun 11, 2017 · 8 comments
Open

Usage with Jest #191

DJTB opened this issue Jun 11, 2017 · 8 comments

Comments

@DJTB
Copy link

DJTB commented Jun 11, 2017

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?

@jdalton
Copy link
Member

jdalton commented Jun 11, 2017

I'll treat this as a feature request for a more robust supports.browser check 😄

@DJTB
Copy link
Author

DJTB commented Jun 11, 2017

Not entirely Benchmark's fault since Jest defaults to a jsdom environment 😄

Benchmark works as expected when the environment is set to node at the top of a test file.

/**
 * @jest-environment node
 */

@franky47
Copy link

franky47 commented Sep 5, 2017

I have the same error on repl.it:
https://repl.it/Kh98/1

@wongjiahau
Copy link

I have the same error as well in Jest.

@hexpunk
Copy link

hexpunk commented Mar 27, 2018

Same error in CodeSandbox: https://codesandbox.io/s/30l42zjjv1

@PhilippeMorier
Copy link

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 😇?

module.exports = {
  testEnvironment: 'node',
  ...
};

@wongrichardalex
Copy link

What if I have code that needs to run in jsdom - is there a way to hack support.browser to be false? :)

@Stephanemw
Copy link

There's a jest reporter now, https://github.com/pckhoi/jest-bench - just wondering how to use it to create a baseline...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

8 participants