-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: move tmpdir to submodule of common
Move tmpdir functionality to its own module (common/tmpdir). PR-URL: #17856 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
- Loading branch information
1 parent
ae372f0
commit eb25252
Showing
155 changed files
with
645 additions
and
456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* eslint-disable required-modules */ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
function rimrafSync(p) { | ||
let st; | ||
try { | ||
st = fs.lstatSync(p); | ||
} catch (e) { | ||
if (e.code === 'ENOENT') | ||
return; | ||
} | ||
|
||
try { | ||
if (st && st.isDirectory()) | ||
rmdirSync(p, null); | ||
else | ||
fs.unlinkSync(p); | ||
} catch (e) { | ||
if (e.code === 'ENOENT') | ||
return; | ||
if (e.code === 'EPERM') | ||
return rmdirSync(p, e); | ||
if (e.code !== 'EISDIR') | ||
throw e; | ||
rmdirSync(p, e); | ||
} | ||
} | ||
|
||
function rmdirSync(p, originalEr) { | ||
try { | ||
fs.rmdirSync(p); | ||
} catch (e) { | ||
if (e.code === 'ENOTDIR') | ||
throw originalEr; | ||
if (e.code === 'ENOTEMPTY' || e.code === 'EEXIST' || e.code === 'EPERM') { | ||
const enc = process.platform === 'linux' ? 'buffer' : 'utf8'; | ||
fs.readdirSync(p, enc).forEach((f) => { | ||
if (f instanceof Buffer) { | ||
const buf = Buffer.concat([Buffer.from(p), Buffer.from(path.sep), f]); | ||
rimrafSync(buf); | ||
} else { | ||
rimrafSync(path.join(p, f)); | ||
} | ||
}); | ||
fs.rmdirSync(p); | ||
} | ||
} | ||
} | ||
|
||
const testRoot = process.env.NODE_TEST_DIR ? | ||
fs.realpathSync(process.env.NODE_TEST_DIR) : path.resolve(__dirname, '..'); | ||
|
||
// Using a `.` prefixed name, which is the convention for "hidden" on POSIX, | ||
// gets tools to ignore it by default or by simple rules, especially eslint. | ||
let tmpdirName = '.tmp'; | ||
if (process.env.TEST_THREAD_ID) { | ||
tmpdirName += `.${process.env.TEST_THREAD_ID}`; | ||
} | ||
exports.path = path.join(testRoot, tmpdirName); | ||
|
||
exports.refresh = () => { | ||
rimrafSync(exports.path); | ||
fs.mkdirSync(exports.path); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.