Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modifications to mocha.js and some TestExecutor logic #1334

Merged
merged 25 commits into from
Oct 14, 2016
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
53d9f1a
have run_tests return structured result used by TestExecutor
ozyx Oct 3, 2016
b047224
have run_tests accept test data from stdin
ozyx Oct 4, 2016
63d75a2
run_tests receives test data over stdin
ozyx Oct 4, 2016
f86fa0c
expose StandardOutput and disable async readline
ozyx Oct 5, 2016
20a9973
TestExecutor receives test results over process StandardOutput
ozyx Oct 5, 2016
eb19e28
include testing framework in testInfo object sent to run_tests.js
ozyx Oct 5, 2016
831f60a
comments
ozyx Oct 6, 2016
22a5d5d
close readline interface after running test
ozyx Oct 7, 2016
566851c
revert ProcessOutput
ozyx Oct 7, 2016
1faba48
use JsonConvert.DeserializeObject<TestResult>() instead
ozyx Oct 7, 2016
b82e88d
create GetTestResultFromProcess() method
ozyx Oct 7, 2016
2113caf
use Process, copy over helper methods from ProcessOutput
ozyx Oct 7, 2016
a512751
close StandardInput after sending test info
ozyx Oct 7, 2016
3e8e08d
include dependency for copied ProcessOutput method
ozyx Oct 7, 2016
ca7f182
launch node inside of RunTestCases instead
ozyx Oct 7, 2016
bc92e13
remove some debugging stuff
ozyx Oct 7, 2016
0b78611
handle case if result is null
ozyx Oct 7, 2016
5338a27
pass in streams as parameters to allow continual reading/writing
ozyx Oct 7, 2016
7a93d78
move setup logic to RunTests
ozyx Oct 10, 2016
7eb9142
only remove double quotes from test case info
ozyx Oct 10, 2016
f0dc92d
move Process launch logic into function
ozyx Oct 11, 2016
f48b8c9
mocha uses runner events to determine test pass/fail
ozyx Oct 12, 2016
89837b6
get TestExecutor in working state, still launching one process per on…
ozyx Oct 12, 2016
dc5df19
get TextExecutor code into working state
ozyx Oct 12, 2016
36f018a
fixes from PR feedback
ozyx Oct 14, 2016
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
50 changes: 47 additions & 3 deletions Nodejs/Product/Nodejs/TestFrameworks/mocha/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@
var EOL = require('os').EOL;
var fs = require('fs');
var path = require('path');

var result = {
"title": "",
"passed": false,
"stdOut": "",
"stdErr": ""
};
// Choose 'tap' rather than 'min' or 'xunit'. The reason is that
// 'min' produces undisplayable text to stdout and stderr under piped/redirect,
// and 'xunit' does not print the stack trace from the test.
var defaultMochaOptions = { ui: 'tdd', reporter: 'tap', timeout: 2000 };

function hook_stdout(callback) {
var old_write = process.stdout.write;

process.stdout.write = (function (write) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use process.stdout.write = callback here

return function (string, encoding, fd) {
callback(string, encoding, fd)
//write.apply(process.stdout, arguments)
}
})(process.stdout.write)

return function () {
process.stdout.write = old_write
}
}

var find_tests = function (testFileList, discoverResultFile, projectFolder) {
var Mocha = detectMocha(projectFolder);
if (!Mocha) {
Expand Down Expand Up @@ -57,11 +77,16 @@ var find_tests = function (testFileList, discoverResultFile, projectFolder) {
module.exports.find_tests = find_tests;

var run_tests = function (testName, testFile, workingFolder, projectFolder) {
//var testResults = [];
var Mocha = detectMocha(projectFolder);
if (!Mocha) {
return;
}

var unhook = hook_stdout(function (string, encoding, fd) {
result.stdOut += string;
});

var mocha = initializeMocha(Mocha, projectFolder);

if (testName) {
Expand All @@ -70,10 +95,29 @@ var run_tests = function (testName, testFile, workingFolder, projectFolder) {
else
mocha.grep(testName); // prior Mocha 3.0.0
}

mocha.addFile(testFile);

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

runner.on('start', function () {
});
runner.on('test', function (test) {
result.title = test.title;
});
runner.on('end', function () {
unhook();
console.log(JSON.stringify(result));
process.exit(0);
});
runner.on('pass', function (test) {
result.passed = true;
//testResults.push(result);
});
runner.on('fail', function (test, err) {
result.passed = false;
//testResults.push(result);
});
};

Expand Down
31 changes: 24 additions & 7 deletions Nodejs/Product/Nodejs/TestFrameworks/run_tests.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
var framework;
try {
framework = require('./' + process.argv[2] + '/' + process.argv[2] + '.js');
} catch (exception) {
console.log("NTVS_ERROR:Failed to load TestFramework (" + process.argv[2] + "), " + exception);
process.exit(1);
}
var readline = require('readline');

framework.run_tests(process.argv[3], process.argv[4], process.argv[5], process.argv[6]);
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

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

try {
framework = require('./' + testInfo.framework + '/' + testInfo.framework + '.js');
} catch (exception) {
console.log("NTVS_ERROR:Failed to load TestFramework (" + process.argv[2] + "), " + exception);
process.exit(1);
}
// run the test
framework.run_tests(testInfo.testName, testInfo.testFile, testInfo.workingFolder, testInfo.projectFolder);

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