Skip to content

Commit

Permalink
test(flop) read: options
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Feb 7, 2017
1 parent e9f2e80 commit 476af2d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@
"devDependencies": {
"babel-cli": "^6.22.2",
"babel-preset-es2015": "^6.22.0",
"chalk": "^1.1.3",
"coveralls": "^2.11.16",
"eslint": "^3.14.1",
"nodemon": "^1.11.0",
"nyc": "^10.1.2",
"redrun": "^5.9.5",
"sinon": "^1.17.7",
"tape": "^4.6.3"
}
}
40 changes: 32 additions & 8 deletions test/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ const path = require('path');

const test = require('tape');
const mkdirp = require('mkdirp');
const sinon = require('sinon');

const flop = require('..');

const fixture = path.join(__dirname, 'fixture');
const empty = path.join(fixture, 'empty');
mkdirp.sync(empty);

const stub = (name, fn) => {
require.cache[require.resolve(name)].exports = fn;
};

const clean = (name) => {
delete require.cache[require.resolve(name)];
};

test('flop: read: size', (t) => {
flop.read(empty, 'size', (e, size) => {
t.equal(size, '0b', 'should size to be equal');
Expand Down Expand Up @@ -61,13 +71,27 @@ test('flop: read', (t) => {
});

test('flop: read: options', (t) => {
flop.read(empty, (e, result) => {
const expect = {
path: empty + path.sep,
files: []
};
t.deepEqual(result, expect, 'should return result');
t.end();
});
const readify = sinon.stub();

clean('..');
stub('readify/legacy', readify);
const flop = require('..');

const callback = sinon.stub();
const options = {
order: 'asc',
sort: 'name',
};

flop.read(empty, options, callback);

const expect = [
empty,
options,
callback,
];

t.deepEqual(readify.args.pop(), expect, 'should call with args');
t.end();
});

0 comments on commit 476af2d

Please sign in to comment.