Skip to content

Commit dc5d324

Browse files
committed
Merge pull request #56 from dgreene-r7/remove-electron-deps-from-local-testing
Remove electron dependency from local testing
2 parents 6da6411 + 4ec2a24 commit dc5d324

File tree

7 files changed

+48
-13
lines changed

7 files changed

+48
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules/
22
dist/
33
*.log
44
.DS_Store
5+
test/data/test.json

app.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
const electron = require('electron');
44
const Application = electron.app;
55
const BrowserWindow = electron.BrowserWindow;
6-
7-
const Storage = require('./lib/storage');
6+
const app = require('app');
7+
const path = require('path');
88
const Server = require('./lib/server');
99
const config = require('./config');
10+
const storagePath = path.join(app.getPath('userData'), 'data.json');
11+
12+
global.Storage = require('./lib/storage')(storagePath);
1013

1114
const WindowWidth = 800;
1215
const WindowHeight = 800;
@@ -45,8 +48,8 @@ Application.on('ready', () => {
4548
width: lastWindowState.width,
4649
height: lastWindowState.height,
4750
show: false,
48-
'webPreferences': {
49-
'nodeIntegration': false
51+
webPreferences: {
52+
nodeIntegration: false
5053
}
5154
});
5255

@@ -73,5 +76,6 @@ Application.on('ready', () => {
7376
console.log('Reloading...'); // eslint-disable-line no-console
7477
mainWindow.loadURL(Server.get('entryPointUrl'));
7578
}, (config.aws.duration - 10) * 1000); // eslint-disable-line rapid7/static-magic-numbers
79+
7680
Server.set('tokenRefreshInterval', tokenRefreshInterval);
7781
});

lib/server.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const xpath = require('xpath.js');
1919
const config = require('../config');
2020
const Auth = require('../lib/auth');
2121
const AwsCredentials = require('../lib/aws-credentials');
22-
const Storage = require('../lib/storage');
2322

2423
const sessionSecret = '491F9BAD-DFFF-46E2-A0F9-56397B538060';
2524

lib/storage.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
'use strict';
22

3-
const app = require('app');
43
const fs = require('fs');
5-
const path = require('path');
64

75
class Storage {
8-
constructor() {
6+
/**
7+
* Constructor
8+
* @param {string} file
9+
*/
10+
constructor(file) {
911
this.data = null;
10-
this.file = path.join(app.getPath('userData'), 'data.json');
12+
this.file = file;
1113
}
1214

15+
/**
16+
* Load the storage file
17+
*/
1318
load() {
1419
if (this.data !== null) {
1520
return;
@@ -21,18 +26,31 @@ class Storage {
2126
this.data = JSON.parse(fs.readFileSync(this.file, 'utf8'));
2227
}
2328

29+
/**
30+
* Save the storage file
31+
*/
2432
save() {
2533
if (this.data !== null) {
2634
fs.writeFileSync(this.file, JSON.stringify(this.data), 'utf8');
2735
}
2836
}
2937

38+
/**
39+
* Set the value specified by key
40+
* @param {string} key
41+
* @param {*} value
42+
*/
3043
set(key, value) {
3144
this.load();
3245
this.data[key] = value;
3346
this.save();
3447
}
3548

49+
/**
50+
* Get the value by key
51+
* @param {string} key
52+
* @returns {*}
53+
*/
3654
get(key) {
3755
let value = null;
3856

@@ -44,4 +62,4 @@ class Storage {
4462
}
4563
}
4664

47-
module.exports = new Storage();
65+
module.exports = (path) => new Storage(path);

local.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
const path = require('path');
3+
const Server = require('./lib/server');
4+
const storagePath = path.join(__dirname, 'test', 'data', 'test.json');
5+
6+
global.Storage = require('./lib/storage')(storagePath);
7+
8+
const host = Server.get('host');
9+
const port = Server.get('port');
10+
11+
Server.listen(port, host, () => {
12+
console.log('Server listening on http://%s:%s', host, port); // eslint-disable-line no-console
13+
});

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
},
1313
"main": "app.js",
1414
"scripts": {
15-
"debug": "electron . --debug",
16-
"start": "node app.js",
17-
"app": "electron .",
15+
"electron-debug": "electron . --debug",
16+
"electron-start": "electron .",
17+
"local-start": "node local.js",
1818
"prebuild": "rm -rf dist/",
1919
"build": "electron-packager . Awsaml --asar --ignore=node_modules/electron --ignore=dist --out=dist --platform=darwin,linux,win32 --arch=x64 --version=0.37.8 --app-version=${npm_package_version} --app-bundle-id=com.rapid7.awsaml --helper-bundle-id=com.rapid7.awsaml.helper",
2020
"postbuild": "export platform=darwin; npm run zip & export platform=linux; npm run zip & export platform=win32; npm run zip",

test/data/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)