Skip to content

Commit

Permalink
Merge branch 'master' into partial_reload
Browse files Browse the repository at this point in the history
  • Loading branch information
mhvsa committed Oct 17, 2019
2 parents 83ccb74 + f51dcc1 commit 5839b11
Show file tree
Hide file tree
Showing 74 changed files with 554 additions and 313 deletions.
104 changes: 97 additions & 7 deletions cli/file_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,16 @@ fn map_content_type(path: &Path, content_type: Option<&str>) -> msg::MediaType {
| "text/typescript"
| "video/vnd.dlna.mpeg-tts"
| "video/mp2t"
| "application/x-typescript" => msg::MediaType::TypeScript,
| "application/x-typescript" => {
map_js_like_extension(path, msg::MediaType::TypeScript)
}
"application/javascript"
| "text/javascript"
| "application/ecmascript"
| "text/ecmascript"
| "application/x-javascript" => msg::MediaType::JavaScript,
| "application/x-javascript" => {
map_js_like_extension(path, msg::MediaType::JavaScript)
}
"application/json" | "text/json" => msg::MediaType::Json,
"text/plain" => map_file_extension(path),
_ => {
Expand All @@ -528,6 +532,21 @@ fn map_content_type(path: &Path, content_type: Option<&str>) -> msg::MediaType {
}
}

fn map_js_like_extension(
path: &Path,
default: msg::MediaType,
) -> msg::MediaType {
match path.extension() {
None => default,
Some(os_str) => match os_str.to_str() {
None => default,
Some("jsx") => msg::MediaType::JSX,
Some("tsx") => msg::MediaType::TSX,
Some(_) => default,
},
}
}

fn filter_shebang(bytes: Vec<u8>) -> Vec<u8> {
let string = str::from_utf8(&bytes).unwrap();
if let Some(i) = string.find('\n') {
Expand Down Expand Up @@ -1495,7 +1514,7 @@ mod tests {
}

#[test]
fn test_map_content_type() {
fn test_map_content_type_extension_only() {
// Extension only
assert_eq!(
map_content_type(Path::new("foo/bar.ts"), None),
Expand All @@ -1513,6 +1532,10 @@ mod tests {
map_content_type(Path::new("foo/bar.js"), None),
msg::MediaType::JavaScript
);
assert_eq!(
map_content_type(Path::new("foo/bar.txt"), None),
msg::MediaType::Unknown
);
assert_eq!(
map_content_type(Path::new("foo/bar.jsx"), None),
msg::MediaType::JSX
Expand All @@ -1521,15 +1544,14 @@ mod tests {
map_content_type(Path::new("foo/bar.json"), None),
msg::MediaType::Json
);
assert_eq!(
map_content_type(Path::new("foo/bar.txt"), None),
msg::MediaType::Unknown
);
assert_eq!(
map_content_type(Path::new("foo/bar"), None),
msg::MediaType::Unknown
);
}

#[test]
fn test_map_content_type_media_type_with_no_extension() {
// Media Type
assert_eq!(
map_content_type(Path::new("foo/bar"), Some("application/typescript")),
Expand Down Expand Up @@ -1579,6 +1601,10 @@ mod tests {
map_content_type(Path::new("foo/bar"), Some("text/json")),
msg::MediaType::Json
);
}

#[test]
fn test_map_file_extension_media_type_with_extension() {
assert_eq!(
map_content_type(Path::new("foo/bar.ts"), Some("text/plain")),
msg::MediaType::TypeScript
Expand All @@ -1587,6 +1613,70 @@ mod tests {
map_content_type(Path::new("foo/bar.ts"), Some("foo/bar")),
msg::MediaType::Unknown
);
assert_eq!(
map_content_type(
Path::new("foo/bar.tsx"),
Some("application/typescript")
),
msg::MediaType::TSX
);
assert_eq!(
map_content_type(
Path::new("foo/bar.tsx"),
Some("application/javascript")
),
msg::MediaType::TSX
);
assert_eq!(
map_content_type(
Path::new("foo/bar.tsx"),
Some("application/x-typescript")
),
msg::MediaType::TSX
);
assert_eq!(
map_content_type(
Path::new("foo/bar.tsx"),
Some("video/vnd.dlna.mpeg-tts")
),
msg::MediaType::TSX
);
assert_eq!(
map_content_type(Path::new("foo/bar.tsx"), Some("video/mp2t")),
msg::MediaType::TSX
);
assert_eq!(
map_content_type(
Path::new("foo/bar.jsx"),
Some("application/javascript")
),
msg::MediaType::JSX
);
assert_eq!(
map_content_type(
Path::new("foo/bar.jsx"),
Some("application/x-typescript")
),
msg::MediaType::JSX
);
assert_eq!(
map_content_type(
Path::new("foo/bar.jsx"),
Some("application/ecmascript")
),
msg::MediaType::JSX
);
assert_eq!(
map_content_type(Path::new("foo/bar.jsx"), Some("text/ecmascript")),
msg::MediaType::JSX
);
assert_eq!(
map_content_type(
Path::new("foo/bar.jsx"),
Some("application/x-javascript")
),
msg::MediaType::JSX
);
}

#[test]
Expand Down
23 changes: 23 additions & 0 deletions cli/tests/048_media_types_jsx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// When run against the test HTTP server, it will serve different media types
// based on the URL containing `.t#.` strings, which exercises the different
// mapping of media types end to end.
import { loaded as loadedTsx1 } from "http://localhost:4545/cli/tests/subdir/mt_text_typescript_tsx.t1.tsx";
import { loaded as loadedTsx2 } from "http://localhost:4545/cli/tests/subdir/mt_video_vdn_tsx.t2.tsx";
import { loaded as loadedTsx3 } from "http://localhost:4545/cli/tests/subdir/mt_video_mp2t_tsx.t3.tsx";
import { loaded as loadedTsx4 } from "http://localhost:4545/cli/tests/subdir/mt_application_x_typescript_tsx.t4.tsx";
import { loaded as loadedJsx1 } from "http://localhost:4545/cli/tests/subdir/mt_text_javascript_jsx.j1.jsx";
import { loaded as loadedJsx2 } from "http://localhost:4545/cli/tests/subdir/mt_application_ecmascript_jsx.j2.jsx";
import { loaded as loadedJsx3 } from "http://localhost:4545/cli/tests/subdir/mt_text_ecmascript_jsx.j3.jsx";
import { loaded as loadedJsx4 } from "http://localhost:4545/cli/tests/subdir/mt_application_x_javascript_jsx.j4.jsx";

console.log(
"success",
loadedTsx1,
loadedTsx2,
loadedTsx3,
loadedTsx4,
loadedJsx1,
loadedJsx2,
loadedJsx3,
loadedJsx4
);
1 change: 1 addition & 0 deletions cli/tests/048_media_types_jsx.ts.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
success true true true true true true true true
14 changes: 14 additions & 0 deletions cli/tests/049_info_flag_script_jsx.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
local: [WILDCARD]048_media_types_jsx.ts
type: TypeScript
compiled: [WILDCARD]048_media_types_jsx.ts.js
map: [WILDCARD]048_media_types_jsx.ts.js.map
deps:
http://127.0.0.1:4545/cli/tests/048_media_types_jsx.ts
├── http://localhost:4545/cli/tests/subdir/mt_text_typescript_tsx.t1.tsx
├── http://localhost:4545/cli/tests/subdir/mt_video_vdn_tsx.t2.tsx
├── http://localhost:4545/cli/tests/subdir/mt_video_mp2t_tsx.t3.tsx
├── http://localhost:4545/cli/tests/subdir/mt_application_x_typescript_tsx.t4.tsx
├── http://localhost:4545/cli/tests/subdir/mt_text_javascript_jsx.j1.jsx
├── http://localhost:4545/cli/tests/subdir/mt_application_ecmascript_jsx.j2.jsx
├── http://localhost:4545/cli/tests/subdir/mt_text_ecmascript_jsx.j3.jsx
└── http://localhost:4545/cli/tests/subdir/mt_application_x_javascript_jsx.j4.jsx
12 changes: 12 additions & 0 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,18 @@ itest!(_047_jsx {
output: "047_jsx_test.jsx.out",
});

itest!(_048_media_types_jsx {
args: "run --reload 048_media_types_jsx.ts",
output: "048_media_types_jsx.ts.out",
http_server: true,
});

itest!(_049_info_flag_script_jsx {
args: "info http://127.0.0.1:4545/cli/tests/048_media_types_jsx.ts",
output: "049_info_flag_script_jsx.out",
http_server: true,
});

itest!(async_error {
exit_code: 1,
args: "run --reload async_error.ts",
Expand Down
5 changes: 5 additions & 0 deletions cli/tests/subdir/mt_application_ecmascript_jsx.j2.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const React = {
createElement() {}
}
const temp = <div></div>;
export const loaded = true;
5 changes: 5 additions & 0 deletions cli/tests/subdir/mt_application_x_javascript_jsx.j4.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const React = {
createElement() {}
}
const temp = <div></div>;
export const loaded = true;
5 changes: 5 additions & 0 deletions cli/tests/subdir/mt_application_x_typescript_tsx.t4.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const React = {
createElement() {}
}
const temp = <div></div>;
export const loaded = true;
5 changes: 5 additions & 0 deletions cli/tests/subdir/mt_javascript_jsx.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const React = {
createElement() {}
}
const temp = <div></div>;
export const loaded = true;
5 changes: 5 additions & 0 deletions cli/tests/subdir/mt_text_ecmascript_jsx.j3.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const React = {
createElement() {}
}
const temp = <div></div>;
export const loaded = true;
5 changes: 5 additions & 0 deletions cli/tests/subdir/mt_text_javascript_jsx.j1.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const React = {
createElement() {}
}
const temp = <div></div>;
export const loaded = true;
5 changes: 5 additions & 0 deletions cli/tests/subdir/mt_text_typescript_tsx.t1.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const React = {
createElement() {}
}
const temp = <div></div>;
export const loaded = true;
5 changes: 5 additions & 0 deletions cli/tests/subdir/mt_video_mp2t_tsx.t3.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const React = {
createElement() {}
}
const temp = <div></div>;
export const loaded = true;
5 changes: 5 additions & 0 deletions cli/tests/subdir/mt_video_vdn_tsx.t2.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const React = {
createElement() {}
}
const temp = <div></div>;
export const loaded = true;
2 changes: 1 addition & 1 deletion std/archive/tar_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import { test, runIfMain } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";

import { resolve } from "../path/mod.ts";
import { Tar, Untar } from "./tar.ts";
import { resolve } from "../fs/path/mod.ts";

const filePath = resolve("archive", "testdata", "example.txt");

Expand Down
2 changes: 1 addition & 1 deletion std/encoding/toml_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { runIfMain, test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { existsSync } from "../fs/exists.ts";
import { readFileStrSync } from "../fs/read_file_str.ts";
import * as path from "../path/mod.ts";
import { parse, stringify } from "./toml.ts";
import * as path from "../fs/path/mod.ts";

const testFilesDir = path.resolve("encoding", "testdata");

Expand Down
36 changes: 36 additions & 0 deletions std/flags/bool_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,39 @@ test(function booleanParsingTrueLike(): void {
const parsed3 = parse(["-t", "false123"], { boolean: ["t"] });
assertEquals(parsed3.t, true);
});

test(function booleanNegationAfterBoolean(): void {
const parsed = parse(["--foo", "--no-foo"], { boolean: ["foo"] });
assertEquals(parsed.foo, false);

const parsed2 = parse(["--foo", "--no-foo", "123"], { boolean: ["foo"] });
assertEquals(parsed2.foo, false);
});

test(function booleanAfterBooleanNegation(): void {
const parsed = parse(["--no--foo", "--foo"], { boolean: ["foo"] });
assertEquals(parsed.foo, true);

const parsed2 = parse(["--no--foo", "--foo", "123"], { boolean: ["foo"] });
assertEquals(parsed2.foo, true);
});

test(function latestFlagIsBooleanNegation(): void {
const parsed = parse(["--no-foo", "--foo", "--no-foo"], { boolean: ["foo"] });
assertEquals(parsed.foo, false);

const parsed2 = parse(["--no-foo", "--foo", "--no-foo", "123"], {
boolean: ["foo"]
});
assertEquals(parsed2.foo, false);
});

test(function latestFlagIsBoolean(): void {
const parsed = parse(["--foo", "--no-foo", "--foo"], { boolean: ["foo"] });
assertEquals(parsed.foo, true);

const parsed2 = parse(["--foo", "--no-foo", "--foo", "123"], {
boolean: ["foo"]
});
assertEquals(parsed2.foo, true);
});
2 changes: 1 addition & 1 deletion std/fs/copy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import * as path from "./path/mod.ts";
import * as path from "../path/mod.ts";
import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
import { isSubdir, getFileInfoType } from "./utils.ts";

Expand Down
2 changes: 1 addition & 1 deletion std/fs/copy_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
assertThrowsAsync,
assert
} from "../testing/asserts.ts";
import * as path from "../path/mod.ts";
import { copy, copySync } from "./copy.ts";
import { exists, existsSync } from "./exists.ts";
import * as path from "./path/mod.ts";
import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
import { ensureFile, ensureFileSync } from "./ensure_file.ts";
import { ensureSymlink, ensureSymlinkSync } from "./ensure_symlink.ts";
Expand Down
2 changes: 1 addition & 1 deletion std/fs/empty_dir_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
assertThrows,
assertThrowsAsync
} from "../testing/asserts.ts";
import * as path from "../path/mod.ts";
import { emptyDir, emptyDirSync } from "./empty_dir.ts";
import * as path from "./path/mod.ts";

const testdataDir = path.resolve("fs", "testdata");

Expand Down
2 changes: 1 addition & 1 deletion std/fs/ensure_dir_test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertThrows, assertThrowsAsync } from "../testing/asserts.ts";
import * as path from "../path/mod.ts";
import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
import * as path from "./path/mod.ts";
import { ensureFile, ensureFileSync } from "./ensure_file.ts";

const testdataDir = path.resolve("fs", "testdata");
Expand Down
2 changes: 1 addition & 1 deletion std/fs/ensure_file.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import * as path from "./path/mod.ts";
import * as path from "../path/mod.ts";
import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
import { getFileInfoType } from "./utils.ts";

Expand Down
2 changes: 1 addition & 1 deletion std/fs/ensure_file_test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertThrows, assertThrowsAsync } from "../testing/asserts.ts";
import * as path from "../path/mod.ts";
import { ensureFile, ensureFileSync } from "./ensure_file.ts";
import * as path from "./path/mod.ts";

const testdataDir = path.resolve("fs", "testdata");

Expand Down
2 changes: 1 addition & 1 deletion std/fs/ensure_link.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import * as path from "./path/mod.ts";
import * as path from "../path/mod.ts";
import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
import { exists, existsSync } from "./exists.ts";
import { getFileInfoType } from "./utils.ts";
Expand Down
Loading

0 comments on commit 5839b11

Please sign in to comment.