feature(cloudcmd) move out dist from route

This commit is contained in:
coderaiser 2018-05-11 13:03:58 +03:00
parent bb44a14780
commit 4e99372e6f
6 changed files with 94 additions and 163 deletions

View file

@ -1,5 +1,7 @@
'use strict';
const path = require('path');
const test = require('tape');
const diff = require('sinon-called-with-diff');
const sinon = diff(require('sinon'));
@ -201,6 +203,23 @@ function credentials() {
return set(reset);
}
test('cloudcmd: getIndexPath: production', (t) => {
const isDev = false;
const name = path.join(__dirname, '..', '..', 'dist', 'index.html');
t.equal(cloudcmd._getIndexPath(isDev), name);
t.end();
});
test('cloudcmd: getIndexPath: development', (t) => {
const isDev = true;
const name = path.join(__dirname, '..', '..', 'dist-dev', 'index.html');
t.equal(cloudcmd._getIndexPath(isDev), name);
t.end();
});
function cleanNodeEnv() {
const {NODE_ENV} = process.env;
process.env.NODE_ENV = '';

View file

@ -16,11 +16,6 @@ const routePath = `${rootDir}/server/route`;
const cloudcmdPath = `${rootDir}/server/cloudcmd`;
const beforePath = path.join(__dirname, '../before');
const {
_getIndexPath,
} = require(routePath);
const route = require(routePath);
const {connect} = require(beforePath);
const warp = (fn, ...a) => (...b) => fn(...b, ...a);
@ -36,25 +31,6 @@ const getStr = (url) => {
.catch(console.log);
};
test('cloudcmd: route: no args', (t) => {
t.throws(route, /req could not be empty!/, 'should throw when no args');
t.end();
});
test('cloudcmd: route: no res', (t) => {
const fn = () => route({});
t.throws(fn, /res could not be empty!/, 'should throw when no res');
t.end();
});
test('cloudcmd: route: no next', (t) => {
const fn = () => route({}, {});
t.throws(fn, /next should be function!/, 'should throw when no next');
t.end();
});
test('cloudcmd: route: buttons: no console', async (t) => {
const config = {
console: false
@ -167,22 +143,6 @@ test('cloudcmd: route: keys panel', async (t) => {
done();
});
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: fs', async (t) => {
const root = path.join(__dirname, '..', 'fixture', 'empty-file');
const config = {
@ -257,31 +217,6 @@ test('cloudcmd: route: realpath: error', async (t) => {
done();
});
test('cloudcmd: route: sendIndex: error', async (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 {port, done} = await connect();
const data = await getStr(`http://localhost:${port}`);
t.equal(data, error.message, 'should return error');
done();
t.end();
});
test('cloudcmd: route: sendIndex: encode', async (t) => {
const name = '"><svg onload=alert(3);>';
const nameEncoded = '&quot;&gt;&lt;svg&nbsp;onload=alert(3);&gt;';