mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(package) add sinon-called-with-diff
This commit is contained in:
parent
7c38e5b8c6
commit
f8e868eaaf
6 changed files with 7 additions and 66 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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 = '../..';
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const withDiff = require('./sinon-called-with-diff');
|
||||
|
||||
module.exports = withDiff(require('sinon'));
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue