Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor CLI to make it easier to add pkg opts
- Loading branch information
Showing
3 changed files
with
44 additions
and
26 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,18 +1,3 @@ | ||
#!/usr/bin/env node | ||
|
||
var _ = require('lodash'), | ||
teenytest = require('../index'), | ||
argv = require('minimist')(process.argv.slice(2)) | ||
testGlob = _.last(argv['_']) || 'test/lib/**/*.js', | ||
helperPath = argv['helper'] || 'test/helper.js', | ||
asyncTimeout = argv['timeout'] || 5000 | ||
fs = require('fs') | ||
|
||
teenytest(testGlob, { | ||
helperPath: fs.existsSync(helperPath) ? helperPath : null, | ||
asyncTimeout: asyncTimeout | ||
}, function(er, passing) { | ||
process.exit(!er && passing ? 0 : 1) | ||
}) | ||
|
||
|
||
require('../lib/cli')() |
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,20 +1,24 @@ | ||
var _ = require('lodash') | ||
var fs = require('fs') | ||
var path = require('path') | ||
|
||
function noOpHook () {} | ||
|
||
module.exports = function (helperPath, cwd) { | ||
return _.assign({}, { | ||
beforeAll: function () {}, | ||
afterAll: function () {}, | ||
beforeEach: function () {}, | ||
afterEach: function () {}, | ||
return _.defaults(buildUserHelper, { | ||
beforeAll: noOpHook, | ||
afterAll: noOpHook, | ||
beforeEach: noOpHook, | ||
afterEach: noOpHook, | ||
options: {} | ||
}, buildUserHelper(helperPath, cwd)) | ||
}) | ||
} | ||
|
||
var buildUserHelper = function (helperPath, cwd) { | ||
if (!helperPath) { return {} } | ||
return _.assign({}, require(path.resolve(cwd, helperPath)), { | ||
file: helperPath | ||
}) | ||
if (helperPath && fs.existsSync(helperPath)) { | ||
return _.assign({}, require(path.resolve(cwd, helperPath)), { | ||
file: helperPath | ||
}) | ||
} | ||
} | ||
|
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,29 @@ | ||
var _ = require('lodash') | ||
var minimist = require('minimist') | ||
|
||
var teenytest = require('../../index') | ||
|
||
module.exports = function () { | ||
var options = _.defaults(argv(), defaults()) | ||
teenytest(options.testGlob, options, function (er, passing) { | ||
process.exit(!er && passing ? 0 : 1) | ||
}) | ||
} | ||
|
||
function defaults () { | ||
return { | ||
testGlob: 'test/lib/**/*.js', | ||
helperPath: 'test/helper.js', | ||
asyncTimeout: 5000 | ||
} | ||
} | ||
|
||
function argv () { | ||
var argv = minimist(process.argv.slice(2)) | ||
|
||
return { | ||
testGlob: _.last(argv['_']), | ||
helperPath: argv['helper'], | ||
asyncTimeout: argv['timeout'] | ||
} | ||
} |