Skip to content

Commit

Permalink
Add mock test to test ELECTRON_RUN_AS_NOD env var
Browse files Browse the repository at this point in the history
  • Loading branch information
bcomnes committed Mar 29, 2017
1 parent fe9e1e9 commit d26ce71
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/util/versioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ function get_runtime_abi(runtime, target_version) {
if (runtime === 'node-webkit') {
return get_node_webkit_abi(runtime, target_version || process.versions['node-webkit']);
} else if (runtime === 'electron') {
return get_electron_abi(runtime, target_version || process.versions.electron);
var electron_version = target_version || process.versions.electron
if (!electron_version) {
// TODO PR something to electron to pass in the version number for forks
// https://github.com/electron/electron/issues/9058
try { electron_version = require('electron/package.json').version }
catch (_) {}
}
return get_electron_abi(runtime, electron_version);
} else {
if (runtime != 'node') {
throw new Error("Unknown Runtime: '" + runtime + "'");
Expand Down Expand Up @@ -245,12 +252,9 @@ function get_process_runtime(versions) {
var runtime = 'node';
if (versions['node-webkit']) {
runtime = 'node-webkit';
} else if (versions.electron) {
runtime = 'electron';
} else if (process.env.ELECTRON_RUN_AS_NODE) {
// Running in a childProcess.fork of electron
} else if (versions.electron || process.env.ELECTRON_RUN_AS_NODE) {
// Running in electron or a childProcess.fork of electron
runtime = 'electron';
process.versions.electron = require('electron/package.json').version;
}
return runtime;
}
Expand Down
6 changes: 6 additions & 0 deletions test/versioning.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ describe('versioning', function() {
"node-webkit": '0.37.3',
};
assert.equal(versioning.get_process_runtime(mock_process_versions3),'node-webkit');
var mock_process_versions4 = {
"node": '0.8.0'
}
process.env.ELECTRON_RUN_AS_NODE = 1
assert.equal(versioning.get_process_runtime(mock_process_versions4),'electron');
delete process.env.ELECTRON_RUN_AS_NODE
});

it('should detect abi for electron runtime', function() {
Expand Down

0 comments on commit d26ce71

Please sign in to comment.