mattermost-desktop/test/modules/environment.js

77 lines
2.1 KiB
JavaScript
Raw Normal View History

2016-05-02 06:34:00 -07:00
'use strict';
process.env.TEST = 'test';
2016-05-02 06:34:00 -07:00
2016-06-05 08:41:35 -07:00
const chai = require('chai');
chai.should();
2016-12-27 05:10:53 -08:00
const fs = require('fs');
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') {
return path.join(sourceRootDir, 'node_modules/electron/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/dist/electron' + exeExtension);
2016-05-02 06:34:00 -07:00
})();
const userDataDir = path.join(sourceRootDir, 'test/testUserData/');
const configFilePath = path.join(userDataDir, 'config.json');
2016-12-27 05:10:53 -08:00
const boundsInfoPath = path.join(userDataDir, 'bounds-info.json');
2016-09-25 07:14:01 -07:00
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,
2016-12-27 05:10:53 -08:00
boundsInfoPath,
2016-09-25 07:14:01 -07:00
mattermostURL,
2016-12-27 05:10:53 -08:00
cleanTestConfig() {
[configFilePath, boundsInfoPath].forEach((file) => {
try {
fs.unlinkSync(file);
} catch (err) {
if (err.code !== 'ENOENT') {
console.error(err);
}
}
});
},
2016-09-25 07:14:01 -07:00
getSpectronApp() {
return new Application({
2016-09-25 07:14:01 -07:00
path: electronBinaryPath,
2017-03-06 06:37:35 -08:00
args: [`${path.join(sourceRootDir, 'src')}`, `--data-dir=${userDataDir}`, '--disable-dev-mode']
2016-05-21 01:23:23 -07:00
});
2016-05-21 04:57:59 -07:00
},
2016-09-25 07:14:01 -07:00
addClientCommands(client) {
client.addCommand('loadSettingsPage', function async() {
2017-03-06 04:31:17 -08:00
return this.url('file://' + path.join(sourceRootDir, 'src/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
};