Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testEnvironmentOptions to apply to jsdom options or node context. #5003

Merged
merged 10 commits into from
Dec 6, 2017

Conversation

kmashint
Copy link
Contributor

@kmashint kmashint commented Dec 2, 2017

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:

{
  "jest": {
    "testEnvironmentOptions": {
      "userAgent": "Agent/007"
    }
  }
}

my.test.js:

describe("testEnvironmentOptions", function () {
  it("is Agent/007", function () {
    expect(navigator.userAgent).toBe("Agent/007");
  });
});

Command-line test run:

$ ../jest/jest
PASS .\my.test.js
  testEnvironmentOptions
    √ is Agent/007 (3ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.683s
Ran all test suites.

@codecov-io
Copy link

codecov-io commented Dec 2, 2017

Codecov Report

Merging #5003 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #5003   +/-   ##
=======================================
  Coverage   60.37%   60.37%           
=======================================
  Files         198      198           
  Lines        6637     6637           
  Branches        4        4           
=======================================
  Hits         4007     4007           
  Misses       2630     2630
Impacted Files Coverage Δ
packages/jest-config/src/normalize.js 92.94% <ø> (ø) ⬆️
packages/jest-config/src/valid_config.js 100% <ø> (ø) ⬆️
packages/jest-config/src/index.js 23.8% <ø> (ø) ⬆️
packages/jest-config/src/defaults.js 100% <ø> (ø) ⬆️
packages/jest-environment-jsdom/src/index.js 40% <100%> (ø) ⬆️
packages/jest-environment-node/src/index.js 76.66% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6ade256...9f5b435. Read the comment docs.

docs/Configuration.md Outdated Show resolved Hide resolved
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! Not sure if @cpojer is up for it, though 🙂

Can you add an integration test verifying that options are passed in?

@kmashint
Copy link
Contributor Author

kmashint commented Dec 3, 2017

Thanks for the review, I'll add an integration test for passing the options.

@cpojer
Copy link
Member

cpojer commented Dec 4, 2017

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.

@kmashint
Copy link
Contributor Author

kmashint commented Dec 6, 2017

@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.

@SimenB
Copy link
Member

SimenB commented Dec 6, 2017

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?

@kmashint
Copy link
Contributor Author

kmashint commented Dec 6, 2017

I've updated some lint glitches and a CHANGELOG merge conflict.

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants