Skip to content

Commit 58aaf58

Browse files
targosaddaleax
authored andcommitted
test: fix test-repl-require-after-write
Currently, the test creates a file in the cwd and doesn't clean it up. Use a temporary directory instead. PR-URL: #27088 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 3d8532f commit 58aaf58

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

test/parallel/test-repl-require-after-write.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
'use strict';
22

33
const common = require('../common');
4+
const tmpdir = require('../common/tmpdir');
45
const assert = require('assert');
5-
66
const spawn = require('child_process').spawn;
7+
const path = require('path');
8+
9+
tmpdir.refresh();
10+
11+
const requirePath = JSON.stringify(path.join(tmpdir.path, 'non-existent.json'));
12+
713
// Use -i to force node into interactive mode, despite stdout not being a TTY
814
const child = spawn(process.execPath, ['-i']);
915

1016
let out = '';
11-
const input = "try { require('./non-existent.json'); } catch {} " +
12-
"require('fs').writeFileSync('./non-existent.json', '1');" +
13-
"require('./non-existent.json');";
17+
const input = `try { require(${requirePath}); } catch {} ` +
18+
`require('fs').writeFileSync(${requirePath}, '1');` +
19+
`require(${requirePath});`;
1420

1521
child.stderr.on('data', common.mustNotCall());
1622

0 commit comments

Comments
 (0)