mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from vscode 112fa76c775ecb79ac2c9e9e5dba0d711d523543 (#6388)
This commit is contained in:
123
test/all.js
123
test/all.js
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user