Created
November 7, 2011 05:12
-
-
Save leviwilson/1344226 to your computer and use it in GitHub Desktop.
Reporting Jasmine Results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ResultsReporter : IJavaScriptReporter | |
{ | |
private readonly Dictionary<string, string> _results = new Dictionary<string,string>(); | |
public Dictionary<string, string> Results | |
{ | |
get { return _results; } | |
} | |
public string Result | |
{ | |
get { throw new NotImplementedException(); } | |
} | |
public void Passed(string name) | |
{ | |
_results.Add(name, null); | |
} | |
public void Failed(string name, object[] errors) | |
{ | |
var scriptError = errors.Cast<string>() | |
.Aggregate((error, nextError) => error + Environment.NewLine + nextError); | |
_results.Add(name, scriptError); | |
} | |
public void Finished() | |
{ | |
} | |
} | |
[TestFixture] | |
public class HeadlessTestingDemo | |
{ | |
[Test, TestCaseSource("JasmineResults")] | |
public void Expect(string testName, string errors) | |
{ | |
Assert.That(errors, Is.Null); | |
} | |
public object [] JasmineResults | |
{ | |
get | |
{ | |
var testRunner = new JavaScriptTestRunner(); | |
testRunner.Include(JavaScriptLibrary.jQuery_1_6_4_min); | |
testRunner.Include(JavaScriptLibrary.Jasmine_1_1_0); | |
// load the "Roman.js" file from the resource specified in <T>, which happens to be this assembly but could be in another project. | |
testRunner.LoadFromResource<HeadlessTestingDemo>("Roman.js"); | |
testRunner.LoadFromResource<HeadlessTestingDemo>("RomanSpec.js"); | |
testRunner.LoadFromResource<HeadlessTestingDemo>("SpecHelper.js"); | |
var testReporter = new ResultsReporter(); | |
testRunner.RunJasmineSpecs(testReporter); | |
return testReporter.Results | |
.Select(x => new[] {x.Key, x.Value}) | |
.ToArray(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment