1 | var test = require('tape');
|
---|
2 | var keys = require('object-keys');
|
---|
3 | var resolve = require('../');
|
---|
4 |
|
---|
5 | test('core modules', function (t) {
|
---|
6 | t.test('isCore()', function (st) {
|
---|
7 | st.ok(resolve.isCore('fs'));
|
---|
8 | st.ok(resolve.isCore('net'));
|
---|
9 | st.ok(resolve.isCore('http'));
|
---|
10 |
|
---|
11 | st.ok(!resolve.isCore('seq'));
|
---|
12 | st.ok(!resolve.isCore('../'));
|
---|
13 |
|
---|
14 | st.ok(!resolve.isCore('toString'));
|
---|
15 |
|
---|
16 | st.end();
|
---|
17 | });
|
---|
18 |
|
---|
19 | t.test('core list', function (st) {
|
---|
20 | var cores = keys(resolve.core);
|
---|
21 | st.plan(cores.length);
|
---|
22 |
|
---|
23 | for (var i = 0; i < cores.length; ++i) {
|
---|
24 | var mod = cores[i];
|
---|
25 | var requireFunc = function () { require(mod); }; // eslint-disable-line no-loop-func
|
---|
26 | console.log(mod, resolve.core, resolve.core[mod]);
|
---|
27 | if (resolve.core[mod]) {
|
---|
28 | st.doesNotThrow(requireFunc, mod + ' supported; requiring does not throw');
|
---|
29 | } else {
|
---|
30 | st.throws(requireFunc, mod + ' not supported; requiring throws');
|
---|
31 | }
|
---|
32 | }
|
---|
33 |
|
---|
34 | st.end();
|
---|
35 | });
|
---|
36 |
|
---|
37 | t.test('core via repl module', { skip: !resolve.core.repl }, function (st) {
|
---|
38 | var libs = require('repl')._builtinLibs; // eslint-disable-line no-underscore-dangle
|
---|
39 | if (!libs) {
|
---|
40 | st.skip('module.builtinModules does not exist');
|
---|
41 | return st.end();
|
---|
42 | }
|
---|
43 | for (var i = 0; i < libs.length; ++i) {
|
---|
44 | var mod = libs[i];
|
---|
45 | st.ok(resolve.core[mod], mod + ' is a core module');
|
---|
46 | st.doesNotThrow(
|
---|
47 | function () { require(mod); }, // eslint-disable-line no-loop-func
|
---|
48 | 'requiring ' + mod + ' does not throw'
|
---|
49 | );
|
---|
50 | }
|
---|
51 | st.end();
|
---|
52 | });
|
---|
53 |
|
---|
54 | t.test('core via builtinModules list', { skip: !resolve.core.module }, function (st) {
|
---|
55 | var libs = require('module').builtinModules;
|
---|
56 | if (!libs) {
|
---|
57 | st.skip('module.builtinModules does not exist');
|
---|
58 | return st.end();
|
---|
59 | }
|
---|
60 | var blacklist = [
|
---|
61 | '_debug_agent',
|
---|
62 | 'v8/tools/tickprocessor-driver',
|
---|
63 | 'v8/tools/SourceMap',
|
---|
64 | 'v8/tools/tickprocessor',
|
---|
65 | 'v8/tools/profile'
|
---|
66 | ];
|
---|
67 | for (var i = 0; i < libs.length; ++i) {
|
---|
68 | var mod = libs[i];
|
---|
69 | if (blacklist.indexOf(mod) === -1) {
|
---|
70 | st.ok(resolve.core[mod], mod + ' is a core module');
|
---|
71 | st.doesNotThrow(
|
---|
72 | function () { require(mod); }, // eslint-disable-line no-loop-func
|
---|
73 | 'requiring ' + mod + ' does not throw'
|
---|
74 | );
|
---|
75 | }
|
---|
76 | }
|
---|
77 | st.end();
|
---|
78 | });
|
---|
79 |
|
---|
80 | t.end();
|
---|
81 | });
|
---|