Skip to content

Commit

Permalink
[Fix] fix broken core tests; change core.json to be an object instead…
Browse files Browse the repository at this point in the history
… of an array; fix results
  • Loading branch information
ljharb committed Oct 24, 2017
1 parent e66117d commit b826f30
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 63 deletions.
30 changes: 21 additions & 9 deletions lib/core.js
@@ -1,22 +1,34 @@
var current = (process.versions && process.versions.node && process.versions.node.split('.')) || [];

function versionIncluded(version) {
if (version === '*') return true;
var versionParts = version.split('.');
function versionIncluded(specifier) {
if (specifier === true) { return true; }
var parts = specifier.split(' ');
var op = parts[0];
var versionParts = parts[1].split('.');

for (var i = 0; i < 3; ++i) {
if ((current[i] || 0) >= (versionParts[i] || 0)) return true;
var cur = Number(current[i] || 0);
var ver = Number(versionParts[i] || 0);
if (cur === ver) {
continue; // eslint-disable-line no-restricted-syntax, no-continue
}
if (op === '<') {
return cur < ver;
} else if (op === '>=') {
return cur >= ver;
} else {
return false;
}
}
return false;
}

var data = require('./core.json');

var core = {};
for (var version in data) { // eslint-disable-line no-restricted-syntax
if (Object.prototype.hasOwnProperty.call(data, version) && versionIncluded(version)) {
for (var i = 0; i < data[version].length; ++i) {
core[data[version][i]] = true;
}
for (var mod in data) { // eslint-disable-line no-restricted-syntax
if (Object.prototype.hasOwnProperty.call(data, mod)) {
core[mod] = versionIncluded(data[mod]);
}
}
module.exports = core;
88 changes: 40 additions & 48 deletions lib/core.json
@@ -1,50 +1,42 @@
{
"*": [
"assert",
"buffer_ieee754",
"buffer",
"child_process",
"cluster",
"console",
"constants",
"crypto",
"_debugger",
"dgram",
"dns",
"domain",
"events",
"freelist",
"fs",
"http",
"https",
"_linklist",
"module",
"net",
"os",
"path",
"punycode",
"querystring",
"readline",
"repl",
"stream",
"string_decoder",
"sys",
"timers",
"tls",
"tty",
"url",
"util",
"vm",
"zlib"
],
"0.11": [
"_http_server"
],
"1.0": [
"process",
"v8"
],
"8.5": [
"perf_hooks"
]
"assert": true,
"buffer_ieee754": "< 0.9.7",
"buffer": true,
"child_process": true,
"cluster": true,
"console": true,
"constants": true,
"crypto": true,
"_debugger": "< 8",
"dgram": true,
"dns": true,
"domain": true,
"events": true,
"freelist": "< 6.0.0",
"fs": true,
"http": true,
"https": true,
"_http_server": ">= 0.11",
"_linklist": "< 8.0.0",
"module": true,
"net": true,
"os": true,
"path": true,
"perf_hooks": ">= 8.5",
"process": ">= 1",
"punycode": true,
"querystring": true,
"readline": true,
"repl": true,
"stream": true,
"string_decoder": true,
"sys": true,
"timers": true,
"tls": true,
"tty": true,
"url": true,
"util": true,
"v8": ">= 1",
"vm": true,
"zlib": true
}
19 changes: 13 additions & 6 deletions test/core.js
@@ -1,4 +1,5 @@
var test = require('tape');
var keys = require('object-keys');
var resolve = require('../');

test('core modules', function (t) {
Expand All @@ -13,13 +14,19 @@ test('core modules', function (t) {
});

t.test('core list', function (st) {
st.plan(resolve.core.length);
var cores = keys(resolve.core);
st.plan(cores.length);

for (var i = 0; i < resolve.core.length; ++i) {
st.doesNotThrow(
function () { require(resolve.core[i]); }, // eslint-disable-line no-loop-func
'requiring ' + resolve.core[i] + ' does not throw'
);
for (var i = 0; i < cores.length; ++i) {
var mod = cores[i];
if (resolve.core[mod]) {
st.doesNotThrow(
function () { require(mod); }, // eslint-disable-line no-loop-func
'requiring ' + mod + ' does not throw'
);
} else {
st.skip(mod + ' not supported');
}
}

st.end();
Expand Down

0 comments on commit b826f30

Please sign in to comment.