3
3
var test = require ( 'tape' ) ;
4
4
var keys = require ( 'object-keys' ) ;
5
5
var semver = require ( 'semver' ) ;
6
+ var mockProperty = require ( 'mock-property' ) ;
7
+
6
8
var isCore = require ( '../' ) ;
7
9
var data = require ( '../core.json' ) ;
8
10
@@ -51,16 +53,18 @@ test('core modules', function (t) {
51
53
function ( ) { require ( mod ) ; } , // eslint-disable-line no-loop-func
52
54
'requiring ' + mod + ' does not throw'
53
55
) ;
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
+ }
64
68
}
65
69
}
66
70
}
@@ -79,6 +83,10 @@ test('core modules', function (t) {
79
83
'v8/tools/tickprocessor' ,
80
84
'v8/tools/profile'
81
85
] ;
86
+ // see https://github.com/nodejs/node/issues/42785
87
+ if ( semver . satisfies ( process . version , '>= 18' ) ) {
88
+ libs = libs . concat ( 'node:test' ) ;
89
+ }
82
90
for ( var i = 0 ; i < libs . length ; ++ i ) {
83
91
var mod = libs [ i ] ;
84
92
if ( excludeList . indexOf ( mod ) === - 1 ) {
@@ -87,16 +95,18 @@ test('core modules', function (t) {
87
95
function ( ) { require ( mod ) ; } , // eslint-disable-line no-loop-func
88
96
'requiring ' + mod + ' does not throw'
89
97
) ;
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
+ }
100
110
}
101
111
}
102
112
}
@@ -105,18 +115,11 @@ test('core modules', function (t) {
105
115
} ) ;
106
116
107
117
t . test ( 'Object.prototype pollution' , function ( st ) {
108
- /* eslint no-extend-native: 1 */
109
118
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 } ) ) ;
120
123
121
124
st . equal ( isCore ( 'fs' ) , true , 'fs is a core module even if Object.prototype lies' ) ;
122
125
st . equal ( isCore ( 'path' ) , true , 'path is a core module even if Object.prototype lies' ) ;
0 commit comments