mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-27 01:11:13 -06:00
add unt test framework (#23)
This commit is contained in:
parent
9554c2d79a
commit
d4ef876828
@ -31,5 +31,11 @@ In order to achieve those goals Symphony is participating and working in close c
|
|||||||
- To change the start url (i.e., pod url), edit config/Symphony.config and change 'url' variable. if no protocol provided, then https will be added.
|
- To change the start url (i.e., pod url), edit config/Symphony.config and change 'url' variable. if no protocol provided, then https will be added.
|
||||||
- The installer will include file config/Symphony.config next to executable. Changes in this file will effect all users.
|
- The installer will include file config/Symphony.config next to executable. Changes in this file will effect all users.
|
||||||
|
|
||||||
|
## Tests and Code Coverage
|
||||||
|
- jest framework is used to run tests: http://facebook.github.io/jest/
|
||||||
|
- to run tests and get code coverage report: npm test
|
||||||
|
- code coverage reports are placed in dir: converage
|
||||||
|
- tests are located in dir: tests
|
||||||
|
|
||||||
## Misc notes
|
## Misc notes
|
||||||
If desiring to run against server without proper cert use cmd line option: --ignore-certificate-errors
|
If desiring to run against server without proper cert use cmd line option: --ignore-certificate-errors
|
||||||
|
@ -4,7 +4,8 @@ const electron = require('electron');
|
|||||||
const app = electron.app;
|
const app = electron.app;
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { isDevEnv, isMac } = require('./utils.js');
|
const isDevEnv = require('./utils.js').isDevEnv;
|
||||||
|
const isMac = require('./utils.js').isMac;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reads global configuration file: config/Symphony.config. this file is
|
* reads global configuration file: config/Symphony.config. this file is
|
||||||
@ -13,7 +14,7 @@ const { isDevEnv, isMac } = require('./utils.js');
|
|||||||
* this file is located relative to the executable - it is placed there by
|
* this file is located relative to the executable - it is placed there by
|
||||||
* the installer. this makes the file easily modifable by admin (or person who
|
* the installer. this makes the file easily modifable by admin (or person who
|
||||||
* installed app). for dev env, the file is read directly from packed asar file.
|
* installed app). for dev env, the file is read directly from packed asar file.
|
||||||
*
|
*
|
||||||
* @return {Object} configuration parameters (e.g., url)
|
* @return {Object} configuration parameters (e.g., url)
|
||||||
*/
|
*/
|
||||||
function getConfig() {
|
function getConfig() {
|
||||||
@ -30,7 +31,7 @@ function getConfig() {
|
|||||||
let execPath = path.dirname(app.getPath('exe'));
|
let execPath = path.dirname(app.getPath('exe'));
|
||||||
// for mac exec is stored in subdir, for linux/windows config
|
// for mac exec is stored in subdir, for linux/windows config
|
||||||
// dir is in the same location.
|
// dir is in the same location.
|
||||||
configPath = path.join(execPath, isMac ? '..' : '', configFile)
|
configPath = path.join(execPath, isMac ? '..' : '', configFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.readFile(configPath, 'utf8', function (err, data) {
|
fs.readFile(configPath, 'utf8', function (err, data) {
|
||||||
|
14
js/utils.js
14
js/utils.js
@ -8,16 +8,16 @@ const isMac = (process.platform === 'darwin');
|
|||||||
/**
|
/**
|
||||||
* Generates a guid,
|
* Generates a guid,
|
||||||
* http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
|
* http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
|
||||||
*
|
*
|
||||||
* @return {String} guid value in string
|
* @return {String} guid value in string
|
||||||
*/
|
*/
|
||||||
function getGuid() {
|
function getGuid() {
|
||||||
function s4() {
|
var guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
|
||||||
return Math.floor((1 + Math.random()) * 0x10000).toString(16)
|
function(c) {
|
||||||
.substring(1);
|
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
|
||||||
}
|
return v.toString(16);
|
||||||
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
|
});
|
||||||
s4() + '-' + s4() + s4() + s4();
|
return guid;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
30
package.json
30
package.json
@ -13,24 +13,33 @@
|
|||||||
"dist-win": "build --win --x64",
|
"dist-win": "build --win --x64",
|
||||||
"dist-win-x86": "build --win --ia32",
|
"dist-win-x86": "build --win --ia32",
|
||||||
"unpacked-win": "build --win --x64 --dir",
|
"unpacked-win": "build --win --x64 --dir",
|
||||||
"unpacked-win-x86": "build --win --ia32 --dir"
|
"unpacked-win-x86": "build --win --ia32 --dir",
|
||||||
|
"test": "jest --coverage"
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
"files" : "!installer/*",
|
"files": [ "!installer/*", "!tests/*" ],
|
||||||
"extraFiles": "config/Symphony.config",
|
"extraFiles": "config/Symphony.config",
|
||||||
"appId": "symphony-electron-desktop",
|
"appId": "symphony-electron-desktop",
|
||||||
"mac": {
|
"mac": {
|
||||||
"target": "dmg",
|
"target": "dmg",
|
||||||
"category": "public.app-category.business"
|
"category": "public.app-category.business"
|
||||||
},
|
},
|
||||||
"dmg": {
|
"dmg": {
|
||||||
"contents": [
|
"contents": [
|
||||||
{ "x": 140, "y": 184 },
|
{
|
||||||
{ "x": 412, "y": 184, "type": "link", "path": "/Applications" }
|
"x": 140,
|
||||||
]
|
"y": 184
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"x": 412,
|
||||||
|
"y": 184,
|
||||||
|
"type": "link",
|
||||||
|
"path": "/Applications"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"win": {
|
"win": {
|
||||||
"target": "squirrel"
|
"target": "squirrel"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@ -48,8 +57,9 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"electron": "1.5.1",
|
"electron": "1.5.1",
|
||||||
"electron-builder": "^13.9.0",
|
"electron-builder": "^13.9.0",
|
||||||
|
"electron-builder-squirrel-windows": "^12.3.0",
|
||||||
"electron-packager": "^8.5.2",
|
"electron-packager": "^8.5.2",
|
||||||
"electron-builder-squirrel-windows": "^12.3.0"
|
"jest": "^19.0.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"electron-squirrel-startup": "^1.0.0"
|
"electron-squirrel-startup": "^1.0.0"
|
||||||
|
17
tests/__mocks__/electron.js
Normal file
17
tests/__mocks__/electron.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
function pathToConfigDir() {
|
||||||
|
return path.join(__dirname, '..');
|
||||||
|
}
|
||||||
|
const app = {
|
||||||
|
getAppPath: pathToConfigDir,
|
||||||
|
getPath: pathToConfigDir
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
require: jest.genMockFunction(),
|
||||||
|
match: jest.genMockFunction(),
|
||||||
|
app: app,
|
||||||
|
remote: jest.genMockFunction(),
|
||||||
|
dialog: jest.genMockFunction()
|
||||||
|
};
|
15
tests/getConfig.test.js
Normal file
15
tests/getConfig.test.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
const getConfig = require('../js/getconfig');
|
||||||
|
|
||||||
|
// mock required so getConfig reads config from correct path
|
||||||
|
jest.mock('../js/utils', function() {
|
||||||
|
return {
|
||||||
|
isDevEnv: false,
|
||||||
|
isMac: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('getConfig should have proper url', function() {
|
||||||
|
return getConfig(false).then(function(result) {
|
||||||
|
expect(result.url).toBe('https://foundation-dev.symphony.com');
|
||||||
|
});
|
||||||
|
});
|
25
tests/utils.test.js
Normal file
25
tests/utils.test.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
const utils = require('../js/utils');
|
||||||
|
|
||||||
|
describe('guid tests', function() {
|
||||||
|
it('should have valid length', function() {
|
||||||
|
var guid = utils.getGuid();
|
||||||
|
expect(guid.length).toBe(36);
|
||||||
|
var parts = guid.split('-');
|
||||||
|
expect(parts.length).toBe(5);
|
||||||
|
expect(parts[0].length).toBe(8);
|
||||||
|
expect(parts[1].length).toBe(4);
|
||||||
|
expect(parts[2].length).toBe(4);
|
||||||
|
expect(parts[3].length).toBe(4);
|
||||||
|
expect(parts[4].length).toBe(12);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should only contains hex chars', function() {
|
||||||
|
for(var i = 0; i < 100; i++) {
|
||||||
|
var guid = utils.getGuid();
|
||||||
|
var parts = guid.split('-');
|
||||||
|
parts.forEach(function(part) {
|
||||||
|
expect(/^([A-Fa-f0-9]{2})+$/.test(part)).toBe(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user