Skip to content

Commit

Permalink
test: use tmpdir.resolve()
Browse files Browse the repository at this point in the history
PR-URL: #49136
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
LiviaMedeiros authored and UlisesGascon committed Sep 10, 2023
1 parent 1704f24 commit e391f4b
Show file tree
Hide file tree
Showing 49 changed files with 97 additions and 118 deletions.
2 changes: 1 addition & 1 deletion test/addons/symlinked-module/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const tmpdir = require('../../common/tmpdir');
tmpdir.refresh();

const addonPath = path.join(__dirname, 'build', common.buildType);
const addonLink = path.join(tmpdir.path, 'addon');
const addonLink = tmpdir.resolve('addon');

try {
fs.symlinkSync(addonPath, addonLink, 'dir');
Expand Down
5 changes: 2 additions & 3 deletions test/async-hooks/test-statwatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ const assert = require('assert');
const initHooks = require('./init-hooks');
const { checkInvocations } = require('./hook-checks');
const fs = require('fs');
const path = require('path');

if (!common.isMainThread)
common.skip('Worker bootstrapping works differently -> different async IDs');

tmpdir.refresh();

const file1 = path.join(tmpdir.path, 'file1');
const file2 = path.join(tmpdir.path, 'file2');
const file1 = tmpdir.resolve('file1');
const file2 = tmpdir.resolve('file2');

const onchangex = (x) => (curr, prev) => {
console.log(`Watcher: ${x}`);
Expand Down
7 changes: 3 additions & 4 deletions test/common/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

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

function buildSnapshot(entry, env) {
const child = spawnSync(process.execPath, [
'--snapshot-blob',
path.join(tmpdir.path, 'snapshot.blob'),
tmpdir.resolve('snapshot.blob'),
'--build-snapshot',
entry,
], {
Expand All @@ -29,14 +28,14 @@ function buildSnapshot(entry, env) {

assert.strictEqual(child.status, 0);

const stats = fs.statSync(path.join(tmpdir.path, 'snapshot.blob'));
const stats = fs.statSync(tmpdir.resolve('snapshot.blob'));
assert(stats.isFile());

return { child, stderr, stdout };
}

function runWithSnapshot(entry, env) {
const args = ['--snapshot-blob', path.join(tmpdir.path, 'snapshot.blob')];
const args = ['--snapshot-blob', tmpdir.resolve('snapshot.blob')];
if (entry !== undefined) {
args.push(entry);
}
Expand Down
2 changes: 1 addition & 1 deletion test/doctool/test-apilinks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fs.readdirSync(apilinks).forEach((fixture) => {
const input = path.join(apilinks, fixture);

const expectedContent = fs.readFileSync(`${input}on`, 'utf8');
const outputPath = path.join(tmpdir.path, `${fixture}on`);
const outputPath = tmpdir.resolve(`${fixture}on`);
execFileSync(
process.execPath,
[script, outputPath, input],
Expand Down
3 changes: 1 addition & 2 deletions test/doctool/test-doctool-versions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import tmpdir from '../common/tmpdir.js';
import assert from 'assert';
import { spawnSync } from 'child_process';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import util from 'util';

Expand All @@ -29,7 +28,7 @@ const expected = [
];

tmpdir.refresh();
const versionsFile = path.join(tmpdir.path, 'versions.json');
const versionsFile = tmpdir.resolve('versions.json');
debuglog(`${process.execPath} ${versionsTool} ${versionsFile}`);
const opts = { cwd: tmpdir.path, encoding: 'utf8' };
const cp = spawnSync(process.execPath, [ versionsTool, versionsFile ], opts);
Expand Down
4 changes: 2 additions & 2 deletions test/embedding/test-embedding.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function getReadFileCodeForPath(path) {
for (const extraSnapshotArgs of [[], ['--embedder-snapshot-as-file']]) {
// readSync + eval since snapshots don't support userland require() (yet)
const snapshotFixture = fixtures.path('snapshot', 'echo-args.js');
const blobPath = path.join(tmpdir.path, 'embedder-snapshot.blob');
const blobPath = tmpdir.resolve('embedder-snapshot.blob');
const buildSnapshotArgs = [
`eval(${getReadFileCodeForPath(snapshotFixture)})`, 'arg1', 'arg2',
'--embedder-snapshot-blob', blobPath, '--embedder-snapshot-create',
Expand Down Expand Up @@ -94,7 +94,7 @@ for (const extraSnapshotArgs of [[], ['--embedder-snapshot-as-file']]) {
// Create workers and vm contexts after deserialization
{
const snapshotFixture = fixtures.path('snapshot', 'create-worker-and-vm.js');
const blobPath = path.join(tmpdir.path, 'embedder-snapshot.blob');
const blobPath = tmpdir.resolve('embedder-snapshot.blob');
const buildSnapshotArgs = [
`eval(${getReadFileCodeForPath(snapshotFixture)})`,
'--embedder-snapshot-blob', blobPath, '--embedder-snapshot-create',
Expand Down
12 changes: 6 additions & 6 deletions test/es-module/test-esm-extension-lookup-deprecation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('ESM in main field', { concurrency: true }, () => {
before(() => tmpdir.refresh());

it('should handle fully-specified relative path without any warning', async () => {
const cwd = path.join(tmpdir.path, Math.random().toString());
const cwd = tmpdir.resolve(Math.random().toString());
const pkgPath = path.join(cwd, './node_modules/pkg/');
await mkdir(pkgPath, { recursive: true });
await writeFile(path.join(pkgPath, './index.js'), 'console.log("Hello World!")');
Expand All @@ -29,7 +29,7 @@ describe('ESM in main field', { concurrency: true }, () => {
assert.strictEqual(code, 0);
});
it('should handle fully-specified absolute path without any warning', async () => {
const cwd = path.join(tmpdir.path, Math.random().toString());
const cwd = tmpdir.resolve(Math.random().toString());
const pkgPath = path.join(cwd, './node_modules/pkg/');
await mkdir(pkgPath, { recursive: true });
await writeFile(path.join(pkgPath, './index.js'), 'console.log("Hello World!")');
Expand All @@ -48,7 +48,7 @@ describe('ESM in main field', { concurrency: true }, () => {
});

it('should emit warning when "main" and "exports" are missing', async () => {
const cwd = path.join(tmpdir.path, Math.random().toString());
const cwd = tmpdir.resolve(Math.random().toString());
const pkgPath = path.join(cwd, './node_modules/pkg/');
await mkdir(pkgPath, { recursive: true });
await writeFile(path.join(pkgPath, './index.js'), 'console.log("Hello World!")');
Expand All @@ -65,7 +65,7 @@ describe('ESM in main field', { concurrency: true }, () => {
assert.strictEqual(code, 0);
});
it('should emit warning when "main" is falsy', async () => {
const cwd = path.join(tmpdir.path, Math.random().toString());
const cwd = tmpdir.resolve(Math.random().toString());
const pkgPath = path.join(cwd, './node_modules/pkg/');
await mkdir(pkgPath, { recursive: true });
await writeFile(path.join(pkgPath, './index.js'), 'console.log("Hello World!")');
Expand All @@ -83,7 +83,7 @@ describe('ESM in main field', { concurrency: true }, () => {
assert.strictEqual(code, 0);
});
it('should emit warning when "main" is a relative path without extension', async () => {
const cwd = path.join(tmpdir.path, Math.random().toString());
const cwd = tmpdir.resolve(Math.random().toString());
const pkgPath = path.join(cwd, './node_modules/pkg/');
await mkdir(pkgPath, { recursive: true });
await writeFile(path.join(pkgPath, './index.js'), 'console.log("Hello World!")');
Expand All @@ -101,7 +101,7 @@ describe('ESM in main field', { concurrency: true }, () => {
assert.strictEqual(code, 0);
});
it('should emit warning when "main" is an absolute path without extension', async () => {
const cwd = path.join(tmpdir.path, Math.random().toString());
const cwd = tmpdir.resolve(Math.random().toString());
const pkgPath = path.join(cwd, './node_modules/pkg/');
await mkdir(pkgPath, { recursive: true });
await writeFile(path.join(pkgPath, './index.js'), 'console.log("Hello World!")');
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-resolve-type.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const {
defaultResolve: resolve
} = internalResolve;

const rel = (file) => path.join(tmpdir.path, file);
const rel = (file) => tmpdir.resolve(file);
const previousCwd = process.cwd();
const nmDir = rel('node_modules');

Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-symlink-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const fs = require('fs');
tmpdir.refresh();

const realPath = path.resolve(__dirname, '../fixtures/es-modules/symlink.mjs');
const symlinkPath = path.resolve(tmpdir.path, 'symlink.mjs');
const symlinkPath = tmpdir.resolve('symlink.mjs');

try {
fs.symlinkSync(realPath, symlinkPath);
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const imp = (file) => {

(async () => {
tmpdir.refresh();
const rel = (file) => path.join(tmpdir.path, file);
const rel = (file) => tmpdir.resolve(file);

{ // Load a single script
const file = rel('con.mjs');
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/test-runner/concurrency/a.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { setTimeout } from 'node:timers/promises';
import fs from 'node:fs/promises';
import path from 'node:path';

await fs.writeFile(path.resolve(tmpdir.path, 'test-runner-concurrency'), 'a.mjs');
await fs.writeFile(tmpdir.resolve('test-runner-concurrency'), 'a.mjs');
while (true) {
const file = await fs.readFile(path.resolve(tmpdir.path, 'test-runner-concurrency'), 'utf8');
const file = await fs.readFile(tmpdir.resolve('test-runner-concurrency'), 'utf8');
if (file === 'b.mjs') {
break;
}
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/test-runner/concurrency/b.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import fs from 'node:fs/promises';
import path from 'node:path';

while (true) {
const file = await fs.readFile(path.resolve(tmpdir.path, 'test-runner-concurrency'), 'utf8');
const file = await fs.readFile(tmpdir.resolve('test-runner-concurrency'), 'utf8');
if (file === 'a.mjs') {
await fs.writeFile(path.resolve(tmpdir.path, 'test-runner-concurrency'), 'b.mjs');
await fs.writeFile(tmpdir.resolve('test-runner-concurrency'), 'b.mjs');
break;
}
await setTimeout(10);
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/watch-mode/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const url = require('node:url');
const fs = require('node:fs');
const tmpdir = require('../../common/tmpdir');

const tmpfile = path.join(tmpdir.path, 'file');
const tmpfile = tmpdir.resolve('file');
fs.writeFileSync(tmpfile, '');

process.send({ 'watch:require': [path.resolve(__filename)] });
Expand Down
6 changes: 3 additions & 3 deletions test/internet/test-corepack-yarn-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 corepackYarnPath = path.join(
Expand Down
3 changes: 1 addition & 2 deletions test/internet/test-trace-events-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
const path = require('path');
const tmpdir = require('../common/tmpdir');
const fs = require('fs');
const util = require('util');
Expand Down Expand Up @@ -57,7 +56,7 @@ for (const tr in tests) {
throw new Error(`${tr}:\n${util.inspect(proc)}`);
}

const file = path.join(tmpdir.path, traceFile);
const file = tmpdir.resolve(traceFile);

const data = fs.readFileSync(file);
const traces = JSON.parse(data.toString()).traceEvents
Expand Down
2 changes: 1 addition & 1 deletion test/node-api/test_general/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tmpdir.refresh();
}

{
const urlTestDir = path.join(tmpdir.path, 'foo%#bar');
const urlTestDir = tmpdir.resolve('foo%#bar');
const urlTestFile = path.join(urlTestDir, path.basename(filename));
fs.mkdirSync(urlTestDir, { recursive: true });
fs.copyFileSync(filename, urlTestFile);
Expand Down
3 changes: 1 addition & 2 deletions test/node-api/test_policy/test_policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const tmpdir = require('../../common/tmpdir');
const { spawnSync } = require('child_process');
const crypto = require('crypto');
const fs = require('fs');
const path = require('path');
const { pathToFileURL } = require('url');

tmpdir.refresh();
Expand All @@ -19,7 +18,7 @@ function hash(algo, body) {
return h.digest('base64');
}

const policyFilepath = path.join(tmpdir.path, 'policy');
const policyFilepath = tmpdir.resolve('policy');

const depFilepath = require.resolve(`./build/${common.buildType}/binding.node`);
const depURL = pathToFileURL(depFilepath);
Expand Down
3 changes: 1 addition & 2 deletions test/pummel/test-fs-largefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ const common = require('../common');

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

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

try {

const filepath = path.join(tmpdir.path, 'large.txt');
const filepath = tmpdir.resolve('large.txt');
const fd = fs.openSync(filepath, 'w+');
const offset = 5 * 1024 * 1024 * 1024; // 5GB
const message = 'Large File';
Expand Down
3 changes: 1 addition & 2 deletions test/pummel/test-fs-readfile-tostring-fail.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ if (!common.enoughTestMem)

const assert = require('assert');
const fs = require('fs');
const path = require('path');
const cp = require('child_process');
const kStringMaxLength = require('buffer').constants.MAX_STRING_LENGTH;
if (common.isAIX && (Number(cp.execSync('ulimit -f')) * 512) < kStringMaxLength)
Expand All @@ -20,7 +19,7 @@ if (!tmpdir.hasEnoughSpace(kStringMaxLength)) {
common.skip(`Not enough space in ${tmpdir.path}`);
}

const file = path.join(tmpdir.path, 'toobig.txt');
const file = tmpdir.resolve('toobig.txt');
const stream = fs.createWriteStream(file, {
flags: 'a',
});
Expand Down
3 changes: 1 addition & 2 deletions test/pummel/test-fs-watch-file-slow.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
'use strict';
require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');

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

tmpdir.refresh();
const FILENAME = path.join(tmpdir.path, 'watch-me');
const FILENAME = tmpdir.resolve('watch-me');
const TIMEOUT = 1300;

let nevents = 0;
Expand Down
2 changes: 1 addition & 1 deletion test/pummel/test-policy-integrity-dep.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function drainQueue() {
assert.notStrictEqual(status, 0, 'Should not allow multiple policies');
}
{
const enoentFilepath = path.join(tmpdir.path, 'enoent');
const enoentFilepath = tmpdir.resolve('enoent');
try {
fs.unlinkSync(enoentFilepath);
} catch {
Expand Down
2 changes: 1 addition & 1 deletion test/pummel/test-policy-integrity-parent-commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function drainQueue() {
assert.notStrictEqual(status, 0, 'Should not allow multiple policies');
}
{
const enoentFilepath = path.join(tmpdir.path, 'enoent');
const enoentFilepath = tmpdir.resolve('enoent');
try {
fs.unlinkSync(enoentFilepath);
} catch {
Expand Down
2 changes: 1 addition & 1 deletion test/pummel/test-policy-integrity-parent-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function drainQueue() {
assert.notStrictEqual(status, 0, 'Should not allow multiple policies');
}
{
const enoentFilepath = path.join(tmpdir.path, 'enoent');
const enoentFilepath = tmpdir.resolve('enoent');
try {
fs.unlinkSync(enoentFilepath);
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function drainQueue() {
assert.notStrictEqual(status, 0, 'Should not allow multiple policies');
}
{
const enoentFilepath = path.join(tmpdir.path, 'enoent');
const enoentFilepath = tmpdir.resolve('enoent');
try {
fs.unlinkSync(enoentFilepath);
} catch {
Expand Down
2 changes: 1 addition & 1 deletion test/pummel/test-policy-integrity-worker-commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function drainQueue() {
assert.notStrictEqual(status, 0, 'Should not allow multiple policies');
}
{
const enoentFilepath = path.join(tmpdir.path, 'enoent');
const enoentFilepath = tmpdir.resolve('enoent');
try {
fs.unlinkSync(enoentFilepath);
} catch {
Expand Down
2 changes: 1 addition & 1 deletion test/pummel/test-policy-integrity-worker-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function drainQueue() {
assert.notStrictEqual(status, 0, 'Should not allow multiple policies');
}
{
const enoentFilepath = path.join(tmpdir.path, 'enoent');
const enoentFilepath = tmpdir.resolve('enoent');
try {
fs.unlinkSync(enoentFilepath);
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function drainQueue() {
assert.notStrictEqual(status, 0, 'Should not allow multiple policies');
}
{
const enoentFilepath = path.join(tmpdir.path, 'enoent');
const enoentFilepath = tmpdir.resolve('enoent');
try {
fs.unlinkSync(enoentFilepath);
} catch {
Expand Down
3 changes: 1 addition & 2 deletions test/pummel/test-watch-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir');

tmpdir.refresh();
const f = path.join(tmpdir.path, 'x.txt');
const f = tmpdir.resolve('x.txt');
fs.closeSync(fs.openSync(f, 'w'));

let changes = 0;
Expand Down
Loading

0 comments on commit e391f4b

Please sign in to comment.