-
Notifications
You must be signed in to change notification settings - Fork 142
TestPattern Setting
When Chutzpah reports test results it also tells you what line they are on. The way this is accomplished is by having a regex for each testing framework which describes where to find the names of your tests. For example for QUnit Chutzpah uses the following:
((?<!\.)\b(?:QUnit\.)?(test|asyncTest)[\t ]*\([\t ]*["'](?<TestName>.*)["'])
This works pretty well but if you use a library which provides a different syntax for specifying tests then this will fail. This results in all tests having no line number information. To fix this problem Chutzpah now offers a TestPattern setting in the chutzpah.json file. This lets you specify your own regex for Chutzpah to use. The requirement for this regex is that it needs to capture the name of the test in a capture group called TestName. For example lets say this is how your test file looks:
function TestClass() {
}
TestClass.prototype.test = function(name, callback) {
QUnit.test(name, callback);
};
TestClass.prototype.testCase = function (name, callback) {
QUnit.test(name, callback);
};
TestClass.prototype.registerTests = function(callback) {
callback.call(this);
};
var testClass = new TestClass();
testClass.registerTests(function() {
this.test("Pattern 1", function() {
ok(true, "this test is fine");
});
this.testCase("Pattern 2", function () {
ok(true, "this test is fine");
});
});
Then you can use the following chutzpah.json to get correct line number information.
{
"Framework": "qunit",
"TestPattern": "this\\.(testCase|test)\\([\"'](?<TestName>.*)[\"']"
}