Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions Nodejs/Product/Nodejs/TestFrameworks/ExportRunner/exportrunner.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
var fs = require('fs');
var path = require('path');
var vm = require('vm');
var result = {
'title': '',
'passed': false,
'stdOut': '',
'stdErr': '',
'time': 0
};

function append_stdout(string, encoding, fd) {
result.stdOut += string;
}
function append_stderr(string, encoding, fd) {
result.stdErr += string;
}
process.stdout.write = append_stdout;
process.stderr.write = append_stderr;

var find_tests = function (testFileList, discoverResultFile) {
var debug;
Expand Down Expand Up @@ -50,8 +66,31 @@ var find_tests = function (testFileList, discoverResultFile) {
};
module.exports.find_tests = find_tests;

var run_tests = function (testName, testFile) {
var testCase = require(testFile);
testCase[testName]();
var run_tests = function (testCases, callback) {
var test_results = [];
for (var test in testCases) {
try {
var testCase = require(testCases[test].testFile);
result.title = testCases[test].testName;
result.time = Date.now();
testCase[testCases[test].testName]();
result.time = Date.now() - result.time;
result.passed = true;
} catch (err) {
result.time = Date.now() - result.time;
result.passed = false;
console.error(err.name);
console.error(err.message);
}
test_results.push(result)
result = {
'title': '',
'passed': false,
'stdOut': '',
'stdErr': '',
'time': 0
};
}
callback(test_results);
};
module.exports.run_tests = run_tests;
57 changes: 36 additions & 21 deletions Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ var EOL = require('os').EOL;
var fs = require('fs');
var path = require('path');
var result = {
"title": "",
"passed": false,
"stdOut": "",
"stdErr": ""
'title': '',
'passed': false,
'stdOut': '',
'stdErr': '',
'time': 0
};

process.stdout.write = function (string, encoding, fd) {
function append_stdout(string, encoding, fd) {
result.stdOut += string;
}

process.stderr.write = function (string, encoding, fd) {
function append_stderr(string, encoding, fd) {
result.stdErr += string;
}

Expand All @@ -24,7 +24,7 @@ function find_tests(testFileList, discoverResultFile, projectFolder) {
}

var harness = test.getHarness({ exit: false });
var tests = harness["_tests"];
var tests = harness['_tests'];

var count = 0;
var testList = [];
Expand All @@ -51,28 +51,43 @@ function find_tests(testFileList, discoverResultFile, projectFolder) {
};
module.exports.find_tests = find_tests;

function run_tests(testName, testFile, workingFolder, projectFolder, callback) {
var testCases = loadTestCases(testFile);
result.title = testName;
function run_tests(testInfo, callback) {
var testResults = [];
var testCases = loadTestCases(testInfo[0].testFile);
process.stdout.write = append_stdout;
process.stderr.write = append_stderr;
if (testCases === null) {
return;
}

var test = findTape(projectFolder);
if (test === null) {
var tape = findTape(testInfo[0].projectFolder);
if (tape === null) {
return;
}

try {
var harness = test.getHarness();
harness.only(testName);
result.passed = true;
} catch (e) {
logError("Error running test:", testName, "in", testFile, e);
result.passed = false;
for (var test in testInfo) {
result.title = testInfo[test].testName;
try {
result.time = Date.now();
var harness = tape.getHarness();
harness(testInfo[test].testName);
result.passed = true;
} catch (e) {
result.passed = false;
logError('Error running test:', testInfo[test].testName, 'in', testInfo[test].testFile, e);
}
result.time = Date.now() - result.time;
testResults.push(result);
result = {
'title': '',
'passed': false,
'stdOut': '',
'stdErr': '',
'time': 0
};
}

callback(result);
callback(testResults);
}
module.exports.run_tests = run_tests;

Expand Down
54 changes: 33 additions & 21 deletions Nodejs/Product/Nodejs/TestFrameworks/mocha/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ var EOL = require('os').EOL;
var fs = require('fs');
var path = require('path');
var result = {
"title": "",
"passed": false,
"stdOut": "",
"stdErr": ""
'title': '',
'passed': false,
'stdOut': '',
'stdErr': '',
'time': 0
};
// Choose 'tap' rather than 'min' or 'xunit'. The reason is that
// 'min' produces undisplayable text to stdout and stderr under piped/redirect,
Expand Down Expand Up @@ -69,54 +70,65 @@ var find_tests = function (testFileList, discoverResultFile, projectFolder) {
};
module.exports.find_tests = find_tests;

var run_tests = function (testName, testFile, workingFolder, projectFolder, callback) {
//var testResults = [];
var Mocha = detectMocha(projectFolder);
var run_tests = function (testCases, callback) {
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}

var testResults = [];
var Mocha = detectMocha(testCases[0].projectFolder);
if (!Mocha) {
return;
}

var mocha = initializeMocha(Mocha, projectFolder);
var mocha = initializeMocha(Mocha, testCases[0].projectFolder);

//if (testName) {
// if (typeof mocha.fgrep === 'function')
// mocha.fgrep(testName); // since Mocha 3.0.0
// else
// mocha.grep(testName); // prior Mocha 3.0.0
//}
var testGrepString = '^(' + testCases.map(function (testCase) {
return testCase.testName
}).join('|') + ')$';

if (testGrepString) {
mocha.grep(new RegExp(testGrepString));
}

mocha.addFile(testFile);
mocha.addFile(testCases[0].testFile);

// run tests
var runner = mocha.run(function (code) { process.exit(code); });
var runner = mocha.run(function (code) { });

runner.on('start', function () {
});
runner.on('test', function (test) {
result.title = test.title;
result.title = test.fullTitle();
result.time = Date.now();
process.stdout.write = append_stdout;
process.stderr.write = append_stderr;
});
runner.on('end', function () {
callback(testResults);
});
runner.on('pass', function (test) {
result.passed = true;
callback(result);
result.time = Date.now() - result.time;
testResults.push(result);
result = {
'title': '',
'passed': false,
'stdOut': '',
'stdErr': ''
'stdErr': '',
'time': ''
}
});
runner.on('fail', function (test, err) {
result.passed = false;
callback(result);
result.time = Date.now() - result.time;
testResults.push(result);
result = {
'title': '',
'passed': false,
'stdOut': '',
'stdErr': ''
'stdErr': '',
'time': ''
}
});
};
Expand Down
26 changes: 16 additions & 10 deletions Nodejs/Product/Nodejs/TestFrameworks/run_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,34 @@ var rl = readline.createInterface({
});

rl.on('line', (line) => {
var testInfo = JSON.parse(line);
var testCases = JSON.parse(line);
// get rid of leftover quotations from C# (necessary?)
for(var s in testInfo) {
testInfo[s] = testInfo[s].replace(/["]+/g, '');
for (var test in testCases) {
for (var value in testCases[test]) {
testCases[test][value] = testCases[test][value].replace(/["]+/g, '');
}
}

try {
framework = require('./' + testInfo.framework + '/' + testInfo.framework + '.js');
framework = require('./' + testCases[0].framework + '/' + testCases[0].framework + '.js');
} catch (exception) {
console.log("NTVS_ERROR:Failed to load TestFramework (" + process.argv[2] + "), " + exception);
console.log("NTVS_ERROR:Failed to load TestFramework (" + testCases[0].framework + "), " + exception);
process.exit(1);
}

function sendResult(result) {
function returnResult(result) {
// unhook stdout and stderr
process.stdout.write = old_stdout;
process.stderr.write = old_stderr;
console.log(JSON.stringify(result));
//process.exit(0);
if (result) {
console.log(JSON.stringify(result));
}
// end process, tests are done running.
process.exit(0);
}
// run the test
framework.run_tests(testInfo.testName, testInfo.testFile, testInfo.workingFolder, testInfo.projectFolder, sendResult);
framework.run_tests(testCases, returnResult);

// close readline interface
//rl.close();
rl.close();
});
Loading