-
-
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
Created --notifyMode option for notifications on certain events #5125
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
You need to use yarn as we use yarn workspaces in this repo. Not sure about your error, the URL in you comment (https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.35.tgz) resolves for me. Can you try again, making sure you are on 1.3.2 of yarn? Also, this needs some sort of test to illustrate it's working (although I understand it's hard to add a test when you're unable to install the repo) |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
@SimenB I understand I was hoping someone would happen to know how to fix this when I made the PR, and I would be able to quickly update my PR. It seems that updating yarn fixed my second issue, and running I have a few issues now that it's running and I will try to update the PR soon. Thank you! |
docs/Configuration.md
Outdated
@@ -378,9 +378,9 @@ array of absolute paths to additional locations to search when resolving | |||
modules. Use the `<rootDir>` string token to include the path to your project's | |||
root directory. Example: `["<rootDir>/app/"]`. | |||
|
|||
### `notify` [boolean] | |||
### `notify` [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.
I'm not sure we want this to overload. Maybe a separate notify-mode
or something? Changing its type is a breaking change, and would mean we couldn't merge this PR for months
Something like what travis gives you, where you can get a notification on failure, and when that turns green, but not green after one another. (https://docs.travis-ci.com/user/notifications/#Changing-notification-frequency)
The you could have onFailure
, onSuccess
, onChange
. for instance.
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.
That sounds like a better design. I like the additional events travis has as well. I'll try to spend some time tonight.
CHANGELOG.md
Outdated
@@ -74,7 +74,8 @@ None | |||
matcher ([#4917](https://github.com/facebook/jest/pull/4917)) | |||
|
|||
### Features | |||
|
|||
* `[jest-cli]` --notify is now configurable. `onFailure` or `onSuccess` are now valid options. |
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.
you can run yarn lint:md
to autofix formatting in markdown files
dbb1363
to
409be3c
Compare
} | ||
|
||
onRunComplete(contexts: Set<Context>, result: AggregatedResult): void { | ||
const success = | ||
result.numFailedTests === 0 && result.numRuntimeErrorTestSuites === 0; | ||
|
||
if (success) { | ||
const notifyMode = this._globalConfig.notifyMode; |
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.
Not sure what else I'm missing but when I log globalConfig I see that notify is set to true but notifyMode is undefined. However when I go into https://github.com/facebook/jest/blob/v22.0.0/packages/jest-cli/src/cli/index.js#L72
I see that notifyMode is set to the value I pass in.
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 think you might be hit by https://github.com/facebook/jest/pull/4639/files#r143555141
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.
That was it 🥇 still have to work on the change option though. It seems like a new instance of NotifyReporter is created every time jest --watch
reruns. I'll look into that.
There are flow errors, run |
packages/jest-cli/src/run_jest.js
Outdated
firstRun: true, | ||
previousSuccess: true, | ||
}; | ||
|
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.
Let me know what you think of this. I wasn't sure what the best practice for updating the state from my previous run in NotifyReporter would be.
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.
The NotifyReporter
can have local state, can't it? Why not just have this._firstRun = false
etc in there?
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.
run_jest seems to create a new instance of TestScheduler every time a file changes with --watch
and TestScheduler creates a new instance of NotifyReporter.
Codecov Report
@@ Coverage Diff @@
## master #5125 +/- ##
==========================================
+ Coverage 61.42% 61.65% +0.22%
==========================================
Files 213 213
Lines 7059 7067 +8
Branches 4 3 -1
==========================================
+ Hits 4336 4357 +21
+ Misses 2722 2709 -13
Partials 1 1
Continue to review full report at Codecov.
|
* `always`: always send a notification. | ||
* `failure`: send a notification when tests fail. | ||
* `success`: send a notification when tests pass. | ||
* `change`: send a notification when the status changed. |
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 missing the mode I would use, which is "on every failure, and change to success". I want a notification that my tests are still red on every run until they're green, and when it turns green, but not on every run when it's green. I'm not sure how to best express it, though. Travis has onSuccess
and onFailure
with different modes, but it feels a bit overkill to add two new options.
What about: always
, failure
, success
, change
, failure-always
, failure-change
, success-always
, success-change
, and allow notifyMode
to be passed an array instead of a single string?
I'm not sure if that's the best option, it's just what I could come up with without thinking too much about it
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.
What would be the difference between failure-always and failure (same with success and success-always)? I personally would prefer keeping it a string because I can only imagine 2 cases from the current combination of options. e.g. ['failure', 'change']
to accomplish the case you mentioned, and I think it would be better expressed as a string with failure-change
success-change
would accomplish the inverse.
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.
What would be the difference between failure-always and failure
Good point, those would be the same. failure
, success
, always
, change
, failure-change
and success-change
works for me
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.
Just added those :)
packages/jest-cli/src/run_jest.js
Outdated
@@ -75,6 +75,12 @@ const processResults = (runResults, options) => { | |||
return options.onComplete && options.onComplete(runResults); | |||
}; | |||
|
|||
// eslint-disable-next-line prefer-const |
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.
why is this needed?
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.
eslint didn't seem to recognize that this will be mutated in NotifyReporter
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.
You mutate the content, not the variable itself, can't this be const
?
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.
Oh looks like I just learned something https://jack.ofspades.com/es6-const-not-immutable/index.html
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, there's no true native immutability in JS :(
docs/Configuration.md
Outdated
|
||
Default: `always` | ||
|
||
Specifies notification mode. |
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.
Can you add that it also needs notify: true
?
CHANGELOG.md
Outdated
@@ -75,6 +75,8 @@ None | |||
|
|||
### Features | |||
|
|||
* `[jest-cli]` created `--notifyMode` added to specify when to be notified. |
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.
"added --notifyMode
to specify when to be notified."
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.
Wait, I didn't notice this does not have tests 😱
Can you add some?
@psilospore ping 🙂 |
@SimenB sorry I've been busy lately but I'll try to make time this weekend! |
5379f7f
to
65c9295
Compare
New test is failing CI, could you look into it? This also needs a rebase 🙂 |
@SimenB did you see my comment here: https://github.com/facebook/jest/pull/5125/files/65c929505f640531ea6b842867a002215e9bf9e7#diff-87435080064bc991e719d23f2a2ee8dd I wanted to know if that was ok before I continued. |
@psilospore I'm unable to find the comment you're referring to... |
@SimenB This was the comment. |
Ah, you have to submit it for me to see it 🙂 But yeah, the test looks good! |
Oh I see. I'll try to work on it a bit this weekend. Add some more test cases, and everything else. |
65c9295
to
4b9ecf1
Compare
42cd78c
to
0f3c9e1
Compare
|
||
const testModes = (notifyMode: string, arl: Array<AggregatedResult>) => { | ||
const notify = require('node-notifier'); | ||
notify.notify.mock.calls = []; |
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.
mock.calls contains the calls of my previous tests. Is there a better way to do this?
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.
Call jest.clearAllMocks()
in afterEach
fb2b81e
to
c98a36d
Compare
Alright all ready :) |
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 is awesome, thank you so much for sticking with it!
CHANGELOG.md
Outdated
@@ -286,6 +286,8 @@ | |||
|
|||
### Features | |||
|
|||
* `[jest-cli]` Added --notifyMode to specify when to be notified. |
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.
Can you move this up under master
? (sorry 😅)
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.
never mind, I can do it (and rebase, as it gave a conflict)
forgot about other notifyMode configs add notifyMode to normalize Created TestSchedulerContext to save previous status of test to make the change option work updated docs minor linting fix Added additional options such as success-change and failure-change Put conditions back in if else clauses Fixed documentation on notifyMode Added notify reporter test (for review) Finished NotifyReporter tests. Testing against simulated sequences of events.
fff7535
to
fc99e6d
Compare
@SimenB no problem 😄 thanks so much for the help! This might be my first PR to get into a large open source project so I'm excited to see it out! |
@psilospore looking forward to more features from you 🙂 It's been released in 22.2.0. |
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
I would like notifications only on failure. It seems that someone else wanted something similar: #1839
Test plan
Unfortunately I'm not able to run yarn test. I end up with this error:
Also
yarn install
didn't work for me. I usednpm install
instead since I got this error:error An unexpected error occurred: "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.35.tgz: Request failed \"404 Not Found\"".
I followed the the contribution guide as well https://github.com/facebook/jest/blob/master/CONTRIBUTING.md
Updated Test Plan
run
yarn jest --watch --notify --notifyMode=failure examples
with the various notifyMode options.success
,always
,failure
, andchange
Modify examples/snapshot/tests/link.react.test.js and check if notifications appear when appropriate.