Skip to content

Commit

Permalink
fix: resolve symlinks for test context's path (#1079)
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 authored Dec 23, 2024
1 parent 2d508ab commit 6ea2d7b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/temp-directory.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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';

Expand All @@ -11,6 +11,10 @@ export async function create(context) {
} else {
context.path = join(tmpdir(), randomUUID());
}

await fs.mkdir(context.path, { recursive: true });
context.path = realpathSync(context.path);

context.emit(
'data',
'verbose',
Expand Down

0 comments on commit 6ea2d7b

Please sign in to comment.