mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-20 11:48:30 -06:00
Electron-308 - Optimized code and added error logs
This commit is contained in:
parent
20c3368272
commit
b58d116903
@ -1,6 +1,7 @@
|
||||
const Application = require('./spectronSetup');
|
||||
const {isMac} = require('../../js/utils/misc.js');
|
||||
const childProcess = require('child_process');
|
||||
const constants = require('./spectronConstants');
|
||||
|
||||
let app = new Application({});
|
||||
let robot;
|
||||
@ -20,9 +21,15 @@ describe('Tests for Always on top', () => {
|
||||
getConfigPath().then((config) => {
|
||||
configPath = config;
|
||||
done();
|
||||
}).catch((err) => {
|
||||
console.error(constants.UNABLE_TO_GET_USER_CONFIG_PATH, err);
|
||||
expect(err).toBeNull();
|
||||
done();
|
||||
});
|
||||
}).catch((err) => {
|
||||
console.error(constants.UNABLE_TO_START_APPLICATION, err);
|
||||
expect(err).toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -35,7 +42,7 @@ describe('Tests for Always on top', () => {
|
||||
})
|
||||
});
|
||||
app.client.getUserDataPath().then((userConfigPath) => {
|
||||
resolve(userConfigPath.value + '/Symphony.config')
|
||||
resolve(userConfigPath.value)
|
||||
}).catch((err) => {
|
||||
reject(err);
|
||||
});
|
||||
|
@ -1,4 +1,6 @@
|
||||
const Application = require('./spectronSetup');
|
||||
const constants = require('./spectronConstants');
|
||||
|
||||
let app = new Application({});
|
||||
|
||||
describe('Tests for Bring to front', () => {
|
||||
@ -11,7 +13,9 @@ describe('Tests for Bring to front', () => {
|
||||
app = startedApp;
|
||||
done();
|
||||
}).catch((err) => {
|
||||
console.error(constants.UNABLE_TO_START_APPLICATION, err);
|
||||
expect(err).toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
const Application = require('./spectronSetup');
|
||||
const path = require('path');
|
||||
const constants = require('./spectronConstants');
|
||||
|
||||
let app = new Application({});
|
||||
|
||||
describe('Tests for clipboard', () => {
|
||||
@ -11,6 +13,10 @@ describe('Tests for clipboard', () => {
|
||||
return app.startApplication().then((startedApp) => {
|
||||
app = startedApp;
|
||||
done();
|
||||
}).catch((err) => {
|
||||
console.error(constants.UNABLE_TO_START_APPLICATION, err);
|
||||
expect(err).toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1,18 +1,21 @@
|
||||
const Application = require('./spectronSetup');
|
||||
const constants = require('./spectronConstants');
|
||||
|
||||
let app = new Application({});
|
||||
|
||||
describe('Tests for Close', () => {
|
||||
|
||||
let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
|
||||
|
||||
let app;
|
||||
|
||||
beforeAll((done) => {
|
||||
const Application = require('./spectronSetup');
|
||||
app = new Application({});
|
||||
return app.startApplication().then((startedApp) => {
|
||||
app = startedApp;
|
||||
done();
|
||||
}).catch((err) => {
|
||||
console.error(constants.UNABLE_TO_START_APPLICATION, err);
|
||||
expect(err).toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1,11 +1,10 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const childProcess = require('child_process');
|
||||
const Application = require('./spectronSetup');
|
||||
const {isMac} = require('../../js/utils/misc');
|
||||
const { isMac } = require('../../js/utils/misc');
|
||||
const constants = require('./spectronConstants');
|
||||
|
||||
let robot;
|
||||
let configPath;
|
||||
|
||||
let app = new Application({});
|
||||
|
||||
describe('Tests for Full screen', () => {
|
||||
@ -22,10 +21,14 @@ describe('Tests for Full screen', () => {
|
||||
configPath = config;
|
||||
done();
|
||||
}).catch((err) => {
|
||||
console.error(constants.UNABLE_TO_GET_USER_CONFIG_PATH, err);
|
||||
expect(err).toBeNull();
|
||||
done();
|
||||
});
|
||||
}).catch((err) => {
|
||||
console.error(constants.UNABLE_TO_START_APPLICATION, err);
|
||||
expect(err).toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -38,7 +41,7 @@ describe('Tests for Full screen', () => {
|
||||
})
|
||||
});
|
||||
app.client.getUserDataPath().then((userConfigPath) => {
|
||||
resolve(userConfigPath.value + '/Symphony.config')
|
||||
resolve(userConfigPath.value)
|
||||
}).catch((err) => {
|
||||
reject(err);
|
||||
});
|
||||
|
@ -1,11 +1,10 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const childProcess = require('child_process');
|
||||
const Application = require('./spectronSetup');
|
||||
const {isMac} = require('../../js/utils/misc');
|
||||
const { isMac } = require('../../js/utils/misc');
|
||||
const constants = require('./spectronConstants');
|
||||
|
||||
let robot;
|
||||
let configPath;
|
||||
|
||||
let app = new Application({});
|
||||
|
||||
describe('Tests for Minimize on Close', () => {
|
||||
@ -22,10 +21,14 @@ describe('Tests for Minimize on Close', () => {
|
||||
configPath = config;
|
||||
done();
|
||||
}).catch((err) => {
|
||||
console.error(constants.UNABLE_TO_GET_USER_CONFIG_PATH, err);
|
||||
expect(err).toBeNull();
|
||||
done();
|
||||
});
|
||||
}).catch((err) => {
|
||||
console.error(constants.UNABLE_TO_START_APPLICATION, err);
|
||||
expect(err).toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -38,7 +41,7 @@ describe('Tests for Minimize on Close', () => {
|
||||
})
|
||||
});
|
||||
app.client.getUserDataPath().then((userConfigPath) => {
|
||||
resolve(userConfigPath.value + '/Symphony.config')
|
||||
resolve(userConfigPath.value)
|
||||
}).catch((err) => {
|
||||
reject(err);
|
||||
});
|
||||
|
@ -1,6 +1,8 @@
|
||||
const Application = require('./spectronSetup');
|
||||
const path = require('path');
|
||||
const {isMac} = require('../../js/utils/misc');
|
||||
const { isMac } = require('../../js/utils/misc');
|
||||
const constants = require('./spectronConstants');
|
||||
|
||||
let app = new Application({});
|
||||
|
||||
describe('Tests for Notification position', () => {
|
||||
@ -13,7 +15,9 @@ describe('Tests for Notification position', () => {
|
||||
app = startedApp;
|
||||
done();
|
||||
}).catch((err) => {
|
||||
console.error(constants.UNABLE_TO_START_APPLICATION, err);
|
||||
expect(err).toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
14
tests/spectron/spectronConstants.js
Normal file
14
tests/spectron/spectronConstants.js
Normal file
@ -0,0 +1,14 @@
|
||||
module.exports = {
|
||||
|
||||
SYMPHONY_CONFIG_FILE_NAME: "/Symphony.config",
|
||||
|
||||
ELECTRON_GLOBAL_CONFIG_PATH_MAC: "node_modules/electron/dist/Electron.app/Contents/config",
|
||||
ELECTRON_GLOBAL_CONFIG_PATH_WIN: "node_modules/electron/dist/config",
|
||||
|
||||
SEARCH_LIBRARY_PATH_MAC: "node_modules/electron/dist/Electron.app/Contents/library",
|
||||
SEARCH_LIBRARY_PATH_WIN: "node_modules/electron/dist/library",
|
||||
|
||||
|
||||
UNABLE_TO_START_APPLICATION: "Unable to start application error: ",
|
||||
UNABLE_TO_GET_USER_CONFIG_PATH: "Unable to get user config path error: "
|
||||
};
|
@ -3,6 +3,7 @@ const path = require('path');
|
||||
const fs = require('fs');
|
||||
const { isMac, isWindowsOS } = require('../../js/utils/misc');
|
||||
const ncp = require('ncp').ncp;
|
||||
const constants = require('./spectronConstants.js');
|
||||
|
||||
class App {
|
||||
|
||||
@ -15,8 +16,16 @@ class App {
|
||||
this.options.args = [path.join(__dirname, '..', '..', 'js/main.js')];
|
||||
}
|
||||
|
||||
App.copyConfigPath();
|
||||
App.copyLibraries();
|
||||
if (isMac) {
|
||||
App.copyConfigPath(constants.ELECTRON_GLOBAL_CONFIG_PATH_MAC);
|
||||
App.copyLibraries(constants.SEARCH_LIBRARY_PATH_MAC);
|
||||
}
|
||||
|
||||
if (isWindowsOS) {
|
||||
App.copyConfigPath(constants.ELECTRON_GLOBAL_CONFIG_PATH_WIN);
|
||||
App.copyLibraries(constants.SEARCH_LIBRARY_PATH_WIN);
|
||||
}
|
||||
|
||||
|
||||
this.app = new Application(this.options);
|
||||
}
|
||||
@ -43,70 +52,62 @@ class App {
|
||||
|
||||
static readConfig(configPath) {
|
||||
|
||||
if (!fs.existsSync(configPath)) {
|
||||
return new Promise(function (resolve) {
|
||||
this.copyConfigPath().then(() => {
|
||||
fs.readFile(configPath, 'utf-8', function (err, data) {
|
||||
const configFilePath = configPath + constants.SYMPHONY_CONFIG_FILE_NAME;
|
||||
|
||||
if (!fs.existsSync(configFilePath)) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
App.copyConfigPath(configPath).then(() => {
|
||||
fs.readFile(configFilePath, 'utf-8', function (err, data) {
|
||||
if (err) {
|
||||
throw new Error("Unable to read user config file " + err);
|
||||
throw new Error(`Unable to read user config file at ${configFilePath} ${err}`);
|
||||
}
|
||||
resolve(JSON.parse(data));
|
||||
let parsedData;
|
||||
try {
|
||||
parsedData = JSON.parse(data);
|
||||
} catch (err) {
|
||||
return reject(err);
|
||||
}
|
||||
return resolve(parsedData);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return new Promise(function (resolve) {
|
||||
fs.readFile(configPath, 'utf-8', function (err, data) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
fs.readFile(configFilePath, 'utf-8', function (err, data) {
|
||||
if (err) {
|
||||
throw new Error("Unable to read user config file " + err);
|
||||
throw new Error(`Unable to read user config file at ${configFilePath} ${err}`);
|
||||
}
|
||||
resolve(JSON.parse(data));
|
||||
let parsedData;
|
||||
try {
|
||||
parsedData = JSON.parse(data);
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
resolve(parsedData);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static copyConfigPath() {
|
||||
static copyConfigPath(configPath) {
|
||||
return new Promise((resolve) => {
|
||||
if (isMac) {
|
||||
ncp('config', 'node_modules/electron/dist/Electron.app/Contents/config', function (err) {
|
||||
if (err) {
|
||||
throw new Error("Unable to copy config file to Electron dir " + err);
|
||||
}
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
|
||||
if (isWindowsOS) {
|
||||
ncp('config', 'node_modules/electron/dist/config', function (err) {
|
||||
if (err) {
|
||||
throw new Error("Unable to copy config file to Electron dir " + err);
|
||||
}
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
ncp('config', configPath, function (err) {
|
||||
if (err) {
|
||||
throw new Error("Unable to copy config file to Electron dir " + err);
|
||||
}
|
||||
return resolve();
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
static copyLibraries() {
|
||||
static copyLibraries(libraryPath) {
|
||||
return new Promise((resolve) => {
|
||||
if (isMac) {
|
||||
return ncp('library', 'node_modules/electron/dist/Electron.app/Contents/library', function (err) {
|
||||
if (err) {
|
||||
throw new Error("Unable to copy Swift search Libraries " + err);
|
||||
}
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
|
||||
if (isWindowsOS) {
|
||||
return ncp('library', 'node_modules/electron/dist/library', function (err) {
|
||||
if (err) {
|
||||
throw new Error("Unable to copy Swift search Libraries " + err);
|
||||
}
|
||||
return resolve();
|
||||
});
|
||||
}
|
||||
return ncp('library', libraryPath, function (err) {
|
||||
if (err) {
|
||||
throw new Error("Unable to copy Swift search Libraries " + err);
|
||||
}
|
||||
return resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,8 @@ const Application = require('./spectronSetup');
|
||||
const path = require('path');
|
||||
const {isMac} = require('../../js/utils/misc.js');
|
||||
const childProcess = require('child_process');
|
||||
const constants = require('./spectronConstants');
|
||||
|
||||
let app = new Application({});
|
||||
let robot;
|
||||
|
||||
@ -11,11 +13,15 @@ describe('Tests for spellChecker', () => {
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut();
|
||||
|
||||
beforeAll((done) => {
|
||||
childProcess.exec(`npm rebuild robotjs --target=${process.version} --build-from-source`, function () {
|
||||
childProcess.exec(`npm rebuild robotjs --target=${process.version} --build-from-source`, () => {
|
||||
robot = require('robotjs');
|
||||
app.startApplication().then((startedApp) => {
|
||||
app = startedApp;
|
||||
done();
|
||||
}).catch((err) => {
|
||||
console.error(constants.UNABLE_TO_START_APPLICATION, err);
|
||||
expect(err).toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,8 +1,8 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const childProcess = require('child_process');
|
||||
const Application = require('./spectronSetup');
|
||||
const {isMac} = require('../../js/utils/misc');
|
||||
const { isMac } = require('../../js/utils/misc');
|
||||
const constants = require('./spectronConstants');
|
||||
|
||||
let robot;
|
||||
let configPath;
|
||||
|
||||
@ -22,10 +22,14 @@ describe('Tests for Zoom in and Zoom out', () => {
|
||||
configPath = config;
|
||||
done();
|
||||
}).catch((err) => {
|
||||
console.error(constants.UNABLE_TO_GET_USER_CONFIG_PATH, err);
|
||||
expect(err).toBeNull();
|
||||
done();
|
||||
});
|
||||
}).catch((err) => {
|
||||
console.error(constants.UNABLE_TO_START_APPLICATION, err);
|
||||
expect(err).toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -38,7 +42,7 @@ describe('Tests for Zoom in and Zoom out', () => {
|
||||
})
|
||||
});
|
||||
app.client.getUserDataPath().then((userConfigPath) => {
|
||||
resolve(userConfigPath.value + '/Symphony.config')
|
||||
resolve(userConfigPath.value)
|
||||
}).catch((err) => {
|
||||
reject(err);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user