Add testEnvironmentOptions to apply to jsdom options or node context.#5003
Add testEnvironmentOptions to apply to jsdom options or node context.#5003cpojer merged 10 commits intojestjs:masterfrom
testEnvironmentOptions to apply to jsdom options or node context.#5003Conversation
Codecov Report
@@ Coverage Diff @@
## master #5003 +/- ##
=======================================
Coverage 60.37% 60.37%
=======================================
Files 198 198
Lines 6637 6637
Branches 4 4
=======================================
Hits 4007 4007
Misses 2630 2630
Continue to review full report at Codecov.
|
|
Thanks for the review, I'll add an integration test for passing the options. |
|
I'm ok with it. Many people have asked for it and there is no reason for me to keep pushing back on a config option for this. |
|
@SimenB I've added an integration test for the testEnvironmentOptions. The config.test.js seemed the most applicable place, but let me know if it should live elsewhere. |
|
The new test is failing CI. I'm wondering if one should key the config per environment? Is it an issue that jsdom options are passed to vm, or the other way around? |
|
I've updated some lint glitches and a CHANGELOG merge conflict. |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
There wasn't a way to override options given to jsdom or node environments, e.g. jsdom only allowed for url: config.testURL. But we need to adjust jsdom options such as "userAgent": "Agent/007" or "runScripts": "outside-only", or "resources": "enable".
This adds an optional testEnvironmentOptions Object to the Config that's then Object.assign()ed to the jsdom options or node context.
Test plan
After adjusting the code and docs, the project was built locally and a simple test as below shows the testEnvironmentOptions can be used to override the userAgent given to jsdom.
package.json:
my.test.js:
Command-line test run: