Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/unit/fullJsonStreamReporter.js
3520 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
const { constants } = require('mocha/lib/runner');
7
const BaseRunner = require('mocha/lib/reporters/base');
8
9
const {
10
EVENT_TEST_BEGIN,
11
EVENT_TEST_PASS,
12
EVENT_TEST_FAIL,
13
EVENT_RUN_BEGIN,
14
EVENT_RUN_END,
15
} = constants;
16
17
/**
18
* Similar to the mocha JSON stream, but includes additional information
19
* on failure. Specifically, the mocha json-stream does not include unmangled
20
* expected versus actual results.
21
*
22
* Writes a superset of the data that json-stream normally would.
23
*/
24
module.exports = class FullJsonStreamReporter extends BaseRunner {
25
constructor(runner, options) {
26
super(runner, options);
27
28
const total = runner.total;
29
runner.once(EVENT_RUN_BEGIN, () => this.writeEvent(['start', { total }]));
30
runner.once(EVENT_RUN_END, () => this.writeEvent(['end', this.stats]));
31
32
// custom coverage events:
33
runner.on('coverage init', (c) => this.writeEvent(['coverageInit', c]));
34
runner.on('coverage increment', (context, coverage) => this.writeEvent(['coverageIncrement', { ...context, coverage }]));
35
36
runner.on(EVENT_TEST_BEGIN, test => this.writeEvent(['testStart', clean(test)]));
37
runner.on(EVENT_TEST_PASS, test => this.writeEvent(['pass', clean(test)]));
38
runner.on(EVENT_TEST_FAIL, (test, err) => {
39
test = clean(test);
40
test.actual = err.actual;
41
test.expected = err.expected;
42
test.actualJSON = err.actualJSON;
43
test.expectedJSON = err.expectedJSON;
44
test.snapshotPath = err.snapshotPath;
45
test.err = err.message;
46
test.stack = err.stack || null;
47
this.writeEvent(['fail', test]);
48
});
49
}
50
51
drain() {
52
return Promise.resolve(this.lastEvent);
53
}
54
55
writeEvent(event) {
56
this.lastEvent = new Promise(r => process.stdout.write(JSON.stringify(event) + '\n', r));
57
}
58
};
59
60
const clean = test => ({
61
title: test.title,
62
fullTitle: test.fullTitle(),
63
duration: test.duration,
64
currentRetry: test.currentRetry()
65
});
66
67