summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/http_util.rs9
-rw-r--r--cli/js/fetch_test.ts18
-rw-r--r--cli/js/files_test.ts4
-rw-r--r--cli/js/read_dir_test.ts2
-rw-r--r--cli/js/read_file_test.ts8
-rw-r--r--cli/js/stat_test.ts24
-rw-r--r--cli/tests/fetch_deps.ts14
-rw-r--r--cli/tests/fixture.json14
l---------cli/tests/symlink_to_subdir1
9 files changed, 49 insertions, 45 deletions
diff --git a/cli/http_util.rs b/cli/http_util.rs
index 754cd60d2..d3bc16415 100644
--- a/cli/http_util.rs
+++ b/cli/http_util.rs
@@ -143,7 +143,8 @@ mod tests {
fn test_fetch_sync_string() {
let http_server_guard = crate::test_util::http_server();
// Relies on external http server. See tools/http_server.py
- let url = Url::parse("http://127.0.0.1:4545/package.json").unwrap();
+ let url =
+ Url::parse("http://127.0.0.1:4545/cli/tests/fixture.json").unwrap();
let fut = fetch_string_once(&url).then(|result| match result {
Ok(FetchOnceResult::Code(code, maybe_content_type)) => {
@@ -162,9 +163,11 @@ mod tests {
fn test_fetch_string_once_with_redirect() {
let http_server_guard = crate::test_util::http_server();
// Relies on external http server. See tools/http_server.py
- let url = Url::parse("http://127.0.0.1:4546/package.json").unwrap();
+ let url =
+ Url::parse("http://127.0.0.1:4546/cli/tests/fixture.json").unwrap();
// Dns resolver substitutes `127.0.0.1` with `localhost`
- let target_url = Url::parse("http://localhost:4545/package.json").unwrap();
+ let target_url =
+ Url::parse("http://localhost:4545/cli/tests/fixture.json").unwrap();
let fut = fetch_string_once(&url).then(move |result| match result {
Ok(FetchOnceResult::Redirect(url)) => {
assert_eq!(url, target_url);
diff --git a/cli/js/fetch_test.ts b/cli/js/fetch_test.ts
index 56c693681..1b9450dcd 100644
--- a/cli/js/fetch_test.ts
+++ b/cli/js/fetch_test.ts
@@ -21,7 +21,7 @@ testPerm({ net: true }, async function fetchConnectionError(): Promise<void> {
});
testPerm({ net: true }, async function fetchJsonSuccess(): Promise<void> {
- const response = await fetch("http://localhost:4545/package.json");
+ const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
const json = await response.json();
assertEquals(json.name, "deno");
});
@@ -29,7 +29,7 @@ testPerm({ net: true }, async function fetchJsonSuccess(): Promise<void> {
test(async function fetchPerm(): Promise<void> {
let err;
try {
- await fetch("http://localhost:4545/package.json");
+ await fetch("http://localhost:4545/cli/tests/fixture.json");
} catch (err_) {
err = err_;
}
@@ -38,19 +38,19 @@ test(async function fetchPerm(): Promise<void> {
});
testPerm({ net: true }, async function fetchUrl(): Promise<void> {
- const response = await fetch("http://localhost:4545/package.json");
- assertEquals(response.url, "http://localhost:4545/package.json");
+ const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
+ assertEquals(response.url, "http://localhost:4545/cli/tests/fixture.json");
});
testPerm({ net: true }, async function fetchHeaders(): Promise<void> {
- const response = await fetch("http://localhost:4545/package.json");
+ const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
const headers = response.headers;
assertEquals(headers.get("Content-Type"), "application/json");
assert(headers.get("Server").startsWith("SimpleHTTP"));
});
testPerm({ net: true }, async function fetchBlob(): Promise<void> {
- const response = await fetch("http://localhost:4545/package.json");
+ const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
const headers = response.headers;
const blob = await response.blob();
assertEquals(blob.type, headers.get("Content-Type"));
@@ -58,7 +58,7 @@ testPerm({ net: true }, async function fetchBlob(): Promise<void> {
});
testPerm({ net: true }, async function fetchBodyUsed(): Promise<void> {
- const response = await fetch("http://localhost:4545/package.json");
+ const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
assertEquals(response.bodyUsed, false);
assertThrows(
(): void => {
@@ -71,7 +71,7 @@ testPerm({ net: true }, async function fetchBodyUsed(): Promise<void> {
});
testPerm({ net: true }, async function fetchAsyncIterator(): Promise<void> {
- const response = await fetch("http://localhost:4545/package.json");
+ const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
const headers = response.headers;
let total = 0;
for await (const chunk of response.body) {
@@ -82,7 +82,7 @@ testPerm({ net: true }, async function fetchAsyncIterator(): Promise<void> {
});
testPerm({ net: true }, async function responseClone(): Promise<void> {
- const response = await fetch("http://localhost:4545/package.json");
+ const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
const response1 = response.clone();
assert(response !== response1);
assertEquals(response.status, response1.status);
diff --git a/cli/js/files_test.ts b/cli/js/files_test.ts
index 004cb662b..2eaa3b9be 100644
--- a/cli/js/files_test.ts
+++ b/cli/js/files_test.ts
@@ -8,7 +8,7 @@ test(function filesStdioFileDescriptors(): void {
});
testPerm({ read: true }, async function filesCopyToStdout(): Promise<void> {
- const filename = "package.json";
+ const filename = "cli/tests/fixture.json";
const file = await Deno.open(filename);
assert(file.rid > 2);
const bytesWritten = await Deno.copy(Deno.stdout, file);
@@ -81,7 +81,7 @@ testPerm({ write: false }, async function writePermFailure(): Promise<void> {
testPerm({ read: false }, async function readPermFailure(): Promise<void> {
let caughtError = false;
try {
- await Deno.open("package.json", "r");
+ await Deno.open("cli/tests/fixture.json", "r");
} catch (e) {
caughtError = true;
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
diff --git a/cli/js/read_dir_test.ts b/cli/js/read_dir_test.ts
index 3e11df9fe..f75aca996 100644
--- a/cli/js/read_dir_test.ts
+++ b/cli/js/read_dir_test.ts
@@ -43,7 +43,7 @@ testPerm({ read: true }, function readDirSyncNotDir(): void {
let src;
try {
- src = Deno.readDirSync("package.json");
+ src = Deno.readDirSync("cli/tests/fixture.json");
} catch (err) {
caughtError = true;
assertEquals(err.kind, Deno.ErrorKind.Other);
diff --git a/cli/js/read_file_test.ts b/cli/js/read_file_test.ts
index 7d4f4789c..a7ffec578 100644
--- a/cli/js/read_file_test.ts
+++ b/cli/js/read_file_test.ts
@@ -2,7 +2,7 @@
import { testPerm, assert, assertEquals } from "./test_util.ts";
testPerm({ read: true }, function readFileSyncSuccess(): void {
- const data = Deno.readFileSync("package.json");
+ const data = Deno.readFileSync("cli/tests/fixture.json");
assert(data.byteLength > 0);
const decoder = new TextDecoder("utf-8");
const json = decoder.decode(data);
@@ -13,7 +13,7 @@ testPerm({ read: true }, function readFileSyncSuccess(): void {
testPerm({ read: false }, function readFileSyncPerm(): void {
let caughtError = false;
try {
- Deno.readFileSync("package.json");
+ Deno.readFileSync("cli/tests/fixture.json");
} catch (e) {
caughtError = true;
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
@@ -36,7 +36,7 @@ testPerm({ read: true }, function readFileSyncNotFound(): void {
});
testPerm({ read: true }, async function readFileSuccess(): Promise<void> {
- const data = await Deno.readFile("package.json");
+ const data = await Deno.readFile("cli/tests/fixture.json");
assert(data.byteLength > 0);
const decoder = new TextDecoder("utf-8");
const json = decoder.decode(data);
@@ -47,7 +47,7 @@ testPerm({ read: true }, async function readFileSuccess(): Promise<void> {
testPerm({ read: false }, async function readFilePerm(): Promise<void> {
let caughtError = false;
try {
- await Deno.readFile("package.json");
+ await Deno.readFile("cli/tests/fixture.json");
} catch (e) {
caughtError = true;
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
diff --git a/cli/js/stat_test.ts b/cli/js/stat_test.ts
index 6c42b277c..38bd3f6c6 100644
--- a/cli/js/stat_test.ts
+++ b/cli/js/stat_test.ts
@@ -4,11 +4,11 @@ import { testPerm, assert, assertEquals } from "./test_util.ts";
// TODO Add tests for modified, accessed, and created fields once there is a way
// to create temp files.
testPerm({ read: true }, async function statSyncSuccess(): Promise<void> {
- const packageInfo = Deno.statSync("package.json");
+ const packageInfo = Deno.statSync("README.md");
assert(packageInfo.isFile());
assert(!packageInfo.isSymlink());
- const modulesInfo = Deno.statSync("node_modules");
+ const modulesInfo = Deno.statSync("cli/tests/symlink_to_subdir");
assert(modulesInfo.isDirectory());
assert(!modulesInfo.isSymlink());
@@ -20,7 +20,7 @@ testPerm({ read: true }, async function statSyncSuccess(): Promise<void> {
testPerm({ read: false }, async function statSyncPerm(): Promise<void> {
let caughtError = false;
try {
- Deno.statSync("package.json");
+ Deno.statSync("README.md");
} catch (e) {
caughtError = true;
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
@@ -46,11 +46,11 @@ testPerm({ read: true }, async function statSyncNotFound(): Promise<void> {
});
testPerm({ read: true }, async function lstatSyncSuccess(): Promise<void> {
- const packageInfo = Deno.lstatSync("package.json");
+ const packageInfo = Deno.lstatSync("README.md");
assert(packageInfo.isFile());
assert(!packageInfo.isSymlink());
- const modulesInfo = Deno.lstatSync("node_modules");
+ const modulesInfo = Deno.lstatSync("cli/tests/symlink_to_subdir");
assert(!modulesInfo.isDirectory());
assert(modulesInfo.isSymlink());
@@ -62,7 +62,7 @@ testPerm({ read: true }, async function lstatSyncSuccess(): Promise<void> {
testPerm({ read: false }, async function lstatSyncPerm(): Promise<void> {
let caughtError = false;
try {
- Deno.lstatSync("package.json");
+ Deno.lstatSync("README.md");
} catch (e) {
caughtError = true;
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
@@ -88,11 +88,11 @@ testPerm({ read: true }, async function lstatSyncNotFound(): Promise<void> {
});
testPerm({ read: true }, async function statSuccess(): Promise<void> {
- const packageInfo = await Deno.stat("package.json");
+ const packageInfo = await Deno.stat("README.md");
assert(packageInfo.isFile());
assert(!packageInfo.isSymlink());
- const modulesInfo = await Deno.stat("node_modules");
+ const modulesInfo = await Deno.stat("cli/tests/symlink_to_subdir");
assert(modulesInfo.isDirectory());
assert(!modulesInfo.isSymlink());
@@ -104,7 +104,7 @@ testPerm({ read: true }, async function statSuccess(): Promise<void> {
testPerm({ read: false }, async function statPerm(): Promise<void> {
let caughtError = false;
try {
- await Deno.stat("package.json");
+ await Deno.stat("README.md");
} catch (e) {
caughtError = true;
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
@@ -130,11 +130,11 @@ testPerm({ read: true }, async function statNotFound(): Promise<void> {
});
testPerm({ read: true }, async function lstatSuccess(): Promise<void> {
- const packageInfo = await Deno.lstat("package.json");
+ const packageInfo = await Deno.lstat("README.md");
assert(packageInfo.isFile());
assert(!packageInfo.isSymlink());
- const modulesInfo = await Deno.lstat("node_modules");
+ const modulesInfo = await Deno.lstat("cli/tests/symlink_to_subdir");
assert(!modulesInfo.isDirectory());
assert(modulesInfo.isSymlink());
@@ -146,7 +146,7 @@ testPerm({ read: true }, async function lstatSuccess(): Promise<void> {
testPerm({ read: false }, async function lstatPerm(): Promise<void> {
let caughtError = false;
try {
- await Deno.lstat("package.json");
+ await Deno.lstat("README.md");
} catch (e) {
caughtError = true;
assertEquals(e.kind, Deno.ErrorKind.PermissionDenied);
diff --git a/cli/tests/fetch_deps.ts b/cli/tests/fetch_deps.ts
deleted file mode 100644
index e6ef8854e..000000000
--- a/cli/tests/fetch_deps.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-// Run ./tools/http_server.py too in order for this test to run.
-import { assert } from "../std/testing/asserts.ts";
-
-// TODO Top level await https://github.com/denoland/deno/issues/471
-async function main(): Promise<void> {
- const response = await fetch("http://localhost:4545/package.json");
- const json = await response.json();
- const deps = Object.keys(json.devDependencies);
- console.log("Deno JS Deps");
- console.log(deps.map((d): string => `* ${d}`).join("\n"));
- assert(deps.includes("typescript"));
-}
-
-main();
diff --git a/cli/tests/fixture.json b/cli/tests/fixture.json
new file mode 100644
index 000000000..56e056b6a
--- /dev/null
+++ b/cli/tests/fixture.json
@@ -0,0 +1,14 @@
+{
+ "name": "deno",
+ "private": true,
+ "devDependencies": {
+ "@types/prettier": "1.16.1",
+ "@typescript-eslint/eslint-plugin": "2.5.0",
+ "@typescript-eslint/parser": "2.5.0",
+ "eslint": "5.15.1",
+ "eslint-config-prettier": "4.1.0",
+ "magic-string": "0.25.2",
+ "prettier": "1.17.1",
+ "typescript": "3.6.3"
+ }
+}
diff --git a/cli/tests/symlink_to_subdir b/cli/tests/symlink_to_subdir
new file mode 120000
index 000000000..fe0c45aa4
--- /dev/null
+++ b/cli/tests/symlink_to_subdir
@@ -0,0 +1 @@
+subdir/ \ No newline at end of file