Skip to content

Commit

Permalink
test: fix test-repl-require-after-write
Browse files Browse the repository at this point in the history
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 <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
targos authored and addaleax committed Apr 6, 2019
1 parent 3d8532f commit 58aaf58
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions test/parallel/test-repl-require-after-write.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
'use strict';

const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');

const spawn = require('child_process').spawn;
const path = require('path');

tmpdir.refresh();

const requirePath = JSON.stringify(path.join(tmpdir.path, 'non-existent.json'));

// Use -i to force node into interactive mode, despite stdout not being a TTY
const child = spawn(process.execPath, ['-i']);

let out = '';
const input = "try { require('./non-existent.json'); } catch {} " +
"require('fs').writeFileSync('./non-existent.json', '1');" +
"require('./non-existent.json');";
const input = `try { require(${requirePath}); } catch {} ` +
`require('fs').writeFileSync(${requirePath}, '1');` +
`require(${requirePath});`;

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

Expand Down

0 comments on commit 58aaf58

Please sign in to comment.