test: regression test tmpdir
PR-URL: https://github.com/nodejs/node/pull/28035 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
This commit is contained in:
parent
9032ab4763
commit
2f8cf5e5b5
@ -23,8 +23,11 @@
|
|||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const hijackstdio = require('../common/hijackstdio');
|
const hijackstdio = require('../common/hijackstdio');
|
||||||
const fixtures = require('../common/fixtures');
|
const fixtures = require('../common/fixtures');
|
||||||
|
const tmpdir = require('../common/tmpdir');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const { execFile } = require('child_process');
|
const { execFile } = require('child_process');
|
||||||
|
const { writeFileSync, existsSync } = require('fs');
|
||||||
|
const { join } = require('path');
|
||||||
|
|
||||||
// Test for leaked global detection
|
// Test for leaked global detection
|
||||||
{
|
{
|
||||||
@ -124,8 +127,20 @@ const HIJACK_TEST_ARRAY = [ 'foo\n', 'bar\n', 'baz\n' ];
|
|||||||
assert.strictEqual(originalWrite, stream.write);
|
assert.strictEqual(originalWrite, stream.write);
|
||||||
});
|
});
|
||||||
|
|
||||||
// hijackStderr and hijackStdout again
|
// Test `tmpdir`.
|
||||||
// for console
|
{
|
||||||
|
tmpdir.refresh();
|
||||||
|
assert.ok(/\.tmp\.\d+/.test(tmpdir.path));
|
||||||
|
const sentinelPath = join(tmpdir.path, 'gaga');
|
||||||
|
writeFileSync(sentinelPath, 'googoo');
|
||||||
|
tmpdir.refresh();
|
||||||
|
assert.strictEqual(existsSync(tmpdir.path), true);
|
||||||
|
assert.strictEqual(existsSync(sentinelPath), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// hijackStderr and hijackStdout again for console
|
||||||
|
// Must be last, since it uses `process.on('uncaughtException')`
|
||||||
|
{
|
||||||
[['err', 'error'], ['out', 'log']].forEach(([type, method]) => {
|
[['err', 'error'], ['out', 'log']].forEach(([type, method]) => {
|
||||||
hijackstdio[`hijackStd${type}`](common.mustCall(function(data) {
|
hijackstdio[`hijackStd${type}`](common.mustCall(function(data) {
|
||||||
assert.strictEqual(data, 'test\n');
|
assert.strictEqual(data, 'test\n');
|
||||||
@ -146,3 +161,4 @@ process.on('uncaughtException', common.mustCallAtLeast(function(e) {
|
|||||||
e.message,
|
e.message,
|
||||||
`console ${(['err', 'out'])[uncaughtTimes++]} error`);
|
`console ${(['err', 'out'])[uncaughtTimes++]} error`);
|
||||||
}, 2));
|
}, 2));
|
||||||
|
} // End of "Must be last".
|
||||||
|
Loading…
x
Reference in New Issue
Block a user