From 6ea2d7b3fcccba3473ec4936682b2c79046be7f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Mon, 23 Dec 2024 09:41:49 +0100 Subject: [PATCH] fix: resolve symlinks for test context's path (#1079) 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. --- lib/temp-directory.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/temp-directory.js b/lib/temp-directory.js index 6b00490d..84e60331 100644 --- a/lib/temp-directory.js +++ b/lib/temp-directory.js @@ -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'; @@ -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',