Skip to content

Commit

Permalink
Docs: Add example to QUnit.config.testTimeout()
Browse files Browse the repository at this point in the history
  • Loading branch information
Krinkle committed Jun 1, 2024
1 parent 2e924a5 commit 08e6259
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions docs/api/config/testTimeout.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ This can be overridden on a per-test basis via [assert.timeout()](../assert/time

It is recommended to keep the global default at `3000` (3 seconds) or higher, to avoid intermittent test failures from unrelated delays that may periodically occur inside a browser or CI service.

## Introducing a timeout

Prior to QUnit 3, there has not been a default timeout. This meant that a test could time out or get stuck for many seconds or minutes before diagnostic details are presented (e.g. after a CI job reaches the maximum run time).

QUnit 3.0 will change the default timeout from undefined (Infinity) to 3 seconds.

### Deprecated: No timeout set

Starting in QUnit 2.21, a deprecation warning will be logged if a test takes longer than 3 seconds, when there is no timeout set.
Expand All @@ -34,9 +40,13 @@ Starting in QUnit 2.21, a deprecation warning will be logged if a test takes lon
Test {name} took longer than 3000ms, but no timeout was set.
```

You can prepare yourself for QUnit 3 when this happens, by either calling `assert.timeout()` inside those tests, or by setting `QUnit.config.testTimeout` once globally with a higher timeout (in your [HTML or bootstrap script](../config/index.md)).
You can prepare yourself for QUnit 3 when this happens, by calling [assert.timeout()](../assert/timeout.md) inside the slow test, or by setting `QUnit.config.testTimeout` once globally with a higher timeout (in your [HTML or bootstrap script](../config/index.md)).

```js
QUnit.config.testTimeout = 60000; // 1 minute
```

Depending on your test runner of choice, there may be more convenient ways to set configuration:
Depending on your test runner of choice, there may be also other convenient ways to set configuration:

* Set `qunit_config_testtimeout` via [preconfig](../config/index.md) as environment variables (for Node.js), or as global variables for HTML/browser environments (before QUnit is loaded).
* Set `testTimeout` via [karma-qunit](https://github.com/karma-runner/karma-qunit/#readme):
Expand All @@ -52,12 +62,6 @@ Depending on your test runner of choice, there may be more convenient ways to se
});
```

### Introducing a timeout

Prior to QUnit 3, there has not been a default timeout. This meant that a test could time out or get stuck for many seconds or minutes before diagnostic details are presented (e.g. after a CI job reaches the maximum run time).

QUnit 3.0 will change the default timeout from undefined (Infinity) to 3 seconds.

### Changelog
## Changelog

| [QUnit 2.21.0](https://github.com/qunitjs/qunit/releases/tag/2.21.0) | Announce change of default from undefined to `3000`, with a deprecation warning.

0 comments on commit 08e6259

Please sign in to comment.