Skip to content

Commit

Permalink
test(cloudcmd) promisify
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Apr 25, 2020
1 parent faef643 commit 28caa05
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 37 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: node_js
node_js:
- 14
- 12
- 10

cache:
npm: false
Expand Down
44 changes: 22 additions & 22 deletions server/distribute/export.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const {once} = require('events');

const test = require('supertape');
const io = require('socket.io-client');

Expand All @@ -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) => {
Expand All @@ -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();
});

30 changes: 16 additions & 14 deletions test/server/console.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const path = require('path');
const {once} = require('events');

const test = require('supertape');
const io = require('socket.io-client');
Expand All @@ -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) => {
Expand All @@ -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();
});

0 comments on commit 28caa05

Please sign in to comment.