vscode-extension-tester
Version:
ExTester is a package that is designed to help you run UI tests for your Visual Studio Code extensions using selenium-webdriver.
99 lines • 4.13 kB
JavaScript
;
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Coverage = void 0;
/*---------------------------------------------------------
* Modified for vscode-extension-tester
*--------------------------------------------------------*/
const c8_1 = require("c8");
const crypto_1 = require("crypto");
const fs_1 = require("fs");
const os_1 = require("os");
const path_1 = require("path");
/**
* Manages collecting coverage data from test runs. All runs, regardless of
* platform, expect coverage data given in the V8 coverage format. We then
* use c8 to convert it to the common Istanbul format and represent it with
* a variety of reporters.
*/
class Coverage {
targetDir = (0, path_1.join)((0, os_1.tmpdir)(), `vsc-coverage-${(0, crypto_1.randomUUID)()}`);
userOptions;
constructor() {
(0, fs_1.mkdirSync)(this.targetDir, { recursive: true });
}
async loadConfig() {
// Read nyc/c8 JSON configuration file for reading user-defined coverage report options.
const mod = await import('find-up');
const config = mod.findUpSync(['.c8rc', '.c8rc.json', '.nycrc', '.nycrc.json']);
if (config) {
try {
const json = (0, fs_1.readFileSync)(config).toString();
this.userOptions = JSON.parse(json);
}
catch (err) {
console.error(`An error was found in reading coverage configuration from ${config}`);
throw err;
}
}
}
async write() {
const reportOptions = {
reporter: ['text', 'html'],
all: false,
excludeNodeModules: true,
include: [],
exclude: [
'coverage/**',
'packages/*/test{,s}/**',
'**/*.d.ts',
'test{,s}/**',
'test{,-*}.{js,cjs,mjs,ts,tsx,jsx}',
'**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx}',
'**/__tests__/**',
'**/{ava,babel,nyc}.config.{js,cjs,mjs}',
'**/jest.config.{js,cjs,mjs,ts}',
'**/{karma,rollup,webpack}.config.js',
'**/.{eslint,mocha}rc.{js,cjs}',
],
extension: ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx'],
excludeAfterRemap: false,
skipFull: false,
tempDirectory: this.targetDir,
resolve: '',
omitRelative: true,
allowExternal: false,
};
if (this.userOptions) {
Object.assign(reportOptions, this.userOptions);
// These two options require special treatments.
['report-dir', 'reports-dir'].forEach((key) => {
if (this.userOptions[key]) {
reportOptions['reportsDirectory'] = this.userOptions[key];
}
});
}
try {
const report = new c8_1.Report(reportOptions);
// A hacky fix due to an outstanding bug in Istanbul's exclusion testing
// code: its subdirectory checks are case-sensitive on Windows, but file
// URIs might have mixed casing.
//
// Setting `relativePath: false` on the exclude bypasses this code path.
//
// https://github.com/istanbuljs/test-exclude/issues/43
// https://github.com/istanbuljs/test-exclude/blob/a5b1d07584109f5f553ccef97de64c6cbfca4764/index.js#L91
report.exclude.relativePath = false;
await report.run();
}
catch (e) {
// throw new CliExpectedError(
throw new Error(`Coverage report generated failed, please file an issue with original reports located in ${this.targetDir}:\n\n${e}`);
}
await fs_1.promises.rm(this.targetDir, { recursive: true, force: true });
}
}
exports.Coverage = Coverage;
//# sourceMappingURL=coverage.js.map