Skip to content

Commit

Permalink
feature(package) sinon, sinon-called-with-diff -> @cloudcmd/stub
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Nov 23, 2018
1 parent ae4b04a commit 11d0b9b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 49 deletions.
5 changes: 2 additions & 3 deletions lib/rest/common/operate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

const test = require('tape');
const tryToCatch = require('try-to-catch');
const sinon = require('sinon');
const stub = require('@cloudcmd/stub');

const operate = require('./operate');

const reject = Promise.reject.bind(Promise);

test('restbox: operate', async (t) => {
const copy = sinon
.stub()
const copy = stub()
.returns(reject(Error('error')));

const [e] = await tryToCatch(operate, copy, 'token', 'dir', [
Expand Down
9 changes: 3 additions & 6 deletions lib/rest/copy.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const calledWithDiff = require('sinon-called-with-diff');
const sinon = calledWithDiff(require('sinon'));
const stub = require('@cloudcmd/stub');
const test = require('tape');

const mockRequire = require('mock-require');
Expand All @@ -27,8 +26,7 @@ test('restbox: copy: no token', async (t) => {
});

test('restbox: copy', async (t) => {
const operate = sinon
.stub()
const operate = stub()
.returns(Promise.resolve());

mockRequire('./common/operate', operate);
Expand Down Expand Up @@ -63,8 +61,7 @@ test('restbox: copy', async (t) => {
});

test('restbox: copy: response', async (t) => {
const operate = sinon
.stub()
const operate = stub()
.returns(Promise.resolve());

mockRequire('./common/operate', operate);
Expand Down
21 changes: 7 additions & 14 deletions lib/rest/delete.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';

const calledWithDiff = require('sinon-called-with-diff');
const sinon = calledWithDiff(require('sinon'));
const test = require('tape');
const stub = require('@cloudcmd/stub');

const mockRequire = require('mock-require');
const {reRequire} = mockRequire;
Expand All @@ -13,6 +12,8 @@ const {request} = require('serve-once')(restbox);
const pathDelete = './delete';
const pathRestbox = '../restbox';

const resolve = async () => {};

test('restbox: delete: no token', async (t) => {
const {body} = await request.delete('/dropbox/fs/temp');

Expand All @@ -21,9 +22,7 @@ test('restbox: delete: no token', async (t) => {
});

test('restbox: delete: dropbox.remove', async (t) => {
const remove = sinon
.stub()
.returns(Promise.resolve());
const remove = stub(resolve);

mockRequire('@cloudcmd/dropbox', {
remove,
Expand All @@ -48,9 +47,7 @@ test('restbox: delete: dropbox.remove', async (t) => {
});

test('restbox: delete: root: dropbox.remove', async (t) => {
const remove = sinon
.stub()
.returns(Promise.resolve());
const remove = stub(resolve);

mockRequire('@cloudcmd/dropbox', {
remove,
Expand All @@ -76,9 +73,7 @@ test('restbox: delete: root: dropbox.remove', async (t) => {
});

test('restbox: delete', async (t) => {
const remove = sinon
.stub()
.returns(Promise.resolve());
const remove = stub(resolve);

mockRequire('@cloudcmd/dropbox', {
remove,
Expand All @@ -103,9 +98,7 @@ test('restbox: delete', async (t) => {
});

test('restbox: delete: dropbox.remove: files', async (t) => {
const operate = sinon
.stub()
.returns(Promise.resolve());
const operate = stub(resolve);

mockRequire('./common/operate', operate);

Expand Down
12 changes: 4 additions & 8 deletions lib/rest/get.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';

const calledWithDiff = require('sinon-called-with-diff');
const sinon = calledWithDiff(require('sinon'));
const test = require('tape');
const stub = require('@cloudcmd/stub');
const fullstore = require('fullstore');

const stringToStream = require('string-to-stream');
Expand All @@ -23,8 +22,7 @@ test('restbox: get: no token', async (t) => {
});

test('restbox: get: readbox', async (t) => {
const readbox = sinon
.stub()
const readbox = stub()
.returns(stringToStream('hello'));

mockRequire('readbox', readbox);
Expand All @@ -50,8 +48,7 @@ test('restbox: get: readbox', async (t) => {
});

test('restbox: get: readbox: directory', async (t) => {
const readbox = sinon
.stub()
const readbox = stub()
.returns({
...stringToStream('hello'),
type: 'directory',
Expand Down Expand Up @@ -127,8 +124,7 @@ test('restbox: get: readbox: size', async (t) => {
test('restbox: get: readbox: hash', async (t) => {
const {random} = Math;

Math.random = sinon
.stub()
Math.random = stub()
.returns(31337);

const res = await request.get('/dropbox/fs/?hash');
Expand Down
9 changes: 3 additions & 6 deletions lib/rest/move.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';

const calledWithDiff = require('sinon-called-with-diff');
const sinon = calledWithDiff(require('sinon'));
const test = require('tape');
const stub = require('@cloudcmd/stub');

const mockRequire = require('mock-require');
const {reRequire} = mockRequire;
Expand All @@ -27,8 +26,7 @@ test('restbox: move: no token', async (t) => {
});

test('restbox: move', async (t) => {
const operate = sinon
.stub()
const operate = stub()
.returns(Promise.resolve());

mockRequire('./common/operate', operate);
Expand Down Expand Up @@ -63,8 +61,7 @@ test('restbox: move', async (t) => {
});

test('restbox: move: response', async (t) => {
const operate = sinon
.stub()
const operate = stub()
.returns(Promise.resolve());

mockRequire('./common/operate', operate);
Expand Down
15 changes: 5 additions & 10 deletions lib/rest/put.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const calledWithDiff = require('sinon-called-with-diff');
const sinon = calledWithDiff(require('sinon'));
const stub = require('@cloudcmd/stub');
const test = require('tape');
const through2 = require('through2');

Expand All @@ -22,8 +21,7 @@ test('restbox: put: no token', async (t) => {
});

test('restbox: put: mkdir', async (t) => {
const mkdir = sinon
.stub()
const mkdir = stub()
.returns(Promise.resolve());

mockRequire('@cloudcmd/dropbox', {
Expand All @@ -50,8 +48,7 @@ test('restbox: put: mkdir', async (t) => {

test('restbox: put: response', async (t) => {
const stream = through2((chunk, enc, fn) => fn(null, chunk));
const createWriteStream = sinon
.stub()
const createWriteStream = stub()
.returns(stream);

mockRequire('@cloudcmd/dropbox', {
Expand Down Expand Up @@ -83,8 +80,7 @@ test('restbox: put: response', async (t) => {

test('restbox: put: createWriteStream', async (t) => {
const stream = through2((chunk, enc, fn) => fn(null, chunk));
const createWriteStream = sinon
.stub()
const createWriteStream = stub()
.returns(stream);

mockRequire('@cloudcmd/dropbox', {
Expand Down Expand Up @@ -116,8 +112,7 @@ test('restbox: put: createWriteStream', async (t) => {

test('restbox: put: unzip', async (t) => {
const stream = through2((chunk, enc, fn) => fn(null, chunk));
const createWriteStream = sinon
.stub()
const createWriteStream = stub()
.returns(stream);

mockRequire('@cloudcmd/dropbox', {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"wraptile": "^2.0.0"
},
"devDependencies": {
"@cloudcmd/stub": "^2.0.0",
"coveralls": "^3.0.0",
"eslint": "^5.0.0",
"eslint-plugin-node": "^8.0.0",
Expand All @@ -37,8 +38,6 @@
"redrun": "^7.0.0",
"request": "^2.79.0",
"serve-once": "^1.0.0",
"sinon": "^7.0.0",
"sinon-called-with-diff": "^3.0.0",
"string-to-stream": "^1.1.1",
"tape": "^4.5.1",
"through2": "^3.0.0",
Expand Down

0 comments on commit 11d0b9b

Please sign in to comment.