diff options
author | 木杉 <zhmushan@qq.com> | 2019-12-08 21:59:27 +0800 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2019-12-08 14:59:27 +0100 |
commit | 90c5aadbca8b47fc43bd3ece80e007b1b546c402 (patch) | |
tree | 6ecb65a3e213d1d7e08a264214b9b14e39a3fafe /std/installer/test.ts | |
parent | 50b6907bc332315eeb13c05bf687b990bc8dd936 (diff) |
fix(installer): installs to the wrong directory on Windows (#3462)
Close: #3443
Diffstat (limited to 'std/installer/test.ts')
-rw-r--r-- | std/installer/test.ts | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/std/installer/test.ts b/std/installer/test.ts index 3e6572485..371cbdfa0 100644 --- a/std/installer/test.ts +++ b/std/installer/test.ts @@ -42,8 +42,10 @@ function installerTest(t: TestFunction, useOriginHomeDir = false): void { const tempDir = await makeTempDir(); const envVars = env(); const originalHomeDir = envVars["HOME"]; + const originalUserProfile = envVars["USERPROFILE"]; if (!useOriginHomeDir) { envVars["HOME"] = tempDir; + envVars["USERPROFILE"] = tempDir; } try { @@ -54,6 +56,9 @@ function installerTest(t: TestFunction, useOriginHomeDir = false): void { if (originalHomeDir) { envVars["HOME"] = originalHomeDir; } + if (originalUserProfile) { + envVars["USERPROFILE"] = originalUserProfile; + } } }; @@ -400,6 +405,63 @@ installerTest(async function installAndMakesureArgsRight(): Promise<void> { assert(!thrown, "It should not throw an error"); }, true); // set true to install module in your real $HOME dir. +installerTest(async function installWithoutHOMEVar(): Promise<void> { + const { HOME } = env(); + env()["HOME"] = ""; + + await install( + "echo_test", + "http://localhost:4500/installer/testdata/echo.ts", + [] + ); + + env()["HOME"] = HOME; + + const filePath = path.resolve(HOME, ".deno/bin/echo_test"); + const fileInfo = await stat(filePath); + assert(fileInfo.isFile()); + + if (path.isWindows) { + assertEquals( + await fs.readFileStr(filePath + ".cmd"), + /* eslint-disable max-len */ + `% This executable is generated by Deno. Please don't modify it unless you know what it means. % +@IF EXIST "%~dp0\deno.exe" ( + "%~dp0\deno.exe" "run" "http://localhost:4500/installer/testdata/echo.ts" %* +) ELSE ( + @SETLOCAL + @SET PATHEXT=%PATHEXT:;.TS;=;% + "deno" "run" "http://localhost:4500/installer/testdata/echo.ts" %* +) +` + /* eslint-enable max-len */ + ); + } + + assertEquals( + await fs.readFileStr(filePath), + /* eslint-disable max-len */ + `#!/bin/sh +# This executable is generated by Deno. Please don't modify it unless you know what it means. +basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')") + +case \`uname\` in + *CYGWIN*) basedir=\`cygpath -w "$basedir"\`;; +esac + +if [ -x "$basedir/deno" ]; then + "$basedir/deno" "run" "http://localhost:4500/installer/testdata/echo.ts" "$@" + ret=$? +else + "deno" "run" "http://localhost:4500/installer/testdata/echo.ts" "$@" + ret=$? +fi +exit $ret +` + /* eslint-enable max-len */ + ); +}); + test(function testIsRemoteUrl(): void { assert(isRemoteUrl("https://deno.land/std/http/file_server.ts")); assert(isRemoteUrl("http://deno.land/std/http/file_server.ts")); |