Skip to content

Commit

Permalink
[New] add many missing core modules.
Browse files Browse the repository at this point in the history
Also add better tests.
  • Loading branch information
ljharb committed Mar 15, 2018
1 parent 2acf953 commit 88c0778
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 6 deletions.
25 changes: 22 additions & 3 deletions lib/core.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var current = (process.versions && process.versions.node && process.versions.node.split('.')) || [];

function versionIncluded(specifier) {
if (specifier === true) { return true; }
function specifierIncluded(specifier) {
var parts = specifier.split(' ');
var op = parts[0];
var versionParts = parts[1].split('.');
Expand All @@ -20,7 +19,27 @@ function versionIncluded(specifier) {
return false;
}
}
return false;
return op === '>=';
}

function matchesRange(range) {
var specifiers = range.split(/ ?&& ?/);
if (specifiers.length === 0) { return false; }
for (var i = 0; i < specifiers.length; ++i) {
if (!specifierIncluded(specifiers[i])) { return false; }
}
return true;
}

function versionIncluded(specifierValue) {
if (typeof specifierValue === 'boolean') { return specifierValue; }
if (specifierValue && typeof specifierValue === 'object') {
for (var i = 0; i < specifierValue.length; ++i) {
if (matchesRange(specifierValue[i])) { return true; }
}
return false;
}
return matchesRange(specifierValue);
}

var data = require('./core.json');
Expand Down
27 changes: 26 additions & 1 deletion lib/core.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@
"events": true,
"freelist": "< 6",
"fs": true,
"_http_agent": ">= 0.11.1",
"_http_client": ">= 0.11.1",
"_http_common": ">= 0.11.1",
"_http_incoming": ">= 0.11.1",
"_http_outgoing": ">= 0.11.1",
"_http_server": ">= 0.11.1",
"http": true,
"http2": ">= 8.8",
"https": true,
"_http_server": ">= 0.11",
"inspector": ">= 8.0.0",
"_linklist": "< 8",
"module": true,
"net": true,
"node-inspect/lib/_inspect": ">= 7.6.0",
"node-inspect/lib/internal/inspect_client": ">= 7.6.0",
"node-inspect/lib/internal/inspect_repl": ">= 7.6.0",
"os": true,
"path": true,
"perf_hooks": ">= 8.5",
Expand All @@ -30,14 +39,30 @@
"querystring": true,
"readline": true,
"repl": true,
"smalloc": ">= 0.11.5 && < 3",
"_stream_duplex": ">= 0.9.4",
"_stream_transform": ">= 0.9.4",
"_stream_wrap": ">= 1.4.1",
"_stream_passthrough": ">= 0.9.4",
"_stream_readable": ">= 0.9.4",
"_stream_writable": ">= 0.9.4",
"stream": true,
"string_decoder": true,
"sys": true,
"timers": true,
"_tls_common": ">= 0.11.13",
"_tls_legacy": ">= 0.11.3",
"_tls_wrap": ">= 0.11.3",
"tls": true,
"tty": true,
"url": true,
"util": true,
"v8/tools/codemap": [">= 4.4.0 && < 5", ">= 5.2.0"],
"v8/tools/consarray": [">= 4.4.0 && < 5", ">= 5.2.0"],
"v8/tools/csvparser": [">= 4.4.0 && < 5", ">= 5.2.0"],
"v8/tools/logreader": [">= 4.4.0 && < 5", ">= 5.2.0"],
"v8/tools/profile_view": [">= 4.4.0 && < 5", ">= 5.2.0"],
"v8/tools/splaytree": [">= 4.4.0 && < 5", ">= 5.2.0"],
"v8": ">= 1",
"vm": true,
"zlib": true
Expand Down
49 changes: 47 additions & 2 deletions test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,60 @@ test('core modules', function (t) {
if (resolve.core[mod]) {
st.doesNotThrow(
function () { require(mod); }, // eslint-disable-line no-loop-func
'requiring ' + mod + ' does not throw'
mod + ' supported; requiring does not throw'
);
} else {
st.skip(mod + ' not supported');
st.throws(
function () { require(mod); }, // eslint-disable-line no-loop-func
mod + ' not supported; requiring throws'
);
}
}

st.end();
});

t.test('core via repl module', { skip: !resolve.core.repl }, function (st) {
var libs = require('repl')._builtinLibs; // eslint-disable-line no-underscore-dangle
if (!libs) {
st.skip('module.builtinModules does not exist');
return st.end();
}
for (var i = 0; i < libs.length; ++i) {
var mod = libs[i];
st.ok(resolve.core[mod], mod + ' is a core module');
st.doesNotThrow(
function () { require(mod); }, // eslint-disable-line no-loop-func
'requiring ' + mod + ' does not throw'
);
}
st.end();
});

t.test('core via buildinModules list', { skip: !resolve.core.module }, function (st) {
var libs = require('module').builtinModules;
if (!libs) {
st.skip('module.builtinModules does not exist');
return st.end();
}
var blacklist = [
'v8/tools/tickprocessor-driver',
'v8/tools/SourceMap',
'v8/tools/tickprocessor',
'v8/tools/profile'
];
for (var i = 0; i < libs.length; ++i) {
var mod = libs[i];
if (blacklist.indexOf(mod) === -1) {
st.ok(resolve.core[mod], mod + ' is a core module');
st.doesNotThrow(
function () { require(mod); }, // eslint-disable-line no-loop-func
'requiring ' + mod + ' does not throw'
);
}
}
st.end();
});

t.end();
});

0 comments on commit 88c0778

Please sign in to comment.