|
23 | 23 | constcommon=require('../common'); |
24 | 24 | consthijackstdio=require('../common/hijackstdio'); |
25 | 25 | constfixtures=require('../common/fixtures'); |
| 26 | +consttmpdir=require('../common/tmpdir'); |
26 | 27 | constassert=require('assert'); |
27 | 28 | const{ execFile }=require('child_process'); |
| 29 | +const{ writeFileSync, existsSync }=require('fs'); |
| 30 | +const{ join }=require('path'); |
28 | 31 |
|
29 | 32 | // Test for leaked global detection |
30 | 33 | { |
@@ -124,25 +127,38 @@ const HIJACK_TEST_ARRAY = [ 'foo\n', 'bar\n', 'baz\n' ]; |
124 | 127 | assert.strictEqual(originalWrite,stream.write); |
125 | 128 | }); |
126 | 129 |
|
127 | | -// hijackStderr and hijackStdout again |
128 | | -// for console |
129 | | -[['err','error'],['out','log']].forEach(([type,method])=>{ |
130 | | -hijackstdio[`hijackStd${type}`](common.mustCall(function(data){ |
131 | | -assert.strictEqual(data,'test\n'); |
| 130 | +// Test `tmpdir`. |
| 131 | +{ |
| 132 | +tmpdir.refresh(); |
| 133 | +assert.ok(/\.tmp\.\d+/.test(tmpdir.path)); |
| 134 | +constsentinelPath=join(tmpdir.path,'gaga'); |
| 135 | +writeFileSync(sentinelPath,'googoo'); |
| 136 | +tmpdir.refresh(); |
| 137 | +assert.strictEqual(existsSync(tmpdir.path),true); |
| 138 | +assert.strictEqual(existsSync(sentinelPath),false); |
| 139 | +} |
132 | 140 |
|
133 | | -// throw an error |
134 | | -thrownewError(`console ${type} error`); |
135 | | -})); |
| 141 | +// hijackStderr and hijackStdout again for console |
| 142 | +// Must be last, since it uses `process.on('uncaughtException')` |
| 143 | +{ |
| 144 | +[['err','error'],['out','log']].forEach(([type,method])=>{ |
| 145 | +hijackstdio[`hijackStd${type}`](common.mustCall(function(data){ |
| 146 | +assert.strictEqual(data,'test\n'); |
136 | 147 |
|
137 | | -console[method]('test'); |
138 | | -hijackstdio[`restoreStd${type}`](); |
139 | | -}); |
| 148 | +// throw an error |
| 149 | +thrownewError(`console ${type} error`); |
| 150 | +})); |
| 151 | + |
| 152 | +console[method]('test'); |
| 153 | +hijackstdio[`restoreStd${type}`](); |
| 154 | +}); |
140 | 155 |
|
141 | | -letuncaughtTimes=0; |
142 | | -process.on('uncaughtException',common.mustCallAtLeast(function(e){ |
143 | | -assert.strictEqual(uncaughtTimes<2,true); |
144 | | -assert.strictEqual(einstanceofError,true); |
145 | | -assert.strictEqual( |
146 | | -e.message, |
147 | | -`console ${(['err','out'])[uncaughtTimes++]} error`); |
148 | | -},2)); |
| 156 | +letuncaughtTimes=0; |
| 157 | +process.on('uncaughtException',common.mustCallAtLeast(function(e){ |
| 158 | +assert.strictEqual(uncaughtTimes<2,true); |
| 159 | +assert.strictEqual(einstanceofError,true); |
| 160 | +assert.strictEqual( |
| 161 | +e.message, |
| 162 | +`console ${(['err','out'])[uncaughtTimes++]} error`); |
| 163 | +},2)); |
| 164 | +}// End of "Must be last". |
0 commit comments