mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
test(route) getIndexPath
This commit is contained in:
parent
1005690acb
commit
e3e9e92b44
2 changed files with 25 additions and 5 deletions
|
|
@ -5,6 +5,7 @@ const DIR_SERVER = './';
|
|||
const DIR_COMMON = '../common/';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const flop = require('flop');
|
||||
const ponse = require('ponse');
|
||||
|
|
@ -23,9 +24,9 @@ const Template = require(DIR_SERVER + 'template')();
|
|||
const prefix = squad(prefixer, apart(config, 'prefix'));
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
|
||||
const getIndexPath = () => {
|
||||
const getIndexPath = (isDev) => {
|
||||
const dist = isDev ? 'dist-dev' : 'dist';
|
||||
return DIR + `${dist}/index.html`;
|
||||
return path.join(DIR, `${dist}/index.html`);
|
||||
};
|
||||
|
||||
const FS = CloudFunc.FS;
|
||||
|
|
@ -36,6 +37,8 @@ module.exports = (req, res, next) => {
|
|||
route(req, res, next);
|
||||
};
|
||||
|
||||
module.exports._getIndexPath = getIndexPath;
|
||||
|
||||
/**
|
||||
* additional processing of index file
|
||||
*/
|
||||
|
|
@ -142,7 +145,7 @@ function route(request, response, callback) {
|
|||
|
||||
if (!error)
|
||||
return buildIndex(dir, (error, data) => {
|
||||
p.name = getIndexPath();
|
||||
p.name = getIndexPath(isDev);
|
||||
|
||||
if (error)
|
||||
return ponse.sendError(error, p);
|
||||
|
|
|
|||
|
|
@ -164,14 +164,15 @@ test('cloudcmd: route: keys panel', (t) => {
|
|||
});
|
||||
|
||||
test('cloudcmd: route: no index', (t) => {
|
||||
const name = path.join(__dirname, '../../dist-dev/index.html');
|
||||
const nameAfter = path.join(__dirname, '../../dist-dev/index1.html');
|
||||
const name = path.join(__dirname, '../../dist/index.html');
|
||||
const nameAfter = path.join(__dirname, '../../dist/index1.html');
|
||||
|
||||
fs.renameSync(name, nameAfter);
|
||||
|
||||
before({}, (port, after) => {
|
||||
getStr(`http://localhost:${port}/`)
|
||||
.then((result) => {
|
||||
console.log(result);
|
||||
fs.renameSync(nameAfter, name);
|
||||
t.equal(result.indexOf('ENOENT'), 0, 'should not found index.html');
|
||||
t.end();
|
||||
|
|
@ -180,6 +181,22 @@ test('cloudcmd: route: no index', (t) => {
|
|||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: route: getIndexPath: production', (t) => {
|
||||
const isDev = false;
|
||||
const name = path.join(__dirname, '..', '..', 'dist', 'index.html');
|
||||
|
||||
t.equal(route._getIndexPath(isDev), name);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: route: getIndexPath: development', (t) => {
|
||||
const isDev = true;
|
||||
const name = path.join(__dirname, '..', '..', 'dist-dev', 'index.html');
|
||||
|
||||
t.equal(route._getIndexPath(isDev), name);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: route: file', (t) => {
|
||||
const root = path.join(__dirname, '..', 'fixture', 'empty-file');
|
||||
const config = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue