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

Set Jest's testEnvironment to "node" when not targetting a browser #1020

Closed
edmorley opened this issue Aug 15, 2018 · 2 comments
Closed

Set Jest's testEnvironment to "node" when not targetting a browser #1020

edmorley opened this issue Aug 15, 2018 · 2 comments
Labels
Milestone

Comments

@edmorley
Copy link
Member

Currently the @neutrinojs/jest preset doesn't define testEnvironment, so Jest uses the default of 'jsdom':
https://jestjs.io/docs/en/configuration.html#testenvironment-string

This seems fine for projects that are targetting the browser (eg @neutrinojs/web, ...), however for @neutrinojs/node or @neutrinojs/library (with target: 'node') a more suitable value for testEnvironment would be 'node'.

I'm not sure of the best way of checking within @neutrinojs/jest when to override the environment - hardcoding presets is a non-starter, so perhaps by inspecting the babel preset-env compile targets?

@eliperelman
Copy link
Member

eliperelman commented Aug 15, 2018

What about getting the value of neutrino.config.target()? For example:

testEnvironment: neutrino.config.get('target') === 'node' ? 'node' : 'jsdom'

@edmorley
Copy link
Member Author

Oh right yeah I forgot about the top level webpack target property. That will work well.

eliperelman pushed a commit that referenced this issue Aug 21, 2018
Since the `testEnvironment` default of `'jsdom'` is only suitable
when testing code intended to run in a browser environment. See:
https://jestjs.io/docs/en/configuration.html#testenvironment-string

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

No branches or pull requests

2 participants