-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
jest-circus async tests #3819
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
jest-circus async tests #3819
Conversation
b629332
to
cbd70ce
Compare
cbd70ce
to
09a8561
Compare
@@ -43,6 +43,32 @@ const initialize = ({ | |||
global.fit = global.it.only; | |||
global.fdescribe = global.describe.only; | |||
|
|||
global.test.concurrent = ( |
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 including test.concurrent
into jest-circus
as a core functionality. In the current state it's never going to work properly (can't use certain matchers/hooks/proper .skip/.only/etc).
I also think we shouldn't document it either. It will be harder to reimplement it properly in the future if people start using 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.
we could actually make a breaking change to test.concurrent
to pass the context as first argument (rather than "done") like we were planning to do, that way we could make it work properly with state.
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's too many changes that need to be made before we can do that.
it's easier to keep it as it is right now and we'll focus on redesigning it later
|}; | ||
|
||
export type TestStatus = 'pass' | 'fail' | 'skip'; | ||
export type TestStatus = 'skip' | 'done'; |
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 removed fail
status, since it's a derived value that can be calculated from test.errors.length
.
All we need to know is whether it was skipped or finished running
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.
how about 'skip' | 'complete' then? Any other words instead of 'done'?
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.
'finish' maybe?
// failing before hook | ||
beforeAll(() => { | ||
return new Promise(resolve => setTimeout(resolve, 100)); | ||
}, 10); | ||
}, 11); |
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 it 11 now?
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.
easier to find in the console :)
|
||
'use strict'; | ||
|
||
const testEventHandler = (event, state) => { |
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 really nice, I love how you are testing this. Could we make it a bit more generic somehow so that we don't have to keep this file in sync, though?
const TEST_EVENT_HANDLER_PATH = path.resolve(__dirname, './test_event_handler'); | ||
|
||
const runTest = (source: string) => { | ||
const tmpFilename = path.join(os.tmpdir(), 'circus-test-file.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.
Why do we write this into tmp?
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 the safest, but not the most pleasant way of writing files.
I was thinking about creating a gitignored directory (files_for_integration_tests
) and write everything there, so it's easy to cd into the dir and see what's up in there
`"currentDescribeBlock" has to be there since we're finishing its definition.`, | ||
); | ||
} | ||
invariant(currentDescribeBlock, `currentDescribeBlock mest to be 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.
mest? What?
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 it's something in between jest
, must
and has
. i can't spell :'(
if (currentDescribeBlock.parent) { | ||
state.currentDescribeBlock = currentDescribeBlock.parent; | ||
} | ||
break; | ||
} | ||
case 'add_hook': { | ||
const {currentDescribeBlock} = state; | ||
const {fn, hookType: type} = event; | ||
currentDescribeBlock.hooks.push({fn, type}); | ||
const {fn, hookType: type, timeout} = event; |
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 I like the aliasing. Why do we need to rename hookType to type?
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 looks really good overall, just some small comments
@@ -0,0 +1,75 @@ | |||
/** |
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 really nice!
const {type} = hook; | ||
|
||
if (type === 'beforeAll') { | ||
invariant(describeBlock, 'always present for `*All` hooks'); |
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 we need to add a prefix to the message? Similar to the contentBlock invariant message
// too complicated, so we'll consider them to be global. | ||
state.unhandledErrors.push(error); | ||
} else { | ||
invariant(test, 'always present for `*Each` hooks'); |
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 we need to add a prefix to the message? Similar to the contentBlock invariant message
break; | ||
} | ||
case 'test_skip': { | ||
event.test.status = 'skip'; | ||
break; | ||
} | ||
case 'test_failure': { | ||
event.test.status = 'fail'; |
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.
Do we not need the fail
status anymore?
|
||
const test = (testName: TestName, fn?: TestFn) => | ||
dispatch({fn, name: 'add_test', testName}); | ||
const test = (testName: TestName, fn?: TestFn, timeout?: number) => |
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: line 37 uses timeout: ?number
instead of timeout?: number
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's expected though! :)
in this function timeout
is optional, and on line37, it's always passed, but can be null
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.
Got it
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. |
makes
integration_tests/__tests__/jasmine_async-test.js
pass.jest-circus
in isolationtest/*Each/*All
as a last argument