From ae6936d3c27d5affd6290e6ab6e06215ac310819 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 14 Nov 2018 16:49:13 +0200 Subject: [PATCH] test(route) terminal --- server/route.spec.js | 29 +++++++++++++++++++++++------ server/terminal.js | 4 +++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/server/route.spec.js b/server/route.spec.js index 29124ece..17653d72 100644 --- a/server/route.spec.js +++ b/server/route.spec.js @@ -14,6 +14,7 @@ const fixtureDir = path.join(__dirname, '..', 'test', 'fixture'); const routePath = './route'; const cloudcmdPath = './cloudcmd'; +const terminalPath = './terminal'; const cloudcmd = require(cloudcmdPath); const serveOnce = require('serve-once'); @@ -362,7 +363,6 @@ test('cloudcmd: route: buttons: no terminal', async (t) => { config, } - const {request} = serveOnce(cloudcmd); const {body} = await request.get('/', { options }); @@ -389,22 +389,39 @@ test('cloudcmd: route: no termianl: /fs', async (t) => { t.end(); }); -test('cloudcmd: route: buttons: terminal', async (t) => { +test('cloudcmd: route: buttons: terminal: can not load', async (t) => { const config = { terminal: true, - terminalPath: 'gritty', + terminalPath: 'xxxxxxxxxxxx', }; const options = { config, - } + }; - const {request} = serveOnce(cloudcmd); const {body} = await request.get('/', { options }); - t.notOk(/icon-terminal none/.test(body), 'should enable terminal'); + t.ok(/icon-terminal none/.test(body), 'should not enable terminal'); + t.end(); +}); + +test('cloudcmd: route: buttons: terminal', async (t) => { + const config = { + terminal: true, + terminalPath: 'console-io', + }; + + const options = { + config, + }; + + const {body} = await request.get('/', { + options + }); + + t.notOk(/icon-terminal none/.test(body), 'should not enable terminal'); t.end(); }); diff --git a/server/terminal.js b/server/terminal.js index af40d224..5be754d0 100644 --- a/server/terminal.js +++ b/server/terminal.js @@ -3,7 +3,9 @@ const tryCatch = require('try-catch'); const config = require('./config'); -const noop = () => {}; +const noop = (req, res, next) => { + next && next(); +}; noop.listen = noop; module.exports = (arg) => getTerminal(config('terminal'), arg);