Skip to content

Instantly share code, notes, and snippets.

@leviwilson
Created November 7, 2011 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leviwilson/1344226 to your computer and use it in GitHub Desktop.
Save leviwilson/1344226 to your computer and use it in GitHub Desktop.
Reporting Jasmine Results
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