Commit f6325fae authored by Tom Jorquera's avatar Tom Jorquera
Browse files

Fix styling issues

Fix styling issues identified by xo
parent da9b08a5
...@@ -19,28 +19,25 @@ let mockFiles = Object.create(null); ...@@ -19,28 +19,25 @@ let mockFiles = Object.create(null);
// This is a custom function that our tests can use during setup to specify // This is a custom function that our tests can use during setup to specify
// what the files on the "mock" filesystem should look like when any of the // what the files on the "mock" filesystem should look like when any of the
// `moz/fs` APIs are used. // `moz/fs` APIs are used.
fs.__setup = function(newMockFiles){ fs.__setup = function (newMockFiles) {
mockFiles = newMockFiles; mockFiles = newMockFiles;
} };
fs.readFile = function(filePath, ...rest) { fs.readFile = function (filePath) {
if(Object.keys(mockFiles).includes(filePath)){ if (Object.keys(mockFiles).includes(filePath)) {
return Promise.resolve(mockFiles[filePath]); return Promise.resolve(mockFiles[filePath]);
} else {
return Promise.reject(new Error('no such file or directory'));
} }
return Promise.reject(new Error('no such file or directory'));
}; };
fs.readdir = function(dirPath, ...rest) { fs.readdir = function (dirPath) {
const res = Object.keys(mockFiles) const res = Object.keys(mockFiles)
.filter(f => path.dirname(f) == dirPath) .filter(f => path.dirname(f) === dirPath)
.map(f => path.basename(f)); .map(f => path.basename(f));
if(res.length != 0) { if (res.length !== 0) {
return Promise.resolve(res); return Promise.resolve(res);
} else {
return Promise.reject(new Error('no such file or directory')) ;
} }
return Promise.reject(new Error('no such file or directory'));
}; };
module.exports = fs; module.exports = fs;
...@@ -5,9 +5,10 @@ const controller = require('./lib/controller.js')('./client'); ...@@ -5,9 +5,10 @@ const controller = require('./lib/controller.js')('./client');
controller.loadAll('controller', 'lib', 'robot') controller.loadAll('controller', 'lib', 'robot')
.then(modules => { .then(modules => {
let client = runner.run(modules, config.visio.url, 'test-bot'); // Note: result can be stored in a variable to control further the browser
// e.g.: let client = runner.run(...); client.end();
runner.run(modules, config.visio.url, 'test-bot');
}) })
.catch(err => { .catch(err => {
console.error(err); console.error(err);
return;
}); });
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
// //
// It is the first file of the `controller` folder to be loaded in the client. // It is the first file of the `controller` folder to be loaded in the client.
/* global robotController:true document angular easyrtc */
/* exported robotController */
const room = arguments[0]; const room = arguments[0];
const name = arguments[1]; const name = arguments[1];
...@@ -15,40 +18,40 @@ robotController = { ...@@ -15,40 +18,40 @@ robotController = {
return easyrtc.getRoomOccupantsAsArray(room); return easyrtc.getRoomOccupantsAsArray(room);
}, },
getRemoteStream: (participant) => { getRemoteStream: participant => {
return easyrtc.getRemoteStream(participant); return easyrtc.getRemoteStream(participant);
}, },
getRemoteStreams: () => { getRemoteStreams: () => {
let participants = robotController.getParticipants(); const participants = robotController.getParticipants();
let res = {}; const res = {};
for(let i = 0; i < participants.length; i++){ for (let i = 0; i < participants.length; i++) {
let participant = participants[i]; const participant = participants[i];
try{ try {
let mediaStream = robotController.getRemoteStream(participant); const mediaStream = robotController.getRemoteStream(participant);
if(mediaStream !== null){ if (mediaStream !== null) {
res[participant] = mediaStream; res[participant] = mediaStream;
} }
} catch (e){ } catch (err) {
console.error('could not get remote stream for %s', participant); console.error('could not get remote stream for %s', participant);
console.error(e); console.error(err);
} }
} }
return res; return res;
} }
}; };
robotController.$scope.$on('conferencestate:attendees:push', function(event, data) { robotController.$scope.$on('conferencestate:attendees:push', (event, data) => {
console.log('### someone connected %j %j', event, data); console.log('### someone connected %j %j', event, data);
console.log('RemoteMediaStream %j', robotController.getRemoteStream(data.easyrtcid)); console.log('RemoteMediaStream %j', robotController.getRemoteStream(data.easyrtcid));
robotController.chatService.sendMessage({author: name, displayName: name, message: 'Hello!'}); robotController.chatService.sendMessage({author: name, displayName: name, message: 'Hello!'});
}); });
robotController.$scope.$on('conferencestate:attendees:remove', function(event, data) { robotController.$scope.$on('conferencestate:attendees:remove', (event, data) => {
console.log('### someone leaved %j %j', event, data); console.log('### someone leaved %j %j', event, data);
robotController.chatService.sendMessage({author: name, displayName: name, message: 'Goodbye!'}); robotController.chatService.sendMessage({author: name, displayName: name, message: 'Goodbye!'});
}); });
robotController.$scope.$on('attendee:update', function(event, data){ robotController.$scope.$on('attendee:update', (event, data) => {
console.log('### received update %j %j', event, data); console.log('### received update %j %j', event, data);
}); });
// Populated by the different libraries loaded into the client.
// populated by the different libraries loaded into the client.
// //
// It is the first file of the `lib` folder to be loaded in the client. // It is the first file of the `lib` folder to be loaded in the client.
/* global robotLib:true */
/* exported robotLib */
robotLib = { robotLib = {
// populated at runtime // Populated at runtime
}; };
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
// //
// It is the first file of the `robot` folder to be loaded in the client. // It is the first file of the `robot` folder to be loaded in the client.
/* global robot:true */
/* exported robot */
robot = { robot = {
// TODO // TODO
}; };
...@@ -3,52 +3,47 @@ ...@@ -3,52 +3,47 @@
const fs = require('mz/fs'); const fs = require('mz/fs');
module.exports = root => { module.exports = root => {
const controller = { const controller = {
load: (module) => new Promise((resolve, reject) => { load: module => new Promise((resolve, reject) => {
// First we read the file with the same name than the folder
// first we read the file with the same name than the folder
fs.readFile(root + '/' + module + '/' + module + '.js', 'utf8') fs.readFile(root + '/' + module + '/' + module + '.js', 'utf8')
.then(content => { .then(content => {
// Then we read all the other files in the folder
// then we read all the other files in the folder
fs.readdir(root + '/' + module) fs.readdir(root + '/' + module)
.then(files => { .then(files => {
// Remove the file we already read
// remove the file we already read
files.splice(files.indexOf(module + '.js'), 1); files.splice(files.indexOf(module + '.js'), 1);
Promise.all(files.map( Promise.all(files.map(
f => fs.readFile(root + '/' + module + '/' + f, 'utf8') f => fs.readFile(root + '/' + module + '/' + f, 'utf8')
)) ))
.then(contents => { .then(contents => {
// concatenate all the files and resolve // Concatenate all the files and resolve
resolve([content].concat(contents)); resolve([content].concat(contents));
}) })
.catch(err => { reject(err); }); .catch(err => {
reject(err);
});
}) })
.catch(err => { reject(err); }); .catch(err => {
reject(err);
});
}) })
.catch(err => { reject(err); }); .catch(err => {
reject(err);
});
}), }),
loadAll: (...modules) => new Promise((resolve, reject) => { loadAll: (...modules) => new Promise((resolve, reject) => {
// Load all the passed modules
// load all the passed modules
Promise.all( Promise.all(
modules.map(f => controller.load(f))) modules.map(f => controller.load(f)))
.then(values => { .then(values => {
// Concatenate all the arrays into a single one
// concatenate all the arrays into a single one
resolve(Array.prototype.concat.apply([], values)); resolve(Array.prototype.concat.apply([], values));
}).catch(err => { }).catch(err => {
reject(err); reject(err);
}); });
}) })
}; };
......
...@@ -3,13 +3,12 @@ ...@@ -3,13 +3,12 @@
jest.mock('mz/fs'); jest.mock('mz/fs');
describe('loadModules', () => { describe('loadModules', () => {
const MOCK_FILES = { const MOCK_FILES = {
'/test/controller/controller.js': '1', '/test/controller/controller.js': '1',
'/test/controller/test.js': '2', '/test/controller/test.js': '2',
'/test/lib/lib.js': '3', '/test/lib/lib.js': '3',
'/test/robot/robot.js': '4', '/test/robot/robot.js': '4',
'/test/notavalidmodule/test.js':'5' '/test/notavalidmodule/test.js': '5'
}; };
beforeEach(() => { beforeEach(() => {
...@@ -17,8 +16,7 @@ describe('loadModules', () => { ...@@ -17,8 +16,7 @@ describe('loadModules', () => {
}); });
describe('loading a module', () => { describe('loading a module', () => {
test('should include all (and only) files in its dir.', done => {
test('should include all (and only) files in its dir.', (done) => {
const controller = require('./controller.js')('/test'); const controller = require('./controller.js')('/test');
controller.load('controller') controller.load('controller')
...@@ -30,7 +28,7 @@ describe('loadModules', () => { ...@@ -30,7 +28,7 @@ describe('loadModules', () => {
}); });
}); });
test('should return the files in the correct order', (done) => { test('should return the files in the correct order', done => {
const controller = require('./controller.js')('/test'); const controller = require('./controller.js')('/test');
controller.load('controller') controller.load('controller')
...@@ -41,25 +39,23 @@ describe('loadModules', () => { ...@@ -41,25 +39,23 @@ describe('loadModules', () => {
}); });
}); });
test('should fail for a nonexistent module', (done) => { test('should fail for a nonexistent module', done => {
const controller = require('./controller.js')('/test'); const controller = require('./controller.js')('/test');
controller.load('nonexistent') controller.load('nonexistent')
.catch(() => done()); .catch(() => done());
}); });
test('should fail for a module missing its base file', (done) => { test('should fail for a module missing its base file', done => {
const controller = require('./controller.js')('/test'); const controller = require('./controller.js')('/test');
controller.load('notavalidmodule') controller.load('notavalidmodule')
.catch(() => done()); .catch(() => done());
}); });
}); });
describe('loading several modules', () => { describe('loading several modules', () => {
test('should include all files from all modules', done => {
test('should include all files from all modules', (done) => {
const controller = require('./controller.js')('/test'); const controller = require('./controller.js')('/test');
controller.loadAll('controller', 'lib', 'robot') controller.loadAll('controller', 'lib', 'robot')
...@@ -73,7 +69,7 @@ describe('loadModules', () => { ...@@ -73,7 +69,7 @@ describe('loadModules', () => {
}); });
}); });
test('should return files in correct order', (done) => { test('should return files in correct order', done => {
const controller = require('./controller.js')('/test'); const controller = require('./controller.js')('/test');
controller.loadAll('controller', 'lib', 'robot') controller.loadAll('controller', 'lib', 'robot')
...@@ -86,18 +82,16 @@ describe('loadModules', () => { ...@@ -86,18 +82,16 @@ describe('loadModules', () => {
}); });
}); });
test('should fail when trying to load a non-existent module ', (done) => { test('should fail when trying to load a non-existent module ', done => {
const controller = require('./controller.js')('/test'); const controller = require('./controller.js')('/test');
controller.loadAll('controller', 'lib', 'robot', 'nonexistent') controller.loadAll('controller', 'lib', 'robot', 'nonexistent')
.catch(() => done()); .catch(() => done());
}); });
test('should fail when trying to load an invalid module', (done) => { test('should fail when trying to load an invalid module', done => {
const controller = require('./controller.js')('/test'); const controller = require('./controller.js')('/test');
controller.loadAll('controller', 'lib', 'robot', 'invalid') controller.loadAll('controller', 'lib', 'robot', 'invalid')
.catch(() => done()); .catch(() => done());
}); });
}); });
}); });
const webdriverio = require('webdriverio'); const webdriverio = require('webdriverio');
module.exports = (config) => ({ module.exports = config => ({
run: (controllerFilesList, server, room) => { run: (controllerFilesList, server, room) => {
const client = webdriverio.remote(config.driver); const client = webdriverio.remote(config.driver);
return client.init() return client.init()
......
...@@ -4,14 +4,14 @@ ...@@ -4,14 +4,14 @@
"repository": "https://ci.linagora.com/labs/hublot/", "repository": "https://ci.linagora.com/labs/hublot/",
"version": "0.0.1", "version": "0.0.1",
"main": "app.js", "main": "app.js",
"scripts":{ "scripts": {
"start": "node app.js", "start": "node app.js",
"test": "xo && jest", "test": "xo && jest",
"test:watch": "jest --watch" "test:watch": "jest --watch"
}, },
"dependencies":{ "dependencies": {
"webdriverio": "4.7.1", "mz": "2.6.0",
"mz": "2.6.0" "webdriverio": "4.7.1"
}, },
"devDependencies": { "devDependencies": {
"jest": "20.0.0", "jest": "20.0.0",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment