Evaluate string with code against provided test suite.
npm install tommy-the-runner --save
Execute tests. Returns Promise resolved with reporter or rejected with eval error
code
is a String with javascript code to evaluate
specs
is a String with mocha test suite written using bdd interface.
runnerOptions
is an Object of options for the runner. Available options:
extraModules
is an Object with custom modules requirable in the spec code. The key is module name and the value is an object returned by the require call to that modules
Module exported in code
is available under require('subject')
in specs
code
Compile CommonJS module. Returns value of module.exports
code
is a String with javascript code to evaluate
const tommy = require('tommy-the-runner')
const code = `
function sum(a, b) {
return a + b
}
module.exports = sum
`
const specs = `
const expect = require('chai').expect
const sum = require('subject')
describe('sum', function () {
it('should sum two numbers', function () {
expect(sum(1, 1)).to.equal(2)
})
})
`
tommy.run(code, specs)
.then(reporter => {
console.log(reporter.stats)
})
.catch(err => {
console.log('Execution error', err)
})
result:
{ suites: 2,
tests: 1,
passes: 1,
pending: 0,
failures: 0,
start: 'Tue Apr 05 2016 22:22:10 GMT+0200 (CEST)',
end: 'Tue Apr 05 2016 22:22:10 GMT+0200 (CEST)',
duration: 4 }