mattermost-desktop/test/modules/environment.js

67 lines
2 KiB
JavaScript
Raw Normal View History

2016-05-02 06:34:00 -07:00
'use strict';
2016-06-05 08:41:35 -07:00
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
chai.should();
chai.use(chaiAsPromised);
2016-05-02 06:34:00 -07:00
const path = require('path');
2016-05-21 01:23:23 -07:00
const Application = require('spectron').Application;
2016-05-02 06:34:00 -07:00
const source_root_dir = path.join(__dirname, '../..');
const electron_binary_path = (function() {
if (process.platform === 'darwin') {
return path.join(source_root_dir, 'node_modules/electron-prebuilt/dist/Electron.app/Contents/MacOS/Electron');
}
else {
const exe_extension = (process.platform === 'win32') ? '.exe' : '';
return path.join(source_root_dir, 'node_modules/electron-prebuilt/dist/electron' + exe_extension);
}
})();
2016-05-16 07:01:26 -07:00
const config_file_path = path.join(source_root_dir, 'test/test_config.json');
2016-05-02 06:34:00 -07:00
const mattermost_url = 'http://example.com/team';
module.exports = {
sourceRootDir: source_root_dir,
configFilePath: config_file_path,
mattermostURL: mattermost_url,
2016-05-21 01:23:23 -07:00
getSpectronApp: function() {
2016-06-05 08:41:35 -07:00
const app = new Application({
2016-05-21 01:23:23 -07:00
path: electron_binary_path,
args: [`${path.join(source_root_dir, 'dist')}`, '--config-file=' + config_file_path]
});
2016-06-05 08:41:35 -07:00
chaiAsPromised.transferPromiseness = app.transferPromiseness
return app;
2016-05-21 04:57:59 -07:00
},
addClientCommands: function(client) {
client.addCommand('loadSettingsPage', function async() {
return this
.url('file://' + path.join(source_root_dir, 'dist/browser/settings.html'))
.waitUntilWindowLoaded();
});
client.addCommand('isNodeEnabled', function async() {
return this.execute(function() {
try {
return require('child_process') ? true : false;
}
catch (e) {
return false;
}
}).then((require_result) => {
return require_result.value;
});
});
},
// execute the test only when `condition` is true
shouldTest: function(it, condition) {
return condition ? it : it.skip;
},
isOneOf(platforms) {
return (platforms.indexOf(process.platform) !== -1);
2016-05-02 06:34:00 -07:00
}
}