Skip to content

Commit

Permalink
fix: resolve symlinks for test context's path
Browse files Browse the repository at this point in the history
On macOS, `os.tmpdir()` returns a path that contains a symbolic link.
This can cause issues with modules that expect the environment to only
contain real paths. For example, the `resolve` module uses the HOME env
variable, which is derived from the context's path.
  • Loading branch information
targos committed Dec 21, 2024
1 parent 75d09b0 commit 045d7fe
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/temp-directory.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { join } from 'path';
import { promises as fs } from 'fs';
import { promises as fs, realpathSync } from 'fs';
import { randomUUID } from 'crypto';
import { tmpdir } from 'os';

import { removeDirectory } from './utils.js';

export async function create(context) {
if (context.options && context.options.tmpDir) {
context.path = join(context.options.tmpDir, randomUUID());
context.path = join(realpathSync(context.options.tmpDir), randomUUID());
} else {
context.path = join(tmpdir(), randomUUID());
context.path = join(realpathSync(tmpdir()), randomUUID());
}
context.emit(
'data',
Expand Down

0 comments on commit 045d7fe

Please sign in to comment.