Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ozyx committed Dec 5, 2016
1 parent a0acb7a commit ef497da
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions Nodejs/Product/TestAdapter/TestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,6 @@
using Newtonsoft.Json;

namespace Microsoft.NodejsTools.TestAdapter {

class TestEvent {
public string type { get; set; }
public string title { get; set; }
public ResultObject result { get; set; }
}
class ResultObject {
public ResultObject() {
title = String.Empty;
passed = false;
stdout = String.Empty;
stderr = String.Empty;
}
public string title { get; set; }
public bool passed { get; set; }
public string stdout { get; set; }
public string stderr { get; set; }
}

[ExtensionUri(TestExecutor.ExecutorUriString)]
class TestExecutor : ITestExecutor {
public const string ExecutorUriString = "executor://NodejsTestExecutor/v1";
Expand Down Expand Up @@ -79,20 +60,21 @@ public void Cancel() {

private void ProcessTestEvent(object sender, DataReceivedEventArgs e) {
try {
TestEvent testEvent = JsonConvert.DeserializeObject<TestEvent>(e.Data);
// Extract test from list of tests
var test = _currentTests.Where(n => n.DisplayName == testEvent.title);
if (test.Count() > 0) {
if (testEvent.type == "testStart") {
_currentResult = new TestResult(test.First());
_currentResult.StartTime = DateTimeOffset.Now;
_frameworkHandle.RecordStart(test.First());
}
else if (testEvent.type == "result") {
RecordEnd(_frameworkHandle, test.First(), _currentResult, testEvent.result);
if (e.Data != null) {
TestEvent testEvent = JsonConvert.DeserializeObject<TestEvent>(e.Data);
// Extract test from list of tests
var test = _currentTests.Where(n => n.DisplayName == testEvent.title);
if (test.Count() > 0) {
if (testEvent.type == "test start") {
_currentResult = new TestResult(test.First());
_currentResult.StartTime = DateTimeOffset.Now;
_frameworkHandle.RecordStart(test.First());
} else if (testEvent.type == "result") {
RecordEnd(_frameworkHandle, test.First(), _currentResult, testEvent.result);
}
} else if (testEvent.type == "suite end") {
_currentResultObject = testEvent.result;
}
} else if (testEvent.type == "suite end") {
_currentResultObject = testEvent.result;
}
} catch (Exception) { }
}
Expand Down Expand Up @@ -266,11 +248,13 @@ private void RunTestCases(IEnumerable<TestCase> tests, IRunContext runContext, I

// Automatically fail tests that haven't been run by this point (failures in before() hooks)
foreach(TestCase notRunTest in _currentTests) {
TestResult res = new TestResult(notRunTest);
res.Outcome = TestOutcome.Failed;
res.Messages.Add(new TestResultMessage(TestResultMessage.StandardOutCategory, _currentResultObject.stdout));
res.Messages.Add(new TestResultMessage(TestResultMessage.StandardErrorCategory, _currentResultObject.stderr));
frameworkHandle.RecordResult(res);
TestResult result = new TestResult(notRunTest);
result.Outcome = TestOutcome.Failed;
if(_currentResultObject != null) {
result.Messages.Add(new TestResultMessage(TestResultMessage.StandardOutCategory, _currentResultObject.stdout));
result.Messages.Add(new TestResultMessage(TestResultMessage.StandardErrorCategory, _currentResultObject.stderr));
}
frameworkHandle.RecordResult(result);
frameworkHandle.RecordEnd(notRunTest, TestOutcome.Failed);
}

Expand Down Expand Up @@ -416,6 +400,25 @@ public NodejsProjectSettings() {
public string ProjectRootDir { get; set; }
}

class ResultObject {
public ResultObject() {
title = String.Empty;
passed = false;
stdout = String.Empty;
stderr = String.Empty;
}
public string title { get; set; }
public bool passed { get; set; }
public string stdout { get; set; }
public string stderr { get; set; }
}

class TestEvent {
public string type { get; set; }
public string title { get; set; }
public ResultObject result { get; set; }
}

class TestCaseObject {
public TestCaseObject() {
framework = String.Empty;
Expand All @@ -437,5 +440,4 @@ public TestCaseObject(string framework, string testName, string testFile, string
public string testFile { get; set; }
public string workingFolder { get; set; }
public string projectFolder { get; set; }

}

0 comments on commit ef497da

Please sign in to comment.