@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
87 lines (85 loc) • 3.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const child_process_1 = tslib_1.__importDefault(require("child_process"));
const fs_1 = tslib_1.__importDefault(require("fs"));
const path_1 = tslib_1.__importDefault(require("path"));
const fancy_log_1 = tslib_1.__importDefault(require("fancy-log"));
const plugin_error_1 = tslib_1.__importDefault(require("plugin-error"));
const PLUGIN_NAME = 'test-runner';
function runPester(options, callback) {
const powerShell = 'powershell.exe';
const script = path_1.default.normalize(__dirname + '..\\..\\..\\tools\\scripts\\Invoke-PesterTest.ps1');
// get output directory
const outputDir = path_1.default.dirname(options.outputPath);
// make results dir if it doesn't exist
if (!fs_1.default.existsSync(outputDir)) {
fs_1.default.mkdirSync(outputDir);
}
const args = ['-NoProfile', '-File', script];
if (options.srcPath) {
args.push('-SrcPath', options.srcPath);
}
if (options.testPath) {
args.push('-TestPath', options.testPath);
}
if (options.outputPath) {
args.push('-OutputPath', options.outputPath);
}
if (!options.verbose) {
args.push('-Quiet');
}
(0, fancy_log_1.default)(powerShell, args.join(' '));
const cmd = child_process_1.default.spawn(powerShell, args);
const errors = [];
cmd.stdout.on('data', function (data) {
const message = data.toString().trim();
if (message && message.length) {
(0, fancy_log_1.default)(`${options.logIdentifier} - ${data.toString().trim()}`);
}
});
cmd.stderr.on('data', function (data) {
const message = data.toString().trim();
if (message.toUpperCase().startsWith('ERROR')) {
fancy_log_1.default.error(`${options.logIdentifier} - ${message}`);
errors.push(`${options.logIdentifier} - ${message}`);
}
else if (message && message.length) {
(0, fancy_log_1.default)(`${options.logIdentifier} - ${message}`);
}
});
cmd.on('exit', function (code) {
if (code !== 0) {
callback('Powershell Unit tests failed. Please check the log for errors or failed tests.');
return;
}
callback();
});
}
function run(options, callback) {
const tests = [];
const next = () => {
if (tests.length > 0) {
tests[0]((err) => {
if (!err) {
// remove first test runner
tests.splice(0, 1);
// call next runner
next();
}
else {
callback(new plugin_error_1.default({ plugin: PLUGIN_NAME, message: err }));
}
});
}
else {
callback();
}
};
if (options.pester) {
tests.push((cb) => runPester(options.pester, cb));
}
next();
}
module.exports = run;
//# sourceMappingURL=index.js.map