Skip to content

Commit

Permalink
Fix(utils.isNode) Incompatibility of utils.isNode Function with signa…
Browse files Browse the repository at this point in the history
…l-exit AlaSQL#1889
  • Loading branch information
vishal diyora authored and vishal diyora committed Mar 16, 2024
1 parent d3faf32 commit 7e42397
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/15utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ utils.isWebWorker = (function () {
*/
utils.isNode = (function () {
try {
return utils.isNativeFunction(utils.global.process.reallyExit);
if (typeof process === 'undefined' || !process.versions || !process.versions.node) {
return false;
}
return true;
} catch (e) {
return false;
}
Expand Down
38 changes: 38 additions & 0 deletions test/test1889.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
}

var test = '1889'; // insert test file number

describe('Test 1889 - Ensure utils.isNode handles node and non-Node environments', function () {
let originalProcess;

before(function() {
// Store the original process object
originalProcess = global.process;
});

after(function() {
// Restore the original process object after all tests
global.process = originalProcess;
});

it('Positive: Detect Node environment', function () {
// No modification needed here, running in actual Node.js environment
const isNode = alasql.utils.isNode;
assert.strictEqual(isNode, true, 'utils.isNode should return true in a Node.js environment');
});

it('Negative: Detect Node environment', function () {
// Temporarily override the global process object
global.process = null;

delete require.cache[require.resolve('..')];
const reloadedAlasql = require('..');

const isNodeAfterModification = reloadedAlasql.utils.isNode;
assert.strictEqual(isNodeAfterModification, false, 'utils.isNode should return true in a Node.js environment');
});

});

0 comments on commit 7e42397

Please sign in to comment.