Skip to content

Commit

Permalink
[minor] detect empty or falsy stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Swaagie committed Mar 27, 2015
1 parent 8022f93 commit 5f74dd7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
8 changes: 7 additions & 1 deletion index.js
@@ -1,6 +1,7 @@
'use strict';

var path = require('path')
var empty = require('is-empty')
, path = require('path')
, fs = require('fs');

/**
Expand All @@ -20,6 +21,11 @@ var path = require('path')
function fabricator(stack, options) {
options = options || {};

//
// Empty strings, arrays or objects should not be processed, return early.
//
if (empty(stack)) return [];

switch (is(stack)) {
case 'string':
stack = read(stack, options);
Expand Down
5 changes: 4 additions & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "fabricator",
"version": "0.4.4",
"version": "0.5.0",
"description": "Discover collections of constructible instances from strings (filepaths), arrays or objects",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -31,5 +31,8 @@
"istanbul": "0.3.x",
"mocha": "2.1.x",
"pre-commit": "1.0.x"
},
"dependencies": {
"is-empty": "0.0.1"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/index.js
Expand Up @@ -7,7 +7,7 @@
* @api private
*/
function fn() {
function Y() { /* nope */ }
function Y(x, y) { x = y; }
Y.prototype.name = '';

return Y;
Expand Down
9 changes: 8 additions & 1 deletion test/index.test.js
Expand Up @@ -20,6 +20,13 @@ describe('Fabricator', function () {
});
});

it('returns early if the stack is empty or falsy', function () {
var result = fabricator([false]);

assume(result).to.be.an('array');
assume(result.length).to.equal(0);
});

it('can init constructors from file paths', function () {
var result = fabricator(fixtures.string);

Expand Down Expand Up @@ -67,7 +74,7 @@ describe('Fabricator', function () {
});

it('throws an error when we receive an invalid type', function (next) {
try { fabricator(new Date()); }
try { fabricator(Date.now()); }
catch (e) { next(); }
});

Expand Down

0 comments on commit 5f74dd7

Please sign in to comment.