| | |
| | | var test = require('tape'); |
| | | var keys = require('object-keys'); |
| | | var semver = require('semver'); |
| | | var mockProperty = require('mock-property'); |
| | | |
| | | var isCore = require('../'); |
| | | var data = require('../core.json'); |
| | | |
| | |
| | | function () { require(mod); }, // eslint-disable-line no-loop-func |
| | | 'requiring ' + mod + ' does not throw' |
| | | ); |
| | | if (supportsNodePrefix) { |
| | | st.doesNotThrow( |
| | | function () { require('node:' + mod); }, // eslint-disable-line no-loop-func |
| | | 'requiring node:' + mod + ' does not throw' |
| | | ); |
| | | } else { |
| | | st['throws']( |
| | | function () { require('node:' + mod); }, // eslint-disable-line no-loop-func |
| | | 'requiring node:' + mod + ' throws' |
| | | ); |
| | | if (mod.slice(0, 5) !== 'node:') { |
| | | if (supportsNodePrefix) { |
| | | st.doesNotThrow( |
| | | function () { require('node:' + mod); }, // eslint-disable-line no-loop-func |
| | | 'requiring node:' + mod + ' does not throw' |
| | | ); |
| | | } else { |
| | | st['throws']( |
| | | function () { require('node:' + mod); }, // eslint-disable-line no-loop-func |
| | | 'requiring node:' + mod + ' throws' |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | 'v8/tools/tickprocessor', |
| | | 'v8/tools/profile' |
| | | ]; |
| | | // see https://github.com/nodejs/node/issues/42785 |
| | | if (semver.satisfies(process.version, '>= 18')) { |
| | | libs = libs.concat('node:test'); |
| | | } |
| | | for (var i = 0; i < libs.length; ++i) { |
| | | var mod = libs[i]; |
| | | if (excludeList.indexOf(mod) === -1) { |
| | |
| | | function () { require(mod); }, // eslint-disable-line no-loop-func |
| | | 'requiring ' + mod + ' does not throw' |
| | | ); |
| | | if (supportsNodePrefix) { |
| | | st.doesNotThrow( |
| | | function () { require('node:' + mod); }, // eslint-disable-line no-loop-func |
| | | 'requiring node:' + mod + ' does not throw' |
| | | ); |
| | | } else { |
| | | st['throws']( |
| | | function () { require('node:' + mod); }, // eslint-disable-line no-loop-func |
| | | 'requiring node:' + mod + ' throws' |
| | | ); |
| | | if (mod.slice(0, 5) !== 'node:') { |
| | | if (supportsNodePrefix) { |
| | | st.doesNotThrow( |
| | | function () { require('node:' + mod); }, // eslint-disable-line no-loop-func |
| | | 'requiring node:' + mod + ' does not throw' |
| | | ); |
| | | } else { |
| | | st['throws']( |
| | | function () { require('node:' + mod); }, // eslint-disable-line no-loop-func |
| | | 'requiring node:' + mod + ' throws' |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | }); |
| | | |
| | | t.test('Object.prototype pollution', function (st) { |
| | | /* eslint no-extend-native: 1 */ |
| | | var nonKey = 'not a core module'; |
| | | st.teardown(function () { |
| | | delete Object.prototype.fs; |
| | | delete Object.prototype.path; |
| | | delete Object.prototype.http; |
| | | delete Object.prototype[nonKey]; |
| | | }); |
| | | Object.prototype.fs = false; |
| | | Object.prototype.path = '>= 999999999'; |
| | | Object.prototype.http = data.http; |
| | | Object.prototype[nonKey] = true; |
| | | st.teardown(mockProperty(Object.prototype, 'fs', { value: false })); |
| | | st.teardown(mockProperty(Object.prototype, 'path', { value: '>= 999999999' })); |
| | | st.teardown(mockProperty(Object.prototype, 'http', { value: data.http })); |
| | | st.teardown(mockProperty(Object.prototype, nonKey, { value: true })); |
| | | |
| | | st.equal(isCore('fs'), true, 'fs is a core module even if Object.prototype lies'); |
| | | st.equal(isCore('path'), true, 'path is a core module even if Object.prototype lies'); |