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 shorthand for watch plugins and runners #7213

Merged
merged 9 commits into from
Oct 26, 2018

Conversation

rogeliog
Copy link
Contributor

Summary

This PR fixes #7156

Test plan

Tests were added.

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.

This is awesome! Turned out pretty clean 🙂

Should we update some docs for this?

});

if (!module) {
throw createValidationError(
Copy link
Member

Choose a reason for hiding this comment

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

seems like you could throw this in resolveWithPrefix? They're all identical except for, in this case, Test environment and 'testEnvironment'.

So you could end up with e.g.

export const getTestEnvironment = ({
  rootDir,
  testEnvironment: filePath,
}: Object) => {
  return resolveWithPrefix(null, {
    filePath,
    prefix: 'jest-environment-',
    rootDir,
    optionName: 'testEnvironment',
    humanOptionName: 'Test environment',
  });
};

or something like that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally left it out because the watch plugin validation happens as an element in an array. But I guess it is fine to show the same message.

export const getTestEnvironment = ({
rootDir,
testEnvironment: filePath,
}: Object) => {
Copy link
Member

@SimenB SimenB Oct 20, 2018

Choose a reason for hiding this comment

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

can we use a better type than Object here? I know you didn't introduce it

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.

Should be mentioned in the docs.

https://jestjs.io/docs/en/configuration#runner-string

Watch plugins are actually missing from https://jestjs.io/docs/en/configuration...

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.

So good!

@SimenB
Copy link
Member

SimenB commented Oct 20, 2018

Flow errors :(

@@ -55,10 +55,10 @@ async function runTestInternal(

let testEnvironment = config.testEnvironment;

if (customEnvironment) {
if (customEnvironment && customEnvironment[0]) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was failing Flow because it was passing an array instead of a string(and before the flow type was more relaxed)

From what I understand this only workder because at some point in getTestEnviromnent we are doing jest-environment-${env} which if env was an array(jest-envrionment-${['my-env']}), it would just get stringified as jest-environment-my-env. Same story when it does require.resolve(${prefix}${fileName}).

Does this change make sense? From what I can think you can only pass one env per docblock

Copy link
Member

Choose a reason for hiding this comment

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

Does this change make sense? From what I can think you can only pass one env per docblock

Yeah, it does! We might want to allow multiple envs in the future (to test in both node and the browser), but for now this is correct 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I might just add a @FlowFixMe because it seems that even though the type says Array<string> | string it seems to be a string when passing the docblock.

I'll investigate more later today because I have to head out.

@thymikee
Copy link
Collaborator

Mind rebasing? :)

@SimenB
Copy link
Member

SimenB commented Oct 26, 2018

Is this ready to land @rogeliog? I was holding off on merging due to #7213 (comment)

@thymikee
Copy link
Collaborator

@SimenB it was addressed in 3d72075

@thymikee thymikee merged commit c22d9f5 into jestjs:master Oct 26, 2018
@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 12, 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.

Support shorthand notation for jest-watch-<plugin_name>
4 participants