summaryrefslogtreecommitdiff
path: root/installer/test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'installer/test.ts')
-rw-r--r--installer/test.ts90
1 files changed, 71 insertions, 19 deletions
diff --git a/installer/test.ts b/installer/test.ts
index 1b1aa4200..d28a9d448 100644
--- a/installer/test.ts
+++ b/installer/test.ts
@@ -1,5 +1,5 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-const { readFile, run, stat, makeTempDir, remove, env } = Deno;
+const { run, stat, makeTempDir, remove, env } = Deno;
import { test, runIfMain, TestFunction } from "../testing/mod.ts";
import { assert, assertEquals, assertThrowsAsync } from "../testing/asserts.ts";
@@ -7,8 +7,10 @@ import { BufReader, EOF } from "../io/bufio.ts";
import { TextProtoReader } from "../textproto/mod.ts";
import { install, uninstall } from "./mod.ts";
import * as path from "../fs/path.ts";
+import * as fs from "../fs/mod.ts";
let fileServer: Deno.Process;
+const isWindows = Deno.platform.os === "win";
// copied from `http/file_server_test.ts`
async function startFileServer(): Promise<void> {
@@ -63,11 +65,40 @@ installerTest(async function installBasic(): Promise<void> {
const fileInfo = await stat(filePath);
assert(fileInfo.isFile());
- const fileBytes = await readFile(filePath);
- const fileContents = new TextDecoder().decode(fileBytes);
+ if (isWindows) {
+ assertEquals(
+ await fs.readFileStr(filePath + ".cmd"),
+ `% 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/http/file_server.ts %*
+) ELSE (
+ @SETLOCAL
+ @SET PATHEXT=%PATHEXT:;.TS;=;%
+ deno run http://localhost:4500/http/file_server.ts %*
+)
+`
+ );
+ }
+
assertEquals(
- fileContents,
- "#/bin/sh\ndeno http://localhost:4500/http/file_server.ts $@"
+ await fs.readFileStr(filePath),
+ `#/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/http/file_server.ts "$@"
+ ret=$?
+else
+ deno run http://localhost:4500/http/file_server.ts "$@"
+ ret=$?
+fi
+exit $ret
+`
);
});
@@ -81,11 +112,40 @@ installerTest(async function installWithFlags(): Promise<void> {
const { HOME } = env();
const filePath = path.resolve(HOME, ".deno/bin/file_server");
- const fileBytes = await readFile(filePath);
- const fileContents = new TextDecoder().decode(fileBytes);
+ if (isWindows) {
+ assertEquals(
+ await fs.readFileStr(filePath + ".cmd"),
+ `% 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 --allow-net --allow-read http://localhost:4500/http/file_server.ts --foobar %*
+) ELSE (
+ @SETLOCAL
+ @SET PATHEXT=%PATHEXT:;.TS;=;%
+ deno run --allow-net --allow-read http://localhost:4500/http/file_server.ts --foobar %*
+)
+`
+ );
+ }
+
assertEquals(
- fileContents,
- "#/bin/sh\ndeno --allow-net --allow-read http://localhost:4500/http/file_server.ts --foobar $@"
+ await fs.readFileStr(filePath),
+ `#/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 --allow-net --allow-read http://localhost:4500/http/file_server.ts --foobar "$@"
+ ret=$?
+else
+ deno run --allow-net --allow-read http://localhost:4500/http/file_server.ts --foobar "$@"
+ ret=$?
+fi
+exit $ret
+`
);
});
@@ -97,16 +157,8 @@ installerTest(async function uninstallBasic(): Promise<void> {
await uninstall("file_server");
- let thrown = false;
- try {
- await stat(filePath);
- } catch (e) {
- thrown = true;
- assert(e instanceof Deno.DenoError);
- assertEquals(e.kind, Deno.ErrorKind.NotFound);
- }
-
- assert(thrown);
+ assert(!(await fs.exists(filePath)));
+ assert(!(await fs.exists(filePath + ".cmd")));
});
installerTest(async function uninstallNonExistentModule(): Promise<void> {