UNPKG

2.81 kBMarkdownView Raw
1# Debugging Async Leakage Using Test Isolation Validation
2
3## Overview
4
5The `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
9The test isolation validation functionality is available on `ember-qunit` version `4.2.0` or higher.
10
11```bash
12ember install ember-qunit
13```
14
15## How to use
16
17In 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
22import Application from '../app';
23import config from '../config/environment';
24import { setApplication } from '@ember/test-helpers';
25import { start } from 'ember-qunit';
26
27setApplication(Application.create(config.APP));
28
29start({
30 setupTestIsolationValidation: true
31});
32```
33
34## Finding non-isolated tests
35
36Once 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![image](https://user-images.githubusercontent.com/180990/50046470-aeb91d00-0058-11e9-9b9c-d08190e04e6c.png)
39
40As indicated by the assertion message, important (and more useful) information is printed to the console.
41
42![image](https://user-images.githubusercontent.com/180990/50046710-89c6a900-005c-11e9-96b1-e66ac6ef7907.png)
43
44As 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
53In 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
55By 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
57In line 9 below, we can see that an async call was scheduled via `Ember.run.later`:
58
59![image](https://user-images.githubusercontent.com/180990/50046897-f98a6300-005f-11e9-9cd0-dffe0663880a.png)
60
61Having this information will enable you to evaluate the best way to address the particular case of async leakage detected.