Skip to content
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

Wait for plan execution #1918

Closed
afoninsky opened this issue Aug 25, 2018 · 3 comments
Closed

Wait for plan execution #1918

afoninsky opened this issue Aug 25, 2018 · 3 comments
Labels

Comments

@afoninsky
Copy link

I want to create helper, which will wait for execution plan or throw an error on timeout. This will reduce boilerplate required for clean test functions.

Example:

test('some test', async t => {
  t.plan(3)
  ...
  // lots of async stuff
  ...
  await myHelper(t, 3000) // will wait 3 seconds and throw `Planned for 3 assertions, but got 2`
})
  1. Is there any workaround to get current execution plan in test? I couldn't find it :(
  2. What about proposal t.planWait(3000)
@novemberborn
Copy link
Member

Could you elaborate on what you're looking for beyond what AVA already supports? E.g. there is a timeout feature, but it's to help find inactivity in your test suite as a whole, not a particular test.

Are you looking for the timeout error to have feedback on how far pending tests managed to progress towards their execution plan? Or are you hoping to limit how long a particular tests is allowed to run for?

@afoninsky
Copy link
Author

No, I'm looking for a way how can I ensure if plan executed OR timeout achieved in particular test. Sometimes (often, actually :) I have to test async code without clean interceptors or mocks. So I want to have something like:

// just an example
test('some test', async t => {
  t.plan(1) <- set test spaln
  somethingAsync.on('event', () => {
  	t.pass()
  })
  somethingAsync.start()

  await resolveWhenTestPlanAchievedOrRejectAfterTimeout() <- this
})

Sure it is a dummy example, but I hope I was able to convey the idea.

@novemberborn
Copy link
Member

Right, gotcha. AVA's timeout option isn't quite suitable for this.

You could partially get there by calling t.fail() after a timeout, but you'll have to detect whether you've reached the plan count yourself.

I think ideally we'd support this through #1692, where you can use Promise.race() with a timeout promise, and fail the test if the assertions didn't complete on time.

(I'm closing this issue for housekeeping purposes, but let's keep the conversation going.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants