mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
chore: lint
This commit is contained in:
parent
f1279666b5
commit
4717e035ee
173 changed files with 1388 additions and 1627 deletions
|
|
@ -29,6 +29,7 @@ function before(options, fn = options) {
|
|||
|
||||
const app = express();
|
||||
const server = http.createServer(app);
|
||||
|
||||
const after = (cb) => {
|
||||
if (currentConfig)
|
||||
writejson.sync(pathConfig, currentConfig);
|
||||
|
|
@ -47,13 +48,18 @@ function before(options, fn = options) {
|
|||
}));
|
||||
|
||||
server.listen(() => {
|
||||
fn(server.address().port, promisify(after));
|
||||
fn(server
|
||||
.address()
|
||||
.port, promisify(after));
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.connect = promisify((options, fn = options) => {
|
||||
before(options, (port, done) => {
|
||||
fn(null, {port, done});
|
||||
fn(null, {
|
||||
port,
|
||||
done,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -63,4 +69,3 @@ function defaultConfig() {
|
|||
root: __dirname,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,4 +21,3 @@ test('cloudcmd: client: listeners: getIndex: found', (t) => {
|
|||
t.equal(getIndex(array, 'world'), 1, 'should return index');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,12 @@ test('cloudcmd: client: listeners: getRange: direct', (t) => {
|
|||
'hello',
|
||||
'world',
|
||||
];
|
||||
const files = [...expected, 'how', 'come'];
|
||||
|
||||
const files = [
|
||||
...expected,
|
||||
'how',
|
||||
'come',
|
||||
];
|
||||
const result = getRange(0, 1, files);
|
||||
|
||||
t.deepEqual(result, expected, 'should return range');
|
||||
|
|
@ -22,7 +27,12 @@ test('cloudcmd: client: listeners: getRange: reverse', (t) => {
|
|||
'hello',
|
||||
'world',
|
||||
];
|
||||
const files = [...expected, 'how', 'come'];
|
||||
|
||||
const files = [
|
||||
...expected,
|
||||
'how',
|
||||
'come',
|
||||
];
|
||||
const result = getRange(1, 0, files);
|
||||
|
||||
t.deepEqual(result, expected, 'should return range');
|
||||
|
|
@ -31,10 +41,13 @@ test('cloudcmd: client: listeners: getRange: reverse', (t) => {
|
|||
|
||||
test('cloudcmd: client: listeners: getRange: one', (t) => {
|
||||
const expected = ['hello'];
|
||||
const files = [...expected, 'how', 'come'];
|
||||
const files = [
|
||||
...expected,
|
||||
'how',
|
||||
'come',
|
||||
];
|
||||
const result = getRange(0, 0, files);
|
||||
|
||||
t.deepEqual(result, expected, 'should return range');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,8 @@ const tryCatch = require('try-catch');
|
|||
|
||||
const DIR = `${__dirname}/../../`;
|
||||
const COMMONDIR = `${DIR}common/`;
|
||||
const {
|
||||
time,
|
||||
timeEnd,
|
||||
} = require(`${COMMONDIR}util`);
|
||||
|
||||
const {time, timeEnd} = require(`${COMMONDIR}util`);
|
||||
|
||||
const CloudFuncPath = `${COMMONDIR}cloudfunc`;
|
||||
|
||||
|
|
@ -53,17 +51,17 @@ const data = {
|
|||
};
|
||||
|
||||
let Expect = '<div data-name="js-path" class="reduce-text" title="/etc/X11/">' +
|
||||
'<span data-name="js-copy-path" class="path-icon icon-copy-to-clipboard"' +
|
||||
' title="copy path (Ctrl+P)">' +
|
||||
'</span>' +
|
||||
'<a data-name="js-refresh" href="/fs/etc/X11/" ' +
|
||||
'class="path-icon icon-refresh" title="refresh (Ctrl+R)"></a>' +
|
||||
'<span data-name="js-links" class=links>' +
|
||||
'<a data-name="js-path-link" href="/fs/" title="/">/</a>' +
|
||||
'<a data-name="js-path-link" href="/fs/etc/" title="/etc/">' +
|
||||
'etc' +
|
||||
'</a>/X11/' +
|
||||
'</span>' +
|
||||
'<span data-name="js-copy-path" class="path-icon icon-copy-to-clipboard"' +
|
||||
' title="copy path (Ctrl+P)">' +
|
||||
'</span>' +
|
||||
'<a data-name="js-refresh" href="/fs/etc/X11/" ' +
|
||||
'class="path-icon icon-refresh" title="refresh (Ctrl+R)"></a>' +
|
||||
'<span data-name="js-links" class=links>' +
|
||||
'<a data-name="js-path-link" href="/fs/" title="/">/</a>' +
|
||||
'<a data-name="js-path-link" href="/fs/etc/" title="/etc/">' +
|
||||
'etc' +
|
||||
'</a>/X11/' +
|
||||
'</span>' +
|
||||
'</div>';
|
||||
|
||||
test('cloudfunc: render', (t) => {
|
||||
|
|
@ -83,22 +81,18 @@ test('cloudfunc: render', (t) => {
|
|||
.split('')
|
||||
.some((item, number) => {
|
||||
const ret = result[number] !== item;
|
||||
|
||||
|
||||
if (ret) {
|
||||
i = number;
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
});
|
||||
|
||||
timeEnd('CloudFunc.buildFromJSON');
|
||||
|
||||
if (isNotOk) {
|
||||
console.log(
|
||||
`Error in char number: ${i}\n`,
|
||||
`Expect: ${Expect.substr(i)}\n`,
|
||||
`Result: ${result.substr(i)}`,
|
||||
);
|
||||
console.log(`Error in char number: ${i}\n`, `Expect: ${Expect.substr(i)}\n`, `Result: ${result.substr(i)}`);
|
||||
|
||||
console.log('buildFromJSON: Not OK');
|
||||
}
|
||||
|
|
@ -208,4 +202,3 @@ test('cloudfunc: getDotDot: two levels deep', (t) => {
|
|||
t.equal(dotDot, '/home', 'should return up level');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -26,4 +26,3 @@ test('cloudcmd: entity: encode quote', (t) => {
|
|||
t.equal(result, expected, 'should encode entity');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -104,4 +104,3 @@ test('cloudcmd: rest: config: patch: save config', async (t) => {
|
|||
t.equal(configManager('editor'), 'dword', 'should change config file on patch');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -26,9 +26,7 @@ test('cloudcmd: rest: copy', async (t) => {
|
|||
const files = {
|
||||
from: '/fixture/',
|
||||
to: '/fixture/tmp',
|
||||
names: [
|
||||
'copy.txt',
|
||||
],
|
||||
names: ['copy.txt'],
|
||||
};
|
||||
|
||||
mkdirSync(tmp);
|
||||
|
|
@ -42,4 +40,3 @@ test('cloudcmd: rest: copy', async (t) => {
|
|||
t.equal(body, 'copy: ok("["copy.txt"]")', 'should return result');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -19,4 +19,3 @@ test('cloudcmd: rest: fs: path', async (t) => {
|
|||
t.equal(path, '/', 'should dir path be "/"');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -51,9 +51,7 @@ test('cloudcmd: rest: move', async (t) => {
|
|||
const files = {
|
||||
from: '/fixture/',
|
||||
to: '/fixture/tmp/',
|
||||
names: [
|
||||
'move.txt',
|
||||
],
|
||||
names: ['move.txt'],
|
||||
};
|
||||
|
||||
const {body} = await request.put(`/api/v1/move`, {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ const fixture = {
|
|||
tar: fs.readFileSync(pathTarFixture),
|
||||
zip: fs.readFileSync(pathZipFixture),
|
||||
};
|
||||
|
||||
const {request} = serveOnce(cloudcmd, defaultOptions);
|
||||
|
||||
const once = promisify((name, extract, fn) => {
|
||||
|
|
@ -57,7 +58,9 @@ test('cloudcmd: rest: pack: tar: get', async (t) => {
|
|||
|
||||
const extract = tar.extract();
|
||||
|
||||
body.pipe(gunzip()).pipe(extract);
|
||||
body
|
||||
.pipe(gunzip())
|
||||
.pipe(extract);
|
||||
|
||||
const [, stream] = await once('entry', extract);
|
||||
const data = await pullout(stream);
|
||||
|
|
@ -88,7 +91,9 @@ test('cloudcmd: rest: pack: tar: put: file', async (t) => {
|
|||
const file = fs.createReadStream(join(__dirname, '..', name));
|
||||
const extract = tar.extract();
|
||||
|
||||
file.pipe(gunzip()).pipe(extract);
|
||||
file
|
||||
.pipe(gunzip())
|
||||
.pipe(extract);
|
||||
|
||||
const [, stream] = await once('entry', extract);
|
||||
const data = await pullout(stream, 'buffer');
|
||||
|
|
@ -110,6 +115,7 @@ test('cloudcmd: rest: pack: tar: put: response', async (t) => {
|
|||
};
|
||||
|
||||
const name = `${Math.random()}.tar.gz`;
|
||||
|
||||
const {body} = await request.put(`/api/v1/pack`, {
|
||||
options,
|
||||
body: getPackOptions(name),
|
||||
|
|
@ -132,9 +138,7 @@ test('cloudcmd: rest: pack: tar: put: error', async (t) => {
|
|||
|
||||
const {body} = await request.put(`/api/v1/pack`, {
|
||||
options,
|
||||
body: getPackOptions('name', [
|
||||
'not found',
|
||||
]),
|
||||
body: getPackOptions('name', ['not found']),
|
||||
});
|
||||
|
||||
t.match(body, /^ENOENT: no such file or directory/, 'should return error');
|
||||
|
|
@ -169,6 +173,7 @@ test('cloudcmd: rest: pack: zip: put: file', async (t) => {
|
|||
};
|
||||
|
||||
const name = String(Math.random()) + '.zip';
|
||||
|
||||
await request.put(`/api/v1/pack`, {
|
||||
options,
|
||||
body: getPackOptions(name),
|
||||
|
|
@ -191,6 +196,7 @@ test('cloudcmd: rest: pack: zip: put: response', async (t) => {
|
|||
};
|
||||
|
||||
const name = String(Math.random()) + '.zip';
|
||||
|
||||
const {body} = await request.put(`/api/v1/pack`, {
|
||||
options,
|
||||
body: getPackOptions(name),
|
||||
|
|
@ -214,9 +220,7 @@ test('cloudcmd: rest: pack: zip: put: error', async (t) => {
|
|||
|
||||
const {body} = await request.put(`/api/v1/pack`, {
|
||||
options,
|
||||
body: getPackOptions('name', [
|
||||
'not found',
|
||||
]),
|
||||
body: getPackOptions('name', ['not found']),
|
||||
});
|
||||
|
||||
t.match(body, /^ENOENT: no such file or directory/, 'should return error');
|
||||
|
|
@ -230,4 +234,3 @@ function getPackOptions(to, names = ['pack']) {
|
|||
from: '/fixture',
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -111,4 +111,3 @@ test('cloudcmd: rest: rename: no to', async (t) => {
|
|||
t.equal(body, expected);
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ const columnsPath = '../../server/columns';
|
|||
|
||||
test('columns: prod', (t) => {
|
||||
const {NODE_ENV} = process.env;
|
||||
|
||||
process.env.NODE_ENV = '';
|
||||
const columns = reRequire(columnsPath);
|
||||
|
||||
|
|
@ -18,6 +19,7 @@ test('columns: prod', (t) => {
|
|||
|
||||
test('columns: dev', (t) => {
|
||||
const {NODE_ENV} = process.env;
|
||||
|
||||
process.env.NODE_ENV = 'development';
|
||||
|
||||
const columns = reRequire(columnsPath);
|
||||
|
|
@ -28,4 +30,3 @@ test('columns: dev', (t) => {
|
|||
t.equal(columns['name-size-date'], css);
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@ test('cloudcmd: console: enabled', async (t) => {
|
|||
console: true,
|
||||
};
|
||||
|
||||
const {port, done} = await connect({config});
|
||||
const {port, done} = await connect({
|
||||
config,
|
||||
});
|
||||
const socket = io(`http://localhost:${port}/console`);
|
||||
|
||||
socket.emit('auth', configFn('username'), configFn('password'));
|
||||
|
|
@ -34,7 +36,9 @@ test('cloudcmd: console: disabled', async (t) => {
|
|||
console: false,
|
||||
};
|
||||
|
||||
const {port, done} = await connect({config});
|
||||
const {port, done} = await connect({
|
||||
config,
|
||||
});
|
||||
const socket = io(`http://localhost:${port}/console`);
|
||||
|
||||
const [error] = await once(socket, 'connect_error');
|
||||
|
|
@ -45,4 +49,3 @@ test('cloudcmd: console: disabled', async (t) => {
|
|||
t.equal(error.message, 'Invalid namespace', 'should emit error');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ test('env: bool: true', (t) => {
|
|||
|
||||
test('env: bool: undefined', (t) => {
|
||||
const {cloudcmd_terminal} = process.env;
|
||||
|
||||
process.env.cloudcmd_terminal = undefined;
|
||||
|
||||
t.notOk(env.bool('terminal'), 'should be undefined');
|
||||
|
|
@ -45,4 +46,3 @@ test('env: bool: undefined', (t) => {
|
|||
process.env.cloudcmd_terminal = cloudcmd_terminal;
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const {join} = require('path');
|
||||
const {
|
||||
test,
|
||||
stub,
|
||||
} = require('supertape');
|
||||
const {test, stub} = require('supertape');
|
||||
|
||||
const cloudcmdPath = join(__dirname, '..', '..');
|
||||
const modulesPath = join(cloudcmdPath, 'json', 'modules.json');
|
||||
|
|
@ -28,6 +25,7 @@ test('cloudcmd: modules', async (t) => {
|
|||
},
|
||||
},
|
||||
};
|
||||
|
||||
const options = {
|
||||
modules,
|
||||
};
|
||||
|
|
@ -74,9 +72,10 @@ test('cloudcmd: modules: no', (t) => {
|
|||
const url = '/json/modules.json';
|
||||
const send = stub();
|
||||
|
||||
fn({url}, {send});
|
||||
fn({url}, {
|
||||
send,
|
||||
});
|
||||
|
||||
t.calledWith(send, [localModules], 'should have been called with modules');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -38,4 +38,3 @@ test('cloudcmd: show-config: return', (t) => {
|
|||
t.equal(showConfig(config), result, 'should return table');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ const config = {
|
|||
const {request} = require('serve-once')(cloudcmd, {
|
||||
config,
|
||||
});
|
||||
|
||||
const configFn = cloudcmd.createConfigManager();
|
||||
|
||||
test('cloudcmd: static', async (t) => {
|
||||
|
|
@ -42,6 +43,7 @@ test('cloudcmd: prefix: wrong', async (t) => {
|
|||
};
|
||||
|
||||
const name = Math.random();
|
||||
|
||||
const {status} = await request.get(`/${name}`, {
|
||||
options,
|
||||
});
|
||||
|
|
@ -65,6 +67,7 @@ test('cloudcmd: /cloudcmd.js: auth: access denied', async (t) => {
|
|||
const config = {
|
||||
auth: true,
|
||||
};
|
||||
|
||||
const options = {
|
||||
config,
|
||||
};
|
||||
|
|
@ -84,11 +87,14 @@ test('cloudcmd: /cloudcmd.js: auth: no password', async (t) => {
|
|||
auth: true,
|
||||
username,
|
||||
};
|
||||
|
||||
const options = {
|
||||
config,
|
||||
};
|
||||
|
||||
const encoded = Buffer.from(`${username}:`).toString('base64');
|
||||
const encoded = Buffer
|
||||
.from(`${username}:`)
|
||||
.toString('base64');
|
||||
const authorization = `Basic ${encoded}`;
|
||||
|
||||
const {status} = await request.get(`/${name}`, {
|
||||
|
|
@ -107,11 +113,13 @@ test('cloudcmd: /cloudcmd.js: auth: access granted', async (t) => {
|
|||
const username = 'hello';
|
||||
const password = 'world';
|
||||
const algo = configFn('algo');
|
||||
|
||||
const config = {
|
||||
auth: true,
|
||||
username,
|
||||
password: criton(password, algo),
|
||||
};
|
||||
|
||||
const options = {
|
||||
config,
|
||||
};
|
||||
|
|
@ -140,4 +148,3 @@ test('cloudcmd: /logout', async (t) => {
|
|||
t.equal(status, 401, 'should return 401');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue