Exemplo n.º 1
0
'use strict';

const tryToCatch = require('try-to-catch');
const test = require('supertape');
const putasset = require('..');

const empty = () => {};

const owner = 'coderaiser';
const repo = 'putasset';
const tag = 'v1.0.0';

test('arguments: token', async (t) => {
    const [e] = await tryToCatch(putasset, 123, {owner, repo, tag});
    
    t.equal(e.message, 'token must be a string!', 'should throw when token not string');
    t.end();
});

test('arguments: owner', async (t) => {
    const [e] = await tryToCatch(putasset, '', {repo}, empty);
    
    t.equal(e.message, 'owner must be a string!', 'should throw when token not string');
    t.end();
});

test('arguments: repo', async (t) => {
    const [e] = await tryToCatch(putasset, '', {owner}, empty);
    
    t.equal(e.message, 'repo must be a string!', 'should throw when repo not string');
    t.end();
Exemplo n.º 2
0
    },
});

test('cloudcmd: modules', async (t) => {
    const modules = {
        data: {
            FilePicker: {
                key: 'hello',
            },
        },
    };
    const options = {
        modules,
    };
    
    const expected = {
        ...localModules,
        ...modules,
    };
    
    const {body} = await request.get(`/json/modules.json`, {
        type: 'json',
        options,
    });
    
    t.deepEqual(body, expected, 'should equal');
    t.end();
});

