-
-
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
Add test.todo #6996
Add test.todo #6996
Conversation
This is lovely! |
Thanks for doing this! I love the new state in the output, regardless of the function option. If this is merged, it would be good to add this to the jest-codemods so that pending specs in jasmine/mocha get converted. |
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.
So nice
"FAIL __tests__/todo_non_string.test.js | ||
● Test suite failed to run | ||
|
||
Invalid first argument: () => {}. Todo must be called with a 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.
This might look weird, when the fn is not a oneliner.
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.
True, perhaps we should just remove this as per @rickhanlonii's comments below. I'm pretty flexible with how this API looks. Maybe just validation of a minimum one arg with the first being a 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 think just a simple "todo must be called with just a string", or something similar, is better. No need to stringify the implementation as long as our stack trace point points back to the declaration
| ^ | ||
9 | | ||
|
||
at packages/jest-jasmine2/build/jasmine/Env.js:480:15 |
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 we strip this from stack trace? cc @SimenB
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 please teach me this magic (again), I've tried but not been able to remove it :(
@@ -88,6 +88,10 @@ exports.interface = function(jasmine: Jasmine, env: any) { | |||
return env.xit.apply(env, arguments); | |||
}, | |||
|
|||
tit(description: 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.
lol
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.
haha this was my first attempt at getting it to work - I thought I removed 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.
This is awesome
What do you think about allowing and ignoring the function argument?
I'm thinking of two use cases:
- Stubbing out future tests to finish later
- Making it easy to "disable" tests with a todo to come back and fix them
@skovhus for the codemod ❤️ |
I don't think it's worth it. That's behaviour from almost 6 months ago, and I think a codemod fulfills the same purpose better.
Aren't those covered by |
Does that depend on the use case? What's really the difference between .skip and .todo? |
Generally we don't want to ignore work to be done. I think the first use case; stubbing for later is a valid |
packages/jest-circus/src/index.js
Outdated
@@ -121,6 +121,26 @@ test.only = (testName: TestName, fn: TestFn, timeout?: number) => { | |||
}); | |||
}; | |||
|
|||
test.todo = (testName: TestName, ...rest: Array<mixed>) => { | |||
if (rest.length > 0 || typeof testName !== 'string') { | |||
throw new Error('Todo must be called with only a description.'); |
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.
const e = new Error('Todo must be called with only a description.');
if (Error.captureStackTrace) {
Error.captureStackTrace(e, test.todo);
}
throw e;
ish 🙂
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.
❤️amazing!
I tried something similar to this but wasn't passing the correct call site
We could ignore the implementation and have a lint rule for it. I do like that it throws though, so you don't forget it by accident |
Also missing changelog 😱 |
Codecov Report
@@ Coverage Diff @@
## master #6996 +/- ##
==========================================
- Coverage 66.9% 66.68% -0.22%
==========================================
Files 250 250
Lines 10436 10483 +47
Branches 3 3
==========================================
+ Hits 6982 6991 +9
- Misses 3453 3491 +38
Partials 1 1
Continue to review full report at Codecov.
|
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.
CHANGELOG.md
Outdated
@@ -2,6 +2,8 @@ | |||
|
|||
### Features | |||
|
|||
- `[jest-jasmine2/jest-circus/jest-cli]` Add test.todo ([#6996](https://github.com/facebook/jest/pull/6996)) | |||
|
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.
remove this newline
e2e/__tests__/test-todo.test.js
Outdated
expect(result.status).toBe(1); | ||
const output = extractSummary(result.stderr) | ||
.rest.split('\n') | ||
.map(line => line.trimRight()) |
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 this needed? If yes, please extract to a helper function instead of copying it in every test
eb2289c
to
8891c36
Compare
ping @SimenB just updated with your comments :) |
@cpojer @aaronabramov @mjesun this is new API, so I'd like your approval before merging 🙂 |
I like seeing todo's aggregated separately from skipped tests for reporters. Nice work! |
@mattphillips could you update the error we throw when |
@@ -15,6 +15,7 @@ export const ICONS = { | |||
failed: isWindows ? '\u00D7' : '\u2715', | |||
pending: '\u25CB', | |||
success: isWindows ? '\u221A' : '\u2713', | |||
todo: '\u270E', |
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 check how this looks on windows?
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 I don't have a windows machine, does anyone else have one?
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.
Adding a |
Once we land this you can do that with a custom reporter 🙂 |
jest-reporter-todo would be dope |
@mattphillips ping 🙂 We can iterate on the name after landing if we want |
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
Adds
test.todo
andit.todo
similar to ava's todo. I'm opening this up early for feedback from @SimenB @thymikee @rickhanlonii @aaronabramov 😄Motivation: see comment by @SimenB
Closes #6430 #6602 and addresses #6256
This change re-introduces the behaviour of planning a test, similar to Jest@22
test('do something')
Test plan
Given this test suite:
The new output will look like:
Todo