Merge from vscode 112fa76c775ecb79ac2c9e9e5dba0d711d523543 (#6388)

This commit is contained in:
Anthony Dresser
2019-07-17 01:07:27 -07:00
committed by GitHub
parent 43bd7268e8
commit 2d73b6afb1
59 changed files with 652 additions and 638 deletions

View File

@@ -6,20 +6,12 @@
/*eslint-env mocha*/
/*global define,run*/
var assert = require('assert');
var path = require('path');
var glob = require('glob');
var istanbul = require('istanbul');
var i_remap = require('remap-istanbul/lib/remap');
var jsdom = require('jsdom-no-contextify');
var minimatch = require('minimatch');
var fs = require('fs');
var vm = require('vm');
// {{SQL CARBON EDIT}}
var TEST_GLOB = '**/*test*/**/*.test.js';
// {{SQL CARBON EDIT}}
var SQL_TEST_GLOB = '**/sqltest/**/*.test.js';
const assert = require('assert');
const path = require('path');
const glob = require('glob');
const jsdom = require('jsdom-no-contextify');
const TEST_GLOB = '**/test/**/*.test.js|**/sqltest/**/*.test.js';
const coverage = require('./coverage');
var optimist = require('optimist')
.usage('Run the Code tests. All mocha options apply.')
@@ -27,7 +19,6 @@ var optimist = require('optimist')
.describe('run', 'Run a single file').string('run')
.describe('coverage', 'Generate a coverage report').boolean('coverage')
.describe('only-monaco-editor', 'Run only monaco editor tests').boolean('only-monaco-editor')
.describe('forceLoad', 'Force loading').boolean('forceLoad')
.describe('browser', 'Run tests in a browser').boolean('browser')
.alias('h', 'help').boolean('h')
.describe('h', 'Show help');
@@ -80,111 +71,13 @@ function main() {
};
if (argv.coverage) {
var instrumenter = new istanbul.Instrumenter();
var seenSources = {};
loaderConfig.nodeInstrumenter = function (contents, source) {
seenSources[source] = true;
// {{SQL CARBON EDIT}}
if (minimatch(source, SQL_TEST_GLOB)) {
return contents;
}
return instrumenter.instrumentSync(contents, source);
};
coverage.initialize(loaderConfig);
process.on('exit', function (code) {
if (code !== 0) {
return;
}
if (argv.forceLoad) {
// {{SQL CARBON EDIT}}
var allFiles = glob.sync(out + '/(sqltest|sql)/**/*.js');
allFiles = allFiles.map(function (source) {
return path.join(__dirname, '..', source);
});
allFiles = allFiles.filter(function (source) {
if (seenSources[source]) {
return false;
}
if (minimatch(source, TEST_GLOB)) {
return false;
}
if (/fixtures/.test(source)) {
return false;
}
return true;
});
allFiles.forEach(function (source, index) {
var contents = fs.readFileSync(source).toString();
contents = instrumenter.instrumentSync(contents, source);
var stopAt = contents.indexOf('}\n__cov');
stopAt = contents.indexOf('}\n__cov', stopAt + 1);
var str = '(function() {' + contents.substr(0, stopAt + 1) + '});';
var r = vm.runInThisContext(str, source);
r.call(global);
});
}
// {{SQL CARBON EDIT}}
let remapIgnores = /\b((winjs\.base)|(filters\.perf\.data)|(performance)|(marked)|(raw\.marked)|(nls)|(css))\.js$/;
var remappedCoverage = i_remap(global.__coverage__, { exclude: remapIgnores }).getFinalCoverage();
// The remapped coverage comes out with broken paths
var toUpperDriveLetter = function (str) {
if (/^[a-z]:/.test(str)) {
return str.charAt(0).toUpperCase() + str.substr(1);
}
return str;
};
var toLowerDriveLetter = function (str) {
if (/^[A-Z]:/.test(str)) {
return str.charAt(0).toLowerCase() + str.substr(1);
}
return str;
};
var REPO_PATH = toUpperDriveLetter(path.join(__dirname, '..'));
var fixPath = function (brokenPath) {
var startIndex = brokenPath.indexOf(REPO_PATH);
if (startIndex === -1) {
return toLowerDriveLetter(brokenPath);
}
return toLowerDriveLetter(brokenPath.substr(startIndex));
};
var finalCoverage = {};
for (var entryKey in remappedCoverage) {
var entry = remappedCoverage[entryKey];
entry.path = fixPath(entry.path);
// {{SQL CARBON EDIT}}
if (!entry.path.includes('\\vs\\') && !entry.path.includes('/vs/')) {
finalCoverage[fixPath(entryKey)] = entry;
}
}
var collector = new istanbul.Collector();
collector.add(finalCoverage);
var coveragePath = path.join(path.dirname(__dirname), '.build', 'coverage');
console.log('coverage folder is at: '.concat(coveragePath));
var reportTypes = [];
if (argv.run || argv.runGlob) {
// single file running
coveragePath += '-single';
reportTypes = ['lcovonly'];
} else {
// {{SQL CARBON EDIT}}
reportTypes = ['json', 'lcov', 'html', 'cobertura'];
}
var reporter = new istanbul.Reporter(null, coveragePath);
reporter.addAll(reportTypes);
reporter.write(collector, true, function () { });
coverage.createReport(argv.run || argv.runGlob);
});
}

91
test/coverage.js Normal file
View File

@@ -0,0 +1,91 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
const minimatch = require('minimatch');
const fs = require('fs');
const path = require('path');
const iLibInstrument = require('istanbul-lib-instrument');
const iLibCoverage = require('istanbul-lib-coverage');
const iLibSourceMaps = require('istanbul-lib-source-maps');
const iLibReport = require('istanbul-lib-report');
const iReports = require('istanbul-reports');
// {{SQL CARBON EDIT}}
var SQL_TEST_GLOB = '**/test/**/*.test.js|**/sqltest/**/*.test.jss';
const REPO_PATH = toUpperDriveLetter(path.join(__dirname, '..'));
exports.initialize = function (loaderConfig) {
const instrumenter = iLibInstrument.createInstrumenter();
loaderConfig.nodeInstrumenter = function (contents, source) {
if (minimatch(source, SQL_TEST_GLOB)) { // {{SQL CARBON EDIT}}
// tests don't get instrumented
return contents;
}
// Try to find a .map file
let map = null;
try {
map = JSON.parse(fs.readFileSync(`${source}.map`).toString());
} catch (err) {
// missing source map...
}
return instrumenter.instrumentSync(contents, source, map);
};
};
exports.createReport = function (isSingle) {
const mapStore = iLibSourceMaps.createSourceMapStore();
const coverageMap = iLibCoverage.createCoverageMap(global.__coverage__);
const transformed = mapStore.transformCoverage(coverageMap);
// Paths come out all broken
let newData = Object.create(null);
Object.keys(transformed.map.data).forEach((file) => {
const entry = transformed.map.data[file];
const fixedPath = fixPath(entry.path);
if (!fixedPath.includes('\\vs\\') && !fixedPath.includes('/vs/')) {
entry.data.path = fixedPath;
newData[fixedPath] = entry;
}
});
transformed.map.data = newData;
const tree = iLibReport.summarizers.flat(transformed.map);
const context = iLibReport.createContext({
dir: path.join(__dirname, `../.build/coverage${isSingle ? '-single' : ''}`)
});
let reports = [];
if (isSingle) {
reports.push(iReports.create('lcovonly'));
} else {
reports.push(iReports.create('json'));
reports.push(iReports.create('lcov'));
reports.push(iReports.create('html'));
}
reports.forEach(report => tree.visit(report, context));
};
function toUpperDriveLetter(str) {
if (/^[a-z]:/.test(str)) {
return str.charAt(0).toUpperCase() + str.substr(1);
}
return str;
}
function toLowerDriveLetter(str) {
if (/^[A-Z]:/.test(str)) {
return str.charAt(0).toLowerCase() + str.substr(1);
}
return str;
}
function fixPath(brokenPath) {
const startIndex = brokenPath.lastIndexOf(REPO_PATH);
if (startIndex === -1) {
return toLowerDriveLetter(brokenPath);
}
return toLowerDriveLetter(brokenPath.substr(startIndex));
}

View File

@@ -9,11 +9,9 @@ const { ipcRenderer } = require('electron');
const assert = require('assert');
const path = require('path');
const glob = require('glob');
const minimatch = require('minimatch');
const istanbul = require('istanbul');
const i_remap = require('remap-istanbul/lib/remap');
const util = require('util');
const bootstrap = require('../../src/bootstrap');
const coverage = require('../coverage');
// {{SQL CARBON EDIT}}
require('reflect-metadata');
@@ -68,86 +66,19 @@ function initLoader(opts) {
]
};
// nodeInstrumenter when coverage is requested
if (opts.coverage) {
const instrumenter = new istanbul.Instrumenter();
loaderConfig.nodeInstrumenter = function (contents, source) {
// {{SQL CARBON EDIT}}
if (minimatch(source, _sql_tests_glob)) {
return contents;
}
return minimatch(source, _tests_glob)
? contents // don't instrument tests itself
: instrumenter.instrumentSync(contents, source);
};
// initialize coverage if requested
coverage.initialize(loaderConfig);
}
loader.require.config(loaderConfig);
}
function createCoverageReport(opts) {
return new Promise(resolve => {
if (!opts.coverage) {
return resolve(undefined);
}
const exclude = /\b((marked)|(raw\.marked)|(nls)|(css))\.js$/;
const remappedCoverage = i_remap(global.__coverage__, { exclude: exclude }).getFinalCoverage();
// The remapped coverage comes out with broken paths
function toUpperDriveLetter(str) {
if (/^[a-z]:/.test(str)) {
return str.charAt(0).toUpperCase() + str.substr(1);
}
return str;
}
function toLowerDriveLetter(str) {
if (/^[A-Z]:/.test(str)) {
return str.charAt(0).toLowerCase() + str.substr(1);
}
return str;
}
const REPO_PATH = toUpperDriveLetter(path.join(__dirname, '../..'));
const fixPath = function (brokenPath) {
const startIndex = brokenPath.indexOf(REPO_PATH);
if (startIndex === -1) {
return toLowerDriveLetter(brokenPath);
}
return toLowerDriveLetter(brokenPath.substr(startIndex));
};
const finalCoverage = Object.create(null);
for (const entryKey in remappedCoverage) {
const entry = remappedCoverage[entryKey];
entry.path = fixPath(entry.path);
// {{SQL CARBON EDIT}}
if (!entry.path.includes('\\vs\\') && !entry.path.includes('/vs/')) {
finalCoverage[fixPath(entryKey)] = entry;
}
}
const collector = new istanbul.Collector();
collector.add(finalCoverage);
let coveragePath = path.join(path.dirname(__dirname), '../.build/coverage');
let reportTypes = [];
if (opts.run || opts.runGlob) {
// single file running
coveragePath += '-single';
reportTypes = ['lcovonly'];
} else {
// {{SQL CARBON EDIT}}
reportTypes = ['json', 'lcov', 'html', 'cobertura'];
}
const reporter = new istanbul.Reporter(null, coveragePath);
reporter.addAll(reportTypes);
reporter.write(collector, true, resolve);
});
if (opts.coverage) {
coverage.createReport(opts.run || opts.runGlob);
}
return Promise.resolve(undefined);
}
function loadTestModules(opts) {