test('cloudcmd: modules: wrong route', async (t) => {
    const modules = {
Exemplo n.º 3
0
const test = require('supertape');
const io = require('socket.io-client');

const configPath = path.join(__dirname, '../..', 'server', 'config');
const {connect} = require('../before');
const configFn = require(configPath);

test('cloudcmd: console: enabled', async (t) => {
    const config = {
        console: true,
    };
    
    const {port, done} = await connect({config});
    const socket = io(`http://localhost:${port}/console`);
    
    socket.emit('auth', configFn('username'), configFn('password'));
    socket.once('data', (data) => {
        done();
        socket.close();
        
        t.equal(data, 'client #1 console connected\n', 'should emit data event');
        t.end();
    });
});

test('cloudcmd: console: disabled', async (t) => {
    const config = {
        console: false,
    };
    
    const {port, done} = await connect({config});
Exemplo n.º 4
0
'use strict';

const test = require('supertape');
const env = require('../../server/env');

test('env: small', (t) => {
    process.env.cloudcmd_hello = 'world';
    t.equal(env('hello'), 'world', 'should parse string from env');
    
    delete process.env.cloudcmd_hello;
    t.end();
});

test('env: big', (t) => {
    process.env.CLOUDCMD_HELLO = 'world';
    t.equal(env('hello'), 'world', 'should parse string from env');
    
    delete process.env.CLOUDCMD_HELLO;
    t.end();
});

test('env: bool: false', (t) => {
    process.env.cloudcmd_terminal = 'false';
    t.equal(env.bool('terminal'), false, 'should return false');
    
    delete process.env.cloudcmd_terminal;
    t.end();
});

test('env: bool: true', (t) => {
    process.env.cloudcmd_terminal = 'true';
Exemplo n.º 5
0
'use strict';

const test = require('supertape');
const entity = require('../../common/entity');

test('cloudcmd: entity: encode', (t) => {
    const result = entity.encode('<hello> ');
    const expected = '&lt;hello&gt;&nbsp;';
    
    t.equal(result, expected, 'should encode entity');
    t.end();
});

test('cloudcmd: entity: decode', (t) => {
    const result = entity.decode('&lt;hello&gt;&nbsp;');
    const expected = '<hello> ';
    
    t.equal(result, expected, 'should decode entity');
    t.end();
});

test('cloudcmd: entity: encode', (t) => {
    const result = entity.encode('"hello"');
    const expected = '&quot;hello&quot;';
    
    t.equal(result, expected, 'should encode entity');
    t.end();
});

Exemplo n.º 6
0
const cloudcmd = require('..');
const configFn = require('../server/config');

const config = {
    auth: false,
};
const {request} = require('serve-once')(cloudcmd, {
    config,
});

test('cloudcmd: static', async (t) => {
    const name = 'package.json';
    const {body} = await request.get(`/${name}`, {
        type: 'json',
    });
    
    t.equal(body.name, 'cloudcmd', 'should download file');
    t.end();
});

test('cloudcmd: static: not found', async (t) => {
    const name = Math.random();
    const {status} = await request.get(`/${name}`);
    
    t.equal(status, 404, 'should return 404');
    t.end();
});

test('cloudcmd: prefix: wrong', async (t) => {
    const originalPrefix = configFn('prefix');
Exemplo n.º 7
0
const test = require('supertape');
const stub = require('@cloudcmd/stub');
const mockRequire = require('mock-require');
const {reRequire} = mockRequire;

const pathConfig = './config';
const pathRoot = './root';

test('cloudcmd: root: config', (t) => {
    const config = stub().returns(false);
    
    mockRequire(pathConfig, config);
    const root = reRequire(pathRoot);
    
    root('hello');
    
    mockRequire.stop(pathConfig);
    
    t.ok(config.calledWith('root'), 'should call config');
    t.end();
});

test('cloudcmd: root: mellow', (t) => {
    const config = stub().returns('');
    const pathToWin = stub();
    
    const mellow = {
        pathToWin,
    };
    
Exemplo n.º 8
0
'use strict';

const test = require('supertape');
const exit = require('./exit');
const stub = require('@cloudcmd/stub');

test('cloudcmd: exit: process.exit', (t) => {
    const {exit:exitOriginal} = process;
    process.exit = stub();
    
    exit();
    t.ok(process.exit.calledWith(1), 'should call process.exit');
    process.exit = exitOriginal;
    
    t.end();
});

test('cloudcmd: exit: console.error', (t) => {
    const {exit:exitOriginal} = process;
    const {error} = console;
    
    console.error = stub();
    process.exit = stub();
    
    exit('hello world');
    t.ok(console.error.calledWith('hello world'), 'should call console.error');
    
    process.exit = exitOriginal;
    console.error = error;
    
    t.end();
Exemplo n.º 9
0
'use strict';

const os = require('os');
const test = require('supertape');
const cliParse = require('../lib/cli-parse');

test('cli-parse: series', (t) => {
    const result = cliParse(['--series', 'one', 'two'], {
        one: 'ls',
        two: 'pwd',
    });
    
    const expected = {
        name: 'run',
        cmd: 'ls && pwd',
        quiet: false,
        calm: false,
    };
    
    t.deepEqual(result, expected, 'should build cmd object');
    
    t.end();
});

test('cli-parse: parallel', (t) => {
    const result = cliParse(['--parallel', 'one', 'two'], {
        one: 'ls',
        two: 'pwd',
    });
    
    const expected = {
Exemplo n.º 10
0
'use strict';

const test = require('supertape');
const cloudfunc = require('./cloudfunc');
const {_getSize} = cloudfunc;

test('cloudfunc: getSize: dir', (t) => {
    const type = 'directory';
    const size = 0;
    const result = _getSize({
        type,
        size,
    });
    
    const expected = '&lt;dir&gt;';
    
    t.equal(result, expected, 'should equal');
    t.end();
});

test('cloudfunc: getSize: link: dir', (t) => {
    const type = 'directory-link';
    const size = 0;
    const result = _getSize({
        type,
        size,
    });
    
    const expected = '&lt;link&gt;';
    
    t.equal(result, expected, 'should equal');
Exemplo n.º 11
0
'use strict';

const test = require('supertape');
const fs = require('fs');
const {reRequire} = require('mock-require');
const columnsPath = '../../server/columns';

test('columns', (t) => {
    const {NODE_ENV} = process.env;
    process.env.NODE_ENV = '';
    const columns = reRequire(columnsPath);
    
    process.env.NODE_ENV = NODE_ENV;
    
    t.equal(columns[''], '', 'should equal');
    t.end();
});

test('columns: dev', (t) => {
    const {NODE_ENV} = process.env;
    process.env.NODE_ENV = 'development';
    
    const columns = reRequire(columnsPath);
    const css = fs.readFileSync(`${__dirname}/../../css/columns/name-size-date.css`, 'utf8');
    
    process.env.NODE_ENV = NODE_ENV;
    
    t.equal(columns['name-size-date'], css, 'should equal');
    t.end();
});
Exemplo n.º 12
0
    filter,
    append,
    prepend,
    sort,
    insert,
    intersperse,
    decouple,
    mapsome,
} = mystery;

test('use a few filters', (t) => {
    const fn = mystery([
        filter((a) => a > 1),
        map((a) => ++a),
    ]);
    
    fn([1, 2, 3, 4], (array) => {
        t.deepEqual(array, [3, 4, 5], 'should result be filtered');
        t.end();
    });
});

test('reuse mystery mapper', (t) => {
    const fn = mystery([
        filter((a) => a > 1),
        map((a) => ++a),
    ]);
    
    fn([1, 2, 3, 4], (array) => {
        t.deepEqual(array, [3, 4, 5], 'should result be filtered');
    });
Exemplo n.º 13
0
const markdown = require('./markdown');

const _markdown = promisify(markdown);
const fixtureDir = path.join(__dirname, 'fixture', 'markdown');
const cloudcmd = require('..');
const config = {
    auth: false,
};
const {request} = require('serve-once')(cloudcmd, {
    config,
});

test('cloudcmd: markdown: error', async (t) => {
    const {body} = await request.get('/api/v1/markdown/not-found');
    
    t.ok(/ENOENT/.test(body), 'should not found');
    t.end();
});

test('cloudcmd: markdown: relative: error', async (t) => {
    const {body} = await request.get('/api/v1/markdown/not-found?relative');
    
    t.ok(/ENOENT/.test(body), 'should not found');
    t.end();
});

test('cloudcmd: markdown: relative', async (t) => {
    const {body} = await request.get('/api/v1/markdown/HELP.md?relative');
    
    t.notOk(/ENOENT/.test(body), 'should not return error');
    t.end();
Exemplo n.º 14
0
test('distribute: export', async (t) => {
    const defaultConfig = {
        export: true,
        exportToken: 'a',
        vim: true,
        log: false,
        prefix: '',
    };
    
    const {port, done} = await connect({
        config: defaultConfig,
    });
    
    const url = `http://localhost:${port}/distribute?port=${1111}`;
    const socket = io.connect(url);
    
    socket.on('connect', () => {
        socket.emit('auth', 'a');
    });
    
    socket.on('accept', () => {
        config('vim', false);
        config('auth', true);
    });
    
    socket.on('change', async () => {
        socket.close();
        await done();
        
        t.pass('should emit change');
        t.end();
    });
});
Exemplo n.º 15
0
'use strict';

const test = require('supertape');
const restafary = require('./restafary');

test('cloudcmd: client: rest: replaceHash', (t) => {
    const {_escape} = restafary;
    const url = '/hello/####world';
    const result = _escape(url);
    const expected = '/hello/%23%23%23%23world';
    
    t.equal(result, expected, 'should equal');
    t.end();
});

Exemplo n.º 16
0
'use strict';

const test = require('supertape');
const rest = require('../../server/rest');

const {
    _formatMsg,
    _getWin32RootMsg,
    _isRootWin32,
    _isRootAll,
} = rest;

test('rest: formatMsg', (t) => {
    const result = _formatMsg('hello', 'world');
    
    t.equal(result, 'hello: ok("world")', 'should be equal');
    t.end();
});

test('rest: formatMsg: json', (t) => {
    const result = _formatMsg('hello', {
        name: 'world',
    });
    
    t.equal(result, 'hello: ok("{"name":"world"}")', 'should parse json');
    t.end();
});

test('rest: getWin32RootMsg', (t) => {
    const {message} = _getWin32RootMsg();
    
Exemplo n.º 17
0
test('cloudfunc: render', (t) => {
    const template = readFilesSync(FS_DIR, TMPL, 'utf8');
    const expect = fs.readFileSync(EXPECT_PATH, 'utf8');
    
    time('CloudFunc.buildFromJSON');
    const result = CloudFunc.buildFromJSON({
        prefix  : '',
        data    : JSON_FILES,
        template,
    });
    
    Expect += expect;
    
    let i;
    const isNotOk = Expect
        .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('buildFromJSON: Not OK');
    }
    
    t.equal(Expect, result, 'should be equal rendered json data');
    
    htmlLooksLike(Expect, result);
    
    t.end();
});
Exemplo n.º 18
0
'use strict';

const test = require('supertape');

const dir = '../../../client/listeners';
const getIndex = require(`${dir}/get-index`);

test('cloudcmd: client: listeners: getIndex: not found', (t) => {
    const array = ['hello'];
    
    t.equal(getIndex(array, 'world'), 0, 'should return index');
    t.end();
});

test('cloudcmd: client: listeners: getIndex: found', (t) => {
    const array = ['hello', 'world'];
    
    t.equal(getIndex(array, 'world'), 1, 'should return index');
    t.end();
});

Exemplo n.º 19
0
'use strict';

const test = require('supertape');
const stub = require('@cloudcmd/stub');

const btoa = require('../../common/btoa');

test('btoa: browser', (t) => {
    const btoaOriginal = global.btoa;
    const str = 'hello';
    
    global.btoa = stub();
    
    btoa(str);
    
    t.ok(global.btoa.calledWith(str), 'should call global.btoa');
    t.end();
    
    global.btoa = btoaOriginal;
});

test('btoa: node', (t) => {
    const str = 'hello';
    const expected = 'aGVsbG8=';
    
    const result = btoa(str);
    
    t.equal(result, expected, 'should encode base64');
    t.end();
});