core.js 2.6 KB

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