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

Allow plugins to override other plugins #5878

Merged
merged 2 commits into from
Mar 28, 2018

Conversation

rogeliog
Copy link
Contributor

@rogeliog rogeliog commented Mar 27, 2018

This PR allows third party plugins to override the "key" that an internal plugin is using.

Contributes to #5478

asdsa

Summary

Test plan

@rickhanlonii
Copy link
Member

rickhanlonii commented Mar 27, 2018

I'll review asap - and I can handle the merge conflict too

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 amazing, shaping up! :D

return -1;
}

const usageInfoA = a.getUsageInfo && a.getUsageInfo(globalConfig);
Copy link
Member

Choose a reason for hiding this comment

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

Should the base class every watch plugin extends have a getUsageInfo function which returns null or empty string so you don't have to check for its existence?

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 think this will make the implementation easier, but I'm worried about making the API for the consumers a bit harder. Given that there will be plugins that do not implement it

Copy link
Contributor Author

@rogeliog rogeliog Mar 28, 2018

Choose a reason for hiding this comment

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

I sometimes wonder if we should just move everything to be a jest hook, and make the whole API just around jest hooks

class MyPlugin {
  apply(jestHooks) {
    jestHooks.run(/* ... */);
    jestHooks.getUsageInfo(/* ... */);
    jestHooks.testRunComplete(/* ... */);
    jestHooks.fsChange(/* ... */);
    jestHooks.onData(/* ... */);
    jestHooks.shouldRunTestSuite(/* ... */);
  }
}

instead of

class MyPlugin {
  apply(jestHooks) {
    jestHooks.testRunComplete(/* ... */);
    jestHooks.fsChange(/* ... */);
    jestHooks.shouldRunTestSuite(/* ... */);
  }

  onData(/* ... */) {
    /* ... */
  }

  run(/* ... */) {
    /* ... */
  }

  getUsageInfo(/* ... */) {
    /* ... */
  }
}

Seems like the plugin architecture is working already, which means that changing to an API like the one above should not be that hard.

This means that the apply method is the only method that exists in the class and everything else is a jestHook. Seems that if we would like to make this changes it is better to do them now than later.

thoughts? Which API seems cleaner? Which API would be easier to document?
@rickhanlonii @orta @cpojer @SimenB

Copy link
Member

Choose a reason for hiding this comment

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

I'm worried about the first API being too open. There are other open source tools out there that allow people to do anything they want in a plugin and it generally causes the entire system to slow down considerably. I think we should stick with a more limited API that guides user to build plugins in the way we expect them to be built. Of course, it's still possible to completely break out of that system and do harmful slow things but it is less likely to happen.

Copy link
Member

@rickhanlonii rickhanlonii Mar 29, 2018

Choose a reason for hiding this comment

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

+1 to @cpojer and I like that the current Watch Plugin API is similar in structure to the runner and reporter - implement a class with a specific structure

Copy link
Member

Choose a reason for hiding this comment

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

+1 - slow and deliberate improvements as we need them, I think this looks great

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perfect! 😄

@cpojer cpojer merged commit f099621 into jestjs:master Mar 28, 2018
@cpojer
Copy link
Member

cpojer commented Mar 28, 2018

OMG it's happening.

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

6 participants