-
-
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
Check watch plugins for key conflicts #6697
Check watch plugins for key conflicts #6697
Conversation
packages/jest-cli/src/watch.js
Outdated
const RESERVED_KEY_PLUGINS = new Map([ | ||
[ | ||
UpdateSnapshotsPlugin, | ||
{forbiddenOverwriteMessage: 'updating snapshots ballpark', key: 'u'}, |
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.
Note to reviewers: we specify the keys here because the snapshot built-in plugins only return usage info when the current running context makes them relevant, and this detection is based on internal, “private” field cooking. We don't want to interfere with / mock / hack that.
Codecov Report
@@ Coverage Diff @@
## master #6697 +/- ##
=========================================
+ Coverage 63.55% 63.66% +0.1%
=========================================
Files 235 235
Lines 9030 9059 +29
Branches 3 3
=========================================
+ Hits 5739 5767 +28
- Misses 3290 3291 +1
Partials 1 1
Continue to review full report at Codecov.
|
20cfedc
to
4efebe8
Compare
I just force-pushed an updated branch on top of latest master, to fix conflicts w/o butchering the graph with a reverse merge (as GitHub's UI would do). As I was force-pushing anyway, I fused both commits (original and lint:md:ci fix) as I'm not on in this for the contributors hall of fame anyway 😉 |
We squash on merge anyways 🙂 @rogeliog would you be able to take a look at this? |
I think this deserves some docs as well, mind updating https://github.com/facebook/jest/edit/master/docs/WatchPlugins.md? |
4efebe8
to
08124bb
Compare
@SimenB sure thing, here goes. I took the opportunity to rebase on top of the latest |
@SimenB unrelated: what's the Jest site release process like? I thought this would be automated, but it lags behind a bit most of the time (right now it's stuck on 23.3 for instance). |
See https://jestjs.io/docs/en/next/getting-started.html. We cut new versions when the doc warrants it. None of the changes in 23.4 had doc changes |
Ah, OK. 23.4.1 had (the broader updatable options set), but as it's very recent and a patchlevel, that probably explains why it's not there yet. |
(also weird: the |
packages/jest-cli/src/watch.js
Outdated
const RESERVED_KEY_PLUGINS = new Map([ | ||
[ | ||
UpdateSnapshotsPlugin, | ||
{forbiddenOverwriteMessage: 'updating snapshots ballpark', key: 'u'}, |
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.
Should we change this to just updating snapshots
instead of update snapshots ballpark
?
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.
Trimmed.
continue; | ||
} | ||
const {forbiddenOverwriteMessage} = reservedInfo; | ||
watchPluginKeys.set(key, { |
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.
Given that the key is gotten from getUsageInfo(...)
, a plugin can update their designated key at any time. This is not a documented(or common) use case, so I think if we don't worry about it in this PR.
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.
Indeed. There is no formal way to obtain a list of all possible keys claimed by a plugin, so we have to trust first invocation. Context-based key changes are expected to be rather rare, though (although snapshot updates are a prime example, for instance), so let's not focus too much on that now.
docs/WatchPlugins.md
Outdated
- `p` (test filename pattern) | ||
- `t` (test name pattern) | ||
|
||
Any key not used by built-in functionality remains fair game, as you would expect. Try to avoid using keys that are difficult to obtain on various keyboards (e.g. `é`, `€`), or not visible by default (e.g. many Mac keyboards do not have visual hints for characters such as `|`, `\`, `[`, etc.) |
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.
nit: Don't worry about changing it, but....I'm not sure how remains fair game
sounds for docs purposes
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.
Good point. I wax colloquial sometimes, losing sight of how it can make reading a bit harder for non-native English speakers. Tweaked it.
08124bb
to
703fd05
Compare
I just pushed a rebased history on top of the latest master that addresses @rogeliog's good wording points. |
Dammit, it looks like Netlify's deploy or some underlying API (OpenCollective?) is acting funky again 😒 |
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.
Awesome!
Hey all,
So how do we retrigger checks on this to make it pass? I'm fairly
confident its breakage on Netlify was circumstancial.
On Thu, Jul 19, 2018, at 17:54, Rogelio Guzman wrote:
***@***.**** approved this pull request.
Awesome!
— You are receiving this because you authored the thread. Reply to
this email directly, view it on GitHub[1], or mute the thread[2].
--
Christophe Porteneuve
[email protected]
Links:
1. #6697 (review)
2. https://github.com/notifications/unsubscribe-auth/AAAOqPaydHsrZpUvbGVzPC1oTbjJ9Rwvks5uIKuqgaJpZM4VQOcf
|
I'm not sure how to retrigger the Netlify check. I guess you could amend your last commit and re-push 😕? |
Hi, I've re-triggered the netlify preview. There is a build cache error causing it to fail. |
@endiliey thanks! Dang it, this time it's a Yarn registry timeout that failed test-jest-circus. As for the CHANGELOG conflict, I'll rebase and force push, we'll see how CI goes. |
9a7dc9a
to
cc69070
Compare
packages/jest-cli/src/watch.js
Outdated
error = `Jest configuration error: watch plugins ${plugins} both attempted to register key <${key}>. Please change the key configuration for one of the conflicting plugins to avoid overlap.`; | ||
} | ||
console.error('\n\n' + chalk.red(error)); | ||
exit(64); // EX_USAGE |
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.
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.
@SimenB this is an interesting idea. Am I correct in assuming the right place for this would be in jest-config
’s normalize.js
file, in its existing handling of the watchPlugins
option?
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.
(I'm not entirely sure we'd have sufficient/relevant info to populate the arguments to the plugin's getUsageInfo()
there, I'll check. At the very least we can check inline key configs, though.)
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, in normalize seems natural, imo. Not sure if we have enough information there, but if not we can just hard-code the reserved ones
cc69070
to
00567a8
Compare
@SimenB it turned out that moving that into
I ended up keeping my conflict-checking code in its current location, but moved from manual console error logging and custom exit code to regular |
@@ -364,6 +364,139 @@ describe('Watch mode flows', () => { | |||
expect(run).toHaveBeenCalled(); | |||
}); | |||
|
|||
describe('when dealing with potential watch plugin key conflicts', () => { | |||
|
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.
This line causes lint failure on CI
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.
Dang, should have checked. Just a sec.
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.
yarn lint --fix
should solve your problem 👍
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.
It's odd, I guess my VS Code was overwhelmed with some extension, not to have auto-run Prettier on this.
- Some built-in keys remain overridable (specificically `t` and `p`). - Any key registered by a third-party watch plugin cannot be overridden by one listed later in the plugins list config. Fixes jestjs#6693. Refs jestjs#6473.
621e84e
to
24cf0dc
Compare
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
Watch plugins now are checked for key conflicts…
t
andp
).Fixes #6693.
Refs #6473.
Test plan
Additional tests are provided that check every conflict / overwritable scenario discussed.
Request for feedback / “spec” evolution
The “spec” is an ongoing discussion in #6693 — in particular, the overwritability of some built-in keys, such as
a
,f
ando
, may be subject to discussion. This PR tracks the decisions in there and may evolve a bit still.Ping @SimenB @thymikee @rogeliog for review and discussion.