Skip to content

Commit

Permalink
Switch testing from mocha/should to tape for easier testling support
Browse files Browse the repository at this point in the history
  • Loading branch information
bmpvieira committed Aug 15, 2014
1 parent eaeea48 commit 2257cda
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 57 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ Please write unit tests for your code, and check that everything works by runnin
$ npm test
```

To test on the browser:

```sh
$ npm run test-browser
# if you get "No headless browser found" do:
$ npm install -g phantomjs
$ rm ~/.config/browser-launcher/config.json
```

Please also check for code coverage:

```sh
Expand Down
6 changes: 3 additions & 3 deletions bionode-template.min.js

Large diffs are not rendered by default.

32 changes: 18 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,25 @@
"email": "[email protected]"
},
"dependencies": {
"JSONStream": "^0.9.0",
"through2": "^0.6.1",
"debug": "^1.0.4",
"split": "~0.3.0",
"browserify": "~5.10.0",
"uglify-js": "~2.4.15"
"debug": "^1.0.4"
},
"devDependencies": {
"split": "~0.3.0",
"browserify": "^5.10.0",
"uglify-js": "~2.4.15",
"coveralls": "~2.11.1",
"docco": "~0.6.3",
"istanbul": "~0.3.0",
"mocha": "~1.21.4",
"mocha-lcov-reporter": "0.0.1",
"should": "~4.0.4"
"tape": "^2.14.0",
"tap-spec": "^0.2.0",
"testling": "^1.7.0",
"docco": "~0.6.3"
},
"keywords": [
"bio",
"biology",
"bioinformatics",
"bionode",
"template",
"api",
"streams",
Expand All @@ -40,11 +43,12 @@
"bionode-template": "cli.js"
},
"scripts": {
"test": "mocha --reporter spec",
"coverage": "istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- -R spec && rm -rf ./coverage",
"coveralls": "istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf ./coverage",
"build-docs": "docco ./lib/bionode-template.js",
"build-browser": "browserify browser.js | uglifyjs > bionode-template.min.js"
"test": "node test/bionode-template.js | tap-spec",
"test-browser": "browserify test/bionode-template.js | testling | tap-spec",
"coverage": "istanbul cover test/bionode-template.js --report lcovonly -- | tap-spec && rm -rf ./coverage",
"coveralls": "istanbul cover test/bionode-template.js --report lcovonly -- | tap-spec && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf ./coverage",
"build-browser": "browserify index.js -r ./index.js:bionode-template | uglifyjs > bionode-template.min.js",
"build-docs": "docco ./lib/bionode-template.js"
},
"license": "MIT"
}
77 changes: 37 additions & 40 deletions test/bionode-template.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,46 @@
var fs = require('fs')
var split = require('split')
var test = require('tape')

var template = require('../')
var should = require('should')

require('mocha')

describe("Greet", function() {

var greetings
var result = [
{"greeting":"Hello World"},
{"greeting":"Hello Foo"}
]
function test(cb) {
return function() {
greetings.should.eql(result)
cb()
}
}

it("should take a name argument and return object with greeting", function(done) {
template.greet('World').on('data', function(data) {
data.should.eql({"greeting":"Hello World"})
done()
})
test('Should take a name argument and return object with greeting', function(t) {
t.plan(1)
template.greet('World').on('data', function(data) {
t.deepEqual(data, {'greeting': 'Hello World'})
})
})

it("should write to stream and return objects with greetings", function(done) {
var greet = template.greet()
greet.on('data', function(data) { greetings.push(data) })
greet.on('end', test(done))
greetings = []
greet.write('World')
greet.write('Foo')
greet.end()
})

it("should pipe to stream and return objects with greetings", function(done) {
var greet = template.greet()
greet.on('data', function(data) { greetings.push(data) })
greet.on('end', test(done))
greetings = []
fs.createReadStream('./test/names.txt')
.pipe(split())
.pipe(greet)
})
test('Should write to stream and return objects with greetings', function(t) {
t.plan(1)
var greet = createGreet(t)
greet.write('World')
greet.write('Foo')
greet.end()
})


test('Should pipe to stream and return objects with greetings', function(t) {
t.plan(1)
var greet = createGreet(t)
var names = "World\nFoo"
var stream = split()
stream.pipe(greet)
stream.write(names)
stream.end()

})


function createGreet(t) {
var greetings = []
var result = [
{greeting: 'Hello World'},
{greeting: 'Hello Foo'}
]
var greet = template.greet()
greet.on('data', function(data) { greetings.push(data) })
greet.on('end', function() { t.deepEqual(greetings, result) })
return greet
}

0 comments on commit 2257cda

Please sign in to comment.