Commit ef88e6b6 authored by Tom JORQUERA's avatar Tom JORQUERA
Browse files

Merge branch 'setup-config' into 'master'

Setup config

See merge request !4
parents 58db8361 f6325fae
......@@ -19,28 +19,25 @@ let mockFiles = Object.create(null);
// 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
// `moz/fs` APIs are used.
fs.__setup = function(newMockFiles){
fs.__setup = function (newMockFiles) {
mockFiles = newMockFiles;
}
};
fs.readFile = function(filePath, ...rest) {
if(Object.keys(mockFiles).includes(filePath)){
fs.readFile = function (filePath) {
if (Object.keys(mockFiles).includes(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)
.filter(f => path.dirname(f) == dirPath)
.filter(f => path.dirname(f) === dirPath)
.map(f => path.basename(f));
if(res.length != 0) {
if (res.length !== 0) {
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;
......@@ -5,9 +5,10 @@ const controller = require('./lib/controller.js')('./client');
controller.loadAll('controller', 'lib', 'robot')
.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 => {
console.error(err);
return;
});
......@@ -3,6 +3,9 @@
//
// 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 name = arguments[1];
......@@ -15,40 +18,40 @@ robotController = {
return easyrtc.getRoomOccupantsAsArray(room);
},
getRemoteStream: (participant) => {
getRemoteStream: participant => {
return easyrtc.getRemoteStream(participant);
},
getRemoteStreams: () => {
let participants = robotController.getParticipants();
let res = {};
for(let i = 0; i < participants.length; i++){
let participant = participants[i];
try{
let mediaStream = robotController.getRemoteStream(participant);
if(mediaStream !== null){
const participants = robotController.getParticipants();
const res = {};
for (let i = 0; i < participants.length; i++) {
const participant = participants[i];
try {
const mediaStream = robotController.getRemoteStream(participant);
if (mediaStream !== null) {
res[participant] = mediaStream;
}
} catch (e){
} catch (err) {
console.error('could not get remote stream for %s', participant);
console.error(e);
console.error(err);
}
}
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('RemoteMediaStream %j', robotController.getRemoteStream(data.easyrtcid));
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);
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);
});
// 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.
/* global robotLib:true */
/* exported robotLib */
robotLib = {
// populated at runtime
// Populated at runtime
};
......@@ -2,6 +2,9 @@
//
// It is the first file of the `robot` folder to be loaded in the client.
/* global robot:true */
/* exported robot */
robot = {
// TODO
};
......@@ -3,52 +3,47 @@
const fs = require('mz/fs');
module.exports = root => {
const controller = {
load: (module) => new Promise((resolve, reject) => {
// first we read the file with the same name than the folder
load: module => new Promise((resolve, reject) => {
// First we read the file with the same name than the folder
fs.readFile(root + '/' + module + '/' + module + '.js', 'utf8')
.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)
.then(files => {
// remove the file we already read
// Remove the file we already read
files.splice(files.indexOf(module + '.js'), 1);
Promise.all(files.map(
f => fs.readFile(root + '/' + module + '/' + f, 'utf8')
))
.then(contents => {
// concatenate all the files and resolve
// Concatenate all the files and resolve
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) => {
// load all the passed modules
// Load all the passed modules
Promise.all(
modules.map(f => controller.load(f)))
.then(values => {
// concatenate all the arrays into a single one
// Concatenate all the arrays into a single one
resolve(Array.prototype.concat.apply([], values));
}).catch(err => {
reject(err);
});
})
};
......
......@@ -3,13 +3,12 @@
jest.mock('mz/fs');
describe('loadModules', () => {
const MOCK_FILES = {
'/test/controller/controller.js': '1',
'/test/controller/test.js': '2',
'/test/lib/lib.js': '3',
'/test/robot/robot.js': '4',
'/test/notavalidmodule/test.js':'5'
'/test/notavalidmodule/test.js': '5'
};
beforeEach(() => {
......@@ -17,8 +16,7 @@ describe('loadModules', () => {
});
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');
controller.load('controller')
......@@ -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');
controller.load('controller')
......@@ -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');
controller.load('nonexistent')
.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');
controller.load('notavalidmodule')
.catch(() => done());
});
});
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');
controller.loadAll('controller', 'lib', 'robot')
......@@ -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');
controller.loadAll('controller', 'lib', 'robot')
......@@ -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');
controller.loadAll('controller', 'lib', 'robot', 'nonexistent')
.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');
controller.loadAll('controller', 'lib', 'robot', 'invalid')
.catch(() => done());
});
});
});
const webdriverio = require('webdriverio');
module.exports = (config) => ({
module.exports = config => ({
run: (controllerFilesList, server, room) => {
const client = webdriverio.remote(config.driver);
return client.init()
......
......@@ -4,17 +4,23 @@
"repository": "https://ci.linagora.com/labs/hublot/",
"version": "0.0.1",
"main": "app.js",
"scripts":{
"scripts": {
"start": "node app.js",
"test": "jest"
"test": "xo && jest",
"test:watch": "jest --watch"
},
"dependencies":{
"webdriverio": "4.7.1",
"mz": "2.6.0"
"dependencies": {
"mz": "2.6.0",
"webdriverio": "4.7.1"
},
"devDependencies":{
"jest": "20.0.0"
"devDependencies": {
"jest": "20.0.0",
"xo": "^0.18.2"
},
"author": "Linagora Folks",
"license": "AGPL-3.0"
"license": "AGPL-3.0",
"xo": {
"space": true,
"envs": ["jest"]
}
}
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