Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d6b9849
Showing
10 changed files
with
577 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/local/bin/node | ||
var ooti = require('../lib/ooti.js'); | ||
|
||
var test = ooti.load(node.path.join(node.cwd(), ARGV[2])); | ||
var formatter = ooti.formatter('cli'); | ||
|
||
formatter.observe(test); | ||
test.addListener('test.end', function(stats) { | ||
var exitCode = (stats.fail || stats.wip) | ||
? 1 | ||
: 0; | ||
node.exit(exitCode); | ||
}); | ||
|
||
test.run(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
(function(cli) { | ||
var libUtil = require('../util.js'); | ||
|
||
cli.Formatter = function() { | ||
|
||
}; | ||
|
||
cli.Formatter.prototype.observe = function(test) { | ||
test.addListener('test.start', function() { | ||
puts('==> '+this.path); | ||
}); | ||
|
||
test.addListener('testCase.start', function(testCase) { | ||
testCase | ||
.addListener('step.before', function(step) { | ||
print(step.name+' '); | ||
}) | ||
.addListener('step.assert', function(step) { | ||
print('.'); | ||
}) | ||
.addListener('step.wip', function(step) { | ||
puts(''); | ||
var errStr = 'Wip: Step has no matching step definition'; | ||
puts(libUtil.prefixLines(errStr, ' ')); | ||
}) | ||
.addListener('step.fail', function(step, e) { | ||
puts(''); | ||
var errStr = e.stack.toString(); | ||
if (e.trace) { | ||
errStr = errStr.replace(/\n/, libUtil.sprintf( | ||
" on line %s col %s in %s\n", | ||
e.trace.line, | ||
e.trace.col, | ||
e.trace.path | ||
)); | ||
} | ||
puts(libUtil.prefixLines(errStr, ' ')); | ||
}) | ||
.addListener('step.after', function(step) { | ||
puts(''); | ||
}); | ||
}); | ||
|
||
test.addListener('testCase.end', function(testCase, is) { | ||
puts(''); | ||
}); | ||
|
||
test.addListener('test.end', function(stats) { | ||
puts(libUtil.sprintf( | ||
'%s fail, %s wip, %s pass', | ||
stats.fail, | ||
stats.wip, | ||
stats.pass | ||
)); | ||
}); | ||
}; | ||
})(exports); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(function(ooti) { | ||
var libTest = require('test.js'); | ||
|
||
exports.load = function(path) { | ||
var test = new libTest.Test(); | ||
test.load(path); | ||
return test; | ||
}; | ||
|
||
exports.formatter = function(name) { | ||
// FIXME: ../lib is a hack, would need absolute module path loading for this to work | ||
var formatter = require('../lib/formatter/'+name+'.js'); | ||
return new formatter.Formatter(); | ||
}; | ||
|
||
exports._parse = function(test) { | ||
|
||
}; | ||
})(exports); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
(function(test) { | ||
var libUtil = require('util.js'); | ||
var libTestCase = require('test_case.js'); | ||
|
||
test.Test = function() { | ||
this.async = false; | ||
this.path = null; | ||
this.source = null; | ||
|
||
this.testCases = []; | ||
this.stepDefinitions = []; | ||
|
||
this.stats = {pass: 0, fail: 0, wip: 0}; | ||
}; | ||
node.inherits(test.Test, node.EventEmitter) | ||
|
||
test.Test.prototype.load = function(path) { | ||
this.path = path; | ||
this.source = node.cat(path).wait(); | ||
|
||
this.compile(); | ||
}; | ||
|
||
test.Test.prototype.compile = function() { | ||
var testEnv = function() { | ||
var __content = {testCases: [], stepDefinitions: []}; | ||
|
||
function test(name, step) { | ||
__content.testCases.push({ | ||
name: name, | ||
type: 'test', | ||
steps: [step], | ||
}); | ||
}; | ||
|
||
function spec() { | ||
if (typeof arguments[0] == 'string') { | ||
var steps = arguments[1], name = arguments[0]; | ||
} else { | ||
var steps = arguments[0], name = steps[0]; | ||
} | ||
|
||
__content.testCases.push({ | ||
name: name, | ||
type: 'spec', | ||
steps: steps, | ||
}); | ||
}; | ||
|
||
function define(regex, fn) { | ||
__content.stepDefinitions.push({ | ||
regex: regex, | ||
fn: fn, | ||
}); | ||
}; | ||
|
||
// >>>test_source_goes_here<<< | ||
|
||
;return __content; | ||
}; | ||
|
||
testEnv = testEnv.toString(); | ||
testEnv = testEnv.replace(/\n|\r/g, ''); | ||
testEnv = testEnv.replace('// >>>test_source_goes_here<<<', this.source); | ||
|
||
testEnv = node.compile(testEnv, this.path)(); | ||
this.testCases = testEnv.testCases; | ||
this.stepDefinitions = testEnv.stepDefinitions; | ||
}; | ||
|
||
test.Test.prototype.run = function(options) { | ||
libUtil.extend(this, options); | ||
|
||
this.emit('test.start'); | ||
|
||
var self = this; | ||
libUtil.each(this.testCases, function(i, testCase) { | ||
testCase = new libTestCase.TestCase({ | ||
path: self.path, | ||
name: testCase.name, | ||
type: testCase.type, | ||
steps: testCase.steps, | ||
stepDefinitions: self.stepDefinitions, | ||
}); | ||
|
||
|
||
// Disabled all promise stuff for now - something odd is going on here | ||
var promise = new node.Promise(); | ||
|
||
testCase.addListener('testCase.start', function() { | ||
self.emit('testCase.start', testCase, { | ||
first: (i === 0), | ||
last: (i === self.testCases.length - 1), | ||
}); | ||
}); | ||
|
||
testCase.addListener('testCase.end', function() { | ||
libUtil.each(testCase.stats, function(key, val) { | ||
self.stats[key] = self.stats[key] + val; | ||
}); | ||
|
||
var last = (i === self.testCases.length - 1); | ||
self.emit('testCase.end', testCase, { | ||
first: (i === 0), | ||
last: last, | ||
}); | ||
if (!self.async) { | ||
promise.emitSuccess(); | ||
} | ||
|
||
if (last) { | ||
self.emit('test.end', self.stats); | ||
} | ||
}); | ||
|
||
libTestCase.run(testCase); | ||
|
||
if (!self.async) { | ||
promise.wait(); | ||
} | ||
}); | ||
}; | ||
})(exports); |
Oops, something went wrong.