Skip to content

Support for Top-level Await #145

@antfu

Description

@antfu
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()
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions