mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
test(static) before -> connect
This commit is contained in:
parent
46c6ca51cf
commit
3a740330ec
5 changed files with 136 additions and 155 deletions
|
|
@ -7,7 +7,7 @@ const express = require('express');
|
|||
const io = require('socket.io');
|
||||
const writejson = require('writejson');
|
||||
const readjson = require('readjson');
|
||||
const {promisify} = require('es6-promisify');
|
||||
const {promisify} = require('util');
|
||||
|
||||
process.env.NODE_ENV = 'development';
|
||||
|
||||
|
|
@ -28,11 +28,11 @@ function before(options, fn = options) {
|
|||
|
||||
const app = express();
|
||||
const server = http.createServer(app);
|
||||
const after = () => {
|
||||
const after = (cb) => {
|
||||
if (currentConfig)
|
||||
writejson.sync(pathConfig, currentConfig);
|
||||
|
||||
server.close();
|
||||
server.close(cb);
|
||||
};
|
||||
|
||||
const socket = io.listen(server);
|
||||
|
|
@ -45,7 +45,7 @@ function before(options, fn = options) {
|
|||
}));
|
||||
|
||||
server.listen(() => {
|
||||
fn(server.address().port, after);
|
||||
fn(server.address().port, promisify(after));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -228,10 +228,10 @@ test('cloudcmd: getIndexPath: development', (t) => {
|
|||
test('cloudcmd: sw', async (t) => {
|
||||
const {port, done} = await connect();
|
||||
const {statusCode}= await get(`http://localhost:${port}/sw.js`);
|
||||
done();
|
||||
|
||||
await done();
|
||||
|
||||
t.equal(statusCode, 200, 'should return sw');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ test('cloudcmd: modules', async (t) => {
|
|||
t.deepEqual(result, expected, 'should equal');
|
||||
t.end();
|
||||
|
||||
done();
|
||||
await done();
|
||||
});
|
||||
|
||||
test('cloudcmd: modules: wrong route', async (t) => {
|
||||
|
|
@ -69,7 +69,7 @@ test('cloudcmd: modules: wrong route', async (t) => {
|
|||
t.notDeepEqual(result, expected, 'should not be equal');
|
||||
t.end();
|
||||
|
||||
done();
|
||||
await done();
|
||||
});
|
||||
|
||||
test('cloudcmd: modules: no', (t) => {
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ test('cloudcmd: route: buttons: no console', async (t) => {
|
|||
t.ok(/icon-console none/.test(result), 'should hide console');
|
||||
t.end();
|
||||
|
||||
done();
|
||||
await done();
|
||||
});
|
||||
|
||||
test('cloudcmd: route: buttons: console', async (t) => {
|
||||
|
|
@ -56,7 +56,7 @@ test('cloudcmd: route: buttons: console', async (t) => {
|
|||
t.notOk(/icon-console none/.test(result), 'should not hide console');
|
||||
t.end();
|
||||
|
||||
done();
|
||||
await done();
|
||||
});
|
||||
|
||||
test('cloudcmd: route: buttons: no config', async (t) => {
|
||||
|
|
@ -70,7 +70,7 @@ test('cloudcmd: route: buttons: no config', async (t) => {
|
|||
t.ok(/icon-config none/.test(result), 'should hide config');
|
||||
t.end();
|
||||
|
||||
done();
|
||||
await done();
|
||||
});
|
||||
|
||||
test('cloudcmd: route: buttons: no contact', async (t) => {
|
||||
|
|
@ -84,7 +84,7 @@ test('cloudcmd: route: buttons: no contact', async (t) => {
|
|||
t.ok(/icon-contact none/.test(result), 'should hide contact');
|
||||
t.end();
|
||||
|
||||
done();
|
||||
await done();
|
||||
});
|
||||
|
||||
test('cloudcmd: route: buttons: one panel mode: move', async (t) => {
|
||||
|
|
@ -98,7 +98,7 @@ test('cloudcmd: route: buttons: one panel mode: move', async (t) => {
|
|||
t.ok(/icon-move none/.test(result), 'should hide move button');
|
||||
t.end();
|
||||
|
||||
done();
|
||||
await done();
|
||||
});
|
||||
|
||||
test('cloudcmd: route: buttons: one panel mode: move', async (t) => {
|
||||
|
|
@ -112,7 +112,7 @@ test('cloudcmd: route: buttons: one panel mode: move', async (t) => {
|
|||
t.ok(/icon-copy none/.test(result), 'should hide copy button');
|
||||
t.end();
|
||||
|
||||
done();
|
||||
await done();
|
||||
});
|
||||
|
||||
test('cloudcmd: route: keys panel: hide', async (t) => {
|
||||
|
|
@ -126,7 +126,7 @@ test('cloudcmd: route: keys panel: hide', async (t) => {
|
|||
t.ok(/keyspanel hidden/.test(result), 'should hide keyspanel');
|
||||
t.end();
|
||||
|
||||
done();
|
||||
await done();
|
||||
});
|
||||
|
||||
test('cloudcmd: route: keys panel', async (t) => {
|
||||
|
|
@ -140,7 +140,7 @@ test('cloudcmd: route: keys panel', async (t) => {
|
|||
t.notOk(/keyspanel hidden/.test(result), 'should show keyspanel');
|
||||
t.end();
|
||||
|
||||
done();
|
||||
await done();
|
||||
});
|
||||
|
||||
test('cloudcmd: route: file: fs', async (t) => {
|
||||
|
|
@ -155,7 +155,7 @@ test('cloudcmd: route: file: fs', async (t) => {
|
|||
t.equal(empty, '', 'should equal');
|
||||
t.end();
|
||||
|
||||
done();
|
||||
await done();
|
||||
});
|
||||
|
||||
test('cloudcmd: route: symlink', async (t) => {
|
||||
|
|
@ -176,7 +176,7 @@ test('cloudcmd: route: symlink', async (t) => {
|
|||
fs.unlinkSync(symlink);
|
||||
t.end();
|
||||
|
||||
done();
|
||||
await done();
|
||||
});
|
||||
|
||||
test('cloudcmd: route: not found', async (t) => {
|
||||
|
|
@ -191,7 +191,7 @@ test('cloudcmd: route: not found', async (t) => {
|
|||
t.ok(~data.indexOf('ENOENT: no such file or directory'), 'should return error');
|
||||
t.end();
|
||||
|
||||
done();
|
||||
await done();
|
||||
});
|
||||
|
||||
test('cloudcmd: route: realpath: error', async (t) => {
|
||||
|
|
@ -214,7 +214,7 @@ test('cloudcmd: route: realpath: error', async (t) => {
|
|||
t.ok(/^ENOENT/.test(data), 'should return error');
|
||||
t.end();
|
||||
|
||||
done();
|
||||
await done();
|
||||
});
|
||||
|
||||
test('cloudcmd: route: sendIndex: encode', async (t) => {
|
||||
|
|
@ -248,7 +248,7 @@ test('cloudcmd: route: sendIndex: encode', async (t) => {
|
|||
clear('../../server/cloudcmd');
|
||||
clear(beforePath);
|
||||
|
||||
done();
|
||||
await done();
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
@ -282,7 +282,7 @@ test('cloudcmd: route: sendIndex: encode: not encoded', async (t) => {
|
|||
clear('../../server/cloudcmd');
|
||||
clear(beforePath);
|
||||
|
||||
done();
|
||||
await done();
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
@ -317,7 +317,7 @@ test('cloudcmd: route: sendIndex: ddos: render', async (t) => {
|
|||
clear(cloudcmdPath);
|
||||
clear(beforePath);
|
||||
|
||||
done();
|
||||
await done();
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
@ -331,7 +331,7 @@ test('cloudcmd: route: buttons: no terminal', async (t) => {
|
|||
|
||||
t.ok(/icon-terminal none/.test(result), 'should hide terminal');
|
||||
|
||||
done();
|
||||
await done();
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
@ -346,7 +346,7 @@ test('cloudcmd: route: buttons: terminal', async (t) => {
|
|||
|
||||
t.notOk(/icon-terminal none/.test(result), 'should enable terminal');
|
||||
|
||||
done();
|
||||
await done();
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
241
test/static.js
241
test/static.js
|
|
@ -6,7 +6,7 @@ const pullout = require('pullout');
|
|||
const request = require('request');
|
||||
|
||||
const configFn = require('../server/config');
|
||||
const before = require('./before');
|
||||
const {connect} = require('./before');
|
||||
|
||||
const warp = (fn, ...a) => (...b) => fn(...b, ...a);
|
||||
|
||||
|
|
@ -21,105 +21,99 @@ const get = promisify((url, options, fn) => {
|
|||
fn(null, request(url, options));
|
||||
});
|
||||
|
||||
test('cloudcmd: static', (t) => {
|
||||
before({}, (port, after) => {
|
||||
const name = 'package.json';
|
||||
|
||||
get(`http://localhost:${port}/${name}`)
|
||||
.then(warp(_pullout, 'string'))
|
||||
.then(JSON.parse)
|
||||
.then((json) => {
|
||||
t.equal(json.name, 'cloudcmd', 'should download file');
|
||||
t.end();
|
||||
after();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: static: not found', (t) => {
|
||||
before({}, (port, after) => {
|
||||
const name = Math.random();
|
||||
get(`http://localhost:${port}/${name}`)
|
||||
.then((res) => {
|
||||
res.on('response', (res) => {
|
||||
t.equal(res.statusCode, 404, 'should return 404');
|
||||
});
|
||||
res.on('end', () => {
|
||||
t.end();
|
||||
after();
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: prefix: wrong', (t) => {
|
||||
const prefix = '/hello';
|
||||
const config = {prefix};
|
||||
test('cloudcmd: static', async (t) => {
|
||||
const {port, done} = await connect();
|
||||
const name = 'package.json';
|
||||
|
||||
before({config}, (port, after) => {
|
||||
const name = Math.random();
|
||||
|
||||
get(`http://localhost:${port}/${name}`)
|
||||
.then((res) => {
|
||||
res.on('response', ({statusCode}) => {
|
||||
t.equal(statusCode, 404, 'should return 404');
|
||||
});
|
||||
res.on('end', () => {
|
||||
t.end();
|
||||
after();
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
get(`http://localhost:${port}/${name}`)
|
||||
.then(warp(_pullout, 'string'))
|
||||
.then(JSON.parse)
|
||||
.then((json) => {
|
||||
t.equal(json.name, 'cloudcmd', 'should download file');
|
||||
t.end();
|
||||
})
|
||||
.catch(console.error)
|
||||
.then(done);
|
||||
});
|
||||
|
||||
test('cloudcmd: static: not found', async (t) => {
|
||||
const name = Math.random();
|
||||
|
||||
const {port, done} = await connect({});
|
||||
const res = await get(`http://localhost:${port}/${name}`);
|
||||
|
||||
res.on('response', (res) => {
|
||||
t.equal(res.statusCode, 404, 'should return 404');
|
||||
});
|
||||
|
||||
res.on('error', console.error);
|
||||
res.on('end', async () => {
|
||||
await done();
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: /cloudcmd.js', (t) => {
|
||||
before({}, (port, after) => {
|
||||
const name = 'cloudcmd.js';
|
||||
test('cloudcmd: prefix: wrong', async (t) => {
|
||||
const originalPrefix = configFn('prefix');
|
||||
|
||||
const {port, done} = await connect({
|
||||
config: {
|
||||
prefix: '/hello'
|
||||
}
|
||||
});
|
||||
|
||||
const name = Math.random();
|
||||
const res = await get(`http://localhost:${port}/${name}`);
|
||||
|
||||
res.on('response', async ({statusCode}) => {
|
||||
await done();
|
||||
configFn('prefix', originalPrefix);
|
||||
|
||||
get(`http://localhost:${port}/${name}`)
|
||||
.then((res) => {
|
||||
res.on('response', ({statusCode}) => {
|
||||
t.equal(statusCode, 200, 'should return OK');
|
||||
});
|
||||
res.on('end', () => {
|
||||
t.end();
|
||||
after();
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
console.log(require('../server/config')('prefix'));
|
||||
|
||||
t.equal(statusCode, 404, 'should return 404');
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: /cloudcmd.js: auth: access denied', (t) => {
|
||||
test('cloudcmd: /cloudcmd.js', async (t) => {
|
||||
const name = 'cloudcmd.js';
|
||||
|
||||
const {port, done} = await connect();
|
||||
const res = await get(`http://localhost:${port}/${name}`);
|
||||
|
||||
res.on('response', ({statusCode}) => {
|
||||
t.equal(statusCode, 200, 'should return OK');
|
||||
});
|
||||
|
||||
res.on('end', async () => {
|
||||
await done();
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: /cloudcmd.js: auth: access denied', async (t) => {
|
||||
const name = 'cloudcmd.js';
|
||||
const config = {
|
||||
auth: true
|
||||
};
|
||||
|
||||
before({config}, (port, after) => {
|
||||
const name = 'cloudcmd.js';
|
||||
|
||||
get(`http://localhost:${port}/${name}`)
|
||||
.then((res) => {
|
||||
res.on('response', ({statusCode}) => {
|
||||
t.equal(statusCode, 401, 'should return auth');
|
||||
});
|
||||
res.on('end', () => {
|
||||
t.end();
|
||||
after();
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
const {port, done} = await connect({config});
|
||||
const res = await get(`http://localhost:${port}/${name}`);
|
||||
|
||||
res.on('response', ({statusCode}) => {
|
||||
t.equal(statusCode, 401, 'should return auth');
|
||||
});
|
||||
|
||||
res.on('end', async () => {
|
||||
await done();
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: /cloudcmd.js: auth: no password', (t) => {
|
||||
test('cloudcmd: /cloudcmd.js: auth: no password', async (t) => {
|
||||
const name = 'cloudcmd.js';
|
||||
|
||||
const config = {
|
||||
auth: true
|
||||
};
|
||||
|
|
@ -128,65 +122,52 @@ test('cloudcmd: /cloudcmd.js: auth: no password', (t) => {
|
|||
username: configFn('username'),
|
||||
};
|
||||
|
||||
before({config}, (port, after) => {
|
||||
const name = 'cloudcmd.js';
|
||||
|
||||
get(`http://localhost:${port}/${name}`, {auth})
|
||||
.then((res) => {
|
||||
res.on('response', ({statusCode}) => {
|
||||
t.equal(statusCode, 401, 'should return auth');
|
||||
});
|
||||
res.on('end', () => {
|
||||
t.end();
|
||||
after();
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
const {port, done} = await connect({config});
|
||||
const res = await get(`http://localhost:${port}/${name}`, {auth});
|
||||
|
||||
res.on('response', ({statusCode}) => {
|
||||
t.equal(statusCode, 401, 'should return auth');
|
||||
});
|
||||
res.on('end', async () => {
|
||||
await done();
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: /cloudcmd.js: auth: access granted', (t) => {
|
||||
test('cloudcmd: /cloudcmd.js: auth: access granted', async (t) => {
|
||||
const name = 'cloudcmd.js';
|
||||
const config = {
|
||||
auth: true
|
||||
};
|
||||
|
||||
const auth = {
|
||||
username: configFn('username'),
|
||||
password: configFn('password'),
|
||||
};
|
||||
|
||||
before({config}, (port, after) => {
|
||||
const name = 'cloudcmd.js';
|
||||
|
||||
get(`http://localhost:${port}/${name}`, {auth})
|
||||
.then((res) => {
|
||||
res.on('response', ({statusCode}) => {
|
||||
t.equal(statusCode, 401, 'should return auth');
|
||||
});
|
||||
res.on('end', () => {
|
||||
t.end();
|
||||
after();
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
const {port, done} = await connect({config});
|
||||
const res = await get(`http://localhost:${port}/${name}`, {auth});
|
||||
|
||||
res.on('response', ({statusCode}) => {
|
||||
t.equal(statusCode, 401, 'should return auth');
|
||||
});
|
||||
|
||||
res.on('end', async () => {
|
||||
await done();
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: /logout', (t) => {
|
||||
before({}, (port, after) => {
|
||||
const name = 'logout';
|
||||
|
||||
get(`http://localhost:${port}/${name}`)
|
||||
.then((res) => {
|
||||
res.on('response', ({statusCode}) => {
|
||||
t.equal(statusCode, 401, 'should return 401');
|
||||
});
|
||||
res.on('end', () => {
|
||||
t.end();
|
||||
after();
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
test('cloudcmd: /logout', async (t) => {
|
||||
const name = 'logout';
|
||||
const {port, done} = await connect();
|
||||
const res = await get(`http://localhost:${port}/${name}`);
|
||||
|
||||
res.on('response', ({statusCode}) => {
|
||||
t.equal(statusCode, 401, 'should return 401');
|
||||
});
|
||||
res.on('end', async () => {
|
||||
await done();
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue