1 | # Debugging Async Leakage Using Test Isolation Validation
|
2 |
|
3 | ## Overview
|
4 |
|
5 | The `ember-qunit` test isolation validation feature allows you to opt-in to enabling automatic detection of async execution that extends beyond when the test is considered complete. This can be a particularly difficult problem to detect in your tests, and can contribute to non-deterministic test execution.
|
6 |
|
7 | ## Installation
|
8 |
|
9 | The test isolation validation functionality is available on `ember-qunit` version `4.2.0` or higher.
|
10 |
|
11 | ```bash
|
12 | ember install ember-qunit
|
13 | ```
|
14 |
|
15 | ## How to use
|
16 |
|
17 | In order to enable test isolation validation, you'll need to configure the option, `setupTestIsolationValidation: true` in `ember-qunit`'s `start` function, which starts your application or addon's test run.
|
18 |
|
19 | ```js
|
20 | // tests/test-helper.js
|
21 |
|
22 | import Application from '../app';
|
23 | import config from '../config/environment';
|
24 | import { setApplication } from '@ember/test-helpers';
|
25 | import { start } from 'ember-qunit';
|
26 |
|
27 | setApplication(Application.create(config.APP));
|
28 |
|
29 | start({
|
30 | setupTestIsolationValidation: true
|
31 | });
|
32 | ```
|
33 |
|
34 | ## Finding non-isolated tests
|
35 |
|
36 | Once a test run is started with test isolation validation turned on, analysis will occur on a test-by-test basis. Once a failure is detected, a new assertion will be added that will fail the test, indicating that the test is not isolated.
|
37 |
|
38 | 
|
39 |
|
40 | As indicated by the assertion message, important (and more useful) information is printed to the console.
|
41 |
|
42 | 
|
43 |
|
44 | As you can see, the following information is provided for each test that fails isolation validation:
|
45 | - The test module and test name
|
46 | - The category of failure, one of
|
47 | - Pending AJAX requests
|
48 | - Pending test waiters
|
49 | - Scheduled async
|
50 | - Scheduled autorun
|
51 | - The stack trace of the code that caused the isolation failure (Scheduled async or Scheduled autoruns only)
|
52 |
|
53 | In the case of pending **AJAX requests** and **test waiters**, we see those categorizations of the failures. In the case of **scheduled async** or **scheduled autoruns**, we get a bit more information - stack traces that point to the code that scheduled the async call.
|
54 |
|
55 | By viewing this information output to the console, we can traverse the stack from top to bottom, clicking the associated file/line number to get a more detailed view of the callee.
|
56 |
|
57 | In line 9 below, we can see that an async call was scheduled via `Ember.run.later`:
|
58 |
|
59 | 
|
60 |
|
61 | Having this information will enable you to evaluate the best way to address the particular case of async leakage detected.
|