test(route) sendIndex: coverage

This commit is contained in:
coderaiser 2018-04-17 11:02:49 +03:00
parent 2008f55166
commit c7f14d37e9
2 changed files with 49 additions and 11 deletions

View file

@ -12,6 +12,11 @@ const rootDir = '../..';
const routePath = `${rootDir}/server/route`;
const beforePath = '../before';
const configPath = `${rootDir}/server/config`;
const cloudcmdPath = `${rootDir}/server/cloudcmd`;
const {
_getIndexPath,
} = require(routePath);
const route = require(routePath);
const before = require(beforePath);
@ -300,3 +305,31 @@ test('cloudcmd: route: realpath: error', (t) => {
});
});
test('cloudcmd: route: sendIndex: error', (t) => {
const error = Error('index path error');
const {readFile} = fs;
const isDev = true;
const indexPath = _getIndexPath(isDev);
fs.readFile = (name, options, fn = options) => {
if (name === indexPath) {
fn(error);
fs.readFile = readFile;;
return;
};
return readFile(name, options, fn);
};
const config = {};
before({config}, (port, after) => {
getStr(`http://localhost:${port}`)
.then((data) => {
t.equal(data, error.message, 'should return error');
t.end();
after();
})
});
});