mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
test(cloudcmd) promisify
This commit is contained in:
parent
faef643956
commit
28caa05292
3 changed files with 38 additions and 37 deletions
|
|
@ -2,7 +2,6 @@ language: node_js
|
|||
node_js:
|
||||
- 14
|
||||
- 12
|
||||
- 10
|
||||
|
||||
cache:
|
||||
npm: false
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const {once} = require('events');
|
||||
|
||||
const test = require('supertape');
|
||||
const io = require('socket.io-client');
|
||||
|
||||
|
|
@ -23,22 +25,20 @@ test('distribute: export', async (t) => {
|
|||
const url = `http://localhost:${port}/distribute?port=${1111}`;
|
||||
const socket = io.connect(url);
|
||||
|
||||
socket.on('connect', () => {
|
||||
socket.emit('auth', 'a');
|
||||
});
|
||||
await once(socket, 'connect');
|
||||
socket.emit('auth', 'a');
|
||||
|
||||
socket.on('accept', () => {
|
||||
config('vim', false);
|
||||
config('auth', true);
|
||||
});
|
||||
await once(socket, 'accept');
|
||||
config('vim', false);
|
||||
config('auth', true);
|
||||
|
||||
socket.on('change', async () => {
|
||||
socket.close();
|
||||
await done();
|
||||
|
||||
t.pass('should emit change');
|
||||
t.end();
|
||||
});
|
||||
await once(socket, 'change');
|
||||
|
||||
socket.close();
|
||||
await done();
|
||||
|
||||
t.pass('should emit change');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('distribute: export: config', async (t) => {
|
||||
|
|
@ -56,16 +56,16 @@ test('distribute: export: config', async (t) => {
|
|||
const url = `http://localhost:${port}/distribute?port=${1111}`;
|
||||
const socket = io.connect(url);
|
||||
|
||||
socket.on('connect', () => {
|
||||
socket.once('connect', () => {
|
||||
socket.emit('auth', 'a');
|
||||
});
|
||||
|
||||
socket.on('config', async (data) => {
|
||||
socket.close();
|
||||
await done();
|
||||
|
||||
t.equal(typeof data, 'object', 'should emit object');
|
||||
t.end();
|
||||
});
|
||||
const data = await once(socket, 'config');
|
||||
|
||||
socket.close();
|
||||
await done();
|
||||
|
||||
t.equal(typeof data, 'object', 'should emit object');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const {once} = require('events');
|
||||
|
||||
const test = require('supertape');
|
||||
const io = require('socket.io-client');
|
||||
|
|
@ -18,13 +19,14 @@ test('cloudcmd: console: enabled', async (t) => {
|
|||
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();
|
||||
});
|
||||
|
||||
const [data] = await once(socket, 'data');
|
||||
|
||||
socket.close();
|
||||
await done();
|
||||
|
||||
t.equal(data, 'client #1 console connected\n', 'should emit data event');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: console: disabled', async (t) => {
|
||||
|
|
@ -35,12 +37,12 @@ test('cloudcmd: console: disabled', async (t) => {
|
|||
const {port, done} = await connect({config});
|
||||
const socket = io(`http://localhost:${port}/console`);
|
||||
|
||||
socket.on('error', (error) => {
|
||||
socket.close();
|
||||
done();
|
||||
|
||||
t.equal(error, 'Invalid namespace', 'should emit error');
|
||||
t.end();
|
||||
});
|
||||
const [error] = await once(socket, 'error');
|
||||
|
||||
socket.close();
|
||||
await done();
|
||||
|
||||
t.equal(error, 'Invalid namespace', 'should emit error');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue