33var test = require ( 'tape' ) ;
44var keys = require ( 'object-keys' ) ;
55var semver = require ( 'semver' ) ;
6+ var mockProperty = require ( 'mock-property' ) ;
7+
68var isCore = require ( '../' ) ;
79var data = require ( '../core.json' ) ;
810
@@ -51,16 +53,18 @@ test('core modules', function (t) {
5153 function ( ) { require ( mod ) ; } , // eslint-disable-line no-loop-func
5254 'requiring ' + mod + ' does not throw'
5355 ) ;
54- if ( supportsNodePrefix ) {
55- st . doesNotThrow (
56- function ( ) { require ( 'node:' + mod ) ; } , // eslint-disable-line no-loop-func
57- 'requiring node:' + mod + ' does not throw'
58- ) ;
59- } else {
60- st [ 'throws' ] (
61- function ( ) { require ( 'node:' + mod ) ; } , // eslint-disable-line no-loop-func
62- 'requiring node:' + mod + ' throws'
63- ) ;
56+ if ( mod . slice ( 0 , 5 ) !== 'node:' ) {
57+ if ( supportsNodePrefix ) {
58+ st . doesNotThrow (
59+ function ( ) { require ( 'node:' + mod ) ; } , // eslint-disable-line no-loop-func
60+ 'requiring node:' + mod + ' does not throw'
61+ ) ;
62+ } else {
63+ st [ 'throws' ] (
64+ function ( ) { require ( 'node:' + mod ) ; } , // eslint-disable-line no-loop-func
65+ 'requiring node:' + mod + ' throws'
66+ ) ;
67+ }
6468 }
6569 }
6670 }
@@ -79,6 +83,10 @@ test('core modules', function (t) {
7983 'v8/tools/tickprocessor' ,
8084 'v8/tools/profile'
8185 ] ;
86+ // see https://github.com/nodejs/node/issues/42785
87+ if ( semver . satisfies ( process . version , '>= 18' ) ) {
88+ libs = libs . concat ( 'node:test' ) ;
89+ }
8290 for ( var i = 0 ; i < libs . length ; ++ i ) {
8391 var mod = libs [ i ] ;
8492 if ( excludeList . indexOf ( mod ) === - 1 ) {
@@ -87,16 +95,18 @@ test('core modules', function (t) {
8795 function ( ) { require ( mod ) ; } , // eslint-disable-line no-loop-func
8896 'requiring ' + mod + ' does not throw'
8997 ) ;
90- if ( supportsNodePrefix ) {
91- st . doesNotThrow (
92- function ( ) { require ( 'node:' + mod ) ; } , // eslint-disable-line no-loop-func
93- 'requiring node:' + mod + ' does not throw'
94- ) ;
95- } else {
96- st [ 'throws' ] (
97- function ( ) { require ( 'node:' + mod ) ; } , // eslint-disable-line no-loop-func
98- 'requiring node:' + mod + ' throws'
99- ) ;
98+ if ( mod . slice ( 0 , 5 ) !== 'node:' ) {
99+ if ( supportsNodePrefix ) {
100+ st . doesNotThrow (
101+ function ( ) { require ( 'node:' + mod ) ; } , // eslint-disable-line no-loop-func
102+ 'requiring node:' + mod + ' does not throw'
103+ ) ;
104+ } else {
105+ st [ 'throws' ] (
106+ function ( ) { require ( 'node:' + mod ) ; } , // eslint-disable-line no-loop-func
107+ 'requiring node:' + mod + ' throws'
108+ ) ;
109+ }
100110 }
101111 }
102112 }
@@ -105,18 +115,11 @@ test('core modules', function (t) {
105115 } ) ;
106116
107117 t . test ( 'Object.prototype pollution' , function ( st ) {
108- /* eslint no-extend-native: 1 */
109118 var nonKey = 'not a core module' ;
110- st . teardown ( function ( ) {
111- delete Object . prototype . fs ;
112- delete Object . prototype . path ;
113- delete Object . prototype . http ;
114- delete Object . prototype [ nonKey ] ;
115- } ) ;
116- Object . prototype . fs = false ;
117- Object . prototype . path = '>= 999999999' ;
118- Object . prototype . http = data . http ;
119- Object . prototype [ nonKey ] = true ;
119+ st . teardown ( mockProperty ( Object . prototype , 'fs' , { value : false } ) ) ;
120+ st . teardown ( mockProperty ( Object . prototype , 'path' , { value : '>= 999999999' } ) ) ;
121+ st . teardown ( mockProperty ( Object . prototype , 'http' , { value : data . http } ) ) ;
122+ st . teardown ( mockProperty ( Object . prototype , nonKey , { value : true } ) ) ;
120123
121124 st . equal ( isCore ( 'fs' ) , true , 'fs is a core module even if Object.prototype lies' ) ;
122125 st . equal ( isCore ( 'path' ) , true , 'path is a core module even if Object.prototype lies' ) ;
0 commit comments