From f8e868eaafc9864905918f145924b2e9375952fa Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 7 Apr 2017 11:54:04 +0300 Subject: [PATCH] feature(package) add sinon-called-with-diff --- package.json | 1 + test/server/exit.js | 3 +- test/server/terminal.js | 3 +- test/server/validate.js | 3 +- test/sinon-called-with-diff.js | 57 ---------------------------------- test/sinon.js | 6 ---- 6 files changed, 7 insertions(+), 66 deletions(-) delete mode 100644 test/sinon-called-with-diff.js delete mode 100644 test/sinon.js diff --git a/package.json b/package.json index b1fc9b99..f3c3e55e 100644 --- a/package.json +++ b/package.json @@ -181,6 +181,7 @@ "rimraf": "^2.5.4", "shortdate": "^1.0.1", "sinon": "^2.1.0", + "sinon-called-with-diff": "^1.0.0", "socket.io-client": "^1.5.1", "stylelint": "^7.0.2", "stylelint-config-standard": "^16.0.0", diff --git a/test/server/exit.js b/test/server/exit.js index 2901da67..7039c491 100644 --- a/test/server/exit.js +++ b/test/server/exit.js @@ -2,7 +2,8 @@ const test = require('tape'); const exit = require('../../server/exit'); -const sinon = require('sinon'); +const diff = require('sinon-called-with-diff'); +const sinon = diff(require('sinon')); test('cloudcmd: exit: process.exit', (t) => { const {exit:exitOriginal} = process; diff --git a/test/server/terminal.js b/test/server/terminal.js index 36108730..eb9b3efa 100644 --- a/test/server/terminal.js +++ b/test/server/terminal.js @@ -1,7 +1,8 @@ 'use strict'; const test = require('tape'); -const sinon = require('../sinon'); +const diff = require('sinon-called-with-diff'); +const sinon = diff(require('sinon')); const configPath = '../../server/config'; const terminalPath = '../../server/terminal'; diff --git a/test/server/validate.js b/test/server/validate.js index 9a7cd83c..676588aa 100644 --- a/test/server/validate.js +++ b/test/server/validate.js @@ -3,7 +3,8 @@ const fs = require('fs'); const test = require('tape'); -const sinon = require('../sinon'); +const diff = require('sinon-called-with-diff'); +const sinon = diff(require('sinon')); const before = require('../before'); const dir = '../..'; diff --git a/test/sinon-called-with-diff.js b/test/sinon-called-with-diff.js deleted file mode 100644 index 5aca3e63..00000000 --- a/test/sinon-called-with-diff.js +++ /dev/null @@ -1,57 +0,0 @@ -'use strict'; - -/* eslint-disable no-console */ - -const chalk = require('chalk'); - -module.exports = (sinon) => { - const {stub} = sinon; - - sinon.stub = () => { - const fn = stub(); - const {calledWith:original} = fn; - - fn.calledWith = (...args) => { - if (original.apply(fn, args)) - return true; - - return calledWith.apply(fn, args); - }; - - return fn; - }; - - Object.assign(sinon.stub, stub); - - return sinon; -}; - -function calledWith(...args) { - if (!this.called) { - write(`expected to call with ${JSON.stringify(this.args)}, but not called at all\n`); - return false; - } - - const actual = this.args.pop(); - - write(`wrong arguments in ${this.func.name}`); - writeObjectActual('actual:', actual); - writeObjectExpected('expected:', args); - - return false; -} - -function write(str) { - process.stdout.write(chalk.red(str) + '\n'); -} - -function writeObjectActual(str, object) { - const json = JSON.stringify(object, null, 2); - console.log(str, chalk.yellow(json) + '\n'); -} - -function writeObjectExpected(str, object) { - const json = JSON.stringify(object, null, 2); - console.log(str, chalk.green(json) + '\n'); -} - diff --git a/test/sinon.js b/test/sinon.js deleted file mode 100644 index 2f8aab02..00000000 --- a/test/sinon.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict'; - -const withDiff = require('./sinon-called-with-diff'); - -module.exports = withDiff(require('sinon')); -