@@ -30,15 +30,10 @@ const stream = require('stream');
30
30
const util = require ( 'util' ) ;
31
31
const Timer = process . binding ( 'timer_wrap' ) . Timer ;
32
32
const { fixturesDir } = require ( './fixtures' ) ;
33
-
34
- const testRoot = process . env . NODE_TEST_DIR ?
35
- fs . realpathSync ( process . env . NODE_TEST_DIR ) : path . resolve ( __dirname , '..' ) ;
33
+ const tmpdir = require ( './tmpdir' ) ;
36
34
37
35
const noop = ( ) => { } ;
38
36
39
- // Using a `.` prefixed name, which is the convention for "hidden" on POSIX,
40
- // gets tools to ignore it by default or by simple rules, especially eslint.
41
- let tmpDirName = '.tmp' ;
42
37
// PORT should match the definition in test/testpy/__init__.py.
43
38
exports . PORT = + process . env . NODE_COMMON_PORT || 12346 ;
44
39
exports . isWindows = process . platform === 'win32' ;
@@ -121,63 +116,6 @@ if (process.env.NODE_TEST_WITH_ASYNC_HOOKS) {
121
116
} ) . enable ( ) ;
122
117
}
123
118
124
- function rimrafSync ( p ) {
125
- let st ;
126
- try {
127
- st = fs . lstatSync ( p ) ;
128
- } catch ( e ) {
129
- if ( e . code === 'ENOENT' )
130
- return ;
131
- }
132
-
133
- try {
134
- if ( st && st . isDirectory ( ) )
135
- rmdirSync ( p , null ) ;
136
- else
137
- fs . unlinkSync ( p ) ;
138
- } catch ( e ) {
139
- if ( e . code === 'ENOENT' )
140
- return ;
141
- if ( e . code === 'EPERM' )
142
- return rmdirSync ( p , e ) ;
143
- if ( e . code !== 'EISDIR' )
144
- throw e ;
145
- rmdirSync ( p , e ) ;
146
- }
147
- }
148
-
149
- function rmdirSync ( p , originalEr ) {
150
- try {
151
- fs . rmdirSync ( p ) ;
152
- } catch ( e ) {
153
- if ( e . code === 'ENOTDIR' )
154
- throw originalEr ;
155
- if ( e . code === 'ENOTEMPTY' || e . code === 'EEXIST' || e . code === 'EPERM' ) {
156
- const enc = exports . isLinux ? 'buffer' : 'utf8' ;
157
- fs . readdirSync ( p , enc ) . forEach ( ( f ) => {
158
- if ( f instanceof Buffer ) {
159
- const buf = Buffer . concat ( [ Buffer . from ( p ) , Buffer . from ( path . sep ) , f ] ) ;
160
- rimrafSync ( buf ) ;
161
- } else {
162
- rimrafSync ( path . join ( p , f ) ) ;
163
- }
164
- } ) ;
165
- fs . rmdirSync ( p ) ;
166
- }
167
- }
168
- }
169
-
170
- exports . refreshTmpDir = function ( ) {
171
- rimrafSync ( exports . tmpDir ) ;
172
- fs . mkdirSync ( exports . tmpDir ) ;
173
- } ;
174
-
175
- if ( process . env . TEST_THREAD_ID ) {
176
- exports . PORT += process . env . TEST_THREAD_ID * 100 ;
177
- tmpDirName += `.${ process . env . TEST_THREAD_ID } ` ;
178
- }
179
- exports . tmpDir = path . join ( testRoot , tmpDirName ) ;
180
-
181
119
let opensslCli = null ;
182
120
let inFreeBSDJail = null ;
183
121
let localhostIPv4 = null ;
@@ -271,7 +209,7 @@ Object.defineProperty(exports, 'hasFipsCrypto', {
271
209
} ) ;
272
210
273
211
{
274
- const localRelative = path . relative ( process . cwd ( ) , `${ exports . tmpDir } /` ) ;
212
+ const localRelative = path . relative ( process . cwd ( ) , `${ tmpdir . path } /` ) ;
275
213
const pipePrefix = exports . isWindows ? '\\\\.\\pipe\\' : localRelative ;
276
214
const pipeName = `node-test.${ process . pid } .sock` ;
277
215
exports . PIPE = path . join ( pipePrefix , pipeName ) ;
0 commit comments