From cdae4423c27443e0085d59f45eda1c978f186a1c Mon Sep 17 00:00:00 2001 From: Liam Murphy <43807659+Liamolucko@users.noreply.github.com> Date: Fri, 26 Feb 2021 02:24:05 +1100 Subject: feat(cli/doc): use type definitions "deno doc" if available (#8459) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds support for type definitions in "deno doc"; with this change "deno doc" is able to leverage the same directives as TS compiler. Co-authored-by: Bartek IwaƄczuk --- cli/tests/doc/types_header.out | 6 +++++ cli/tests/doc/types_header.ts | 1 + cli/tests/doc/types_hint.out | 5 ++++ cli/tests/doc/types_hint.ts | 2 ++ cli/tests/doc/types_ref.js | 2 ++ cli/tests/doc/types_ref.out | 5 ++++ cli/tests/integration_tests.rs | 54 +++++++++++++++++++++++++++++++----------- 7 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 cli/tests/doc/types_header.out create mode 100644 cli/tests/doc/types_header.ts create mode 100644 cli/tests/doc/types_hint.out create mode 100644 cli/tests/doc/types_hint.ts create mode 100644 cli/tests/doc/types_ref.js create mode 100644 cli/tests/doc/types_ref.out (limited to 'cli/tests') diff --git a/cli/tests/doc/types_header.out b/cli/tests/doc/types_header.out new file mode 100644 index 000000000..ccff1a373 --- /dev/null +++ b/cli/tests/doc/types_header.out @@ -0,0 +1,6 @@ +Download http://127.0.0.1:4545/xTypeScriptTypes.js +Download http://127.0.0.1:4545/xTypeScriptTypes.d.ts +Defined in http://127.0.0.1:4545/xTypeScriptTypes.d.ts:1:0 + +const foo: "foo" + diff --git a/cli/tests/doc/types_header.ts b/cli/tests/doc/types_header.ts new file mode 100644 index 000000000..b64c8d000 --- /dev/null +++ b/cli/tests/doc/types_header.ts @@ -0,0 +1 @@ +export * from "http://127.0.0.1:4545/xTypeScriptTypes.js"; diff --git a/cli/tests/doc/types_hint.out b/cli/tests/doc/types_hint.out new file mode 100644 index 000000000..7eb05faed --- /dev/null +++ b/cli/tests/doc/types_hint.out @@ -0,0 +1,5 @@ +Defined in [WILDCARD]/type_definitions/foo.d.ts:2:0 + +const foo: string + An exported value. + diff --git a/cli/tests/doc/types_hint.ts b/cli/tests/doc/types_hint.ts new file mode 100644 index 000000000..bacea46db --- /dev/null +++ b/cli/tests/doc/types_hint.ts @@ -0,0 +1,2 @@ +// @deno-types="../type_definitions/foo.d.ts" +export * from "../type_definitions/foo.js"; diff --git a/cli/tests/doc/types_ref.js b/cli/tests/doc/types_ref.js new file mode 100644 index 000000000..03d8b5570 --- /dev/null +++ b/cli/tests/doc/types_ref.js @@ -0,0 +1,2 @@ +/// +export const foo = "foo"; diff --git a/cli/tests/doc/types_ref.out b/cli/tests/doc/types_ref.out new file mode 100644 index 000000000..7eb05faed --- /dev/null +++ b/cli/tests/doc/types_ref.out @@ -0,0 +1,5 @@ +Defined in [WILDCARD]/type_definitions/foo.d.ts:2:0 + +const foo: string + An exported value. + diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 497028cd1..8b8d6354b 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -3669,20 +3669,10 @@ console.log("finish"); exit_code: 0, }); - itest!(deno_doc_builtin { - args: "doc", - output: "deno_doc_builtin.out", - }); - - itest!(deno_doc { - args: "doc deno_doc.ts", - output: "deno_doc.out", - }); - - itest!(deno_doc_import_map { - args: - "doc --unstable --import-map=doc/import_map.json doc/use_import_map.js", - output: "doc/use_import_map.out", + itest!(deno_doc_types_header_direct { + args: "doc --reload http://127.0.0.1:4545/xTypeScriptTypes.js", + output: "doc/types_header.out", + http_server: true, }); itest!(import_data_url_error_stack { @@ -3945,6 +3935,42 @@ console.log("finish"); assert_eq!(output.stderr, b""); } + mod doc { + use super::*; + + itest!(deno_doc_builtin { + args: "doc", + output: "deno_doc_builtin.out", + }); + + itest!(deno_doc { + args: "doc deno_doc.ts", + output: "deno_doc.out", + }); + + itest!(deno_doc_import_map { + args: + "doc --unstable --import-map=doc/import_map.json doc/use_import_map.js", + output: "doc/use_import_map.out", + }); + + itest!(deno_doc_types_hint { + args: "doc doc/types_hint.ts", + output: "doc/types_hint.out", + }); + + itest!(deno_doc_types_ref { + args: "doc doc/types_ref.js", + output: "doc/types_ref.out", + }); + + itest!(deno_doc_types_header { + args: "doc --reload doc/types_header.ts", + output: "doc/types_header.out", + http_server: true, + }); + } + mod coverage { use super::*; -- cgit v1.2.3