2016-05-02 06:34:00 -07:00
|
|
|
'use strict';
|
|
|
|
|
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') {
|
2016-11-07 07:00:45 -08:00
|
|
|
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' : '';
|
2016-11-07 07:00:45 -08:00
|
|
|
return path.join(sourceRootDir, 'node_modules/electron/dist/electron' + exeExtension);
|
2016-05-02 06:34:00 -07:00
|
|
|
})();
|
2016-12-26 05:55:27 -08: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,
|
2017-10-04 08:02:54 -07:00
|
|
|
userDataDir,
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-10-21 08:34:38 -07:00
|
|
|
createTestUserDataDir() {
|
|
|
|
if (!fs.existsSync(userDataDir)) {
|
|
|
|
fs.mkdirSync(userDataDir);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-09-25 07:14:01 -07:00
|
|
|
getSpectronApp() {
|
2017-03-28 08:14:42 -07:00
|
|
|
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-06-25 05:21:10 -07:00
|
|
|
|
2016-09-25 07:14:01 -07:00
|
|
|
addClientCommands(client) {
|
2016-06-25 05:21:10 -07:00
|
|
|
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();
|
2016-06-25 05:21:10 -07:00
|
|
|
});
|
|
|
|
client.addCommand('isNodeEnabled', function async() {
|
2016-09-25 07:14:01 -07:00
|
|
|
return this.execute(() => {
|
2016-06-25 05:21:10 -07:00
|
|
|
try {
|
2016-09-25 07:14:01 -07:00
|
|
|
if (require('child_process')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
} catch (e) {
|
2016-06-25 05:21:10 -07:00
|
|
|
return false;
|
|
|
|
}
|
2016-09-25 07:14:01 -07:00
|
|
|
}).then((requireResult) => {
|
|
|
|
return requireResult.value;
|
2016-06-25 05:21:10 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-06-25 01:05:51 -07:00
|
|
|
// execute the test only when `condition` is true
|
2016-09-25 07:14:01 -07:00
|
|
|
shouldTest(it, condition) {
|
2016-06-25 01:05:51 -07:00
|
|
|
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
|
|
|
};
|