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

Mocha Skip Support for V1.3.x #1586

Merged
merged 3 commits into from
May 24, 2017
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
42 changes: 24 additions & 18 deletions Nodejs/Product/Nodejs/TestFrameworks/mocha/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
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.
Expand All @@ -22,6 +16,17 @@ function hook_outputs() {
process.stdout.write = append_stdout;
process.stderr.write = append_stderr;
}
function reset_result() {
return {
'title': '',
'passed': false,
'pending': false,
'stdOut': '',
'stdErr': ''
};
}

var result = reset_result();

hook_outputs();

Expand Down Expand Up @@ -142,6 +147,17 @@ var run_tests = function (testCases, callback) {
});
});

runner.on('pending', function (test) {
result.pending = true;
result.title = test.fullTitle();
post({
type: 'pending',
title: result.title,
result: result
});
result = reset_result();
});

runner.on('test', function (test) {
result.title = test.fullTitle();
post({
Expand All @@ -164,12 +180,7 @@ var run_tests = function (testCases, callback) {
title: result.title,
result: result
});
result = {
'title': '',
'passed': false,
'stdOut': '',
'stdErr': ''
}
result = reset_result();
});

runner.on('fail', function (test, err) {
Expand All @@ -179,12 +190,7 @@ var run_tests = function (testCases, callback) {
title: result.title,
result: result
});
result = {
'title': '',
'passed': false,
'stdOut': '',
'stdErr': ''
}
result = reset_result();
});
};

Expand Down
47 changes: 34 additions & 13 deletions Nodejs/Product/TestAdapter/TestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,29 @@ private void ProcessTestRunnerEmit(string line)
{
TestEvent testEvent = JsonConvert.DeserializeObject<TestEvent>(line);
// Extract test from list of tests
var test = _currentTests.Where(n => n.DisplayName == testEvent.title);
if (test.Count() > 0)
var tests = _currentTests.Where(n => n.DisplayName == testEvent.title);
if (tests.Count() > 0)
{
if (testEvent.type == "test start")
switch (testEvent.type)
{
_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);
case "test start":
{
_currentResult = new TestResult(tests.First());
_currentResult.StartTime = DateTimeOffset.Now;
_frameworkHandle.RecordStart(tests.First());
}
break;
case "result":
{
RecordEnd(_frameworkHandle, tests.First(), _currentResult, testEvent.result);
}
break;
case "pending":
{
_currentResult = new TestResult(tests.First());
RecordEnd(_frameworkHandle, tests.First(), _currentResult, testEvent.result);
}
break;
}
}
else if (testEvent.type == "suite end")
Expand Down Expand Up @@ -345,9 +356,17 @@ private NodejsProjectSettings LoadProjectSettings(string projectFile) {
private void RecordEnd(IFrameworkHandle frameworkHandle, TestCase test, TestResult result, ResultObject resultObject) {
String[] standardOutputLines = resultObject.stdout.Split('\n');
String[] standardErrorLines = resultObject.stderr.Split('\n');
result.EndTime = DateTimeOffset.Now;
result.Duration = result.EndTime - result.StartTime;
result.Outcome = resultObject.passed ? TestOutcome.Passed : TestOutcome.Failed;

if (null != resultObject.pending && (bool)resultObject.pending)
{
result.Outcome = TestOutcome.Skipped;
}
else
{
result.EndTime = DateTimeOffset.Now;
result.Duration = result.EndTime - result.StartTime;
result.Outcome = resultObject.passed ? TestOutcome.Passed : TestOutcome.Failed;
}
result.Messages.Add(new TestResultMessage(TestResultMessage.StandardOutCategory, String.Join(Environment.NewLine, standardOutputLines)));
result.Messages.Add(new TestResultMessage(TestResultMessage.StandardErrorCategory, String.Join(Environment.NewLine, standardErrorLines)));
result.Messages.Add(new TestResultMessage(TestResultMessage.AdditionalInfoCategory, String.Join(Environment.NewLine, standardErrorLines)));
Expand Down Expand Up @@ -397,11 +416,13 @@ class ResultObject {
public ResultObject() {
title = String.Empty;
passed = false;
pending = false;
stdout = String.Empty;
stderr = String.Empty;
}
public string title { get; set; }
public bool passed { get; set; }
public bool? pending { get; set; }
public string stdout { get; set; }
public string stderr { get; set; }
}
Expand Down