diff --git a/Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js b/Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js index 2bfec5671..00320a7cc 100644 --- a/Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js +++ b/Nodejs/Product/Nodejs/TestFrameworks/Tape/tape.js @@ -2,6 +2,20 @@ var EOL = require('os').EOL; var fs = require('fs'); var path = require('path'); +var result = { + "title": "", + "passed": false, + "stdOut": "", + "stdErr": "" +}; + +process.stdout.write = function (string, encoding, fd) { + result.stdOut += string; +} + +process.stderr.write = function (string, encoding, fd) { + result.stdErr += string; +} function find_tests(testFileList, discoverResultFile, projectFolder) { var test = findTape(projectFolder); @@ -37,8 +51,9 @@ function find_tests(testFileList, discoverResultFile, projectFolder) { }; module.exports.find_tests = find_tests; -function run_tests(testName, testFile, workingFolder, projectFolder) { +function run_tests(testName, testFile, workingFolder, projectFolder, callback) { var testCases = loadTestCases(testFile); + result.title = testName; if (testCases === null) { return; } @@ -51,10 +66,13 @@ function run_tests(testName, testFile, workingFolder, projectFolder) { try { var harness = test.getHarness(); harness.only(testName); + result.passed = true; } catch (e) { logError("Error running test:", testName, "in", testFile, e); - return; + result.passed = false; } + + callback(result); } module.exports.run_tests = run_tests; diff --git a/Nodejs/Product/Nodejs/TestFrameworks/mocha/mocha.js b/Nodejs/Product/Nodejs/TestFrameworks/mocha/mocha.js index 1277b8b65..47168d429 100644 --- a/Nodejs/Product/Nodejs/TestFrameworks/mocha/mocha.js +++ b/Nodejs/Product/Nodejs/TestFrameworks/mocha/mocha.js @@ -12,14 +12,14 @@ var result = { // '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 }; - -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; } +process.stdout.write = append_stdout; +process.stderr.write = append_stderr; var find_tests = function (testFileList, discoverResultFile, projectFolder) { var Mocha = detectMocha(projectFolder); @@ -78,33 +78,46 @@ var run_tests = function (testName, testFile, workingFolder, projectFolder, call var mocha = initializeMocha(Mocha, 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 - } + //if (testName) { + // if (typeof mocha.fgrep === 'function') + // mocha.fgrep(testName); // since Mocha 3.0.0 + // else + // mocha.grep(testName); // prior Mocha 3.0.0 + //} mocha.addFile(testFile); // run tests - var runner = mocha.run(function (code) { }); + var runner = mocha.run(function (code) { process.exit(code); }); runner.on('start', function () { }); runner.on('test', function (test) { result.title = test.title; + process.stdout.write = append_stdout; + process.stderr.write = append_stderr; }); runner.on('end', function () { - callback(result); }); runner.on('pass', function (test) { result.passed = true; - //testResults.push(result); + callback(result); + result = { + 'title': '', + 'passed': false, + 'stdOut': '', + 'stdErr': '' + } }); runner.on('fail', function (test, err) { result.passed = false; - //testResults.push(result); + callback(result); + result = { + 'title': '', + 'passed': false, + 'stdOut': '', + 'stdErr': '' + } }); }; diff --git a/Nodejs/Product/Nodejs/TestFrameworks/run_tests.js b/Nodejs/Product/Nodejs/TestFrameworks/run_tests.js index 4c95d3fae..6cd03870f 100644 --- a/Nodejs/Product/Nodejs/TestFrameworks/run_tests.js +++ b/Nodejs/Product/Nodejs/TestFrameworks/run_tests.js @@ -25,11 +25,11 @@ rl.on('line', (line) => { process.stdout.write = old_stdout; process.stderr.write = old_stderr; console.log(JSON.stringify(result)); - process.exit(0); + //process.exit(0); } // run the test framework.run_tests(testInfo.testName, testInfo.testFile, testInfo.workingFolder, testInfo.projectFolder, sendResult); // close readline interface - rl.close(); + //rl.close(); }); diff --git a/Nodejs/Product/TestAdapter/TestExecutor.cs b/Nodejs/Product/TestAdapter/TestExecutor.cs index 64c6c5cb7..7660e9357 100644 --- a/Nodejs/Product/TestAdapter/TestExecutor.cs +++ b/Nodejs/Product/TestAdapter/TestExecutor.cs @@ -125,14 +125,14 @@ public void RunTests(IEnumerable sources, IRunContext runContext, IFrame args.AddRange(GetDebugArgs(settings, out port)); } - //args.AddRange(GetInterpreterArgs(firstTest, entry.Key, settings.ProjectRootDir)); - - // eventually launch node process here + args.AddRange(GetInterpreterArgs(firstTest, entry.Key, settings.ProjectRootDir)); + // launch node process + LaunchNodeProcess(settings.WorkingDir, settings.NodeExePath, args); // Run all test cases in a given project RunTestCases(entry.Value, runContext, frameworkHandle); - // dispose node process + _nodeProcess.Dispose(); } } } @@ -141,10 +141,26 @@ public void RunTests(IEnumerable tests, IRunContext runContext, IFrame ValidateArg.NotNull(tests, "tests"); ValidateArg.NotNull(runContext, "runContext"); ValidateArg.NotNull(frameworkHandle, "frameworkHandle"); - _cancelRequested.Reset(); + bool hasExited = false; + bool isNull = _nodeProcess == null; + if (!isNull) { + hasExited = _nodeProcess.HasExited; + } + frameworkHandle.SendMessage(TestMessageLevel.Informational, isNull.ToString()); + frameworkHandle.SendMessage(TestMessageLevel.Informational, hasExited.ToString()); + if ( _nodeProcess == null || _nodeProcess.HasExited ) { + frameworkHandle.SendMessage(TestMessageLevel.Informational, "inside RunTests if statement"); + TestCase firstTest = tests.First(); + NodejsProjectSettings settings = LoadProjectSettings(firstTest.Source); + List args = new List(); + args.AddRange(GetInterpreterArgs(firstTest, settings.WorkingDir, settings.ProjectRootDir)); + LaunchNodeProcess(settings.WorkingDir, settings.NodeExePath, args); + } RunTestCases(tests, runContext, frameworkHandle); + + _nodeProcess.Dispose(); } private void RunTestCases(IEnumerable tests, IRunContext runContext, IFrameworkHandle frameworkHandle) { @@ -238,8 +254,6 @@ private void RunTestCase(VisualStudioApp app, IFrameworkHandle frameworkHandle, } lock (_syncObject) { - // launch node process - LaunchNodeProcess(settings.WorkingDir, settings.NodeExePath, args); #if DEBUG frameworkHandle.SendMessage(TestMessageLevel.Informational, "cd " + workingDir); //frameworkHandle.SendMessage(TestMessageLevel.Informational, _nodeProcess.Arguments); @@ -250,8 +264,7 @@ private void RunTestCase(VisualStudioApp app, IFrameworkHandle frameworkHandle, _nodeProcess.StandardInput.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(testObject)); _nodeProcess.StandardInput.Close(); _nodeProcess.WaitForExit(5000); - } - //standardInput.Close(); + } if (runContext.IsBeingDebugged && app != null) { try { //the '#ping=0' is a special flag to tell VS node debugger not to connect to the port, @@ -288,9 +301,6 @@ private void RunTestCase(VisualStudioApp app, IFrameworkHandle frameworkHandle, } else { frameworkHandle.SendMessage(TestMessageLevel.Error, "Failed to obtain result for " + test.DisplayName + " from TestRunner"); } - - // dispose node process - _nodeProcess.Dispose(); } private ResultObject ParseTestResult(string line) { @@ -310,7 +320,6 @@ private ResultObject GetTestResultFromProcess(StreamReader sr) { } break; } - sr.DiscardBufferedData(); return result; }