-
-
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
Changes from 3 commits
fdd340b
3cbe1c0
392c1d0
ec08b6f
663ed55
a720cde
1a17252
54fac6d
8891c36
0e3fb84
7325d16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`shows error messages when called with invalid argument 1`] = ` | ||
"FAIL __tests__/todo_non_string.test.js | ||
● Test suite failed to run | ||
|
||
Invalid first argument: () => {}. Todo must be called with a string. | ||
|
||
6 | */ | ||
7 | | ||
> 8 | it.todo(() => {}); | ||
| ^ | ||
9 | | ||
|
||
at packages/jest-jasmine2/build/jasmine/Env.js:480:15 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 :( |
||
at __tests__/todo_non_string.test.js:8:4 | ||
|
||
" | ||
`; | ||
|
||
exports[`shows error messages when called with multiple arguments 1`] = ` | ||
"FAIL __tests__/todo_multiple_args.test.js | ||
● Test suite failed to run | ||
|
||
Todo must be called with only a description. | ||
|
||
6 | */ | ||
7 | | ||
> 8 | it.todo('todo later', () => {}); | ||
| ^ | ||
9 | | ||
|
||
at packages/jest-jasmine2/build/jasmine/Env.js:476:15 | ||
at __tests__/todo_multiple_args.test.js:8:4 | ||
|
||
" | ||
`; | ||
|
||
exports[`shows error messages when called with no arguments 1`] = ` | ||
"FAIL __tests__/todo_no_args.test.js | ||
● Test suite failed to run | ||
|
||
Todo must be called with only a description. | ||
|
||
6 | */ | ||
7 | | ||
> 8 | it.todo(); | ||
| ^ | ||
9 | | ||
|
||
at packages/jest-jasmine2/build/jasmine/Env.js:476:15 | ||
at __tests__/todo_no_args.test.js:8:4 | ||
|
||
" | ||
`; | ||
|
||
exports[`works with all statuses 1`] = ` | ||
"FAIL __tests__/statuses.test.js | ||
✓ passes | ||
✕ fails | ||
✎ todo | ||
○ skipped 1 test | ||
|
||
● fails | ||
|
||
expect(received).toBe(expected) // Object.is equality | ||
|
||
Expected: 101 | ||
Received: 10 | ||
|
||
11 | | ||
12 | it('fails', () => { | ||
> 13 | expect(10).toBe(101); | ||
| ^ | ||
14 | }); | ||
15 | | ||
16 | it.skip('skips', () => { | ||
|
||
at __tests__/statuses.test.js:13:14 | ||
|
||
" | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Copyright (c) 2018-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const path = require('path'); | ||
const runJest = require('../runJest'); | ||
const {extractSummary} = require('../Utils'); | ||
const dir = path.resolve(__dirname, '../test-todo'); | ||
|
||
test('works with all statuses', () => { | ||
const result = runJest(dir, ['statuses.test.js']); | ||
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 commentThe 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 |
||
.join('\n'); | ||
expect(output).toMatchSnapshot(); | ||
}); | ||
|
||
test('shows error messages when called with no arguments', () => { | ||
const result = runJest(dir, ['todo_no_args.test.js']); | ||
expect(result.status).toBe(1); | ||
const output = extractSummary(result.stderr) | ||
.rest.split('\n') | ||
.map(line => line.trimRight()) | ||
.join('\n'); | ||
expect(output).toMatchSnapshot(); | ||
}); | ||
|
||
test('shows error messages when called with multiple arguments', () => { | ||
const result = runJest(dir, ['todo_multiple_args.test.js']); | ||
expect(result.status).toBe(1); | ||
const output = extractSummary(result.stderr) | ||
.rest.split('\n') | ||
.map(line => line.trimRight()) | ||
.join('\n'); | ||
expect(output).toMatchSnapshot(); | ||
}); | ||
|
||
test('shows error messages when called with invalid argument', () => { | ||
const result = runJest(dir, ['todo_non_string.test.js']); | ||
expect(result.status).toBe(1); | ||
const output = extractSummary(result.stderr) | ||
.rest.split('\n') | ||
.map(line => line.trimRight()) | ||
.join('\n'); | ||
expect(output).toMatchSnapshot(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright (c) 2018-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
it('passes', () => { | ||
expect(10).toBe(10); | ||
}); | ||
|
||
it('fails', () => { | ||
expect(10).toBe(101); | ||
}); | ||
|
||
it.skip('skips', () => { | ||
expect(10).toBe(101); | ||
}); | ||
|
||
it.todo('todo'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Copyright (c) 2018-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
it.todo('todo later', () => {}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Copyright (c) 2018-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
it.todo(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Copyright (c) 2018-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
it.todo(() => {}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"jest": { | ||
"testEnvironment": "node" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict-local | ||
*/ | ||
|
||
'use strict'; | ||
|
||
let circusIt; | ||
|
||
// using jest-jasmine2's 'it' to test jest-circus's 'it'. Had to differentiate | ||
// the two with this alias. | ||
|
||
const aliasCircusIt = () => { | ||
const {it} = require('../index.js'); | ||
circusIt = it; | ||
}; | ||
|
||
aliasCircusIt(); | ||
|
||
describe('test/it.todo error throwing', () => { | ||
it('todo throws error when given no arguments', () => { | ||
expect(() => { | ||
// $FlowFixMe: Testing runitme errors here | ||
circusIt.todo(); | ||
}).toThrowError('Todo must be called with only a description.'); | ||
}); | ||
it('todo throws error when given more than one argument', () => { | ||
expect(() => { | ||
circusIt.todo('test1', () => {}); | ||
}).toThrowError('Todo must be called with only a description.'); | ||
}); | ||
it('todo throws error when given none string description', () => { | ||
expect(() => { | ||
// $FlowFixMe: Testing runitme errors here | ||
circusIt.todo(() => {}); | ||
}).toThrowError( | ||
'Invalid first argument: () => {}. Todo must be called with a string.', | ||
); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,31 @@ test.only = (testName: TestName, fn: TestFn, timeout?: number) => { | |
}); | ||
}; | ||
|
||
test.todo = (testName: TestName, ...rest: Array<mixed>) => { | ||
if (rest.length > 0 || testName === undefined) { | ||
throw new Error('Todo must be called with only a description.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 |
||
} | ||
|
||
if (typeof testName !== 'string') { | ||
throw new Error( | ||
`Invalid first argument: ${testName}. Todo must be called with a string.`, | ||
); | ||
} | ||
const asyncError = new Error(); | ||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(asyncError, test); | ||
} | ||
|
||
return dispatch({ | ||
asyncError, | ||
fn: () => {}, | ||
mode: 'todo', | ||
name: 'add_test', | ||
testName, | ||
timeout: undefined, | ||
}); | ||
}; | ||
|
||
test.each = bindEach(test); | ||
test.only.each = bindEach(test.only); | ||
test.skip.each = bindEach(test.skip); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}; | ||
export const PACKAGE_JSON = 'package.json'; | ||
export const JEST_CONFIG = 'jest.config.js'; |
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