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

Support for Top-level Await #145

Closed
antfu opened this issue Oct 8, 2021 · 2 comments
Closed

Support for Top-level Await #145

antfu opened this issue Oct 8, 2021 · 2 comments

Comments

@antfu
Copy link

antfu commented Oct 8, 2021

import { setTimeout } from 'timers/promises'
import { test } from 'uvu'
import * as assert from 'uvu/assert'

await setTimeout(10)

test('Math.sqrt()', () => {
  assert.is(Math.sqrt(4), 2)
  assert.is(Math.sqrt(144), 12)
  assert.is(Math.sqrt(2), Math.SQRT2)
})

test.run()
 node test.js

  Total:     0
  Passed:    0
  Skipped:   0
  Duration:  0.45ms

If I remove the top-level await it works as expected. It seems like the tests are only collected in the sync context, but since we are explicitly calling test.run() in each file, should we expect uvu to work with top-level await and also the async context?

// same as top-level await
import { test } from 'uvu'
import * as assert from 'uvu/assert'

setTimeout(() => {
  test('Math.sqrt()', () => {
    assert.is(Math.sqrt(4), 2)
    assert.is(Math.sqrt(144), 12)
    assert.is(Math.sqrt(2), Math.SQRT2)
  })

  test.run()
})
@antfu antfu changed the title Top-level Await Support for Top-level Await Oct 8, 2021
@lukeed
Copy link
Owner

lukeed commented Oct 8, 2021

Thanks! TLA was supported through CLI usage, but ya, direct file execution was problematic. Fixed :)

@lukeed lukeed closed this as completed in 2a3a598 Oct 8, 2021
@antfu
Copy link
Author

antfu commented Oct 9, 2021

Working great, thanks for the prompt fix!

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

No branches or pull requests

2 participants