You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.7 KiB

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