diff options
author | Refael Ackermann <refack@gmail.com> | 2019-06-02 17:01:29 -0400 |
---|---|---|
committer | Refael Ackermann <refack@gmail.com> | 2019-06-06 19:38:34 -0400 |
commit | 2f8cf5e5b543c058a00e0a7838287ebb10c158dc (patch) | |
tree | 5792a958955287150cf40143ff6b0f3decdadf29 /test/parallel/test-common.js | |
parent | 9032ab4763fb05d0718c0075d05a023aa0bcbb70 (diff) | |
download | android-node-v8-2f8cf5e5b543c058a00e0a7838287ebb10c158dc.tar.gz android-node-v8-2f8cf5e5b543c058a00e0a7838287ebb10c158dc.tar.bz2 android-node-v8-2f8cf5e5b543c058a00e0a7838287ebb10c158dc.zip |
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>
Diffstat (limited to 'test/parallel/test-common.js')
-rw-r--r-- | test/parallel/test-common.js | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/test/parallel/test-common.js b/test/parallel/test-common.js index ad5680bc2f..1521e153a9 100644 --- a/test/parallel/test-common.js +++ b/test/parallel/test-common.js @@ -23,8 +23,11 @@ const common = require('../common'); const hijackstdio = require('../common/hijackstdio'); const fixtures = require('../common/fixtures'); +const tmpdir = require('../common/tmpdir'); const assert = require('assert'); const { execFile } = require('child_process'); +const { writeFileSync, existsSync } = require('fs'); +const { join } = require('path'); // Test for leaked global detection { @@ -124,25 +127,38 @@ const HIJACK_TEST_ARRAY = [ 'foo\n', 'bar\n', 'baz\n' ]; assert.strictEqual(originalWrite, stream.write); }); -// hijackStderr and hijackStdout again -// for console -[[ 'err', 'error' ], [ 'out', 'log' ]].forEach(([ type, method ]) => { - hijackstdio[`hijackStd${type}`](common.mustCall(function(data) { - assert.strictEqual(data, 'test\n'); +// Test `tmpdir`. +{ + 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); +} - // throw an error - throw new Error(`console ${type} error`); - })); +// hijackStderr and hijackStdout again for console +// Must be last, since it uses `process.on('uncaughtException')` +{ + [['err', 'error'], ['out', 'log']].forEach(([type, method]) => { + hijackstdio[`hijackStd${type}`](common.mustCall(function(data) { + assert.strictEqual(data, 'test\n'); - console[method]('test'); - hijackstdio[`restoreStd${type}`](); -}); + // throw an error + throw new Error(`console ${type} error`); + })); + + console[method]('test'); + hijackstdio[`restoreStd${type}`](); + }); -let uncaughtTimes = 0; -process.on('uncaughtException', common.mustCallAtLeast(function(e) { - assert.strictEqual(uncaughtTimes < 2, true); - assert.strictEqual(e instanceof Error, true); - assert.strictEqual( - e.message, - `console ${([ 'err', 'out' ])[uncaughtTimes++]} error`); -}, 2)); + let uncaughtTimes = 0; + process.on('uncaughtException', common.mustCallAtLeast(function(e) { + assert.strictEqual(uncaughtTimes < 2, true); + assert.strictEqual(e instanceof Error, true); + assert.strictEqual( + e.message, + `console ${(['err', 'out'])[uncaughtTimes++]} error`); + }, 2)); +} // End of "Must be last". |