-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Pass docblock pragmas to TestEnvironment constructor. #8320
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the docblock types exported from anywhere? Maybe not worth the dep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I didn’t think it was worth the dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
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
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