You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Docs: Add ESM dynamic import example and integration test
Make explicit mention of the "Unexpected test after runEnd." warning
to help in discovery through our search function, and general web
search.
Closes#1694.
`QUnit.start()` must be used to start a test run that has [`QUnit.config.autostart`](../config/autostart.md) set to `false`.
13
+
`QUnit.start()`
14
14
15
-
<pclass="note note--warning"markdown="1">Warning: This method was previously used to control async tests on text contexts along with `QUnit.stop`. For asynchronous tests, use [`assert.async`](../assert/async.md) instead.</p>
15
+
Start the test runner manually, when [`QUnit.config.autostart`](../config/autostart.md) is `false`. For example, if you load test files with AMD, RequireJS, or ESM dynamic imports.
16
16
17
-
When your async test has multiple exit points, call `QUnit.start()` for the corresponding number of `QUnit.stop()` increments.
17
+
Note: See [`QUnit.config.autostart`](../config/autostart.md) for detailed examples of how to use this.
18
18
19
-
## Examples
20
-
21
-
A test run that does not begin when the page is done loading. This example uses an Asynchronous Module Definition (AMD) loader-style `require` call.
22
-
23
-
```js
24
-
QUnit.config.autostart=false;
25
-
26
-
require(
27
-
['test/tests1.js', 'test/tests2.js'],
28
-
QUnit.start
29
-
);
30
-
```
19
+
<pclass="note note--warning"markdown="1">**Warning**: Prior to QUnit 1.16, this method was used for resuming an async `QUnit.start` function, as complement to `QUnit.stop()`. To resume asynchronous tests, use [`assert.async()`](../assert/async.md) instead.</p>
Copy file name to clipboardExpand all lines: docs/config/autostart.md
+33-6Lines changed: 33 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
1
---
2
2
layout: page-api
3
3
title: QUnit.config.autostart
4
-
excerpt: Start running the tests once all files have been loaded.
4
+
excerpt: Control when the test run may start.
5
5
groups:
6
6
- config
7
7
version_added: "1.0.0"
8
8
---
9
9
10
-
Start running the tests once all files have been loaded.
10
+
Control when the test run may start, e.g. after asynchronously loading test files with RequireJS, AMD, ES6 dynamic imports, or other means.
11
11
12
12
<table>
13
13
<tr>
@@ -20,13 +20,40 @@ Start running the tests once all files have been loaded.
20
20
</tr>
21
21
</table>
22
22
23
-
By default, QUnit starts running the tests when `load` event is triggered on the `window` (in the browser), or after all specified files have been imported (in the CLI).
23
+
In the browser, QUnit by default waits for all `<script>` elements to finish loading (by means of the window`load` event). When using the QUnit CLI, it waits until the specified files are imported.
24
24
25
-
Set this property to `false`if you load your test files asynchronously through custom means (e.g. RequireJS). Remember to call `QUnit.start()` once you're ready for tests to begin running.
25
+
Set this property to `false`to instruct QUnit to wait longer, allowing you to load test files asynchronously. Remember to call [`QUnit.start()`](../QUnit/start.md) once you're ready for tests to begin running.
26
26
27
-
## Example
27
+
If you asynchronously load test files _without_ disabling autostart, you may encounter this warning:
28
28
29
-
Disable autostart when loading tests asynchronously, such as when using RequireJS:
29
+
<pclass="note note--warning"markdown="1">**warning**: Unexpected test after runEnd.</p>
30
+
31
+
## Examples
32
+
33
+
### ESM Dynamic imports
34
+
35
+
This example uses the [import()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) operator to dynamically load ECMAScript module (ESM) files.
36
+
37
+
```html
38
+
<scriptsrc="../lib/qunit.js"></script>
39
+
<scripttype="module"src="tests.js"></script>
40
+
```
41
+
42
+
```js
43
+
// tests.js
44
+
QUnit.config.autostart=false;
45
+
46
+
Promise.all([
47
+
import('./foo.js'),
48
+
import('./bar.js')
49
+
]).then(function () {
50
+
QUnit.start();
51
+
});
52
+
```
53
+
54
+
### Loading with RequireJS
55
+
56
+
This example uses [RequireJS](https://requirejs.org/) to call a "require" function as defined by the [AMD specification](https://github.com/amdjs/amdjs-api/blob/master/require.md) (Asynchronous Module Definition).
0 commit comments