mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
test(terminal) coverage
This commit is contained in:
parent
6f208c5dfb
commit
b42715950f
1 changed files with 19 additions and 9 deletions
|
|
@ -5,20 +5,12 @@ const mock = require('mock-require');
|
|||
const diff = require('sinon-called-with-diff');
|
||||
const sinon = diff(require('sinon'));
|
||||
|
||||
//const stub = require('mock-require');
|
||||
const stub = require('mock-require');
|
||||
const clean = require('clear-module');
|
||||
|
||||
const configPath = '../../server/config';
|
||||
const terminalPath = '../../server/terminal';
|
||||
|
||||
const {cache, resolve} = require;
|
||||
const stub = (name, exports) => {
|
||||
require(name);
|
||||
|
||||
const resolved = resolve(name);
|
||||
cache[resolved].exports = exports;
|
||||
};
|
||||
|
||||
test('cloudcmd: terminal: disabled', (t) => {
|
||||
clean(terminalPath);
|
||||
stub(configPath, () => {
|
||||
|
|
@ -54,6 +46,24 @@ test('cloudcmd: terminal: disabled: listen', (t) => {
|
|||
});
|
||||
|
||||
test('cloudcmd: terminal: enabled', (t) => {
|
||||
const term = sinon.stub();
|
||||
const arg = 'hello';
|
||||
|
||||
clean(terminalPath);
|
||||
stub(configPath, () => '/terminal');
|
||||
stub('/terminal', term);
|
||||
|
||||
const terminal = require(terminalPath);
|
||||
terminal(arg);
|
||||
|
||||
clean(configPath);
|
||||
require(configPath);
|
||||
|
||||
t.ok(term.calledWith(arg), 'should call terminal');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: terminal: enabled: no string', (t) => {
|
||||
const {log} = console;
|
||||
console.log = sinon.stub();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue