Skip to content

Async QUnit.module bodies #1597

@xmo-odoo

Description

@xmo-odoo

This is a feature request, possibly related to #1568 and #978

Tell us about your runtime:

  • QUnit version: 2.9.1 (but I checked the changelog and nothing related to this seems to have been added since)
  • Which environment are you using? (e.g., browser, Node): browser
  • How are you running QUnit? (e.g., QUnit CLI, Grunt, Karma, manually in browser): Chrome Devtools Protocol

What are you trying to do?

Generative table-based tests, something along the lines of #1568 but the tables (the test suite / module definitions if you will) are defined in external files.

Currently each file yields a test, but in reality each file is composed of multiple semi-independent tests, so ideally each file would be a submodule and each test would be, well, a test. However since the suites are files they need to be loaded asynchronously, and it doesn't look like QUnit.module supports asynchronous bodies (nested scopes).

Not too sure how to create a "clean" reproduction,

QUnit.module('mod1', async () => {
    console.log('mod1: before');
    await Promise.resolve();
    console.log('mod1: after')
    QUnit.test('test', () => {
        assert.expect(0);
        console.log('mod1.test');
    });
});
QUnit.module('mod2', () => {
    console.log('mod2');
    QUnit.test('test', () => {
        assert.expect(0);
        console.log('mod2.test');
    });
})

kinda shows the issue: you can see in the console that mod2's body runs before mod1 is done collecting.

What did you expect to happen?

  • that modules collection support asynchronous bodies
  • or that asynchronous module bodies generate an error

What actually happened?

The rest of the module body runs at the first opportunity after the synchronous collection is done, and things get odd.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions