Open
Description
We have:
- a list of callback methods at https://qunitjs.com/api/callbacks/
- a list of events at https://qunitjs.com/api/callbacks/QUnit.on/
- module hooks https://qunitjs.com/api/QUnit/module/#hooks
- global hooks at https://qunitjs.com/api/QUnit/hooks/
While each is well-documented, and describes when it runs, and how (sync or async), we don't have yet provided an explicit overview of the overall order of events. Where this matters most is:
- between
QUnit.begin()
andQUnit.on('runStart')
which logically run at the same time. Idem forQUnit.done()
andQUnit.on('runEnd')
. Consider a sentence like "QUnit.config.urlConfig
modifications must be made before QUnit.begin". Does that meanrunStart
is fine, or is that too late? And is that supported or accidental? - between
hooks.afterEach
andQUnit.testDone()
, where the order is not obvious per se, ref New test reporter hook #1475.
Life cycle
I wrote up the following to get us started.
QUnit.on('runStart')
[reporter, sync]QUnit.begin()
[plugin, async-await]- For each module:
QUnit.on('suiteStart')
[reporter, sync]QUnit.moduleStart()
[plugin, async-await]- For each test:
QUnit.on('testStart')
[reporter, sync]QUnit.testStart()
[plugin, async-await]hooks.before()
[testing, async-await]- global
QUnit.hooks.beforeEach()
[plugin, async-await] hooks.beforeEach()
[testing, async-await]QUnit.test()
function [testing, async-await]- For each assertion:
QUnit.log()
[plugin, sync]
hooks.afterEach()
[testing, async-await]- global
QUnit.hooks.afterEach()
[plugin, async-await] hooks.after()
[testing, async-await]QUnit.on('testEnd')
[reporter, sync]QUnit.testDone()
[plugin, async-await]
QUnit.on('suiteEnd')
[reporter, sync]QUnit.moduleDone()
[plugin, async-await]
QUnit.on('runEnd')
[reporter, sync]QUnit.done()
[plugin, async-await]
Would a table be clearer?
Event | Purpose | Note |
---|---|---|
QUnit.on('runStart') |
✏️ reporter event [sync] | |
QUnit.begin() |
⚙️ plugin callback [async-await] | |
📦 QUnit.on('suiteStart') |
✏️ reporter event [sync] | For each module |
📦 QUnit.moduleStart() |
⚙️ plugin callback [async-await] | For each module |
↦ QUnit.on('testStart') |
✏️ reporter event [sync] | For each test |
↦ QUnit.testStart() |
⚙️ plugin callback [async-await] | For each test |
↦ hooks.before() |
testing [async-await] | Before first test in a module |
↦ global QUnit.hooks.beforeEach() |
⚙️ plugin [async-await] | For each test |
↦ hooks.beforeEach() |
testing [async-await] | For each test |
↦ QUnit.test() function |
testing [async-await] | For each test |
↦ QUnit.log() |
⚙️ plugin callback [sync] | For each assertion |
↦ hooks.afterEach() |
testing [async-await] | For each test |
↦ global QUnit.hooks.afterEach() |
⚙️ plugin [async-await] | For each test |
↦ hooks.after() |
testing [async-await] | After last test in a module |
↦ QUnit.on('testEnd') |
✏️ reporter event [sync] | For each test |
↦ QUnit.testDone() |
⚙️ plugin callback [async-await] | For each test |
📦 QUnit.on('suiteEnd') |
✏️ reporter event [sync] | For each module |
📦 QUnit.moduleDone() |
⚙️ plugin callback [async-await] | For each module |
QUnit.on('runEnd') |
✏️ reporter event [sync] | |
QUnit.done() |
⚙️ plugin callback [async-await] |