Skip to content

Commit

Permalink
test: use tmpdir.resolve()
Browse files Browse the repository at this point in the history
PR-URL: nodejs#49128
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
  • Loading branch information
LiviaMedeiros authored and rluvaton committed Aug 15, 2023
1 parent e175ce5 commit 54263b8
Show file tree
Hide file tree
Showing 52 changed files with 119 additions and 151 deletions.
3 changes: 1 addition & 2 deletions test/parallel/test-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ 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
{
Expand Down Expand Up @@ -134,7 +133,7 @@ const HIJACK_TEST_ARRAY = [ 'foo\n', 'bar\n', 'baz\n' ];
{
tmpdir.refresh();
assert.match(tmpdir.path, /\.tmp\.\d+/);
const sentinelPath = join(tmpdir.path, 'gaga');
const sentinelPath = tmpdir.resolve('gaga');
writeFileSync(sentinelPath, 'googoo');
tmpdir.refresh();
assert.strictEqual(existsSync(tmpdir.path), true);
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-debugger-heap-profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const tmpdir = require('../common/tmpdir');
const path = require('path');

tmpdir.refresh();

const { readFileSync } = require('fs');

const filename = path.join(tmpdir.path, 'node.heapsnapshot');
const filename = tmpdir.resolve('node.heapsnapshot');

// Heap profiler take snapshot.
{
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-file-write-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
const common = require('../common');
const assert = require('assert');

const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
const fn = path.join(tmpdir.path, 'write.txt');
const fn = tmpdir.resolve('write.txt');
tmpdir.refresh();
const file = fs.createWriteStream(fn, {
highWaterMark: 10
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-file-write-stream2.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@
require('../common');
const assert = require('assert');

const path = require('path');
const fs = require('fs');

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


const filepath = path.join(tmpdir.path, 'write.txt');
const filepath = tmpdir.resolve('write.txt');

const EXPECTED = '012345678910';

Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-file-write-stream3.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');

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


const filepath = path.join(tmpdir.path, 'write_pos.txt');
const filepath = tmpdir.resolve('write_pos.txt');


const cb_expected = 'write open close write open close write open close ';
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-file-write-stream4.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
// Refs: https://github.com/nodejs/node/issues/31366

const common = require('../common');
const path = require('path');
const fs = require('fs');

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

const filepath = path.join(tmpdir.path, 'write_pos.txt');
const filepath = tmpdir.resolve('write_pos.txt');

const fileReadStream = fs.createReadStream(process.execPath);
const fileWriteStream = fs.createWriteStream(filepath, {
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-heap-prof-dir-absolute.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ common.skipIfInspectorDisabled();

const assert = require('assert');
const fs = require('fs');
const path = require('path');
const { spawnSync } = require('child_process');

const tmpdir = require('../common/tmpdir');
Expand All @@ -24,7 +23,7 @@ const {
// Tests absolute --heap-prof-dir
{
tmpdir.refresh();
const dir = path.join(tmpdir.path, 'prof');
const dir = tmpdir.resolve('prof');
const output = spawnSync(process.execPath, [
'--heap-prof',
'--heap-prof-dir',
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-heap-prof-dir-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const {

{
tmpdir.refresh();
const dir = path.join(tmpdir.path, 'prof');
const dir = tmpdir.resolve('prof');
const file = path.join(dir, 'test.heapprofile');
const output = spawnSync(process.execPath, [
'--heap-prof',
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-heap-prof-dir-relative.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ common.skipIfInspectorDisabled();

const assert = require('assert');
const fs = require('fs');
const path = require('path');
const { spawnSync } = require('child_process');

const tmpdir = require('../common/tmpdir');
Expand Down Expand Up @@ -38,7 +37,7 @@ const {
console.log(output.stderr.toString());
}
assert.strictEqual(output.status, 0);
const dir = path.join(tmpdir.path, 'prof');
const dir = tmpdir.resolve('prof');
assert(fs.existsSync(dir));
const profiles = getHeapProfiles(dir);
assert.strictEqual(profiles.length, 1);
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-heap-prof-interval.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ common.skipIfInspectorDisabled();

const assert = require('assert');
const fs = require('fs');
const path = require('path');
const { spawnSync } = require('child_process');

const tmpdir = require('../common/tmpdir');
Expand Down Expand Up @@ -38,7 +37,7 @@ const {
console.log(output.stderr.toString());
}
assert.strictEqual(output.status, 0);
const dir = path.join(tmpdir.path, 'prof');
const dir = tmpdir.resolve('prof');
assert(fs.existsSync(dir));
const profiles = getHeapProfiles(dir);
assert.strictEqual(profiles.length, 2);
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-heap-prof-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const fixtures = require('../common/fixtures');
common.skipIfInspectorDisabled();

const assert = require('assert');
const path = require('path');
const { spawnSync } = require('child_process');

const tmpdir = require('../common/tmpdir');
Expand All @@ -22,7 +21,7 @@ const {

{
tmpdir.refresh();
const file = path.join(tmpdir.path, 'test.heapprofile');
const file = tmpdir.resolve('test.heapprofile');
const output = spawnSync(process.execPath, [
'--heap-prof',
'--heap-prof-name',
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-internal-fs-syncwritestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const SyncWriteStream = require('internal/fs/sync_write_stream');

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

const filename = path.join(tmpdir.path, 'sync-write-stream.txt');
const filename = tmpdir.resolve('sync-write-stream.txt');

// Verify constructing the instance with default options.
{
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-macos-app-sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const nodeBinary = process.execPath;

tmpdir.refresh();

const appBundlePath = path.join(tmpdir.path, 'node_sandboxed.app');
const appBundlePath = tmpdir.resolve('node_sandboxed.app');
const appBundleContentPath = path.join(appBundlePath, 'Contents');
const appExecutablePath = path.join(
appBundleContentPath, 'MacOS', 'node');
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-module-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

const filePath = path.join(tmpdir.path, 'test-module-cache.json');
const filePath = tmpdir.resolve('test-module-cache.json');
assert.throws(
() => require(filePath),
{ code: 'MODULE_NOT_FOUND' }
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-module-loading-globalpaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if (process.argv[2] === 'child') {
tmpdir.refresh();

// Copy node binary into a test $PREFIX directory.
const prefixPath = path.join(tmpdir.path, 'install');
const prefixPath = tmpdir.resolve('install');
fs.mkdirSync(prefixPath);
let testExecPath;
if (common.isWindows) {
Expand Down Expand Up @@ -46,7 +46,7 @@ if (process.argv[2] === 'child') {
delete env.NODE_PATH;

// Test empty global path.
const noPkgHomeDir = path.join(tmpdir.path, 'home-no-pkg');
const noPkgHomeDir = tmpdir.resolve('home-no-pkg');
fs.mkdirSync(noPkgHomeDir);
env.HOME = env.USERPROFILE = noPkgHomeDir;
assert.throws(
Expand Down
17 changes: 8 additions & 9 deletions test/parallel/test-module-multi-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const Module = require('module');
const tmpdir = require('../common/tmpdir');
const file = path.join(tmpdir.path, 'test-extensions.foo.bar');
const dotfile = path.join(tmpdir.path, '.bar');
const dotfileWithExtension = path.join(tmpdir.path, '.foo.bar');
const file = tmpdir.resolve('test-extensions.foo.bar');
const dotfile = tmpdir.resolve('.bar');
const dotfileWithExtension = tmpdir.resolve('.foo.bar');

tmpdir.refresh();
fs.writeFileSync(file, 'console.log(__filename);', 'utf8');
Expand All @@ -20,7 +19,7 @@ fs.writeFileSync(dotfileWithExtension, 'console.log(__filename);', 'utf8');
{
require.extensions['.bar'] = common.mustNotCall();
require.extensions['.foo.bar'] = common.mustCall();
const modulePath = path.join(tmpdir.path, 'test-extensions');
const modulePath = tmpdir.resolve('test-extensions');
require(modulePath);
require(file);
delete require.cache[file];
Expand All @@ -31,7 +30,7 @@ fs.writeFileSync(dotfileWithExtension, 'console.log(__filename);', 'utf8');

{
require.extensions['.foo.bar'] = common.mustCall();
const modulePath = path.join(tmpdir.path, 'test-extensions');
const modulePath = tmpdir.resolve('test-extensions');
require(modulePath);
assert.throws(
() => require(`${modulePath}.foo`),
Expand All @@ -44,7 +43,7 @@ fs.writeFileSync(dotfileWithExtension, 'console.log(__filename);', 'utf8');
}

{
const modulePath = path.join(tmpdir.path, 'test-extensions');
const modulePath = tmpdir.resolve('test-extensions');
assert.throws(
() => require(modulePath),
(err) => err.message.startsWith(`Cannot find module '${modulePath}'`)
Expand All @@ -56,7 +55,7 @@ fs.writeFileSync(dotfileWithExtension, 'console.log(__filename);', 'utf8');
{
require.extensions['.bar'] = common.mustNotCall();
require.extensions['.foo.bar'] = common.mustCall();
const modulePath = path.join(tmpdir.path, 'test-extensions.foo');
const modulePath = tmpdir.resolve('test-extensions.foo');
require(modulePath);
delete require.cache[file];
delete require.extensions['.bar'];
Expand All @@ -66,7 +65,7 @@ fs.writeFileSync(dotfileWithExtension, 'console.log(__filename);', 'utf8');

{
require.extensions['.foo.bar'] = common.mustNotCall();
const modulePath = path.join(tmpdir.path, 'test-extensions.foo');
const modulePath = tmpdir.resolve('test-extensions.foo');
assert.throws(
() => require(modulePath),
(err) => err.message.startsWith(`Cannot find module '${modulePath}'`)
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-module-readonly.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

// Create readOnlyMod.js and set to read only
const readOnlyMod = path.join(tmpdir.path, 'readOnlyMod');
const readOnlyMod = tmpdir.resolve('readOnlyMod');
const readOnlyModRelative = path.relative(__dirname, readOnlyMod);
const readOnlyModFullPath = `${readOnlyMod}.js`;

Expand Down
7 changes: 3 additions & 4 deletions test/parallel/test-module-stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ const Module = require('module');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
const { ok, strictEqual } = require('assert');
const { join } = require('path');

const directory = join(tmpdir.path, 'directory');
const doesNotExist = join(tmpdir.path, 'does-not-exist');
const file = join(tmpdir.path, 'file.js');
const directory = tmpdir.resolve('directory');
const doesNotExist = tmpdir.resolve('does-not-exist');
const file = tmpdir.resolve('file.js');

tmpdir.refresh();
fs.writeFileSync(file, "module.exports = { a: 'b' }");
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-npm-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ const fixtures = require('../common/fixtures');

const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const npmSandbox = path.join(tmpdir.path, 'npm-sandbox');
const npmSandbox = tmpdir.resolve('npm-sandbox');
fs.mkdirSync(npmSandbox);
const homeDir = path.join(tmpdir.path, 'home');
const homeDir = tmpdir.resolve('home');
fs.mkdirSync(homeDir);
const installDir = path.join(tmpdir.path, 'install-dir');
const installDir = tmpdir.resolve('install-dir');
fs.mkdirSync(installDir);

const npmPath = path.join(
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-permission-fs-symlink-target-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const { spawnSync } = require('child_process');
tmpdir.refresh();
}

const readOnlyFolder = path.join(tmpdir.path, 'read-only');
const readWriteFolder = path.join(tmpdir.path, 'read-write');
const writeOnlyFolder = path.join(tmpdir.path, 'write-only');
const readOnlyFolder = tmpdir.resolve('read-only');
const readWriteFolder = tmpdir.resolve('read-write');
const writeOnlyFolder = tmpdir.resolve('write-only');
const file = fixtures.path('permission', 'fs-symlink-target-write.js');
const commonPathWildcard = path.join(__filename, '../../common*');

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-permission-fs-symlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const tmpdir = require('../common/tmpdir');
const file = fixtures.path('permission', 'fs-symlink.js');
const commonPathWildcard = path.join(__filename, '../../common*');
const blockedFile = fixtures.path('permission', 'deny', 'protected-file.md');
const blockedFolder = path.join(tmpdir.path, 'subdirectory');
const symlinkFromBlockedFile = path.join(tmpdir.path, 'example-symlink.md');
const blockedFolder = tmpdir.resolve('subdirectory');
const symlinkFromBlockedFile = tmpdir.resolve('example-symlink.md');

{
tmpdir.refresh();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-permission-fs-traversal-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const tmpdir = require('../common/tmpdir');

const file = fixtures.path('permission', 'fs-traversal.js');
const blockedFolder = tmpdir.path;
const allowedFolder = path.join(tmpdir.path, 'subdirectory/');
const allowedFolder = tmpdir.resolve('subdirectory/');
const commonPathWildcard = path.join(__filename, '../../common*');

{
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-pipe-file-to-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const http = require('http');
const path = require('path');

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

const filename = path.join(tmpdir.path, 'big');
const filename = tmpdir.resolve('big');
let count = 0;

const server = http.createServer((req, res) => {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-policy-parse-integrity.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function hash(algo, body) {
return h.digest('base64');
}

const tmpdirPath = path.join(tmpdir.path, 'test-policy-parse-integrity');
const tmpdirPath = tmpdir.resolve('test-policy-parse-integrity');
fs.rmSync(tmpdirPath, { maxRetries: 3, recursive: true, force: true });
fs.mkdirSync(tmpdirPath, { recursive: true });

Expand Down
5 changes: 2 additions & 3 deletions test/parallel/test-preload-print-process-argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ require('../common');

const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const { join } = require('path');
const { spawnSync } = require('child_process');
const fs = require('fs');

tmpdir.refresh();

fs.writeFileSync(
join(tmpdir.path, 'preload.js'),
tmpdir.resolve('preload.js'),
'console.log(JSON.stringify(process.argv));',
'utf-8');

fs.writeFileSync(
join(tmpdir.path, 'main.js'),
tmpdir.resolve('main.js'),
'console.log(JSON.stringify(process.argv));',
'utf-8');

Expand Down
Loading

0 comments on commit 54263b8

Please sign in to comment.