Skip to content

Commit

Permalink
Fix: Default flags to empty array (fixes #53)
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed May 9, 2019
1 parent eeb439a commit c3b4ff0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ function getFlags(cb) {
if (execErr) {
return cb(execErr);
}
var flags = result.match(/\s\s--[\w-]+/gm)
// If the binary doesn't return flags in the way we expect, default to an empty array
// Reference https://github.com/gulpjs/v8flags/issues/53
var matchedFlags = result.match(/\s\s--[\w-]+/gm) || [];
var flags = matchedFlags
.map(normalizeFlagName)
.filter(function(name) {
return exclusions.indexOf(name) === -1;
Expand Down
Empty file added test/fake-bin
Empty file.
22 changes: 22 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,28 @@ describe('v8flags', function() {
});
});

it('will not throw on non-matching return from node --v8-options', function(done) {
if (os.platform() === 'win32') {
this.skip();
}

eraseHome();
var v8flags = require('../');

// Save original execPath
var execPath = process.execPath;
// Set execPath to our fake-bin
process.execPath = __dirname + '/fake-bin';

v8flags(function(err, flags) {
expect(err).toNotExist();
expect(flags).toEqual([]);
// Restore original execPath
process.execPath = execPath;
done();
});
});

it('should back with an empty array if the runtime is electron', function(done) {
process.versions.electron = 'set';
var v8flags = require('../');
Expand Down

0 comments on commit c3b4ff0

Please sign in to comment.