diff --git a/test/server/terminal.js b/test/server/terminal.js new file mode 100644 index 00000000..36108730 --- /dev/null +++ b/test/server/terminal.js @@ -0,0 +1,67 @@ +'use strict'; + +const test = require('tape'); +const sinon = require('../sinon'); + +const configPath = '../../server/config'; +const terminalPath = '../../server/terminal'; + +test('cloudcmd: terminal: disabled', (t) => { + clean(terminalPath); + stub(configPath, () => { + return false; + }); + + const terminal = require(terminalPath); + const fn = terminal(); + + t.notOk(fn, 'should return noop'); + + clean(configPath); + require(configPath); + + t.end(); +}); + +test('cloudcmd: terminal: disabled: listen', (t) => { + clean(terminalPath); + stub(configPath, () => false); + + const terminal = require('../../server/terminal'); + const fn = terminal.listen(); + + t.notOk(fn, 'should return noop'); + + clean(configPath); + require(configPath); + + t.end(); +}); + +test('cloudcmd: terminal: enabled', (t) => { + const {log} = console; + console.log = sinon.stub(); + + clean(terminalPath); + stub(configPath, () => true); + require(terminalPath); + + const msg = 'cloudcmd --terminal: path must be a string'; + + t.ok(console.log.calledWith(msg), 'should call exit'); + + console.log = log; + + clean(configPath); + + t.end(); +}); + +function clean(path) { + delete require.cache[require.resolve(path)]; +} + +function stub(name, fn) { + require.cache[require.resolve(name)].exports = fn; +} + diff --git a/test/server/validate.js b/test/server/validate.js index 724b6b87..9a7cd83c 100644 --- a/test/server/validate.js +++ b/test/server/validate.js @@ -3,8 +3,7 @@ const fs = require('fs'); const test = require('tape'); -const withDiff = require('../sinon-called-with-diff'); -const sinon = withDiff(require('sinon')); +const sinon = require('../sinon'); const before = require('../before'); const dir = '../..'; diff --git a/test/sinon.js b/test/sinon.js new file mode 100644 index 00000000..2f8aab02 --- /dev/null +++ b/test/sinon.js @@ -0,0 +1,6 @@ +'use strict'; + +const withDiff = require('./sinon-called-with-diff'); + +module.exports = withDiff(require('sinon')); +