Skip to content

Commit

Permalink
mocha-compat: Initial fbp-spec-mocha tool
Browse files Browse the repository at this point in the history
Can read a set of Mocha testcases,
build them into fbp-spec test-suites,
and act as a FBP runtime which can execute
these tests and enforce the results.

Needs a bit more work before being minimally useful

References #36
  • Loading branch information
jonnor committed Jan 5, 2016
1 parent e462797 commit 72a0b8d
Show file tree
Hide file tree
Showing 8 changed files with 452 additions and 1 deletion.
3 changes: 3 additions & 0 deletions bin/fbp-spec-mocha
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node
require('coffee-script/register');
require('../src/mochacompat').main();
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"test": "grunt test --stack"
},
"bin": {
"fbp-spec": "./bin/fbp-spec"
"fbp-spec": "./bin/fbp-spec",
"fbp-spec-mocha": "./bin/fbp-spec-mocha"
},
"dependencies": {
"JSONPath": "0.10.0",
Expand Down
17 changes: 17 additions & 0 deletions spec/fixtures/mochacases/bdd-nested-passing.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

chai = require 'chai'

describe 'nested passing', ->
console.log 'describe fired'

describe 'sub topic', () ->
console.log 'sub describe fired'

it 'should pass', (done) ->
chai.expect(42).to.equal 42
done();

describe 'sub sub topic', () ->
it 'should pass', (done) ->
chai.expect(42).to.equal 42
done();
7 changes: 7 additions & 0 deletions spec/fixtures/mochacases/bdd-simple-failing.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

chai = require 'chai'

describe 'simple failing', () ->
it 'should fail', (done) ->
chai.expect(42).to.equal 41
done();
7 changes: 7 additions & 0 deletions spec/fixtures/mochacases/bdd-simple-passing.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

chai = require 'chai'

describe 'simple passing', () ->
it 'should pass', (done) ->
chai.expect(42).to.equal 42
done();
31 changes: 31 additions & 0 deletions spec/mochacompat.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

require '../src/mochacompat' # Register custom UI
Mocha = require 'mocha'

addTests = (mocha) ->
fs = require 'fs'
path = require 'path'

testDir = path.join __dirname, 'fixtures/mochacases'

fs.readdirSync(testDir).filter (filename) ->
isJs = filename.substr(-3) == '.js';
isCoffee = filename.substr(-7) == '.coffee';
return isJs or isCoffee
.forEach (filename) ->
fullPath = path.join testDir, filename
mocha.addFile fullPath

main = () ->
# See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically
options =
ui: 'fbp-spec'
mocha = new Mocha options
addTests mocha
mocha.run (failures) ->
process.on 'exit', () ->
process.exit failures

main() if not module.parent


Loading

0 comments on commit 72a0b8d

Please sign in to comment.