core.js 2.6 KB

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