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

Pass docblock pragmas to TestEnvironment constructor. #8320

Merged
merged 7 commits into from Apr 13, 2019

Conversation

Projects
None yet
5 participants
@scotthovestadt
Copy link
Contributor

commented Apr 12, 2019

Summary

This simple PR allows test environments to take advantage of docblock pragmas for test file configuration.

For example, in an E2E test, you may want your environment to know during setup that the test user should be configured a certain way. Since that setup may happen when the environment is constructed and before the tests and test hooks are actually run, there needs to be a way for that configuration to be specified.

The docblock is a great fit for that use-case and fits the "Jest way" of doing things, since it's already used in a similar way internally (for specifying the test environment). While it's possible today for any environment to import jest-docblock and re-parse the test file, I thought it would be a better UX to have the pragmas passed in, especially since they are already available.

Test plan

  • All tests pass.
  • Added new test for this feature.
  • Added documentation.

@scotthovestadt scotthovestadt requested a review from SimenB Apr 13, 2019

@SimenB

SimenB approved these changes Apr 13, 2019

Copy link
Collaborator

left a comment

Great idea!

// passed, or not. The context itself is optional, not properties within it.
export type EnvironmentContext = Partial<{
console: Console;
docblockPragmas: {[key: string]: string | Array<string>};

This comment has been minimized.

Copy link
@SimenB

SimenB Apr 13, 2019

Collaborator

Is the docblock types exported from anywhere? Maybe not worth the dep

This comment has been minimized.

Copy link
@scotthovestadt

scotthovestadt Apr 13, 2019

Author Contributor

Yeah, I didn’t think it was worth the dependency.

@jeysal

jeysal approved these changes Apr 13, 2019

Copy link
Collaborator

left a comment

Very good idea indeed. Wondering if you already have use cases for this in mind @scotthovestadt?

*/
'use strict';

test('access env', () => {
expect(property).toBe('value'); // eslint-disable-line no-undef
});

test('docblock pragmas', () => {

This comment has been minimized.

Copy link
@jeysal

jeysal Apr 13, 2019

Collaborator

Would prefer a distinct test file and Environment impl to separate concerns - this one tests ESM default export support and I wouldn't want docblock pragmas to fail as well if that breaks

This comment has been minimized.

Copy link
@scotthovestadt

scotthovestadt Apr 13, 2019

Author Contributor

Done.

@codecov-io

This comment has been minimized.

Copy link

commented Apr 13, 2019

Codecov Report

Merging #8320 into master will not change coverage.
The diff coverage is 0%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #8320   +/-   ##
=======================================
  Coverage   62.17%   62.17%           
=======================================
  Files         266      266           
  Lines       10683    10683           
  Branches     2597     2598    +1     
=======================================
  Hits         6642     6642           
  Misses       3452     3452           
  Partials      589      589
Impacted Files Coverage Δ
packages/jest-runner/src/runTest.ts 2.43% <0%> (ø) ⬆️

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 538cef4...740075b. Read the comment docs.

@scotthovestadt scotthovestadt merged commit 1f280d8 into facebook:master Apr 13, 2019

11 checks passed

ci/circleci: lint-and-typecheck Your tests passed on CircleCI!
Details
ci/circleci: test-browser Your tests passed on CircleCI!
Details
ci/circleci: test-jest-circus Your tests passed on CircleCI!
Details
ci/circleci: test-node-10 Your tests passed on CircleCI!
Details
ci/circleci: test-node-11 Your tests passed on CircleCI!
Details
ci/circleci: test-node-6 Your tests passed on CircleCI!
Details
ci/circleci: test-node-8 Your tests passed on CircleCI!
Details
ci/circleci: test-or-deploy-website Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
deploy/netlify Deploy preview ready!
Details
facebook.jest #20190413.2 succeeded
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.