Skip to content

Commit b4a0e7e

Browse files
committed
test: fix cp.exec-any-shells test on windows with wsl
WSL bash files (from WindowsApps and System32) either cannot be symlinked or don't work as expected from symlinks. This change detects WSL bash and: - Skips testing it if no WSL distro is installed. - Skips symlink tests for all WSL bash executables. Signed-off-by: Nad Alaba <37968805+nadalaba@users.noreply.github.com>
1 parent 02f4630 commit b4a0e7e

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

‎test/parallel/test-child-process-exec-any-shells-windows.js‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,23 @@ cp.exec('where bash', common.mustCall((error, stdout) => {
5959
return;
6060
}
6161
const lines = stdout.trim().split(/[\r\n]+/g);
62-
for (let i = 0; i < lines.length; ++i) {
63-
const bashPath = lines[i].trim();
64-
test(bashPath);
65-
testCopy(`bash_${i}.exe`, bashPath);
66-
}
62+
63+
cp.exec('wsl.exe -l -q', (err, out) => {
64+
const hasWSLDistro = !err && out.trim().length > 0;
65+
66+
for (let i = 0; i < lines.length; ++i) {
67+
const bashPath = lines[i].trim().replace(/^"+|"+$/g, '');
68+
const bashPathLower = bashPath.toLowerCase();
69+
70+
const isWSLBash =
71+
bashPathLower.includes('windowsapps') ||
72+
bashPathLower.includes('\\system32\\bash.exe');
73+
74+
// Skip WSL bash tests if no WSL distro is installed
75+
if (!isWSLBash || hasWSLDistro) test(bashPath);
76+
77+
// Skip symlink tests for WSL bash always
78+
if (!isWSLBash) testCopy(`bash_${i}.exe`, bashPath);
79+
}
80+
});
6781
}));

0 commit comments

Comments
 (0)