mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
test(route) sendIndex: coverage
This commit is contained in:
parent
2008f55166
commit
c7f14d37e9
2 changed files with 49 additions and 11 deletions
|
|
@ -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();
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue