mattermost-desktop/test/modules/environment.js

64 lines
1.8 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
2016-09-25 07:14:01 -07:00
const sourceRootDir = path.join(__dirname, '../..');
const electronBinaryPath = (() => {
2016-05-02 06:34:00 -07:00
if (process.platform === 'darwin') {
2016-09-25 07:14:01 -07:00
return path.join(sourceRootDir, 'node_modules/electron-prebuilt/dist/Electron.app/Contents/MacOS/Electron');
2016-05-02 06:34:00 -07:00
}
2016-09-25 07:14:01 -07:00
const exeExtension = (process.platform === 'win32') ? '.exe' : '';
return path.join(sourceRootDir, 'node_modules/electron-prebuilt/dist/electron' + exeExtension);
2016-05-02 06:34:00 -07:00
})();
2016-09-25 07:14:01 -07:00
const configFilePath = path.join(sourceRootDir, 'test/test_config.json');
const mattermostURL = 'http://example.com/team';
2016-05-02 06:34:00 -07:00
module.exports = {
2016-09-25 07:14:01 -07:00
sourceRootDir,
configFilePath,
mattermostURL,
getSpectronApp() {
2016-06-05 08:41:35 -07:00
const app = new Application({
2016-09-25 07:14:01 -07:00
path: electronBinaryPath,
args: [`${path.join(sourceRootDir, 'dist')}`, '--config-file=' + configFilePath]
2016-05-21 01:23:23 -07:00
});
2016-09-25 07:14:01 -07:00
chaiAsPromised.transferPromiseness = app.transferPromiseness;
2016-06-05 08:41:35 -07:00
return app;
2016-05-21 04:57:59 -07:00
},
2016-09-25 07:14:01 -07:00
addClientCommands(client) {
client.addCommand('loadSettingsPage', function async() {
2016-09-25 07:14:01 -07:00
return this.url('file://' + path.join(sourceRootDir, 'dist/browser/settings.html')).waitUntilWindowLoaded();
});
client.addCommand('isNodeEnabled', function async() {
2016-09-25 07:14:01 -07:00
return this.execute(() => {
try {
2016-09-25 07:14:01 -07:00
if (require('child_process')) {
return true;
}
return false;
} catch (e) {
return false;
}
2016-09-25 07:14:01 -07:00
}).then((requireResult) => {
return requireResult.value;
});
});
},
// execute the test only when `condition` is true
2016-09-25 07:14:01 -07:00
shouldTest(it, condition) {
return condition ? it : it.skip;
},
isOneOf(platforms) {
return (platforms.indexOf(process.platform) !== -1);
2016-05-02 06:34:00 -07:00
}
2016-09-25 07:14:01 -07:00
};