-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
2 changed files
with
88 additions
and
3 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 |
---|---|---|
@@ -1,11 +1,15 @@ | ||
/* jshint node: true */ | ||
|
||
var _ = require('lodash'); | ||
|
||
module.exports = function(options, callback) { | ||
if (!_.isArray(options.tests)) { | ||
return process.nextTick(callback, new Error('options.tests is not a valid array')); | ||
} | ||
|
||
var testNames = options.tests.map(function(test) { | ||
return test.name; | ||
}); | ||
|
||
process.nextTick(function() { | ||
callback(undefined, testNames); | ||
}); | ||
process.nextTick(callback, undefined, testNames); | ||
}; |
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 |
---|---|---|
@@ -1,3 +1,84 @@ | ||
/* jshint node: true, mocha: true, expr: true */ | ||
|
||
var expect = require('chai').expect; | ||
var list = require('../lib/list.js'); | ||
|
||
// this module is a bit silly, but yay tests | ||
|
||
describe('[list]', function() { | ||
[ | ||
// yes, I am running the same test twice, since it tests | ||
// for two different things... yay! | ||
'takes a tests array as an option', | ||
'calls the callback with an array of string names' | ||
].forEach(function(testName) { | ||
it(testName, function(done) { | ||
var names = ['one', 'two', 'three']; | ||
var tests = names.map(function(name) { | ||
return { name: name }; | ||
}); | ||
|
||
list({ tests: tests }, function(err, data) { | ||
expect(err).to.not.be.ok; | ||
expect(data).to.deep.equal(names); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('errors if options.tests is not present', function(done) { | ||
list({}, function(err, data) { | ||
expect(err).to.be.instanceof(Error) | ||
.and.to.have.property('message') | ||
.and.to.equal('options.tests is not a valid array'); | ||
|
||
expect(data).to.be.undefined; | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('errors if options.tests is not an array', function(done) { | ||
list({ tests: 'junk' }, function(err, data) { | ||
expect(err).to.be.instanceof(Error) | ||
.and.to.have.property('message') | ||
.and.to.equal('options.tests is not a valid array'); | ||
|
||
expect(data).to.be.undefined; | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('is asynchronous', function(done) { | ||
var test = false; | ||
|
||
list({ tests: [{ name: 'pineapple' }] }, function(err, data) { | ||
expect(err).to.not.be.ok; | ||
expect(data).to.be.an('array'); | ||
|
||
expect(test).to.equal(true); | ||
|
||
done(); | ||
}); | ||
|
||
test = true; | ||
}); | ||
|
||
it('is asynchronous when it errors', function(done) { | ||
var test = false; | ||
|
||
list({}, function(err, data) { | ||
expect(err).to.be.instanceof(Error); | ||
expect(data).to.be.undefined; | ||
|
||
expect(test).to.equal(true); | ||
|
||
done(); | ||
}); | ||
|
||
test = true; | ||
}); | ||
|
||
}); |