Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/unit/reporter.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 mocha = require('mocha');
7
const FullJsonStreamReporter = require('./fullJsonStreamReporter');
8
const path = require('path');
9
10
function parseReporterOption(value) {
11
const r = /^([^=]+)=(.*)$/.exec(value);
12
return r ? { [r[1]]: r[2] } : {};
13
}
14
15
exports.importMochaReporter = name => {
16
if (name === 'full-json-stream') {
17
return FullJsonStreamReporter;
18
}
19
20
const reporterPath = path.join(path.dirname(require.resolve('mocha')), 'lib', 'reporters', name);
21
return require(reporterPath);
22
};
23
24
exports.applyReporter = (runner, argv) => {
25
let Reporter;
26
try {
27
Reporter = exports.importMochaReporter(argv.reporter);
28
} catch (err) {
29
try {
30
Reporter = require(argv.reporter);
31
} catch (err) {
32
Reporter = process.platform === 'win32' ? mocha.reporters.List : mocha.reporters.Spec;
33
console.warn(`could not load reporter: ${argv.reporter}, using ${Reporter.name}`);
34
}
35
}
36
37
let reporterOptions = argv['reporter-options'];
38
reporterOptions = typeof reporterOptions === 'string' ? [reporterOptions] : reporterOptions;
39
reporterOptions = reporterOptions.reduce((r, o) => Object.assign(r, parseReporterOption(o)), {});
40
41
return new Reporter(runner, { reporterOptions });
42
};
43
44