diff options
| author | David Sherret <dsherret@users.noreply.github.com> | 2021-08-11 10:20:47 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-11 10:20:47 -0400 |
| commit | 15a763152f9d392cb80692262f8de5ef8ae15495 (patch) | |
| tree | fcd1a59777f95920bf3502519983d6cc0d882a9a /cli/tests/testdata | |
| parent | a0285e2eb88f6254f6494b0ecd1878db3a3b2a58 (diff) | |
chore: move test files to testdata directory (#11601)
Diffstat (limited to 'cli/tests/testdata')
977 files changed, 11788 insertions, 0 deletions
diff --git a/cli/tests/testdata/001_hello.js b/cli/tests/testdata/001_hello.js new file mode 100644 index 000000000..accefceba --- /dev/null +++ b/cli/tests/testdata/001_hello.js @@ -0,0 +1 @@ +console.log("Hello World"); diff --git a/cli/tests/testdata/001_hello.js.out b/cli/tests/testdata/001_hello.js.out new file mode 100644 index 000000000..557db03de --- /dev/null +++ b/cli/tests/testdata/001_hello.js.out @@ -0,0 +1 @@ +Hello World diff --git a/cli/tests/testdata/002_hello.ts b/cli/tests/testdata/002_hello.ts new file mode 100644 index 000000000..accefceba --- /dev/null +++ b/cli/tests/testdata/002_hello.ts @@ -0,0 +1 @@ +console.log("Hello World"); diff --git a/cli/tests/testdata/002_hello.ts.out b/cli/tests/testdata/002_hello.ts.out new file mode 100644 index 000000000..557db03de --- /dev/null +++ b/cli/tests/testdata/002_hello.ts.out @@ -0,0 +1 @@ +Hello World diff --git a/cli/tests/testdata/003_relative_import.ts b/cli/tests/testdata/003_relative_import.ts new file mode 100644 index 000000000..01d5d7faa --- /dev/null +++ b/cli/tests/testdata/003_relative_import.ts @@ -0,0 +1,3 @@ +import { printHello } from "./subdir/print_hello.ts"; + +printHello(); diff --git a/cli/tests/testdata/003_relative_import.ts.out b/cli/tests/testdata/003_relative_import.ts.out new file mode 100644 index 000000000..699b756ed --- /dev/null +++ b/cli/tests/testdata/003_relative_import.ts.out @@ -0,0 +1,2 @@ +[WILDCARD] +Hello diff --git a/cli/tests/testdata/004_set_timeout.ts b/cli/tests/testdata/004_set_timeout.ts new file mode 100644 index 000000000..214b25086 --- /dev/null +++ b/cli/tests/testdata/004_set_timeout.ts @@ -0,0 +1,11 @@ +setTimeout(() => { + console.log("World"); +}, 10); + +console.log("Hello"); + +const id = setTimeout(() => { + console.log("Not printed"); +}, 10000); + +clearTimeout(id); diff --git a/cli/tests/testdata/004_set_timeout.ts.out b/cli/tests/testdata/004_set_timeout.ts.out new file mode 100644 index 000000000..f9264f7fb --- /dev/null +++ b/cli/tests/testdata/004_set_timeout.ts.out @@ -0,0 +1,2 @@ +Hello +World diff --git a/cli/tests/testdata/005_more_imports.ts b/cli/tests/testdata/005_more_imports.ts new file mode 100644 index 000000000..0266bf46c --- /dev/null +++ b/cli/tests/testdata/005_more_imports.ts @@ -0,0 +1,11 @@ +import { printHello3, returnsFoo2, returnsHi } from "./subdir/mod1.ts"; + +printHello3(); + +if (returnsHi() !== "Hi") { + throw Error("Unexpected"); +} + +if (returnsFoo2() !== "Foo") { + throw Error("Unexpected"); +} diff --git a/cli/tests/testdata/005_more_imports.ts.out b/cli/tests/testdata/005_more_imports.ts.out new file mode 100644 index 000000000..e965047ad --- /dev/null +++ b/cli/tests/testdata/005_more_imports.ts.out @@ -0,0 +1 @@ +Hello diff --git a/cli/tests/testdata/006_url_imports.ts b/cli/tests/testdata/006_url_imports.ts new file mode 100644 index 000000000..4036f27ed --- /dev/null +++ b/cli/tests/testdata/006_url_imports.ts @@ -0,0 +1,3 @@ +import { printHello } from "http://localhost:4545/subdir/mod2.ts"; +printHello(); +console.log("success"); diff --git a/cli/tests/testdata/006_url_imports.ts.out b/cli/tests/testdata/006_url_imports.ts.out new file mode 100644 index 000000000..989ce33e9 --- /dev/null +++ b/cli/tests/testdata/006_url_imports.ts.out @@ -0,0 +1,2 @@ +Hello +success diff --git a/cli/tests/testdata/012_async.ts b/cli/tests/testdata/012_async.ts new file mode 100644 index 000000000..536197b68 --- /dev/null +++ b/cli/tests/testdata/012_async.ts @@ -0,0 +1,11 @@ +// Check that we can use the async keyword. +async function main() { + await new Promise((resolve) => { + console.log("2"); + setTimeout(resolve, 100); + }); + console.log("3"); +} + +console.log("1"); +main(); diff --git a/cli/tests/testdata/012_async.ts.out b/cli/tests/testdata/012_async.ts.out new file mode 100644 index 000000000..01e79c32a --- /dev/null +++ b/cli/tests/testdata/012_async.ts.out @@ -0,0 +1,3 @@ +1 +2 +3 diff --git a/cli/tests/testdata/013_dynamic_import.ts b/cli/tests/testdata/013_dynamic_import.ts new file mode 100644 index 000000000..d4dc55152 --- /dev/null +++ b/cli/tests/testdata/013_dynamic_import.ts @@ -0,0 +1,15 @@ +(async () => { + const { returnsHi, returnsFoo2, printHello3 } = await import( + "./subdir/mod1.ts" + ); + + printHello3(); + + if (returnsHi() !== "Hi") { + throw Error("Unexpected"); + } + + if (returnsFoo2() !== "Foo") { + throw Error("Unexpected"); + } +})(); diff --git a/cli/tests/testdata/013_dynamic_import.ts.out b/cli/tests/testdata/013_dynamic_import.ts.out new file mode 100644 index 000000000..e965047ad --- /dev/null +++ b/cli/tests/testdata/013_dynamic_import.ts.out @@ -0,0 +1 @@ +Hello diff --git a/cli/tests/testdata/014_duplicate_import.ts b/cli/tests/testdata/014_duplicate_import.ts new file mode 100644 index 000000000..88f934526 --- /dev/null +++ b/cli/tests/testdata/014_duplicate_import.ts @@ -0,0 +1,9 @@ +// with all the imports of the same module, the module should only be +// instantiated once +import "./subdir/auto_print_hello.ts"; + +import "./subdir/auto_print_hello.ts"; + +(async () => { + await import("./subdir/auto_print_hello.ts"); +})(); diff --git a/cli/tests/testdata/014_duplicate_import.ts.out b/cli/tests/testdata/014_duplicate_import.ts.out new file mode 100644 index 000000000..4effa19f4 --- /dev/null +++ b/cli/tests/testdata/014_duplicate_import.ts.out @@ -0,0 +1 @@ +hello! diff --git a/cli/tests/testdata/015_duplicate_parallel_import.js b/cli/tests/testdata/015_duplicate_parallel_import.js new file mode 100644 index 000000000..172eeaf53 --- /dev/null +++ b/cli/tests/testdata/015_duplicate_parallel_import.js @@ -0,0 +1,20 @@ +// Importing the same module in parallel, the module should only be +// instantiated once. + +const promises = new Array(100) + .fill(null) + .map(() => import("./subdir/mod1.ts")); + +Promise.all(promises).then((imports) => { + const mod = imports.reduce((first, cur) => { + if (typeof first !== "object") { + throw new Error("Expected an object."); + } + if (first !== cur) { + throw new Error("More than one instance of the same module."); + } + return first; + }); + + mod.printHello3(); +}); diff --git a/cli/tests/testdata/015_duplicate_parallel_import.js.out b/cli/tests/testdata/015_duplicate_parallel_import.js.out new file mode 100644 index 000000000..e965047ad --- /dev/null +++ b/cli/tests/testdata/015_duplicate_parallel_import.js.out @@ -0,0 +1 @@ +Hello diff --git a/cli/tests/testdata/016_double_await.ts b/cli/tests/testdata/016_double_await.ts new file mode 100644 index 000000000..457a53ff3 --- /dev/null +++ b/cli/tests/testdata/016_double_await.ts @@ -0,0 +1,8 @@ +// This is to test if Deno would die at 2nd await +// See https://github.com/denoland/deno/issues/919 +(async () => { + const currDirInfo = await Deno.stat("."); + const parentDirInfo = await Deno.stat(".."); + console.log(currDirInfo.isDirectory); + console.log(parentDirInfo.isFile); +})(); diff --git a/cli/tests/testdata/016_double_await.ts.out b/cli/tests/testdata/016_double_await.ts.out new file mode 100644 index 000000000..da29283aa --- /dev/null +++ b/cli/tests/testdata/016_double_await.ts.out @@ -0,0 +1,2 @@ +true +false diff --git a/cli/tests/testdata/017_import_redirect.ts b/cli/tests/testdata/017_import_redirect.ts new file mode 100644 index 000000000..1265dd4ed --- /dev/null +++ b/cli/tests/testdata/017_import_redirect.ts @@ -0,0 +1,4 @@ +// http -> https redirect would happen: +import { printHello } from "http://gist.githubusercontent.com/ry/f12b2aa3409e6b52645bc346a9e22929/raw/79318f239f51d764384a8bded8d7c6a833610dde/print_hello.ts"; + +printHello(); diff --git a/cli/tests/testdata/017_import_redirect.ts.out b/cli/tests/testdata/017_import_redirect.ts.out new file mode 100644 index 000000000..e965047ad --- /dev/null +++ b/cli/tests/testdata/017_import_redirect.ts.out @@ -0,0 +1 @@ +Hello diff --git a/cli/tests/testdata/017_import_redirect_info.out b/cli/tests/testdata/017_import_redirect_info.out new file mode 100644 index 000000000..d3a2e86fc --- /dev/null +++ b/cli/tests/testdata/017_import_redirect_info.out @@ -0,0 +1,6 @@ +local: [WILDCARD]017_import_redirect.ts +type: TypeScript +dependencies: 1 unique (total 278B) + +file:///[WILDCARD]/017_import_redirect.ts ([WILDCARD]) +└── https://gist.githubusercontent.com/ry/f12b2aa3409e6b52645bc346a9e22929/raw/79318f239f51d764384a8bded8d7c6a833610dde/print_hello.ts ([WILDCARD]) diff --git a/cli/tests/testdata/018_async_catch.ts b/cli/tests/testdata/018_async_catch.ts new file mode 100644 index 000000000..ac43a52e8 --- /dev/null +++ b/cli/tests/testdata/018_async_catch.ts @@ -0,0 +1,14 @@ +function fn(): Promise<never> { + throw new Error("message"); +} +async function call() { + try { + console.log("before await fn()"); + await fn(); + console.log("after await fn()"); + } catch (_error) { + console.log("catch"); + } + console.log("after try-catch"); +} +call().catch(() => console.log("outer catch")); diff --git a/cli/tests/testdata/018_async_catch.ts.out b/cli/tests/testdata/018_async_catch.ts.out new file mode 100644 index 000000000..4fc219973 --- /dev/null +++ b/cli/tests/testdata/018_async_catch.ts.out @@ -0,0 +1,3 @@ +before await fn() +catch +after try-catch diff --git a/cli/tests/testdata/019_media_types.ts b/cli/tests/testdata/019_media_types.ts new file mode 100644 index 000000000..d985bd249 --- /dev/null +++ b/cli/tests/testdata/019_media_types.ts @@ -0,0 +1,24 @@ +// 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 loadedTs1 } from "http://localhost:4545/subdir/mt_text_typescript.t1.ts"; +import { loaded as loadedTs2 } from "http://localhost:4545/subdir/mt_video_vdn.t2.ts"; +import { loaded as loadedTs3 } from "http://localhost:4545/subdir/mt_video_mp2t.t3.ts"; +import { loaded as loadedTs4 } from "http://localhost:4545/subdir/mt_application_x_typescript.t4.ts"; +import { loaded as loadedJs1 } from "http://localhost:4545/subdir/mt_text_javascript.j1.js"; +import { loaded as loadedJs2 } from "http://localhost:4545/subdir/mt_application_ecmascript.j2.js"; +import { loaded as loadedJs3 } from "http://localhost:4545/subdir/mt_text_ecmascript.j3.js"; +import { loaded as loadedJs4 } from "http://localhost:4545/subdir/mt_application_x_javascript.j4.js"; + +console.log( + "success", + loadedTs1, + loadedTs2, + loadedTs3, + loadedTs4, + loadedJs1, + loadedJs2, + loadedJs3, + loadedJs4, +); diff --git a/cli/tests/testdata/019_media_types.ts.out b/cli/tests/testdata/019_media_types.ts.out new file mode 100644 index 000000000..b3e94678c --- /dev/null +++ b/cli/tests/testdata/019_media_types.ts.out @@ -0,0 +1 @@ +[WILDCARD]success true true true true true true true true diff --git a/cli/tests/testdata/020_json_modules.ts b/cli/tests/testdata/020_json_modules.ts new file mode 100644 index 000000000..fdc85c440 --- /dev/null +++ b/cli/tests/testdata/020_json_modules.ts @@ -0,0 +1,2 @@ +import config from "./subdir/config.json"; +console.log(JSON.stringify(config)); diff --git a/cli/tests/testdata/020_json_modules.ts.out b/cli/tests/testdata/020_json_modules.ts.out new file mode 100644 index 000000000..bfb7c80cf --- /dev/null +++ b/cli/tests/testdata/020_json_modules.ts.out @@ -0,0 +1,5 @@ +[WILDCARD] +error: An unsupported media type was attempted to be imported as a module. + Specifier: [WILDCARD]/subdir/config.json + MediaType: Json +[WILDCARD]
\ No newline at end of file diff --git a/cli/tests/testdata/021_mjs_modules.ts b/cli/tests/testdata/021_mjs_modules.ts new file mode 100644 index 000000000..6052b9081 --- /dev/null +++ b/cli/tests/testdata/021_mjs_modules.ts @@ -0,0 +1,2 @@ +import { isMod5 } from "./subdir/mod5.mjs"; +console.log(isMod5); diff --git a/cli/tests/testdata/021_mjs_modules.ts.out b/cli/tests/testdata/021_mjs_modules.ts.out new file mode 100644 index 000000000..27ba77dda --- /dev/null +++ b/cli/tests/testdata/021_mjs_modules.ts.out @@ -0,0 +1 @@ +true diff --git a/cli/tests/testdata/022_info_flag_script.out b/cli/tests/testdata/022_info_flag_script.out new file mode 100644 index 000000000..e86b7dda4 --- /dev/null +++ b/cli/tests/testdata/022_info_flag_script.out @@ -0,0 +1,14 @@ +[WILDCARD] +local: [WILDCARD]http[WILDCARD]127.0.0.1_PORT4545[WILDCARD] +type: TypeScript +dependencies: 8 unique (total [WILDCARD]) + +http://127.0.0.1:4545/019_media_types.ts ([WILDCARD]) +├── http://localhost:4545/subdir/mt_application_ecmascript.j2.js ([WILDCARD]) +├── http://localhost:4545/subdir/mt_application_x_javascript.j4.js ([WILDCARD]) +├── http://localhost:4545/subdir/mt_application_x_typescript.t4.ts ([WILDCARD]) +├── http://localhost:4545/subdir/mt_text_ecmascript.j3.js ([WILDCARD]) +├── http://localhost:4545/subdir/mt_text_javascript.j1.js ([WILDCARD]) +├── http://localhost:4545/subdir/mt_text_typescript.t1.ts ([WILDCARD]) +├── http://localhost:4545/subdir/mt_video_mp2t.t3.ts ([WILDCARD]) +└── http://localhost:4545/subdir/mt_video_vdn.t2.ts ([WILDCARD]) diff --git a/cli/tests/testdata/023_no_ext b/cli/tests/testdata/023_no_ext new file mode 100644 index 000000000..0dcfb6209 --- /dev/null +++ b/cli/tests/testdata/023_no_ext @@ -0,0 +1,2 @@ +import * as mod4 from "./subdir/mod4.js"; +console.log(mod4.isMod4); diff --git a/cli/tests/testdata/023_no_ext.out b/cli/tests/testdata/023_no_ext.out new file mode 100644 index 000000000..27ba77dda --- /dev/null +++ b/cli/tests/testdata/023_no_ext.out @@ -0,0 +1 @@ +true diff --git a/cli/tests/testdata/024_import_no_ext_with_headers.ts b/cli/tests/testdata/024_import_no_ext_with_headers.ts new file mode 100644 index 000000000..c8621d0e6 --- /dev/null +++ b/cli/tests/testdata/024_import_no_ext_with_headers.ts @@ -0,0 +1 @@ +import "./023_no_ext_with_headers"; diff --git a/cli/tests/testdata/024_import_no_ext_with_headers.ts.out b/cli/tests/testdata/024_import_no_ext_with_headers.ts.out new file mode 100644 index 000000000..e427984d4 --- /dev/null +++ b/cli/tests/testdata/024_import_no_ext_with_headers.ts.out @@ -0,0 +1 @@ +HELLO diff --git a/cli/tests/testdata/025_hrtime.ts b/cli/tests/testdata/025_hrtime.ts new file mode 100644 index 000000000..b69d61488 --- /dev/null +++ b/cli/tests/testdata/025_hrtime.ts @@ -0,0 +1,5 @@ +window.onload = async () => { + console.log(performance.now() % 2 !== 0); + await Deno.permissions.revoke({ name: "hrtime" }); + console.log(performance.now() % 2 === 0); +}; diff --git a/cli/tests/testdata/025_hrtime.ts.out b/cli/tests/testdata/025_hrtime.ts.out new file mode 100644 index 000000000..bb101b641 --- /dev/null +++ b/cli/tests/testdata/025_hrtime.ts.out @@ -0,0 +1,2 @@ +true +true diff --git a/cli/tests/testdata/025_reload_js_type_error.js b/cli/tests/testdata/025_reload_js_type_error.js new file mode 100644 index 000000000..3b7c23cc9 --- /dev/null +++ b/cli/tests/testdata/025_reload_js_type_error.js @@ -0,0 +1,6 @@ +// deno-lint-ignore-file +// There was a bug where if this was executed with --reload it would throw a +// type error. +window.test = null; +test = console; +test.log("hello"); diff --git a/cli/tests/testdata/025_reload_js_type_error.js.out b/cli/tests/testdata/025_reload_js_type_error.js.out new file mode 100644 index 000000000..ce0136250 --- /dev/null +++ b/cli/tests/testdata/025_reload_js_type_error.js.out @@ -0,0 +1 @@ +hello diff --git a/cli/tests/testdata/026_redirect_javascript.js b/cli/tests/testdata/026_redirect_javascript.js new file mode 100644 index 000000000..226a6b622 --- /dev/null +++ b/cli/tests/testdata/026_redirect_javascript.js @@ -0,0 +1,2 @@ +import { value } from "http://localhost:4547/redirects/redirect3.js"; +console.log(value); diff --git a/cli/tests/testdata/026_redirect_javascript.js.out b/cli/tests/testdata/026_redirect_javascript.js.out new file mode 100644 index 000000000..290864299 --- /dev/null +++ b/cli/tests/testdata/026_redirect_javascript.js.out @@ -0,0 +1 @@ +3 imports 1 diff --git a/cli/tests/testdata/027_redirect_typescript.ts b/cli/tests/testdata/027_redirect_typescript.ts new file mode 100644 index 000000000..584341975 --- /dev/null +++ b/cli/tests/testdata/027_redirect_typescript.ts @@ -0,0 +1,2 @@ +import { value } from "http://localhost:4547/redirects/redirect4.ts"; +console.log(value); diff --git a/cli/tests/testdata/027_redirect_typescript.ts.out b/cli/tests/testdata/027_redirect_typescript.ts.out new file mode 100644 index 000000000..480d4e8ca --- /dev/null +++ b/cli/tests/testdata/027_redirect_typescript.ts.out @@ -0,0 +1 @@ +4 imports 1 diff --git a/cli/tests/testdata/028_args.ts b/cli/tests/testdata/028_args.ts new file mode 100644 index 000000000..ec41d52f9 --- /dev/null +++ b/cli/tests/testdata/028_args.ts @@ -0,0 +1,3 @@ +Deno.args.forEach((arg) => { + console.log(arg); +}); diff --git a/cli/tests/testdata/028_args.ts.out b/cli/tests/testdata/028_args.ts.out new file mode 100644 index 000000000..0f1b5c59e --- /dev/null +++ b/cli/tests/testdata/028_args.ts.out @@ -0,0 +1,6 @@ +--arg1 +val1 +--arg2=val2 +-- +arg3 +arg4 diff --git a/cli/tests/testdata/029_eval.out b/cli/tests/testdata/029_eval.out new file mode 100644 index 000000000..ce0136250 --- /dev/null +++ b/cli/tests/testdata/029_eval.out @@ -0,0 +1 @@ +hello diff --git a/cli/tests/testdata/030_eval_ts.out b/cli/tests/testdata/030_eval_ts.out new file mode 100644 index 000000000..190a18037 --- /dev/null +++ b/cli/tests/testdata/030_eval_ts.out @@ -0,0 +1 @@ +123 diff --git a/cli/tests/testdata/031_info_ts_error.out b/cli/tests/testdata/031_info_ts_error.out new file mode 100644 index 000000000..2dc7bb4e8 --- /dev/null +++ b/cli/tests/testdata/031_info_ts_error.out @@ -0,0 +1,5 @@ +[WILDCARD] +local: [WILDCARD]031_info_ts_error.ts +type: TypeScript +dependencies: 0 unique (total [WILDCARD]) +[WILDCARD]031_info_ts_error.ts ([WILDCARD]) diff --git a/cli/tests/testdata/031_info_ts_error.ts b/cli/tests/testdata/031_info_ts_error.ts new file mode 100644 index 000000000..9b7492dbe --- /dev/null +++ b/cli/tests/testdata/031_info_ts_error.ts @@ -0,0 +1 @@ +const _foo: string = 1; diff --git a/cli/tests/testdata/033_import_map.out b/cli/tests/testdata/033_import_map.out new file mode 100644 index 000000000..e9b9160e9 --- /dev/null +++ b/cli/tests/testdata/033_import_map.out @@ -0,0 +1,7 @@ +Hello from remapped moment! +Hello from remapped moment dir! +Hello from remapped lodash! +Hello from remapped lodash dir! +Hello from remapped Vue! +Hello from scoped moment! +Hello from scoped! diff --git a/cli/tests/testdata/033_import_map_remote.out b/cli/tests/testdata/033_import_map_remote.out new file mode 100644 index 000000000..804fa0d57 --- /dev/null +++ b/cli/tests/testdata/033_import_map_remote.out @@ -0,0 +1,5 @@ +Hello from remapped moment! +Hello from remapped moment dir! +Hello from remapped lodash! +Hello from remapped lodash dir! +Hello from remapped Vue! diff --git a/cli/tests/testdata/034_onload.out b/cli/tests/testdata/034_onload.out new file mode 100644 index 000000000..9b1f454c9 --- /dev/null +++ b/cli/tests/testdata/034_onload.out @@ -0,0 +1,11 @@ +log from nest_imported script +log from imported script +log from main +got load event in event handler (nest_imported) +got load event in event handler (imported) +got load event in event handler (main) +got load event in onload function +got unload event in event handler (nest_imported) +got unload event in event handler (imported) +got unload event in event handler (main) +got unload event in onunload function diff --git a/cli/tests/testdata/034_onload/imported.ts b/cli/tests/testdata/034_onload/imported.ts new file mode 100644 index 000000000..bac6cf5fa --- /dev/null +++ b/cli/tests/testdata/034_onload/imported.ts @@ -0,0 +1,11 @@ +import { assert } from "../../../../test_util/std/testing/asserts.ts"; +import "./nest_imported.ts"; + +const handler = (e: Event) => { + assert(!e.cancelable); + console.log(`got ${e.type} event in event handler (imported)`); +}; + +window.addEventListener("load", handler); +window.addEventListener("unload", handler); +console.log("log from imported script"); diff --git a/cli/tests/testdata/034_onload/main.ts b/cli/tests/testdata/034_onload/main.ts new file mode 100644 index 000000000..42df21c16 --- /dev/null +++ b/cli/tests/testdata/034_onload/main.ts @@ -0,0 +1,26 @@ +import { assert } from "../../../../test_util/std/testing/asserts.ts"; +import "./imported.ts"; + +assert(window.hasOwnProperty("onload")); +assert(window.onload === null); + +const eventHandler = (e: Event) => { + assert(!e.cancelable); + console.log(`got ${e.type} event in event handler (main)`); +}; + +window.addEventListener("load", eventHandler); + +window.addEventListener("unload", eventHandler); + +window.onload = (e: Event) => { + assert(!e.cancelable); + console.log(`got ${e.type} event in onload function`); +}; + +window.onunload = (e: Event) => { + assert(!e.cancelable); + console.log(`got ${e.type} event in onunload function`); +}; + +console.log("log from main"); diff --git a/cli/tests/testdata/034_onload/nest_imported.ts b/cli/tests/testdata/034_onload/nest_imported.ts new file mode 100644 index 000000000..259e505a2 --- /dev/null +++ b/cli/tests/testdata/034_onload/nest_imported.ts @@ -0,0 +1,10 @@ +import { assert } from "../../../../test_util/std/testing/asserts.ts"; + +const handler = (e: Event) => { + assert(!e.cancelable); + console.log(`got ${e.type} event in event handler (nest_imported)`); +}; + +window.addEventListener("load", handler); +window.addEventListener("unload", handler); +console.log("log from nest_imported script"); diff --git a/cli/tests/testdata/035_cached_only_flag.out b/cli/tests/testdata/035_cached_only_flag.out new file mode 100644 index 000000000..aad3f2fbc --- /dev/null +++ b/cli/tests/testdata/035_cached_only_flag.out @@ -0,0 +1 @@ +error: Specifier not found in cache: "http://127.0.0.1:4545/019_media_types.ts", --cached-only is specified. diff --git a/cli/tests/testdata/036_import_map_fetch.out b/cli/tests/testdata/036_import_map_fetch.out new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/cli/tests/testdata/036_import_map_fetch.out diff --git a/cli/tests/testdata/037_fetch_multiple.out b/cli/tests/testdata/037_fetch_multiple.out new file mode 100644 index 000000000..09c6c0f60 --- /dev/null +++ b/cli/tests/testdata/037_fetch_multiple.out @@ -0,0 +1,5 @@ +Download http://localhost:4545/subdir/mod2.ts +Download http://localhost:4545/subdir/print_hello.ts +Check [WILDCARD]/fetch/test.ts +Download http://localhost:4545/subdir/mt_text_typescript.t1.ts +Check [WILDCARD]/fetch/other.ts diff --git a/cli/tests/testdata/038_checkjs.js b/cli/tests/testdata/038_checkjs.js new file mode 100644 index 000000000..f0856d94c --- /dev/null +++ b/cli/tests/testdata/038_checkjs.js @@ -0,0 +1,5 @@ +// console.log intentionally misspelled to trigger a type error +consol.log("hello world!"); + +// the following error should be ignored and not output to the console +const foo = new Foo(); diff --git a/cli/tests/testdata/038_checkjs.js.out b/cli/tests/testdata/038_checkjs.js.out new file mode 100644 index 000000000..4ea473e4f --- /dev/null +++ b/cli/tests/testdata/038_checkjs.js.out @@ -0,0 +1,22 @@ +[WILDCARD] +error: TS2552 [ERROR]: Cannot find name 'consol'. Did you mean 'console'? +consol.log("hello world!"); +~~~~~~ + at [WILDCARD]/038_checkjs.js:2:1 + + 'console' is declared here. + declare var console: Console; + ~~~~~~~ + at [WILDCARD] + +TS2552 [ERROR]: Cannot find name 'Foo'. Did you mean 'foo'? +const foo = new Foo(); + ~~~ + at [WILDCARD]/038_checkjs.js:5:17 + + 'foo' is declared here. + const foo = new Foo(); + ~~~ + at [WILDCARD]/038_checkjs.js:5:7 + +Found 2 errors. diff --git a/cli/tests/testdata/038_checkjs.tsconfig.json b/cli/tests/testdata/038_checkjs.tsconfig.json new file mode 100644 index 000000000..46d96db9e --- /dev/null +++ b/cli/tests/testdata/038_checkjs.tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "allowJs": true, + "checkJs": true + } +} diff --git a/cli/tests/testdata/041_dyn_import_eval.out b/cli/tests/testdata/041_dyn_import_eval.out new file mode 100644 index 000000000..12a45b8da --- /dev/null +++ b/cli/tests/testdata/041_dyn_import_eval.out @@ -0,0 +1 @@ +Module { isMod4: true } diff --git a/cli/tests/testdata/041_info_flag.out b/cli/tests/testdata/041_info_flag.out new file mode 100644 index 000000000..ded795339 --- /dev/null +++ b/cli/tests/testdata/041_info_flag.out @@ -0,0 +1,5 @@ +DENO_DIR location: "[WILDCARD]" +Remote modules cache: "[WILDCARD]deps" +Emitted modules cache: "[WILDCARD]gen" +Language server registries cache: "[WILDCARD]registries" +Origin storage: "[WILDCARD]location_data" diff --git a/cli/tests/testdata/041_info_flag_location.out b/cli/tests/testdata/041_info_flag_location.out new file mode 100644 index 000000000..207065012 --- /dev/null +++ b/cli/tests/testdata/041_info_flag_location.out @@ -0,0 +1,6 @@ +DENO_DIR location: "[WILDCARD]" +Remote modules cache: "[WILDCARD]deps" +Emitted modules cache: "[WILDCARD]gen" +Language server registries cache: "[WILDCARD]registries" +Origin storage: "[WILDCARD]location_data[WILDCARD]" +Local Storage: "[WILDCARD]location_data[WILDCARD]local_storage" diff --git a/cli/tests/testdata/042_dyn_import_evalcontext.ts b/cli/tests/testdata/042_dyn_import_evalcontext.ts new file mode 100644 index 000000000..ccda3a972 --- /dev/null +++ b/cli/tests/testdata/042_dyn_import_evalcontext.ts @@ -0,0 +1,4 @@ +// @ts-expect-error "Deno.core" is not a public interface +Deno.core.evalContext( + "(async () => console.log(await import('./subdir/mod4.js')))()", +); diff --git a/cli/tests/testdata/042_dyn_import_evalcontext.ts.out b/cli/tests/testdata/042_dyn_import_evalcontext.ts.out new file mode 100644 index 000000000..12a45b8da --- /dev/null +++ b/cli/tests/testdata/042_dyn_import_evalcontext.ts.out @@ -0,0 +1 @@ +Module { isMod4: true } diff --git a/cli/tests/testdata/044_bad_resource.ts b/cli/tests/testdata/044_bad_resource.ts new file mode 100644 index 000000000..05e1354dc --- /dev/null +++ b/cli/tests/testdata/044_bad_resource.ts @@ -0,0 +1,3 @@ +const file = await Deno.open("044_bad_resource.ts", { read: true }); +file.close(); +await file.seek(10, 0); diff --git a/cli/tests/testdata/044_bad_resource.ts.out b/cli/tests/testdata/044_bad_resource.ts.out new file mode 100644 index 000000000..33c95fc44 --- /dev/null +++ b/cli/tests/testdata/044_bad_resource.ts.out @@ -0,0 +1,2 @@ +[WILDCARD]error: Uncaught (in promise) BadResource: Bad resource ID +[WILDCARD] diff --git a/cli/tests/testdata/045_mod.ts b/cli/tests/testdata/045_mod.ts new file mode 100644 index 000000000..b5f2a0b5b --- /dev/null +++ b/cli/tests/testdata/045_mod.ts @@ -0,0 +1,5 @@ +import { output } from "./045_output.ts"; + +if (import.meta.main) { + output("Hello!"); +} diff --git a/cli/tests/testdata/045_output.ts b/cli/tests/testdata/045_output.ts new file mode 100644 index 000000000..398760ca0 --- /dev/null +++ b/cli/tests/testdata/045_output.ts @@ -0,0 +1,3 @@ +export function output(text: string) { + console.log(text); +} diff --git a/cli/tests/testdata/045_programmatic_proxy_client.ts b/cli/tests/testdata/045_programmatic_proxy_client.ts new file mode 100644 index 000000000..cd6659978 --- /dev/null +++ b/cli/tests/testdata/045_programmatic_proxy_client.ts @@ -0,0 +1,16 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. + +const client = Deno.createHttpClient({ + proxy: { + url: "http://localhost:4555", + basicAuth: { username: "username", password: "password" }, + }, +}); + +const res = await fetch( + "http://localhost:4545/045_mod.ts", + { client }, +); +console.log(`Response http: ${await res.text()}`); + +client.close(); diff --git a/cli/tests/testdata/045_proxy_client.ts b/cli/tests/testdata/045_proxy_client.ts new file mode 100644 index 000000000..fe9129312 --- /dev/null +++ b/cli/tests/testdata/045_proxy_client.ts @@ -0,0 +1,5 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +const res = await fetch( + "http://localhost:4545/045_mod.ts", +); +console.log(`Response http: ${await res.text()}`); diff --git a/cli/tests/testdata/045_proxy_test.ts b/cli/tests/testdata/045_proxy_test.ts new file mode 100644 index 000000000..6d8359518 --- /dev/null +++ b/cli/tests/testdata/045_proxy_test.ts @@ -0,0 +1,142 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +import { serve, ServerRequest } from "../../../test_util/std/http/server.ts"; +import { assertEquals } from "../../../test_util/std/testing/asserts.ts"; + +const addr = Deno.args[1] || "127.0.0.1:4555"; + +async function proxyServer() { + const server = serve(addr); + + console.log(`Proxy server listening on http://${addr}/`); + for await (const req of server) { + proxyRequest(req); + } +} + +async function proxyRequest(req: ServerRequest) { + console.log(`Proxy request to: ${req.url}`); + const proxyAuthorization = req.headers.get("proxy-authorization"); + if (proxyAuthorization) { + console.log(`proxy-authorization: ${proxyAuthorization}`); + req.headers.delete("proxy-authorization"); + } + const resp = await fetch(req.url, { + method: req.method, + headers: req.headers, + }); + req.respond({ + status: resp.status, + body: new Uint8Array(await resp.arrayBuffer()), + headers: resp.headers, + }); +} + +async function testFetch() { + const c = Deno.run({ + cmd: [ + Deno.execPath(), + "run", + "--quiet", + "--reload", + "--allow-net", + "045_proxy_client.ts", + ], + stdout: "piped", + env: { + HTTP_PROXY: `http://${addr}`, + }, + }); + + const status = await c.status(); + assertEquals(status.code, 0); + c.close(); +} + +async function testModuleDownload() { + const http = Deno.run({ + cmd: [ + Deno.execPath(), + "cache", + "--reload", + "--quiet", + "http://localhost:4545/045_mod.ts", + ], + stdout: "piped", + env: { + HTTP_PROXY: `http://${addr}`, + }, + }); + + const httpStatus = await http.status(); + assertEquals(httpStatus.code, 0); + http.close(); +} + +async function testFetchNoProxy() { + const c = Deno.run({ + cmd: [ + Deno.execPath(), + "run", + "--quiet", + "--reload", + "--allow-net", + "045_proxy_client.ts", + ], + stdout: "piped", + env: { + HTTP_PROXY: "http://not.exising.proxy.server", + NO_PROXY: "localhost", + }, + }); + + const status = await c.status(); + assertEquals(status.code, 0); + c.close(); +} + +async function testModuleDownloadNoProxy() { + const http = Deno.run({ + cmd: [ + Deno.execPath(), + "cache", + "--reload", + "--quiet", + "http://localhost:4545/045_mod.ts", + ], + stdout: "piped", + env: { + HTTP_PROXY: "http://not.exising.proxy.server", + NO_PROXY: "localhost", + }, + }); + + const httpStatus = await http.status(); + assertEquals(httpStatus.code, 0); + http.close(); +} + +async function testFetchProgrammaticProxy() { + const c = Deno.run({ + cmd: [ + Deno.execPath(), + "run", + "--quiet", + "--reload", + "--allow-net=localhost:4545,localhost:4555", + "--unstable", + "045_programmatic_proxy_client.ts", + ], + stdout: "piped", + }); + const status = await c.status(); + assertEquals(status.code, 0); + c.close(); +} + +proxyServer(); +await testFetch(); +await testModuleDownload(); +await testFetchNoProxy(); +await testModuleDownloadNoProxy(); +await testFetchProgrammaticProxy(); +Deno.exit(0); diff --git a/cli/tests/testdata/045_proxy_test.ts.out b/cli/tests/testdata/045_proxy_test.ts.out new file mode 100644 index 000000000..4ebf97dee --- /dev/null +++ b/cli/tests/testdata/045_proxy_test.ts.out @@ -0,0 +1,6 @@ +Proxy server listening on [WILDCARD] +Proxy request to: http://localhost:4545/045_mod.ts +Proxy request to: http://localhost:4545/045_mod.ts +Proxy request to: http://localhost:4545/045_output.ts +Proxy request to: http://localhost:4545/045_mod.ts +proxy-authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ= diff --git a/cli/tests/testdata/046_jsx_test.tsx b/cli/tests/testdata/046_jsx_test.tsx new file mode 100644 index 000000000..a96e90baf --- /dev/null +++ b/cli/tests/testdata/046_jsx_test.tsx @@ -0,0 +1,12 @@ +declare namespace JSX { + interface IntrinsicElements { + [elemName: string]: any; + } +} +const React = { + createElement(factory: any, props: any, ...children: any[]) { + return { factory, props, children }; + }, +}; +const View = () => <div class="deno">land</div>; +console.log(<View />); diff --git a/cli/tests/testdata/046_jsx_test.tsx.out b/cli/tests/testdata/046_jsx_test.tsx.out new file mode 100644 index 000000000..85cfe824b --- /dev/null +++ b/cli/tests/testdata/046_jsx_test.tsx.out @@ -0,0 +1 @@ +{ factory: [Function: View], props: null, children: [] } diff --git a/cli/tests/testdata/047_jsx_test.jsx b/cli/tests/testdata/047_jsx_test.jsx new file mode 100644 index 000000000..4c2314072 --- /dev/null +++ b/cli/tests/testdata/047_jsx_test.jsx @@ -0,0 +1,7 @@ +const React = { + createElement(factory, props, ...children) { + return { factory, props, children }; + }, +}; +const View = () => <div class="deno">land</div>; +console.log(<View />); diff --git a/cli/tests/testdata/047_jsx_test.jsx.out b/cli/tests/testdata/047_jsx_test.jsx.out new file mode 100644 index 000000000..85cfe824b --- /dev/null +++ b/cli/tests/testdata/047_jsx_test.jsx.out @@ -0,0 +1 @@ +{ factory: [Function: View], props: null, children: [] } diff --git a/cli/tests/testdata/048_media_types_jsx.ts b/cli/tests/testdata/048_media_types_jsx.ts new file mode 100644 index 000000000..8dcd0ad68 --- /dev/null +++ b/cli/tests/testdata/048_media_types_jsx.ts @@ -0,0 +1,32 @@ +// 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/subdir/mt_text_typescript_tsx.t1.tsx"; +import { loaded as loadedTsx2 } from "http://localhost:4545/subdir/mt_video_vdn_tsx.t2.tsx"; +import { loaded as loadedTsx3 } from "http://localhost:4545/subdir/mt_video_mp2t_tsx.t3.tsx"; +import { loaded as loadedTsx4 } from "http://localhost:4545/subdir/mt_application_x_typescript_tsx.t4.tsx"; +import { loaded as loadedJsx1 } from "http://localhost:4545/subdir/mt_text_javascript_jsx.j1.jsx"; +import { loaded as loadedJsx2 } from "http://localhost:4545/subdir/mt_application_ecmascript_jsx.j2.jsx"; +import { loaded as loadedJsx3 } from "http://localhost:4545/subdir/mt_text_ecmascript_jsx.j3.jsx"; +import { loaded as loadedJsx4 } from "http://localhost:4545/subdir/mt_application_x_javascript_jsx.j4.jsx"; + +declare global { + namespace JSX { + interface IntrinsicElements { + // deno-lint-ignore no-explicit-any + [elemName: string]: any; + } + } +} + +console.log( + "success", + loadedTsx1, + loadedTsx2, + loadedTsx3, + loadedTsx4, + loadedJsx1, + loadedJsx2, + loadedJsx3, + loadedJsx4, +); diff --git a/cli/tests/testdata/048_media_types_jsx.ts.out b/cli/tests/testdata/048_media_types_jsx.ts.out new file mode 100644 index 000000000..266cc5741 --- /dev/null +++ b/cli/tests/testdata/048_media_types_jsx.ts.out @@ -0,0 +1,2 @@ +[WILDCARD] +success true true true true true true true true diff --git a/cli/tests/testdata/049_info_flag_script_jsx.out b/cli/tests/testdata/049_info_flag_script_jsx.out new file mode 100644 index 000000000..860d127fe --- /dev/null +++ b/cli/tests/testdata/049_info_flag_script_jsx.out @@ -0,0 +1,14 @@ +[WILDCARD] +local: [WILDCARD]http[WILDCARD]127.0.0.1_PORT4545[WILDCARD] +type: TypeScript +dependencies: 8 unique (total [WILDCARD]) + +http://127.0.0.1:4545/048_media_types_jsx.ts ([WILDCARD]) +├── http://localhost:4545/subdir/mt_application_ecmascript_jsx.j2.jsx ([WILDCARD]) +├── http://localhost:4545/subdir/mt_application_x_javascript_jsx.j4.jsx ([WILDCARD]) +├── http://localhost:4545/subdir/mt_application_x_typescript_tsx.t4.tsx ([WILDCARD]) +├── http://localhost:4545/subdir/mt_text_ecmascript_jsx.j3.jsx ([WILDCARD]) +├── http://localhost:4545/subdir/mt_text_javascript_jsx.j1.jsx ([WILDCARD]) +├── http://localhost:4545/subdir/mt_text_typescript_tsx.t1.tsx ([WILDCARD]) +├── http://localhost:4545/subdir/mt_video_mp2t_tsx.t3.tsx ([WILDCARD]) +└── http://localhost:4545/subdir/mt_video_vdn_tsx.t2.tsx ([WILDCARD]) diff --git a/cli/tests/testdata/052_no_remote_flag.out b/cli/tests/testdata/052_no_remote_flag.out new file mode 100644 index 000000000..c1f9f4e13 --- /dev/null +++ b/cli/tests/testdata/052_no_remote_flag.out @@ -0,0 +1 @@ +error: A remote specifier was requested: "http://127.0.0.1:4545/019_media_types.ts", but --no-remote is specified. diff --git a/cli/tests/testdata/053_import_compression.out b/cli/tests/testdata/053_import_compression.out new file mode 100644 index 000000000..371994979 --- /dev/null +++ b/cli/tests/testdata/053_import_compression.out @@ -0,0 +1,4 @@ +gzip +brotli +console.log('gzip') +console.log('brotli'); diff --git a/cli/tests/testdata/053_import_compression/brotli b/cli/tests/testdata/053_import_compression/brotli new file mode 100644 index 000000000..65f679d57 --- /dev/null +++ b/cli/tests/testdata/053_import_compression/brotli @@ -0,0 +1,2 @@ +‹ +€console.log('brotli');
\ No newline at end of file diff --git a/cli/tests/testdata/053_import_compression/gziped b/cli/tests/testdata/053_import_compression/gziped Binary files differnew file mode 100644 index 000000000..9f9a7bc69 --- /dev/null +++ b/cli/tests/testdata/053_import_compression/gziped diff --git a/cli/tests/testdata/053_import_compression/main.ts b/cli/tests/testdata/053_import_compression/main.ts new file mode 100644 index 000000000..1ff1b0c83 --- /dev/null +++ b/cli/tests/testdata/053_import_compression/main.ts @@ -0,0 +1,13 @@ +import "http://127.0.0.1:4545/053_import_compression/gziped"; +import "http://127.0.0.1:4545/053_import_compression/brotli"; + +console.log( + await fetch( + "http://127.0.0.1:4545/053_import_compression/gziped", + ).then((res) => res.text()), +); +console.log( + await fetch( + "http://127.0.0.1:4545/053_import_compression/brotli", + ).then((res) => res.text()), +); diff --git a/cli/tests/testdata/054_info_local_imports.out b/cli/tests/testdata/054_info_local_imports.out new file mode 100644 index 000000000..cde5ff3ab --- /dev/null +++ b/cli/tests/testdata/054_info_local_imports.out @@ -0,0 +1,8 @@ +local: [WILDCARD]005_more_imports.ts +type: TypeScript +dependencies: 3 unique (total [WILDCARD]) + +file://[WILDCARD]/005_more_imports.ts ([WILDCARD]) +└─┬ file://[WILDCARD]/subdir/mod1.ts ([WILDCARD]) + └─┬ file://[WILDCARD]/subdir/subdir2/mod2.ts ([WILDCARD]) + └── file://[WILDCARD]/subdir/print_hello.ts ([WILDCARD]) diff --git a/cli/tests/testdata/055_info_file_json.out b/cli/tests/testdata/055_info_file_json.out new file mode 100644 index 000000000..4753ef0ef --- /dev/null +++ b/cli/tests/testdata/055_info_file_json.out @@ -0,0 +1,53 @@ +{ + "root": "file://[WILDCARD]/005_more_imports.ts", + "modules": [ + { + "specifier": "file://[WILDCARD]/005_more_imports.ts", + "dependencies": [ + { + "specifier": "./subdir/mod1.ts", + "code": "file://[WILDCARD]/subdir/mod1.ts" + } + ], + "size": 211, + "mediaType": "TypeScript", + "local": "[WILDCARD]005_more_imports.ts", + [WILDCARD] + }, + { + "specifier": "file://[WILDCARD]/subdir/mod1.ts", + "dependencies": [ + { + "specifier": "./subdir2/mod2.ts", + "code": "file://[WILDCARD]/subdir/subdir2/mod2.ts" + } + ], + "size": 308, + "mediaType": "TypeScript", + "local": "[WILDCARD]mod1.ts", + [WILDCARD] + }, + { + "specifier": "file://[WILDCARD]/subdir/print_hello.ts", + "dependencies": [], + "size": 57, + "mediaType": "TypeScript", + "local": "[WILDCARD]print_hello.ts", + [WILDCARD] + }, + { + "specifier": "file://[WILDCARD]/subdir/subdir2/mod2.ts", + "dependencies": [ + { + "specifier": "../print_hello.ts", + "code": "file://[WILDCARD]/subdir/print_hello.ts" + } + ], + "size": 157, + "mediaType": "TypeScript", + "local": "[WILDCARD]mod2.ts", + [WILDCARD] + } + ], + "size": 733 +} diff --git a/cli/tests/testdata/056_make_temp_file_write_perm.out b/cli/tests/testdata/056_make_temp_file_write_perm.out new file mode 100644 index 000000000..c56aae43f --- /dev/null +++ b/cli/tests/testdata/056_make_temp_file_write_perm.out @@ -0,0 +1 @@ +good [WILDCARD]subdir[WILDCARD] diff --git a/cli/tests/testdata/056_make_temp_file_write_perm.ts b/cli/tests/testdata/056_make_temp_file_write_perm.ts new file mode 100644 index 000000000..c0deda8a2 --- /dev/null +++ b/cli/tests/testdata/056_make_temp_file_write_perm.ts @@ -0,0 +1,9 @@ +const path = await Deno.makeTempFile({ dir: `subdir` }); +try { + if (!path.match(/^subdir[/\\][^/\\]+/)) { + throw Error("bad " + path); + } + console.log("good", path); +} finally { + await Deno.remove(path); +} diff --git a/cli/tests/testdata/058_tasks_microtasks_close.ts b/cli/tests/testdata/058_tasks_microtasks_close.ts new file mode 100644 index 000000000..11de55a38 --- /dev/null +++ b/cli/tests/testdata/058_tasks_microtasks_close.ts @@ -0,0 +1,18 @@ +console.log("sync 1"); +setTimeout(() => { + console.log("setTimeout 1"); + Promise.resolve().then(() => { + console.log("Promise resolve in setTimeout 1"); + }); +}); +Promise.resolve().then(() => { + console.log("promise 1"); +}); +window.close(); +console.log("sync 2"); +setTimeout(() => { + console.log("setTimeout 2"); +}); +setTimeout(() => { + console.log("setTimeout 3"); +}, 100); diff --git a/cli/tests/testdata/058_tasks_microtasks_close.ts.out b/cli/tests/testdata/058_tasks_microtasks_close.ts.out new file mode 100644 index 000000000..218273cab --- /dev/null +++ b/cli/tests/testdata/058_tasks_microtasks_close.ts.out @@ -0,0 +1,6 @@ +sync 1 +sync 2 +promise 1 +setTimeout 1 +Promise resolve in setTimeout 1 +setTimeout 2 diff --git a/cli/tests/testdata/059_fs_relative_path_perm.ts b/cli/tests/testdata/059_fs_relative_path_perm.ts new file mode 100644 index 000000000..26630fe1c --- /dev/null +++ b/cli/tests/testdata/059_fs_relative_path_perm.ts @@ -0,0 +1,2 @@ +// The permission error message shouldn't include the CWD. +Deno.readFileSync("non-existent"); diff --git a/cli/tests/testdata/059_fs_relative_path_perm.ts.out b/cli/tests/testdata/059_fs_relative_path_perm.ts.out new file mode 100644 index 000000000..b55412137 --- /dev/null +++ b/cli/tests/testdata/059_fs_relative_path_perm.ts.out @@ -0,0 +1,4 @@ +[WILDCARD]error: Uncaught PermissionDenied: Requires read access to "non-existent", run again with the --allow-read flag +Deno.readFileSync("non-existent"); + ^ + at [WILDCARD] diff --git a/cli/tests/testdata/060_deno_doc_displays_all_overloads_in_details_view.ts b/cli/tests/testdata/060_deno_doc_displays_all_overloads_in_details_view.ts new file mode 100644 index 000000000..854c1b464 --- /dev/null +++ b/cli/tests/testdata/060_deno_doc_displays_all_overloads_in_details_view.ts @@ -0,0 +1,6 @@ +// deno-lint-ignore-file +export namespace NS { + export function test(name: string, fn: Function): void; + export function test(options: object): void; + export function test(name: string | object, fn?: Function): void {} +} diff --git a/cli/tests/testdata/060_deno_doc_displays_all_overloads_in_details_view.ts.out b/cli/tests/testdata/060_deno_doc_displays_all_overloads_in_details_view.ts.out new file mode 100644 index 000000000..f1a5077d8 --- /dev/null +++ b/cli/tests/testdata/060_deno_doc_displays_all_overloads_in_details_view.ts.out @@ -0,0 +1,12 @@ +Defined in [WILDCARD]/060_deno_doc_displays_all_overloads_in_details_view.ts:3:2 + +function test(name: string, fn: Function): void + +Defined in [WILDCARD]/060_deno_doc_displays_all_overloads_in_details_view.ts:4:2 + +function test(options: object): void + +Defined in [WILDCARD]/060_deno_doc_displays_all_overloads_in_details_view.ts:5:2 + +function test(name: string | object, fn?: Function): void + diff --git a/cli/tests/testdata/061_permissions_request.ts b/cli/tests/testdata/061_permissions_request.ts new file mode 100644 index 000000000..c31e7ac42 --- /dev/null +++ b/cli/tests/testdata/061_permissions_request.ts @@ -0,0 +1,9 @@ +const status1 = + (await Deno.permissions.request({ name: "read", path: "foo" })).state; +const status2 = + (await Deno.permissions.query({ name: "read", path: "bar" })).state; +const status3 = + (await Deno.permissions.request({ name: "read", path: "bar" })).state; +console.log(status1); +console.log(status2); +console.log(status3); diff --git a/cli/tests/testdata/061_permissions_request.ts.out b/cli/tests/testdata/061_permissions_request.ts.out new file mode 100644 index 000000000..362425876 --- /dev/null +++ b/cli/tests/testdata/061_permissions_request.ts.out @@ -0,0 +1,3 @@ +[WILDCARD]granted +prompt +denied diff --git a/cli/tests/testdata/062_permissions_request_global.ts b/cli/tests/testdata/062_permissions_request_global.ts new file mode 100644 index 000000000..e431bc31b --- /dev/null +++ b/cli/tests/testdata/062_permissions_request_global.ts @@ -0,0 +1,6 @@ +const status1 = await Deno.permissions.request({ name: "read" }); +console.log(status1); +const status2 = await Deno.permissions.query({ name: "read", path: "foo" }); +console.log(status2); +const status3 = await Deno.permissions.query({ name: "read", path: "bar" }); +console.log(status3); diff --git a/cli/tests/testdata/062_permissions_request_global.ts.out b/cli/tests/testdata/062_permissions_request_global.ts.out new file mode 100644 index 000000000..57b5aa7d8 --- /dev/null +++ b/cli/tests/testdata/062_permissions_request_global.ts.out @@ -0,0 +1,3 @@ +[WILDCARD]PermissionStatus { state: "granted", onchange: null } +PermissionStatus { state: "granted", onchange: null } +PermissionStatus { state: "granted", onchange: null } diff --git a/cli/tests/testdata/063_permissions_revoke.ts b/cli/tests/testdata/063_permissions_revoke.ts new file mode 100644 index 000000000..a81eee7cb --- /dev/null +++ b/cli/tests/testdata/063_permissions_revoke.ts @@ -0,0 +1,6 @@ +const status1 = await Deno.permissions.revoke({ name: "read", path: "foo" }); +console.log(status1); +const status2 = await Deno.permissions.query({ name: "read", path: "bar" }); +console.log(status2); +const status3 = await Deno.permissions.revoke({ name: "read", path: "bar" }); +console.log(status3); diff --git a/cli/tests/testdata/063_permissions_revoke.ts.out b/cli/tests/testdata/063_permissions_revoke.ts.out new file mode 100644 index 000000000..bbd64c557 --- /dev/null +++ b/cli/tests/testdata/063_permissions_revoke.ts.out @@ -0,0 +1,3 @@ +[WILDCARD]PermissionStatus { state: "prompt", onchange: null } +PermissionStatus { state: "granted", onchange: null } +PermissionStatus { state: "prompt", onchange: null } diff --git a/cli/tests/testdata/064_permissions_revoke_global.ts b/cli/tests/testdata/064_permissions_revoke_global.ts new file mode 100644 index 000000000..a9b1fcd40 --- /dev/null +++ b/cli/tests/testdata/064_permissions_revoke_global.ts @@ -0,0 +1,6 @@ +const status1 = await Deno.permissions.revoke({ name: "read" }); +console.log(status1); +const status2 = await Deno.permissions.query({ name: "read", path: "foo" }); +console.log(status2); +const status3 = await Deno.permissions.query({ name: "read", path: "bar" }); +console.log(status3); diff --git a/cli/tests/testdata/064_permissions_revoke_global.ts.out b/cli/tests/testdata/064_permissions_revoke_global.ts.out new file mode 100644 index 000000000..f7e389a76 --- /dev/null +++ b/cli/tests/testdata/064_permissions_revoke_global.ts.out @@ -0,0 +1,3 @@ +[WILDCARD]PermissionStatus { state: "prompt", onchange: null } +PermissionStatus { state: "prompt", onchange: null } +PermissionStatus { state: "prompt", onchange: null } diff --git a/cli/tests/testdata/065_import_map_info.out b/cli/tests/testdata/065_import_map_info.out new file mode 100644 index 000000000..8771d0594 --- /dev/null +++ b/cli/tests/testdata/065_import_map_info.out @@ -0,0 +1,5 @@ +[WILDCARD] +local: [WILDCARD]test.ts +type: TypeScript +dependencies: 7 unique (total [WILDCARD]) +[WILDCARD] diff --git a/cli/tests/testdata/066_prompt.ts b/cli/tests/testdata/066_prompt.ts new file mode 100644 index 000000000..e3daa7ac0 --- /dev/null +++ b/cli/tests/testdata/066_prompt.ts @@ -0,0 +1,21 @@ +const name0 = prompt("What is your name?", "Jane Doe"); // Answer John Doe +console.log(`Your name is ${name0}.`); +const name1 = prompt("What is your name?", "Jane Doe"); // Answer with default +console.log(`Your name is ${name1}.`); +const input = prompt(); // Answer foo +console.log(`Your input is ${input}.`); +const answer0 = confirm("Question 0"); // Answer y +console.log(`Your answer is ${answer0}`); +const answer1 = confirm("Question 1"); // Answer n +console.log(`Your answer is ${answer1}`); +const answer2 = confirm("Question 2"); // Answer with yes (returns false) +console.log(`Your answer is ${answer2}`); +const answer3 = confirm(); // Answer with default +console.log(`Your answer is ${answer3}`); +const windows = prompt("What is Windows EOL?"); +console.log(`Your answer is ${JSON.stringify(windows)}`); +alert("Hi"); +alert(); +console.log("The end of test"); +const eof = prompt("What is EOF?"); +console.log(`Your answer is ${JSON.stringify(eof)}`); diff --git a/cli/tests/testdata/066_prompt.ts.out b/cli/tests/testdata/066_prompt.ts.out new file mode 100644 index 000000000..7defc51e5 --- /dev/null +++ b/cli/tests/testdata/066_prompt.ts.out @@ -0,0 +1,10 @@ +[WILDCARD]What is your name? [Jane Doe] Your name is John Doe. +What is your name? [Jane Doe] Your name is Jane Doe. +Prompt Your input is foo. +Question 0 [y/N] Your answer is true +Question 1 [y/N] Your answer is false +Question 2 [y/N] Your answer is false +Confirm [y/N] Your answer is false +What is Windows EOL? Your answer is "windows" +Hi [Enter] Alert [Enter] The end of test +What is EOF? Your answer is null diff --git a/cli/tests/testdata/070_location.ts b/cli/tests/testdata/070_location.ts new file mode 100644 index 000000000..61256dcbc --- /dev/null +++ b/cli/tests/testdata/070_location.ts @@ -0,0 +1,8 @@ +console.log(Location); +console.log(Location.prototype); +console.log(location); +try { + location.hostname = "bar"; +} catch (error) { + console.log(error.toString()); +} diff --git a/cli/tests/testdata/070_location.ts.out b/cli/tests/testdata/070_location.ts.out new file mode 100644 index 000000000..e05561e58 --- /dev/null +++ b/cli/tests/testdata/070_location.ts.out @@ -0,0 +1,15 @@ +[WILDCARD][Function: Location] +Location {} +Location { + hash: "#bat", + host: "foo", + hostname: "foo", + href: "https://foo/bar?baz#bat", + origin: "https://foo", + pathname: "/bar", + port: "", + protocol: "https:", + search: "?baz" +} +NotSupportedError: Cannot set "location.hostname". +[WILDCARD] diff --git a/cli/tests/testdata/071_location_unset.ts b/cli/tests/testdata/071_location_unset.ts new file mode 100644 index 000000000..bb60df8c4 --- /dev/null +++ b/cli/tests/testdata/071_location_unset.ts @@ -0,0 +1,3 @@ +console.log(Location); +console.log(Location.prototype); +console.log(location); diff --git a/cli/tests/testdata/071_location_unset.ts.out b/cli/tests/testdata/071_location_unset.ts.out new file mode 100644 index 000000000..43308f3bd --- /dev/null +++ b/cli/tests/testdata/071_location_unset.ts.out @@ -0,0 +1,4 @@ +[WILDCARD][Function: Location] +Location {} +error: Uncaught ReferenceError: Access to "location", run again with --location <href>. +[WILDCARD] diff --git a/cli/tests/testdata/072_location_relative_fetch.ts b/cli/tests/testdata/072_location_relative_fetch.ts new file mode 100644 index 000000000..d4764bf7f --- /dev/null +++ b/cli/tests/testdata/072_location_relative_fetch.ts @@ -0,0 +1,2 @@ +const response = await fetch("fetch/hello.txt"); +console.log(await response.text()); diff --git a/cli/tests/testdata/072_location_relative_fetch.ts.out b/cli/tests/testdata/072_location_relative_fetch.ts.out new file mode 100644 index 000000000..8151f6f88 --- /dev/null +++ b/cli/tests/testdata/072_location_relative_fetch.ts.out @@ -0,0 +1,2 @@ +[WILDCARD]Hello, world! + diff --git a/cli/tests/testdata/075_import_local_query_hash.ts b/cli/tests/testdata/075_import_local_query_hash.ts new file mode 100644 index 000000000..99c7ceab4 --- /dev/null +++ b/cli/tests/testdata/075_import_local_query_hash.ts @@ -0,0 +1,2 @@ +import "./001_hello.js?a=b#c"; +import "./002_hello.ts?a=b#c"; diff --git a/cli/tests/testdata/075_import_local_query_hash.ts.out b/cli/tests/testdata/075_import_local_query_hash.ts.out new file mode 100644 index 000000000..340777742 --- /dev/null +++ b/cli/tests/testdata/075_import_local_query_hash.ts.out @@ -0,0 +1,2 @@ +[WILDCARD]Hello World +Hello World diff --git a/cli/tests/testdata/076_info_json_deps_order.out b/cli/tests/testdata/076_info_json_deps_order.out new file mode 100644 index 000000000..bcb2c70ed --- /dev/null +++ b/cli/tests/testdata/076_info_json_deps_order.out @@ -0,0 +1,78 @@ +{ + "root": "file://[WILDCARD]/076_info_json_deps_order.ts", + "modules": [ + { + "specifier": "file://[WILDCARD]/076_info_json_deps_order.ts", + "dependencies": [ + { + "specifier": "./recursive_imports/A.ts", + "code": "file://[WILDCARD]/recursive_imports/A.ts" + } + ], + "size": 81, + "mediaType": "TypeScript", + "local": "[WILDCARD]076_info_json_deps_order.ts", + "checksum": "5dd40fe33e5924cca513489ce568e86c9b9fe318a87975403c8923629018680d" + }, + { + "specifier": "file://[WILDCARD]/recursive_imports/A.ts", + "dependencies": [ + { + "specifier": "./B.ts", + "code": "file://[WILDCARD]/recursive_imports/B.ts" + }, + { + "specifier": "./common.ts", + "code": "file://[WILDCARD]/recursive_imports/common.ts" + } + ], + "size": 108, + "mediaType": "TypeScript", + "local": "[WILDCARD]A.ts", + "checksum": "3b45a105d892584298490cb73372b2cac57118e1e42a677a1d5cacea704d8d3a" + }, + { + "specifier": "file://[WILDCARD]/recursive_imports/B.ts", + "dependencies": [ + { + "specifier": "./C.ts", + "code": "file://[WILDCARD]/recursive_imports/C.ts" + }, + { + "specifier": "./common.ts", + "code": "file://[WILDCARD]/recursive_imports/common.ts" + } + ], + "size": 108, + "mediaType": "TypeScript", + "local": "[WILDCARD]B.ts", + "checksum": "b12b0437ef9a91c4a4b1f66e8e4339f986b60bd8134031ccb296ce49df15b54e" + }, + { + "specifier": "file://[WILDCARD]/recursive_imports/C.ts", + "dependencies": [ + { + "specifier": "./A.ts", + "code": "file://[WILDCARD]/recursive_imports/A.ts" + }, + { + "specifier": "./common.ts", + "code": "file://[WILDCARD]/recursive_imports/common.ts" + } + ], + "size": 126, + "mediaType": "TypeScript", + "local": "[WILDCARD]C.ts", + "checksum": "605875a410741bfaeeade28cbccf45f219ad99d987ea695e35eda75d2c53a658" + }, + { + "specifier": "file://[WILDCARD]/recursive_imports/common.ts", + "dependencies": [], + "size": 28, + "mediaType": "TypeScript", + "local": "[WILDCARD]common.ts", + "checksum": "c70025f0b936c02980c3be1fbd78f6f36b6241927c44ea67580821a6e664d8b3" + } + ], + "size": 451 +} diff --git a/cli/tests/testdata/076_info_json_deps_order.ts b/cli/tests/testdata/076_info_json_deps_order.ts new file mode 100644 index 000000000..b1ae75e68 --- /dev/null +++ b/cli/tests/testdata/076_info_json_deps_order.ts @@ -0,0 +1,2 @@ +// deno-lint-ignore no-unused-vars +import { A } from "./recursive_imports/A.ts"; diff --git a/cli/tests/testdata/077_fetch_empty.ts b/cli/tests/testdata/077_fetch_empty.ts new file mode 100644 index 000000000..b10a9094e --- /dev/null +++ b/cli/tests/testdata/077_fetch_empty.ts @@ -0,0 +1 @@ +await fetch(""); diff --git a/cli/tests/testdata/077_fetch_empty.ts.out b/cli/tests/testdata/077_fetch_empty.ts.out new file mode 100644 index 000000000..e546cfcec --- /dev/null +++ b/cli/tests/testdata/077_fetch_empty.ts.out @@ -0,0 +1,2 @@ +[WILDCARD]error: Uncaught TypeError: Invalid URL +[WILDCARD] diff --git a/cli/tests/testdata/078_unload_on_exit.ts b/cli/tests/testdata/078_unload_on_exit.ts new file mode 100644 index 000000000..43d33eb25 --- /dev/null +++ b/cli/tests/testdata/078_unload_on_exit.ts @@ -0,0 +1,9 @@ +window.onunload = () => { + console.log("onunload is called"); + // This second exit call doesn't trigger unload event, + // and therefore actually stops the process. + Deno.exit(1); + console.log("This doesn't show up in console"); +}; +// This exit call triggers the above unload event handler. +Deno.exit(0); diff --git a/cli/tests/testdata/078_unload_on_exit.ts.out b/cli/tests/testdata/078_unload_on_exit.ts.out new file mode 100644 index 000000000..e213f9632 --- /dev/null +++ b/cli/tests/testdata/078_unload_on_exit.ts.out @@ -0,0 +1 @@ +[WILDCARD]onunload is called diff --git a/cli/tests/testdata/079_location_authentication.ts b/cli/tests/testdata/079_location_authentication.ts new file mode 100644 index 000000000..4989312ac --- /dev/null +++ b/cli/tests/testdata/079_location_authentication.ts @@ -0,0 +1 @@ +console.log(location.href); diff --git a/cli/tests/testdata/079_location_authentication.ts.out b/cli/tests/testdata/079_location_authentication.ts.out new file mode 100644 index 000000000..bb2458497 --- /dev/null +++ b/cli/tests/testdata/079_location_authentication.ts.out @@ -0,0 +1,3 @@ +[WILDCARD] +https://baz/qux +[WILDCARD] diff --git a/cli/tests/testdata/080_deno_emit_permissions.ts b/cli/tests/testdata/080_deno_emit_permissions.ts new file mode 100644 index 000000000..dc550cffb --- /dev/null +++ b/cli/tests/testdata/080_deno_emit_permissions.ts @@ -0,0 +1 @@ +await Deno.emit(new URL("001_hello.js", import.meta.url).href); diff --git a/cli/tests/testdata/080_deno_emit_permissions.ts.out b/cli/tests/testdata/080_deno_emit_permissions.ts.out new file mode 100644 index 000000000..4eb4fd1c1 --- /dev/null +++ b/cli/tests/testdata/080_deno_emit_permissions.ts.out @@ -0,0 +1,2 @@ +[WILDCARD]error: Uncaught (in promise) PermissionDenied: Requires read access to "[WILDCARD]001_hello.js", run again with the --allow-read flag +[WILDCARD] diff --git a/cli/tests/testdata/081_location_relative_fetch_redirect.ts b/cli/tests/testdata/081_location_relative_fetch_redirect.ts new file mode 100644 index 000000000..742ef0afb --- /dev/null +++ b/cli/tests/testdata/081_location_relative_fetch_redirect.ts @@ -0,0 +1,2 @@ +const response = await fetch("/"); +console.log(response.url); diff --git a/cli/tests/testdata/081_location_relative_fetch_redirect.ts.out b/cli/tests/testdata/081_location_relative_fetch_redirect.ts.out new file mode 100644 index 000000000..f62b93195 --- /dev/null +++ b/cli/tests/testdata/081_location_relative_fetch_redirect.ts.out @@ -0,0 +1 @@ +[WILDCARD]http://localhost:4545/ diff --git a/cli/tests/testdata/082_prepare_stack_trace_throw.js b/cli/tests/testdata/082_prepare_stack_trace_throw.js new file mode 100644 index 000000000..8137bfdc8 --- /dev/null +++ b/cli/tests/testdata/082_prepare_stack_trace_throw.js @@ -0,0 +1,6 @@ +Error.prepareStackTrace = () => { + console.trace(); + throw new Error("foo"); +}; + +new Error("bar").stack; diff --git a/cli/tests/testdata/082_prepare_stack_trace_throw.js.out b/cli/tests/testdata/082_prepare_stack_trace_throw.js.out new file mode 100644 index 000000000..751b7c971 --- /dev/null +++ b/cli/tests/testdata/082_prepare_stack_trace_throw.js.out @@ -0,0 +1,2 @@ +[WILDCARD]error: Uncaught Error: foo +[WILDCARD] diff --git a/cli/tests/testdata/083_legacy_external_source_map.ts b/cli/tests/testdata/083_legacy_external_source_map.ts new file mode 100644 index 000000000..73d267b87 --- /dev/null +++ b/cli/tests/testdata/083_legacy_external_source_map.ts @@ -0,0 +1,2 @@ +// - +throw new Error("foo"); diff --git a/cli/tests/testdata/084_worker_custom_inspect.ts b/cli/tests/testdata/084_worker_custom_inspect.ts new file mode 100644 index 000000000..2e7b86a4e --- /dev/null +++ b/cli/tests/testdata/084_worker_custom_inspect.ts @@ -0,0 +1,4 @@ +new Worker( + new URL("084_worker_custom_inspect_worker.ts", import.meta.url).href, + { type: "module" }, +); diff --git a/cli/tests/testdata/084_worker_custom_inspect.ts.out b/cli/tests/testdata/084_worker_custom_inspect.ts.out new file mode 100644 index 000000000..b34300c40 --- /dev/null +++ b/cli/tests/testdata/084_worker_custom_inspect.ts.out @@ -0,0 +1,2 @@ +[WILDCARD]ReadableStream { locked: false } +[WILDCARD] diff --git a/cli/tests/testdata/084_worker_custom_inspect_worker.ts b/cli/tests/testdata/084_worker_custom_inspect_worker.ts new file mode 100644 index 000000000..5be82724e --- /dev/null +++ b/cli/tests/testdata/084_worker_custom_inspect_worker.ts @@ -0,0 +1,2 @@ +console.log(new ReadableStream()); +close(); diff --git a/cli/tests/testdata/085_dynamic_import_async_error.ts b/cli/tests/testdata/085_dynamic_import_async_error.ts new file mode 100644 index 000000000..aa5ff7277 --- /dev/null +++ b/cli/tests/testdata/085_dynamic_import_async_error.ts @@ -0,0 +1,5 @@ +try { + await import("./delayed_error.ts"); +} catch (error) { + console.log(`Caught: ${error.stack}`); +} diff --git a/cli/tests/testdata/085_dynamic_import_async_error.ts.out b/cli/tests/testdata/085_dynamic_import_async_error.ts.out new file mode 100644 index 000000000..974c2e426 --- /dev/null +++ b/cli/tests/testdata/085_dynamic_import_async_error.ts.out @@ -0,0 +1,2 @@ +[WILDCARD]Caught: Error: foo + at [WILDCARD]/delayed_error.ts:[WILDCARD] diff --git a/cli/tests/testdata/086_dynamic_import_already_rejected.ts b/cli/tests/testdata/086_dynamic_import_already_rejected.ts new file mode 100644 index 000000000..359db670c --- /dev/null +++ b/cli/tests/testdata/086_dynamic_import_already_rejected.ts @@ -0,0 +1,11 @@ +try { + await import("./error_001.ts"); +} catch (error) { + console.log(`Caught: ${error.stack}`); +} + +try { + await import("./error_001.ts"); +} catch (error) { + console.log(`Caught: ${error.stack}`); +} diff --git a/cli/tests/testdata/086_dynamic_import_already_rejected.ts.out b/cli/tests/testdata/086_dynamic_import_already_rejected.ts.out new file mode 100644 index 000000000..c3eb66f9e --- /dev/null +++ b/cli/tests/testdata/086_dynamic_import_already_rejected.ts.out @@ -0,0 +1,4 @@ +[WILDCARD]Caught: Error: bad + at [WILDCARD]/error_001.ts:[WILDCARD] +Caught: Error: bad + at [WILDCARD]/error_001.ts:[WILDCARD] diff --git a/cli/tests/testdata/087_hello.ts b/cli/tests/testdata/087_hello.ts new file mode 100644 index 000000000..1a9d8f114 --- /dev/null +++ b/cli/tests/testdata/087_hello.ts @@ -0,0 +1,2 @@ +export type SomeType = unknown; +console.log("Hello, world!"); diff --git a/cli/tests/testdata/087_no_check_imports_not_used_as_values.ts b/cli/tests/testdata/087_no_check_imports_not_used_as_values.ts new file mode 100644 index 000000000..64a13f9b1 --- /dev/null +++ b/cli/tests/testdata/087_no_check_imports_not_used_as_values.ts @@ -0,0 +1,4 @@ +import { SomeType } from "./087_hello.ts"; + +const string: SomeType = "Hi!"; +console.log(string); diff --git a/cli/tests/testdata/087_no_check_imports_not_used_as_values.ts.out b/cli/tests/testdata/087_no_check_imports_not_used_as_values.ts.out new file mode 100644 index 000000000..f744c4183 --- /dev/null +++ b/cli/tests/testdata/087_no_check_imports_not_used_as_values.ts.out @@ -0,0 +1,2 @@ +[WILDCARD]Hello, world! +Hi! diff --git a/cli/tests/testdata/088_dynamic_import_already_evaluating.ts b/cli/tests/testdata/088_dynamic_import_already_evaluating.ts new file mode 100644 index 000000000..272163a5d --- /dev/null +++ b/cli/tests/testdata/088_dynamic_import_already_evaluating.ts @@ -0,0 +1,2 @@ +import("./088_dynamic_import_target.ts").then(() => console.log(3)); +import("./088_dynamic_import_target.ts").then(() => console.log(3)); diff --git a/cli/tests/testdata/088_dynamic_import_already_evaluating.ts.out b/cli/tests/testdata/088_dynamic_import_already_evaluating.ts.out new file mode 100644 index 000000000..a36dd11e7 --- /dev/null +++ b/cli/tests/testdata/088_dynamic_import_already_evaluating.ts.out @@ -0,0 +1,4 @@ +[WILDCARD]1 +2 +3 +3 diff --git a/cli/tests/testdata/088_dynamic_import_target.ts b/cli/tests/testdata/088_dynamic_import_target.ts new file mode 100644 index 000000000..226f1851a --- /dev/null +++ b/cli/tests/testdata/088_dynamic_import_target.ts @@ -0,0 +1,3 @@ +console.log(1); +await new Promise((r) => setTimeout(r, 100)); +console.log(2); diff --git a/cli/tests/testdata/089_run_allow_list.ts b/cli/tests/testdata/089_run_allow_list.ts new file mode 100644 index 000000000..defb3196f --- /dev/null +++ b/cli/tests/testdata/089_run_allow_list.ts @@ -0,0 +1,13 @@ +try { + Deno.run({ + cmd: ["ls"], + }); +} catch (e) { + console.log(e); +} + +const proc = Deno.run({ + cmd: ["curl", "--help"], + stdout: "null", +}); +console.log((await proc.status()).success); diff --git a/cli/tests/testdata/089_run_allow_list.ts.out b/cli/tests/testdata/089_run_allow_list.ts.out new file mode 100644 index 000000000..68a4a2ac5 --- /dev/null +++ b/cli/tests/testdata/089_run_allow_list.ts.out @@ -0,0 +1,3 @@ +[WILDCARD]PermissionDenied: Requires run access to "ls", run again with the --allow-run flag +[WILDCARD] +true diff --git a/cli/tests/testdata/090_run_permissions_request.ts b/cli/tests/testdata/090_run_permissions_request.ts new file mode 100644 index 000000000..044bc6e8e --- /dev/null +++ b/cli/tests/testdata/090_run_permissions_request.ts @@ -0,0 +1,9 @@ +const status1 = + (await Deno.permissions.request({ name: "run", command: "ls" })).state; +const status2 = + (await Deno.permissions.query({ name: "run", command: "cat" })).state; +const status3 = + (await Deno.permissions.request({ name: "run", command: "cat" })).state; +console.log(status1); +console.log(status2); +console.log(status3); diff --git a/cli/tests/testdata/090_run_permissions_request.ts.out b/cli/tests/testdata/090_run_permissions_request.ts.out new file mode 100644 index 000000000..362425876 --- /dev/null +++ b/cli/tests/testdata/090_run_permissions_request.ts.out @@ -0,0 +1,3 @@ +[WILDCARD]granted +prompt +denied diff --git a/cli/tests/testdata/091_use_define_for_class_fields.ts b/cli/tests/testdata/091_use_define_for_class_fields.ts new file mode 100644 index 000000000..46be3ac0b --- /dev/null +++ b/cli/tests/testdata/091_use_define_for_class_fields.ts @@ -0,0 +1,4 @@ +class _A { + b = this.a; + constructor(public a: unknown) {} +} diff --git a/cli/tests/testdata/091_use_define_for_class_fields.ts.out b/cli/tests/testdata/091_use_define_for_class_fields.ts.out new file mode 100644 index 000000000..08f94a967 --- /dev/null +++ b/cli/tests/testdata/091_use_define_for_class_fields.ts.out @@ -0,0 +1,4 @@ +[WILDCARD]error: TS2729 [ERROR]: Property 'a' is used before its initialization. + b = this.a; + ^ +[WILDCARD] diff --git a/cli/tests/testdata/092_import_map_unmapped_bare_specifier.ts b/cli/tests/testdata/092_import_map_unmapped_bare_specifier.ts new file mode 100644 index 000000000..87684430d --- /dev/null +++ b/cli/tests/testdata/092_import_map_unmapped_bare_specifier.ts @@ -0,0 +1 @@ +await import("unmapped"); diff --git a/cli/tests/testdata/092_import_map_unmapped_bare_specifier.ts.out b/cli/tests/testdata/092_import_map_unmapped_bare_specifier.ts.out new file mode 100644 index 000000000..1a55e352b --- /dev/null +++ b/cli/tests/testdata/092_import_map_unmapped_bare_specifier.ts.out @@ -0,0 +1,4 @@ +[WILDCARD]error: Uncaught (in promise) TypeError: Relative import path "unmapped" not prefixed with / or ./ or ../ and not in import map from "[WILDCARD]" +await import("unmapped"); +^ + at [WILDCARD] diff --git a/cli/tests/testdata/095_cache_with_bare_import.ts b/cli/tests/testdata/095_cache_with_bare_import.ts new file mode 100644 index 000000000..c0748305d --- /dev/null +++ b/cli/tests/testdata/095_cache_with_bare_import.ts @@ -0,0 +1 @@ +import "foo"; diff --git a/cli/tests/testdata/095_cache_with_bare_import.ts.out b/cli/tests/testdata/095_cache_with_bare_import.ts.out new file mode 100644 index 000000000..f424f4c3e --- /dev/null +++ b/cli/tests/testdata/095_cache_with_bare_import.ts.out @@ -0,0 +1 @@ +[WILDCARD]error: Relative import path "foo" not prefixed with / or ./ or ../ from "file:///[WILDCARD]/095_cache_with_bare_import.ts" diff --git a/cli/tests/testdata/Component.tsx b/cli/tests/testdata/Component.tsx new file mode 100644 index 000000000..81dfd6957 --- /dev/null +++ b/cli/tests/testdata/Component.tsx @@ -0,0 +1 @@ +import "./046_jsx_test.tsx"; diff --git a/cli/tests/testdata/DenoWinRunner.cs b/cli/tests/testdata/DenoWinRunner.cs new file mode 100644 index 000000000..2f9e9f89f --- /dev/null +++ b/cli/tests/testdata/DenoWinRunner.cs @@ -0,0 +1,127 @@ +using System; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.Runtime.InteropServices; +using System.Threading.Tasks; + +[Flags] +public enum DenoConstraints : int +{ + None = 0, + NoStdin = 1, + NoStdout = 2, + NoStderr = 4 +} + +public class DenoWinRunner +{ + private const int STD_INPUT_HANDLE = -10; + private const int STD_OUTPUT_HANDLE = -11; + private const int STD_ERROR_HANDLE = -12; + + private const int FILE_NOT_FOUND = 2; + private const int WAIT_TIMEOUT = 258; + + [DllImport("kernel32.dll")] + private static extern void SetStdHandle(int nStdHandle, IntPtr handle); + + /// <summary> + /// Runs Deno.exe under the specified constraints + /// </summary> + /// <param name="pathToDenoExe">Path to the Deno.exe file. Can be absolute or relative</param> + /// <param name="pathToTestScript">Path to the script file Deno should run.</param> + /// <param name="constraints">The constraints to apply to the Deno process</param> + /// <param name="timeoutMilliseconds">How long to wait for the Deno process to exit</param> + /// <returns>The deno.exe exit code, or an exit code provided by the test runner</returns> + public static int RunDenoScript(string pathToDenoExe, string pathToTestScript, DenoConstraints constraints, uint timeoutMilliseconds = 1000) + { + try + { + if (!File.Exists(pathToDenoExe)) + { + Console.Error.WriteLine("Cannot find Deno.exe at " + pathToDenoExe); + return FILE_NOT_FOUND; + } + + if (!File.Exists(pathToTestScript)) + { + Console.Error.WriteLine("Cannot find test script at " + pathToTestScript); + return FILE_NOT_FOUND; + } + + ProcessStartInfo startInfo = new ProcessStartInfo(pathToDenoExe) + { + ErrorDialog = false, + UseShellExecute = false, + Arguments = @"run -A " + pathToTestScript, + RedirectStandardInput = !constraints.HasFlag(DenoConstraints.NoStdin), + RedirectStandardOutput = !constraints.HasFlag(DenoConstraints.NoStdout), + RedirectStandardError = !constraints.HasFlag(DenoConstraints.NoStderr) + }; + + startInfo.Environment.Add("RUST_BACKTRACE", "1"); + + if (constraints.HasFlag(DenoConstraints.NoStdin)) + { + SetStdHandle(STD_INPUT_HANDLE, (IntPtr)null); + } + + if (constraints.HasFlag(DenoConstraints.NoStdout)) + { + SetStdHandle(STD_OUTPUT_HANDLE, (IntPtr)null); + } + + if (constraints.HasFlag(DenoConstraints.NoStderr)) + { + SetStdHandle(STD_ERROR_HANDLE, (IntPtr)null); + } + + Process process = new Process { StartInfo = startInfo }; + process.Start(); + + Task<string> stdErrTask = startInfo.RedirectStandardError ? + process.StandardError.ReadToEndAsync() : Task.FromResult<string>(null); + Task<string> stdOutTask = startInfo.RedirectStandardOutput ? + process.StandardOutput.ReadToEndAsync() : Task.FromResult<string>(null); + + if (!process.WaitForExit((int)timeoutMilliseconds)) + { + Console.Error.WriteLine("Timed out waiting for Deno process to exit"); + try + { + process.Kill(); + } + catch + { + // Kill might fail, either because the process already exited or due to some other error + Console.Error.WriteLine("Failure killing the Deno process - possible Zombie Deno.exe process"); + } + return WAIT_TIMEOUT; + } + + // If the Deno process wrote to STDERR - append it to our STDERR + if (!constraints.HasFlag(DenoConstraints.NoStderr)) + { + string error = stdErrTask.Result; + if (!string.IsNullOrWhiteSpace(error)) + { + Console.Error.WriteLine(error); + } + } + + return process.ExitCode; + + } + catch (Win32Exception ex) + { + Console.Error.WriteLine("Win32Exception: code = " + ex.ErrorCode + ", message: " + ex.Message); + return ex.NativeErrorCode; + } + catch (Exception ex) + { + Console.Error.WriteLine("Exception: message: " + ex.Message); + return -1; + } + } +} diff --git a/cli/tests/testdata/DenoWinRunner.ps1 b/cli/tests/testdata/DenoWinRunner.ps1 new file mode 100644 index 000000000..203b5d36c --- /dev/null +++ b/cli/tests/testdata/DenoWinRunner.ps1 @@ -0,0 +1,10 @@ +$Source = [IO.File]::ReadAllText("$PSScriptRoot\DenoWinRunner.cs") +$denoExePath = $args[0] +$scriptPath = $args[1] +$constraints = $args[2] +$timeout = 5000; +Add-Type -TypeDefinition $Source -Language CSharp +Write-Output("Running Deno script: " + $args[1]) +$code = [DenoWinRunner]::RunDenoScript($denoExePath, $scriptPath, $constraints, $timeout) +Write-Output("Deno.exe or the test wrapper has exited with code: $code") +exit $code diff --git a/cli/tests/testdata/async_error.ts b/cli/tests/testdata/async_error.ts new file mode 100644 index 000000000..b55c73aeb --- /dev/null +++ b/cli/tests/testdata/async_error.ts @@ -0,0 +1,9 @@ +console.log("hello"); +// deno-lint-ignore require-await +const foo = async (): Promise<never> => { + console.log("before error"); + throw Error("error"); +}; + +foo(); +console.log("world"); diff --git a/cli/tests/testdata/async_error.ts.out b/cli/tests/testdata/async_error.ts.out new file mode 100644 index 000000000..b424f9072 --- /dev/null +++ b/cli/tests/testdata/async_error.ts.out @@ -0,0 +1,8 @@ +[WILDCARD]hello +before error +world +error: Uncaught (in promise) Error: error + throw Error("error"); + ^ + at foo ([WILDCARD]/async_error.ts:5:9) + at [WILDCARD]/async_error.ts:8:1 diff --git a/cli/tests/testdata/badly_formatted.json b/cli/tests/testdata/badly_formatted.json new file mode 100644 index 000000000..f2bacf73d --- /dev/null +++ b/cli/tests/testdata/badly_formatted.json @@ -0,0 +1,12 @@ +{ + + + "key1": "value1", + "key2": true, + "key3": ["value2", "value3", false], + "keys": { + "more": "values" + } + + +}
\ No newline at end of file diff --git a/cli/tests/testdata/badly_formatted.md b/cli/tests/testdata/badly_formatted.md new file mode 100644 index 000000000..26afe483b --- /dev/null +++ b/cli/tests/testdata/badly_formatted.md @@ -0,0 +1,46 @@ +# Hello Markdown + +```js +console.log("Hello World" + +) +``` + +```javascript +console.log("Hello World2" + +) +``` + +```ts + +function hello(name: string ) { + console.log(name); +}; + +hello( "alice"); +``` + +```typescript +function foo(): number { + return 2; +} +``` + +```jsonc + +{ + // Comment in JSON + "key": "value", + "key2": + "value2", +} + +``` + +```json +{ + "numbers": + ["1", "2"] +} +```
\ No newline at end of file diff --git a/cli/tests/testdata/badly_formatted.mjs b/cli/tests/testdata/badly_formatted.mjs new file mode 100644 index 000000000..bc515a330 --- /dev/null +++ b/cli/tests/testdata/badly_formatted.mjs @@ -0,0 +1,4 @@ +// Deliberately using .mjs to avoid triggering dprint +console.log("Hello World" + +) diff --git a/cli/tests/testdata/badly_formatted_fixed.js b/cli/tests/testdata/badly_formatted_fixed.js new file mode 100644 index 000000000..e9062ba85 --- /dev/null +++ b/cli/tests/testdata/badly_formatted_fixed.js @@ -0,0 +1,2 @@ +// Deliberately using .mjs to avoid triggering dprint +console.log("Hello World"); diff --git a/cli/tests/testdata/badly_formatted_fixed.json b/cli/tests/testdata/badly_formatted_fixed.json new file mode 100644 index 000000000..0d697a2c6 --- /dev/null +++ b/cli/tests/testdata/badly_formatted_fixed.json @@ -0,0 +1,8 @@ +{ + "key1": "value1", + "key2": true, + "key3": ["value2", "value3", false], + "keys": { + "more": "values" + } +} diff --git a/cli/tests/testdata/badly_formatted_fixed.md b/cli/tests/testdata/badly_formatted_fixed.md new file mode 100644 index 000000000..8ba74cac3 --- /dev/null +++ b/cli/tests/testdata/badly_formatted_fixed.md @@ -0,0 +1,37 @@ +# Hello Markdown + +```js +console.log("Hello World"); +``` + +```javascript +console.log("Hello World2"); +``` + +```ts +function hello(name: string) { + console.log(name); +} + +hello("alice"); +``` + +```typescript +function foo(): number { + return 2; +} +``` + +```jsonc +{ + // Comment in JSON + "key": "value", + "key2": "value2" +} +``` + +```json +{ + "numbers": ["1", "2"] +} +``` diff --git a/cli/tests/testdata/blob_gc_finalization.js b/cli/tests/testdata/blob_gc_finalization.js new file mode 100644 index 000000000..34c878513 --- /dev/null +++ b/cli/tests/testdata/blob_gc_finalization.js @@ -0,0 +1,11 @@ +// This test creates 1024 blobs of 128 MB each. This will only work if the blobs +// and their backing data is GCed as expected. +for (let i = 0; i < 1024; i++) { + // Create a 128MB byte array, and then a blob from it. + const buf = new Uint8Array(128 * 1024 * 1024); + new Blob([buf]); + // It is very important that there is a yield here, otherwise the finalizer + // for the blob is not called and the memory is not freed. + await new Promise((resolve) => setTimeout(resolve, 0)); +} +console.log("GCed all blobs"); diff --git a/cli/tests/testdata/blob_gc_finalization.js.out b/cli/tests/testdata/blob_gc_finalization.js.out new file mode 100644 index 000000000..dcc4500f8 --- /dev/null +++ b/cli/tests/testdata/blob_gc_finalization.js.out @@ -0,0 +1 @@ +GCed all blobs diff --git a/cli/tests/testdata/bundle.test.out b/cli/tests/testdata/bundle.test.out new file mode 100644 index 000000000..030c09295 --- /dev/null +++ b/cli/tests/testdata/bundle.test.out @@ -0,0 +1,27 @@ +[WILDCARD] +function printHello() { + console.log("Hello"); +} +function returnsFoo() { + return "Foo"; +} +function printHello2() { + printHello(); +} +function returnsHi1() { + return "Hi"; +} +function returnsFoo21() { + return returnsFoo(); +} +function printHello31() { + printHello2(); +} +function throwsError1() { + throw Error("exception from mod1"); +} +export { returnsHi1 as returnsHi }; +export { returnsFoo21 as returnsFoo2 }; +export { printHello31 as printHello3 }; +export { throwsError1 as throwsError }; + diff --git a/cli/tests/testdata/bundle/file_tests-fixture01.ts b/cli/tests/testdata/bundle/file_tests-fixture01.ts new file mode 100644 index 000000000..3598d0298 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-fixture01.ts @@ -0,0 +1,3 @@ +import * as a from "./subdir/a.ts"; + +console.log(a); diff --git a/cli/tests/testdata/bundle/file_tests-fixture02.ts b/cli/tests/testdata/bundle/file_tests-fixture02.ts new file mode 100644 index 000000000..0cd291329 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-fixture02.ts @@ -0,0 +1,4 @@ +import * as b from "./subdir/b.ts"; + +console.log(b.b); // "b" +console.log(b.c); // { c: "c", default: class C } diff --git a/cli/tests/testdata/bundle/file_tests-fixture03.ts b/cli/tests/testdata/bundle/file_tests-fixture03.ts new file mode 100644 index 000000000..78365ce13 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-fixture03.ts @@ -0,0 +1,3 @@ +import { d } from "./subdir/d.ts"; + +console.log(d); diff --git a/cli/tests/testdata/bundle/file_tests-fixture04.ts b/cli/tests/testdata/bundle/file_tests-fixture04.ts new file mode 100644 index 000000000..590f4fef9 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-fixture04.ts @@ -0,0 +1,3 @@ +const a = await import("./subdir/a.ts"); + +console.log(a); diff --git a/cli/tests/testdata/bundle/file_tests-fixture05.ts b/cli/tests/testdata/bundle/file_tests-fixture05.ts new file mode 100644 index 000000000..19541ce59 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-fixture05.ts @@ -0,0 +1,3 @@ +import { a } from "./subdir/e.ts"; + +console.log(a); diff --git a/cli/tests/testdata/bundle/file_tests-fixture06.ts b/cli/tests/testdata/bundle/file_tests-fixture06.ts new file mode 100644 index 000000000..3d94332df --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-fixture06.ts @@ -0,0 +1,4 @@ +import { isMain, modUrl } from "./subdir/f.ts"; + +console.log(isMain, modUrl); +console.log(import.meta.main, import.meta.url); diff --git a/cli/tests/testdata/bundle/file_tests-fixture07.ts b/cli/tests/testdata/bundle/file_tests-fixture07.ts new file mode 100644 index 000000000..0475a6c53 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-fixture07.ts @@ -0,0 +1,4 @@ +import { G } from "./subdir/g.ts"; +import { H } from "./subdir/h.ts"; + +console.log(new G(true), new H(true)); diff --git a/cli/tests/testdata/bundle/file_tests-fixture08.ts b/cli/tests/testdata/bundle/file_tests-fixture08.ts new file mode 100644 index 000000000..6af5d172e --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-fixture08.ts @@ -0,0 +1 @@ +export * as a from "./subdir/a.ts"; diff --git a/cli/tests/testdata/bundle/file_tests-fixture09.ts b/cli/tests/testdata/bundle/file_tests-fixture09.ts new file mode 100644 index 000000000..30ba983ee --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-fixture09.ts @@ -0,0 +1 @@ +export { a } from "./subdir/k.ts"; diff --git a/cli/tests/testdata/bundle/file_tests-fixture10.ts b/cli/tests/testdata/bundle/file_tests-fixture10.ts new file mode 100644 index 000000000..bec555da8 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-fixture10.ts @@ -0,0 +1,7 @@ +import { a as defaultA } from "./subdir/l.ts"; + +const o: { a?: string } = {}; + +const { a = defaultA } = o; + +console.log(a); diff --git a/cli/tests/testdata/bundle/file_tests-fixture11.ts b/cli/tests/testdata/bundle/file_tests-fixture11.ts new file mode 100644 index 000000000..1c361438f --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-fixture11.ts @@ -0,0 +1,32 @@ +import { a as defaultA, O } from "./subdir/m.ts"; +export { O } from "./subdir/m.ts"; + +interface AOptions { + a?(); + c?: O; +} + +class A { + #a: () => void; + #c?: O; + constructor(o: AOptions = {}) { + const { + a = defaultA, + c, + } = o; + this.#a = a; + this.#c = c; + } + + a() { + this.#a(); + } + + c() { + console.log(this.#c); + } +} + +const a = new A(); +a.a(); +a.c(); diff --git a/cli/tests/testdata/bundle/file_tests-fixture12.ts b/cli/tests/testdata/bundle/file_tests-fixture12.ts new file mode 100644 index 000000000..32b9566bd --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-fixture12.ts @@ -0,0 +1,7 @@ +import { a } from "./subdir/p.ts"; + +function b() { + a(); +} + +b(); diff --git a/cli/tests/testdata/bundle/file_tests-fixture13.ts b/cli/tests/testdata/bundle/file_tests-fixture13.ts new file mode 100644 index 000000000..7dc13534c --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-fixture13.ts @@ -0,0 +1,11 @@ +import { D, d } from "./subdir/q.ts"; + +class A { + private s: D = d(); + + a() { + this.s.resolve(); + } +} + +new A(); diff --git a/cli/tests/testdata/bundle/file_tests-fixture14.ts b/cli/tests/testdata/bundle/file_tests-fixture14.ts new file mode 100644 index 000000000..aa8eef1b8 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-fixture14.ts @@ -0,0 +1,4 @@ +// @deno-types="https://deno.land/x/lib/mod.d.ts" +import * as lib from "https://deno.land/x/lib/mod.js"; + +console.log(lib); diff --git a/cli/tests/testdata/bundle/file_tests-fixture15.ts b/cli/tests/testdata/bundle/file_tests-fixture15.ts new file mode 100644 index 000000000..c1dd3bc89 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-fixture15.ts @@ -0,0 +1,3 @@ +export function getIndex(c: string): number { + return "\x00\r\n\x85\u2028\u2029".indexOf(c); +} diff --git a/cli/tests/testdata/bundle/file_tests-subdir-a.ts b/cli/tests/testdata/bundle/file_tests-subdir-a.ts new file mode 100644 index 000000000..9233cce2f --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-subdir-a.ts @@ -0,0 +1 @@ +export const a = "a"; diff --git a/cli/tests/testdata/bundle/file_tests-subdir-b.ts b/cli/tests/testdata/bundle/file_tests-subdir-b.ts new file mode 100644 index 000000000..1cf751c22 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-subdir-b.ts @@ -0,0 +1,3 @@ +export * as c from "./c.ts"; + +export const b = "b"; diff --git a/cli/tests/testdata/bundle/file_tests-subdir-c.ts b/cli/tests/testdata/bundle/file_tests-subdir-c.ts new file mode 100644 index 000000000..7cc01f993 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-subdir-c.ts @@ -0,0 +1,2 @@ +export const c = "c"; +export default class C {} diff --git a/cli/tests/testdata/bundle/file_tests-subdir-d.ts b/cli/tests/testdata/bundle/file_tests-subdir-d.ts new file mode 100644 index 000000000..9f1ba7f67 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-subdir-d.ts @@ -0,0 +1,3 @@ +import { a } from "./a.ts"; + +export const d = { a }; diff --git a/cli/tests/testdata/bundle/file_tests-subdir-e.ts b/cli/tests/testdata/bundle/file_tests-subdir-e.ts new file mode 100644 index 000000000..55e8e0e18 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-subdir-e.ts @@ -0,0 +1 @@ +export * from "./a.ts"; diff --git a/cli/tests/testdata/bundle/file_tests-subdir-f.ts b/cli/tests/testdata/bundle/file_tests-subdir-f.ts new file mode 100644 index 000000000..8bc8d9bf4 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-subdir-f.ts @@ -0,0 +1,2 @@ +export const isMain = import.meta.main; +export const modUrl = import.meta.url; diff --git a/cli/tests/testdata/bundle/file_tests-subdir-g.ts b/cli/tests/testdata/bundle/file_tests-subdir-g.ts new file mode 100644 index 000000000..3eb4cd3cc --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-subdir-g.ts @@ -0,0 +1,12 @@ +const g: number[] = []; + +export class G { + #g!: number[]; + constructor(shared: boolean) { + if (shared) { + this.#g = g; + } else { + this.#g = []; + } + } +} diff --git a/cli/tests/testdata/bundle/file_tests-subdir-h.ts b/cli/tests/testdata/bundle/file_tests-subdir-h.ts new file mode 100644 index 000000000..9c86dd5c5 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-subdir-h.ts @@ -0,0 +1,12 @@ +const g: number[] = []; + +export class H { + #g!: number[]; + constructor(shared: boolean) { + if (shared) { + this.#g = g; + } else { + this.#g = []; + } + } +} diff --git a/cli/tests/testdata/bundle/file_tests-subdir-i.ts b/cli/tests/testdata/bundle/file_tests-subdir-i.ts new file mode 100644 index 000000000..4ad9ce449 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-subdir-i.ts @@ -0,0 +1,3 @@ +export function a(...d: string[]): string { + return d.join(" "); +} diff --git a/cli/tests/testdata/bundle/file_tests-subdir-j.ts b/cli/tests/testdata/bundle/file_tests-subdir-j.ts new file mode 100644 index 000000000..ac7bce0ea --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-subdir-j.ts @@ -0,0 +1,3 @@ +export function a(...d: string[]): string { + return d.join("/"); +} diff --git a/cli/tests/testdata/bundle/file_tests-subdir-k.ts b/cli/tests/testdata/bundle/file_tests-subdir-k.ts new file mode 100644 index 000000000..1b8a533f1 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-subdir-k.ts @@ -0,0 +1,11 @@ +import * as _i from "./i.ts"; +import * as _j from "./j.ts"; + +const k = globalThis.value ? _i : _j; + +export const i = _i; +export const j = _j; + +export const { + a, +} = k; diff --git a/cli/tests/testdata/bundle/file_tests-subdir-l.ts b/cli/tests/testdata/bundle/file_tests-subdir-l.ts new file mode 100644 index 000000000..d767e6ad0 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-subdir-l.ts @@ -0,0 +1 @@ +export { a } from "./a.ts"; diff --git a/cli/tests/testdata/bundle/file_tests-subdir-m.ts b/cli/tests/testdata/bundle/file_tests-subdir-m.ts new file mode 100644 index 000000000..21e86d07c --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-subdir-m.ts @@ -0,0 +1,2 @@ +export { a } from "./n.ts"; +export { O } from "./o.ts"; diff --git a/cli/tests/testdata/bundle/file_tests-subdir-n.ts b/cli/tests/testdata/bundle/file_tests-subdir-n.ts new file mode 100644 index 000000000..ac3c37005 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-subdir-n.ts @@ -0,0 +1,3 @@ +export function a() { + console.log("a"); +} diff --git a/cli/tests/testdata/bundle/file_tests-subdir-o.ts b/cli/tests/testdata/bundle/file_tests-subdir-o.ts new file mode 100644 index 000000000..ab9753fea --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-subdir-o.ts @@ -0,0 +1,5 @@ +export enum O { + A, + B, + C, +} diff --git a/cli/tests/testdata/bundle/file_tests-subdir-p.ts b/cli/tests/testdata/bundle/file_tests-subdir-p.ts new file mode 100644 index 000000000..19b486f71 --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-subdir-p.ts @@ -0,0 +1 @@ +export * from "./i.ts"; diff --git a/cli/tests/testdata/bundle/file_tests-subdir-q.ts b/cli/tests/testdata/bundle/file_tests-subdir-q.ts new file mode 100644 index 000000000..eebe0a38b --- /dev/null +++ b/cli/tests/testdata/bundle/file_tests-subdir-q.ts @@ -0,0 +1,13 @@ +// deno-lint-ignore-file +export interface D { + resolve: any; + reject: any; +} + +export function d(): D { + let methods; + const promise = new Promise((resolve, reject) => { + methods = { resolve, reject }; + }); + return Object.assign(promise, methods); +} diff --git a/cli/tests/testdata/bundle/fixture01.out b/cli/tests/testdata/bundle/fixture01.out new file mode 100644 index 000000000..a825140b7 --- /dev/null +++ b/cli/tests/testdata/bundle/fixture01.out @@ -0,0 +1,7 @@ +const a = "a"; +const mod = function() { + return { + a: a + }; +}(); +console.log(mod); diff --git a/cli/tests/testdata/bundle/fixture02.out b/cli/tests/testdata/bundle/fixture02.out new file mode 100644 index 000000000..5c502e2f0 --- /dev/null +++ b/cli/tests/testdata/bundle/fixture02.out @@ -0,0 +1,12 @@ +const c = "c"; +class C { +} +const mod = function() { + return { + default: C, + c: c + }; +}(); +const b = "b"; +console.log(b); +console.log(mod); diff --git a/cli/tests/testdata/bundle/fixture03.out b/cli/tests/testdata/bundle/fixture03.out new file mode 100644 index 000000000..524e77abb --- /dev/null +++ b/cli/tests/testdata/bundle/fixture03.out @@ -0,0 +1,5 @@ +const a = "a"; +const d = { + a +}; +console.log(d); diff --git a/cli/tests/testdata/bundle/fixture04.out b/cli/tests/testdata/bundle/fixture04.out new file mode 100644 index 000000000..37869205b --- /dev/null +++ b/cli/tests/testdata/bundle/fixture04.out @@ -0,0 +1,2 @@ +const a = await import("./subdir/a.ts"); +console.log(a); diff --git a/cli/tests/testdata/bundle/fixture05.out b/cli/tests/testdata/bundle/fixture05.out new file mode 100644 index 000000000..1289cca5f --- /dev/null +++ b/cli/tests/testdata/bundle/fixture05.out @@ -0,0 +1,2 @@ +const a = "a"; +console.log(a); diff --git a/cli/tests/testdata/bundle/fixture06.out b/cli/tests/testdata/bundle/fixture06.out new file mode 100644 index 000000000..47288d5e4 --- /dev/null +++ b/cli/tests/testdata/bundle/fixture06.out @@ -0,0 +1,12 @@ +const importMeta = { + url: "file:///tests/subdir/f.ts", + main: false +}; +const isMain = importMeta.main; +const modUrl = importMeta.url; +const importMeta1 = { + url: "file:///tests/fixture06.ts", + main: import.meta.main +}; +console.log(isMain, modUrl); +console.log(importMeta1.main, importMeta1.url); diff --git a/cli/tests/testdata/bundle/fixture07.out b/cli/tests/testdata/bundle/fixture07.out new file mode 100644 index 000000000..39e6a11e8 --- /dev/null +++ b/cli/tests/testdata/bundle/fixture07.out @@ -0,0 +1,23 @@ +const g = []; +class G { + #g; + constructor(shared){ + if (shared) { + this.#g = g; + } else { + this.#g = []; + } + } +} +const g1 = []; +class H { + #g; + constructor(shared1){ + if (shared1) { + this.#g = g1; + } else { + this.#g = []; + } + } +} +console.log(new G(true), new H(true)); diff --git a/cli/tests/testdata/bundle/fixture08.out b/cli/tests/testdata/bundle/fixture08.out new file mode 100644 index 000000000..bfe40aa37 --- /dev/null +++ b/cli/tests/testdata/bundle/fixture08.out @@ -0,0 +1,7 @@ +const a1 = "a"; +const mod = function() { + return { + a: a1 + }; +}(); +export { mod as a }; diff --git a/cli/tests/testdata/bundle/fixture09.out b/cli/tests/testdata/bundle/fixture09.out new file mode 100644 index 000000000..e06cc92de --- /dev/null +++ b/cli/tests/testdata/bundle/fixture09.out @@ -0,0 +1,19 @@ +function a3(...d) { + return d.join(" "); +} +const mod = function() { + return { + a: a3 + }; +}(); +function a1(...d) { + return d.join("/"); +} +const mod1 = function() { + return { + a: a1 + }; +}(); +const k = globalThis.value ? mod : mod1; +const { a: a2 , } = k; +export { a2 as a }; diff --git a/cli/tests/testdata/bundle/fixture10.out b/cli/tests/testdata/bundle/fixture10.out new file mode 100644 index 000000000..5491e5e7f --- /dev/null +++ b/cli/tests/testdata/bundle/fixture10.out @@ -0,0 +1,5 @@ +const a = "a"; +const o = { +}; +const { a: a1 = a } = o; +console.log(a1); diff --git a/cli/tests/testdata/bundle/fixture11.out b/cli/tests/testdata/bundle/fixture11.out new file mode 100644 index 000000000..d143e8723 --- /dev/null +++ b/cli/tests/testdata/bundle/fixture11.out @@ -0,0 +1,30 @@ +function a() { + console.log("a"); +} +var O1; +(function(O1) { + O1[O1["A"] = 0] = "A"; + O1[O1["B"] = 1] = "B"; + O1[O1["C"] = 2] = "C"; +})(O1 || (O1 = { +})); +export { O1 as O }; +class A { + #a; + #c; + constructor(o = { + }){ + const { a: a1 = a , c , } = o; + this.#a = a1; + this.#c = c; + } + a() { + this.#a(); + } + c() { + console.log(this.#c); + } +} +const a2 = new A(); +a2.a(); +a2.c(); diff --git a/cli/tests/testdata/bundle/fixture12.out b/cli/tests/testdata/bundle/fixture12.out new file mode 100644 index 000000000..64e2d6cdb --- /dev/null +++ b/cli/tests/testdata/bundle/fixture12.out @@ -0,0 +1,7 @@ +function a(...d) { + return d.join(" "); +} +function b() { + a(); +} +b(); diff --git a/cli/tests/testdata/bundle/fixture13.out b/cli/tests/testdata/bundle/fixture13.out new file mode 100644 index 000000000..1c7a8c991 --- /dev/null +++ b/cli/tests/testdata/bundle/fixture13.out @@ -0,0 +1,17 @@ +function d() { + let methods; + const promise = new Promise((resolve, reject)=>{ + methods = { + resolve, + reject + }; + }); + return Object.assign(promise, methods); +} +class A { + s = d(); + a() { + this.s.resolve(); + } +} +new A(); diff --git a/cli/tests/testdata/bundle/fixture14.out b/cli/tests/testdata/bundle/fixture14.out new file mode 100644 index 000000000..392bb6478 --- /dev/null +++ b/cli/tests/testdata/bundle/fixture14.out @@ -0,0 +1,2 @@ +const mod = []; +console.log(mod); diff --git a/cli/tests/testdata/bundle/fixture15.out b/cli/tests/testdata/bundle/fixture15.out new file mode 100644 index 000000000..dc72fdeff --- /dev/null +++ b/cli/tests/testdata/bundle/fixture15.out @@ -0,0 +1,4 @@ +function getIndex1(c) { + return "\x00\r\n\x85\u2028\u2029".indexOf(c); +} +export { getIndex1 as getIndex }; diff --git a/cli/tests/testdata/bundle/https_deno.land-x-lib-a.ts b/cli/tests/testdata/bundle/https_deno.land-x-lib-a.ts new file mode 100644 index 000000000..a0a6f8e94 --- /dev/null +++ b/cli/tests/testdata/bundle/https_deno.land-x-lib-a.ts @@ -0,0 +1 @@ +export const a: string[] = []; diff --git a/cli/tests/testdata/bundle/https_deno.land-x-lib-b.js b/cli/tests/testdata/bundle/https_deno.land-x-lib-b.js new file mode 100644 index 000000000..13cacdd8b --- /dev/null +++ b/cli/tests/testdata/bundle/https_deno.land-x-lib-b.js @@ -0,0 +1 @@ +export const b = []; diff --git a/cli/tests/testdata/bundle/https_deno.land-x-lib-c.d.ts b/cli/tests/testdata/bundle/https_deno.land-x-lib-c.d.ts new file mode 100644 index 000000000..fac988e49 --- /dev/null +++ b/cli/tests/testdata/bundle/https_deno.land-x-lib-c.d.ts @@ -0,0 +1 @@ +export const c: string[]; diff --git a/cli/tests/testdata/bundle/https_deno.land-x-lib-c.js b/cli/tests/testdata/bundle/https_deno.land-x-lib-c.js new file mode 100644 index 000000000..620ca0b66 --- /dev/null +++ b/cli/tests/testdata/bundle/https_deno.land-x-lib-c.js @@ -0,0 +1,3 @@ +/// <reference types="./c.d.ts" /> + +export const c = []; diff --git a/cli/tests/testdata/bundle/https_deno.land-x-lib-mod.d.ts b/cli/tests/testdata/bundle/https_deno.land-x-lib-mod.d.ts new file mode 100644 index 000000000..76ed81df0 --- /dev/null +++ b/cli/tests/testdata/bundle/https_deno.land-x-lib-mod.d.ts @@ -0,0 +1,9 @@ +export * as a from "./a.ts"; +export * as b from "./b.js"; +export * as c from "./c.js"; + +export interface A { + a: string; +} + +export const mod: A[]; diff --git a/cli/tests/testdata/bundle/https_deno.land-x-lib-mod.js b/cli/tests/testdata/bundle/https_deno.land-x-lib-mod.js new file mode 100644 index 000000000..505162094 --- /dev/null +++ b/cli/tests/testdata/bundle/https_deno.land-x-lib-mod.js @@ -0,0 +1,5 @@ +export * as a from "./a.ts"; +export * as b from "./b.js"; +export * as c from "./c.js"; + +export const mod = []; diff --git a/cli/tests/testdata/bundle_dynamic_import.ts b/cli/tests/testdata/bundle_dynamic_import.ts new file mode 100644 index 000000000..d8c7d08ec --- /dev/null +++ b/cli/tests/testdata/bundle_dynamic_import.ts @@ -0,0 +1,3 @@ +const mod1 = await import("http://localhost:4545/subdir/mod1.ts"); + +mod1.printHello3(); diff --git a/cli/tests/testdata/bundle_im.json b/cli/tests/testdata/bundle_im.json new file mode 100644 index 000000000..8ebc00c5b --- /dev/null +++ b/cli/tests/testdata/bundle_im.json @@ -0,0 +1,5 @@ +{ + "imports": { + "mod2": "./subdir/subdir2/mod2.ts" + } +} diff --git a/cli/tests/testdata/bundle_im.ts b/cli/tests/testdata/bundle_im.ts new file mode 100644 index 000000000..74834de20 --- /dev/null +++ b/cli/tests/testdata/bundle_im.ts @@ -0,0 +1,17 @@ +import { printHello2, returnsFoo } from "mod2"; + +export function returnsHi(): string { + return "Hi"; +} + +export function returnsFoo2(): string { + return returnsFoo(); +} + +export function printHello3() { + printHello2(); +} + +export function throwsError() { + throw Error("exception from mod1"); +} diff --git a/cli/tests/testdata/bundle_jsx.out b/cli/tests/testdata/bundle_jsx.out new file mode 100644 index 000000000..44c9e4555 --- /dev/null +++ b/cli/tests/testdata/bundle_jsx.out @@ -0,0 +1,10 @@ +[WILDCARD] +const React = { + createElement () { + } +}; +function app() { + return React.createElement("div", null, React.createElement("h2", null, "asdf")); +} +console.log(app); + diff --git a/cli/tests/testdata/cache_extensionless.out b/cli/tests/testdata/cache_extensionless.out new file mode 100644 index 000000000..3694c67cb --- /dev/null +++ b/cli/tests/testdata/cache_extensionless.out @@ -0,0 +1,2 @@ +[WILDCARD] +Check http://localhost:4545/subdir/no_js_ext diff --git a/cli/tests/testdata/cache_random_extension.out b/cli/tests/testdata/cache_random_extension.out new file mode 100644 index 000000000..745a2e0e3 --- /dev/null +++ b/cli/tests/testdata/cache_random_extension.out @@ -0,0 +1,2 @@ +[WILDCARD] +Check http://localhost:4545/subdir/no_js_ext@1.0.0 diff --git a/cli/tests/testdata/cafile_info.ts b/cli/tests/testdata/cafile_info.ts new file mode 100644 index 000000000..b41873f73 --- /dev/null +++ b/cli/tests/testdata/cafile_info.ts @@ -0,0 +1,24 @@ +// 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 loadedTs1 } from "https://localhost:5545/subdir/mt_text_typescript.t1.ts"; +import { loaded as loadedTs2 } from "https://localhost:5545/subdir/mt_video_vdn.t2.ts"; +import { loaded as loadedTs3 } from "https://localhost:5545/subdir/mt_video_mp2t.t3.ts"; +import { loaded as loadedTs4 } from "https://localhost:5545/subdir/mt_application_x_typescript.t4.ts"; +import { loaded as loadedJs1 } from "https://localhost:5545/subdir/mt_text_javascript.j1.js"; +import { loaded as loadedJs2 } from "https://localhost:5545/subdir/mt_application_ecmascript.j2.js"; +import { loaded as loadedJs3 } from "https://localhost:5545/subdir/mt_text_ecmascript.j3.js"; +import { loaded as loadedJs4 } from "https://localhost:5545/subdir/mt_application_x_javascript.j4.js"; + +console.log( + "success", + loadedTs1, + loadedTs2, + loadedTs3, + loadedTs4, + loadedJs1, + loadedJs2, + loadedJs3, + loadedJs4, +); diff --git a/cli/tests/testdata/cafile_info.ts.out b/cli/tests/testdata/cafile_info.ts.out new file mode 100644 index 000000000..3ce03961d --- /dev/null +++ b/cli/tests/testdata/cafile_info.ts.out @@ -0,0 +1,13 @@ +local: [WILDCARD]https[WILDCARD]localhost_PORT5545[WILDCARD] +type: TypeScript +dependencies: 8 unique (total [WILDCARD]) + +https://localhost:5545/cafile_info.ts ([WILDCARD]) +├── https://localhost:5545/subdir/mt_application_ecmascript.j2.js ([WILDCARD]) +├── https://localhost:5545/subdir/mt_application_x_javascript.j4.js ([WILDCARD]) +├── https://localhost:5545/subdir/mt_application_x_typescript.t4.ts ([WILDCARD]) +├── https://localhost:5545/subdir/mt_text_ecmascript.j3.js ([WILDCARD]) +├── https://localhost:5545/subdir/mt_text_javascript.j1.js ([WILDCARD]) +├── https://localhost:5545/subdir/mt_text_typescript.t1.ts ([WILDCARD]) +├── https://localhost:5545/subdir/mt_video_mp2t.t3.ts ([WILDCARD]) +└── https://localhost:5545/subdir/mt_video_vdn.t2.ts ([WILDCARD]) diff --git a/cli/tests/testdata/cafile_ts_fetch.ts b/cli/tests/testdata/cafile_ts_fetch.ts new file mode 100644 index 000000000..03afb6d2f --- /dev/null +++ b/cli/tests/testdata/cafile_ts_fetch.ts @@ -0,0 +1,3 @@ +fetch("https://localhost:5545/cafile_ts_fetch.ts.out") + .then((r) => r.text()) + .then((t) => console.log(t.trimEnd())); diff --git a/cli/tests/testdata/cafile_ts_fetch.ts.out b/cli/tests/testdata/cafile_ts_fetch.ts.out new file mode 100644 index 000000000..e965047ad --- /dev/null +++ b/cli/tests/testdata/cafile_ts_fetch.ts.out @@ -0,0 +1 @@ +Hello diff --git a/cli/tests/testdata/cafile_ts_fetch_unsafe_ssl.ts.out b/cli/tests/testdata/cafile_ts_fetch_unsafe_ssl.ts.out new file mode 100644 index 000000000..1dc61c837 --- /dev/null +++ b/cli/tests/testdata/cafile_ts_fetch_unsafe_ssl.ts.out @@ -0,0 +1,2 @@ +DANGER: TLS certificate validation is disabled for all hostnames +Hello diff --git a/cli/tests/testdata/cafile_url_imports.ts b/cli/tests/testdata/cafile_url_imports.ts new file mode 100644 index 000000000..2355a8628 --- /dev/null +++ b/cli/tests/testdata/cafile_url_imports.ts @@ -0,0 +1,3 @@ +import { printHello } from "https://localhost:5545/subdir/mod2.ts"; +printHello(); +console.log("success"); diff --git a/cli/tests/testdata/cafile_url_imports.ts.out b/cli/tests/testdata/cafile_url_imports.ts.out new file mode 100644 index 000000000..989ce33e9 --- /dev/null +++ b/cli/tests/testdata/cafile_url_imports.ts.out @@ -0,0 +1,2 @@ +Hello +success diff --git a/cli/tests/testdata/cafile_url_imports_unsafe_ssl.ts.out b/cli/tests/testdata/cafile_url_imports_unsafe_ssl.ts.out new file mode 100644 index 000000000..daebcd766 --- /dev/null +++ b/cli/tests/testdata/cafile_url_imports_unsafe_ssl.ts.out @@ -0,0 +1,3 @@ +DANGER: TLS certificate validation is disabled for: localhost +Hello +success diff --git a/cli/tests/testdata/cat.ts b/cli/tests/testdata/cat.ts new file mode 100644 index 000000000..6d8f150e3 --- /dev/null +++ b/cli/tests/testdata/cat.ts @@ -0,0 +1,10 @@ +import { copy } from "../../../test_util/std/io/util.ts"; +async function main() { + for (let i = 1; i < Deno.args.length; i++) { + const filename = Deno.args[i]; + const file = await Deno.open(filename); + await copy(file, Deno.stdout); + } +} + +main(); diff --git a/cli/tests/testdata/circular1.js b/cli/tests/testdata/circular1.js new file mode 100644 index 000000000..8b2cc4960 --- /dev/null +++ b/cli/tests/testdata/circular1.js @@ -0,0 +1,2 @@ +import "./circular2.js"; +console.log("circular1"); diff --git a/cli/tests/testdata/circular1.js.out b/cli/tests/testdata/circular1.js.out new file mode 100644 index 000000000..21f7fd585 --- /dev/null +++ b/cli/tests/testdata/circular1.js.out @@ -0,0 +1,2 @@ +circular2 +circular1 diff --git a/cli/tests/testdata/circular2.js b/cli/tests/testdata/circular2.js new file mode 100644 index 000000000..62127e04d --- /dev/null +++ b/cli/tests/testdata/circular2.js @@ -0,0 +1,2 @@ +import "./circular1.js"; +console.log("circular2"); diff --git a/cli/tests/testdata/cjs_imports.ts b/cli/tests/testdata/cjs_imports.ts new file mode 100644 index 000000000..d8b77c22e --- /dev/null +++ b/cli/tests/testdata/cjs_imports.ts @@ -0,0 +1 @@ +import "./commonjs.cjs"; diff --git a/cli/tests/testdata/cjs_imports.ts.out b/cli/tests/testdata/cjs_imports.ts.out new file mode 100644 index 000000000..557db03de --- /dev/null +++ b/cli/tests/testdata/cjs_imports.ts.out @@ -0,0 +1 @@ +Hello World diff --git a/cli/tests/testdata/commonjs.cjs b/cli/tests/testdata/commonjs.cjs new file mode 100644 index 000000000..7df7d571e --- /dev/null +++ b/cli/tests/testdata/commonjs.cjs @@ -0,0 +1 @@ +console.log("Hello World");
\ No newline at end of file diff --git a/cli/tests/testdata/compiler_api_test.ts b/cli/tests/testdata/compiler_api_test.ts new file mode 100644 index 000000000..92eb4c519 --- /dev/null +++ b/cli/tests/testdata/compiler_api_test.ts @@ -0,0 +1,504 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +import { + assert, + assertEquals, + assertStringIncludes, + assertThrowsAsync, +} from "../../../test_util/std/testing/asserts.ts"; + +Deno.test({ + name: "Deno.emit() - sources provided", + async fn() { + const { diagnostics, files, ignoredOptions, stats } = await Deno.emit( + "/foo.ts", + { + sources: { + "/foo.ts": `import * as bar from "./bar.ts";\n\nconsole.log(bar);\n`, + "/bar.ts": `export const bar = "bar";\n`, + }, + }, + ); + assertEquals(diagnostics.length, 0); + assert(!ignoredOptions); + assertEquals(stats.length, 12); + const keys = Object.keys(files).sort(); + assert(keys[0].endsWith("/bar.ts.js")); + assert(keys[1].endsWith("/bar.ts.js.map")); + assert(keys[2].endsWith("/foo.ts.js")); + assert(keys[3].endsWith("/foo.ts.js.map")); + }, +}); + +Deno.test({ + name: "Deno.emit() - no sources provided", + async fn() { + const { diagnostics, files, ignoredOptions, stats } = await Deno.emit( + "./subdir/mod1.ts", + ); + assertEquals(diagnostics.length, 0); + assert(!ignoredOptions); + assertEquals(stats.length, 12); + const keys = Object.keys(files).sort(); + assertEquals(keys.length, 6); + assert(keys[0].endsWith("subdir/mod1.ts.js")); + assert(keys[1].endsWith("subdir/mod1.ts.js.map")); + }, +}); + +Deno.test({ + name: "Deno.emit() - compiler options effects emit", + async fn() { + const { diagnostics, files, ignoredOptions, stats } = await Deno.emit( + "/foo.ts", + { + compilerOptions: { + module: "amd", + sourceMap: false, + }, + sources: { "/foo.ts": `export const foo = "foo";` }, + }, + ); + assertEquals(diagnostics.length, 0); + assert(!ignoredOptions); + assertEquals(stats.length, 12); + const keys = Object.keys(files); + assertEquals(keys.length, 1); + const key = keys[0]; + assert(key.endsWith("/foo.ts.js")); + assert(files[key].startsWith("define(")); + }, +}); + +Deno.test({ + name: "Deno.emit() - pass lib in compiler options", + async fn() { + const { diagnostics, files, ignoredOptions, stats } = await Deno.emit( + "file:///foo.ts", + { + compilerOptions: { + lib: ["dom", "es2018", "deno.ns"], + }, + sources: { + "file:///foo.ts": `console.log(document.getElementById("foo")); + console.log(Deno.args);`, + }, + }, + ); + assertEquals(diagnostics.length, 0); + assert(!ignoredOptions); + assertEquals(stats.length, 12); + const keys = Object.keys(files).sort(); + assertEquals(keys, ["file:///foo.ts.js", "file:///foo.ts.js.map"]); + }, +}); + +Deno.test({ + name: "Deno.emit() - type references can be loaded", + async fn() { + const { diagnostics, files, ignoredOptions, stats } = await Deno.emit( + "file:///a.ts", + { + sources: { + "file:///a.ts": `/// <reference types="./b.d.ts" /> + const b = new B(); + console.log(b.b);`, + "file:///b.d.ts": `declare class B { + b: string; + }`, + }, + }, + ); + assertEquals(diagnostics.length, 0); + assert(!ignoredOptions); + assertEquals(stats.length, 12); + const keys = Object.keys(files).sort(); + assertEquals(keys, ["file:///a.ts.js", "file:///a.ts.js.map"]); + }, +}); + +Deno.test({ + name: "Deno.emit() - compilerOptions.types", + async fn() { + const { diagnostics, files, ignoredOptions, stats } = await Deno.emit( + "file:///a.ts", + { + compilerOptions: { + types: ["file:///b.d.ts"], + }, + sources: { + "file:///a.ts": `const b = new B(); + console.log(b.b);`, + "file:///b.d.ts": `declare class B { + b: string; + }`, + }, + }, + ); + assertEquals(diagnostics.length, 0); + assert(!ignoredOptions); + assertEquals(stats.length, 12); + const keys = Object.keys(files).sort(); + assertEquals(keys, ["file:///a.ts.js", "file:///a.ts.js.map"]); + }, +}); + +Deno.test({ + name: "Deno.emit() - import maps", + async fn() { + const { diagnostics, files, ignoredOptions, stats } = await Deno.emit( + "file:///a.ts", + { + importMap: { + imports: { + "b": "./b.ts", + }, + }, + importMapPath: "file:///import-map.json", + sources: { + "file:///a.ts": `import * as b from "b" + console.log(b);`, + "file:///b.ts": `export const b = "b";`, + }, + }, + ); + assertEquals(diagnostics.length, 0); + assert(!ignoredOptions); + assertEquals(stats.length, 12); + const keys = Object.keys(files).sort(); + assertEquals( + keys, + [ + "file:///a.ts.js", + "file:///a.ts.js.map", + "file:///b.ts.js", + "file:///b.ts.js.map", + ], + ); + }, +}); + +Deno.test({ + name: "Deno.emit() - no check", + async fn() { + const { diagnostics, files, ignoredOptions, stats } = await Deno.emit( + "/foo.ts", + { + check: false, + sources: { + "/foo.ts": `export enum Foo { Foo, Bar, Baz };\n`, + }, + }, + ); + assertEquals(diagnostics.length, 0); + assert(!ignoredOptions); + assertEquals(stats.length, 3); + const keys = Object.keys(files).sort(); + assert(keys[0].endsWith("/foo.ts.js")); + assert(keys[1].endsWith("/foo.ts.js.map")); + assert(files[keys[0]].startsWith("export var Foo;")); + }, +}); + +Deno.test({ + name: "Deno.emit() - no check - config effects emit", + async fn() { + const { diagnostics, files, ignoredOptions, stats } = await Deno.emit( + "/foo.ts", + { + check: false, + compilerOptions: { removeComments: true }, + sources: { + "/foo.ts": + `/** This is JSDoc */\nexport enum Foo { Foo, Bar, Baz };\n`, + }, + }, + ); + assertEquals(diagnostics.length, 0); + assert(!ignoredOptions); + assertEquals(stats.length, 3); + const keys = Object.keys(files).sort(); + assert(keys[0].endsWith("/foo.ts.js")); + assert(keys[1].endsWith("/foo.ts.js.map")); + assert(!files[keys[0]].includes("This is JSDoc")); + }, +}); + +Deno.test({ + name: "Deno.emit() - bundle as module script - with sources", + async fn() { + const { diagnostics, files, ignoredOptions, stats } = await Deno.emit( + "/foo.ts", + { + bundle: "module", + sources: { + "/foo.ts": `export * from "./bar.ts";\n`, + "/bar.ts": `export const bar = "bar";\n`, + }, + }, + ); + assertEquals(diagnostics.length, 0); + assert(!ignoredOptions); + assertEquals(stats.length, 12); + assertEquals( + Object.keys(files).sort(), + ["deno:///bundle.js", "deno:///bundle.js.map"].sort(), + ); + assert(files["deno:///bundle.js"].includes(`const bar1 = "bar"`)); + }, +}); + +Deno.test({ + name: "Deno.emit() - bundle as module script - no sources", + async fn() { + const { diagnostics, files, ignoredOptions, stats } = await Deno.emit( + "./subdir/mod1.ts", + { + bundle: "module", + }, + ); + assertEquals(diagnostics.length, 0); + assert(!ignoredOptions); + assertEquals(stats.length, 12); + assertEquals( + Object.keys(files).sort(), + ["deno:///bundle.js", "deno:///bundle.js.map"].sort(), + ); + assert(files["deno:///bundle.js"].length); + }, +}); + +Deno.test({ + name: "Deno.emit() - bundle as module script - include js modules", + async fn() { + const { diagnostics, files, ignoredOptions, stats } = await Deno.emit( + "/foo.js", + { + bundle: "module", + sources: { + "/foo.js": `export * from "./bar.js";\n`, + "/bar.js": `export const bar = "bar";\n`, + }, + }, + ); + assertEquals(diagnostics.length, 0); + assert(!ignoredOptions); + assertEquals(stats.length, 12); + assertEquals( + Object.keys(files).sort(), + ["deno:///bundle.js.map", "deno:///bundle.js"].sort(), + ); + assert(files["deno:///bundle.js"].includes(`const bar1 = "bar"`)); + }, +}); + +Deno.test({ + name: "Deno.emit() - generates diagnostics", + async fn() { + const { diagnostics, files } = await Deno.emit( + "/foo.ts", + { + sources: { + "/foo.ts": `document.getElementById("foo");`, + }, + }, + ); + assertEquals(diagnostics.length, 1); + const keys = Object.keys(files).sort(); + assert(keys[0].endsWith("/foo.ts.js")); + assert(keys[1].endsWith("/foo.ts.js.map")); + }, +}); + +// See https://github.com/denoland/deno/issues/6908 +Deno.test({ + name: "Deno.emit() - invalid syntax does not panic", + async fn() { + await assertThrowsAsync(async () => { + await Deno.emit("/main.js", { + sources: { + "/main.js": ` + export class Foo { + constructor() { + console.log("foo"); + } + export get() { + console.log("bar"); + } + }`, + }, + }); + }); + }, +}); + +Deno.test({ + name: 'Deno.emit() - allows setting of "importsNotUsedAsValues"', + async fn() { + const { diagnostics } = await Deno.emit("/a.ts", { + sources: { + "/a.ts": `import { B } from "./b.ts"; + const b: B = { b: "b" };`, + "/b.ts": `export interface B { + b:string; + };`, + }, + compilerOptions: { + importsNotUsedAsValues: "error", + }, + }); + assert(diagnostics); + assertEquals(diagnostics.length, 1); + assert(diagnostics[0].messageText); + assert(diagnostics[0].messageText.includes("This import is never used")); + }, +}); + +Deno.test({ + name: "Deno.emit() - Unknown media type does not panic", + async fn() { + await assertThrowsAsync(async () => { + await Deno.emit("https://example.com/foo", { + sources: { + "https://example.com/foo": `let foo: string = "foo";`, + }, + }); + }); + }, +}); + +Deno.test({ + name: "Deno.emit() - non-normalized specifier and source can compile", + async fn() { + const specifier = "https://example.com/foo//bar.ts"; + const { files } = await Deno.emit(specifier, { + sources: { + [specifier]: `export let foo: string = "foo";`, + }, + }); + assertEquals(files[`${specifier}.js`], 'export let foo = "foo";\n'); + assert(typeof files[`${specifier}.js.map`] === "string"); + }, +}); + +Deno.test({ + name: `Deno.emit() - bundle as classic script iife`, + async fn() { + const { diagnostics, files } = await Deno.emit("/a.ts", { + bundle: "classic", + sources: { + "/a.ts": `import { b } from "./b.ts"; + console.log(b);`, + "/b.ts": `export const b = "b";`, + }, + }); + assert(diagnostics); + assertEquals(diagnostics.length, 0); + assertEquals(Object.keys(files).length, 2); + assert(files["deno:///bundle.js"].startsWith("(function() {\n")); + assert(files["deno:///bundle.js"].endsWith("})();\n")); + assert(files["deno:///bundle.js.map"]); + }, +}); + +Deno.test({ + name: `Deno.emit() - throws descriptive error when unable to load import map`, + async fn() { + await assertThrowsAsync( + async () => { + await Deno.emit("/a.ts", { + bundle: "classic", + sources: { + "/a.ts": `console.log("hello");`, + }, + importMapPath: "file:///import_map_does_not_exist.json", + }); + }, + Error, + "Unable to load 'file:///import_map_does_not_exist.json' import map", + ); + }, +}); + +Deno.test({ + name: `Deno.emit() - support source maps with bundle option`, + async fn() { + { + const { diagnostics, files } = await Deno.emit("/a.ts", { + bundle: "classic", + sources: { + "/a.ts": `import { b } from "./b.ts"; + console.log(b);`, + "/b.ts": `export const b = "b";`, + }, + compilerOptions: { + inlineSourceMap: true, + sourceMap: false, + }, + }); + assert(diagnostics); + assertEquals(diagnostics.length, 0); + assertEquals(Object.keys(files).length, 1); + assertStringIncludes(files["deno:///bundle.js"], "sourceMappingURL"); + } + + const { diagnostics, files } = await Deno.emit("/a.ts", { + bundle: "classic", + sources: { + "/a.ts": `import { b } from "./b.ts"; + console.log(b);`, + "/b.ts": `export const b = "b";`, + }, + }); + assert(diagnostics); + assertEquals(diagnostics.length, 0); + assertEquals(Object.keys(files).length, 2); + assert(files["deno:///bundle.js"]); + assert(files["deno:///bundle.js.map"]); + }, +}); + +Deno.test({ + name: `Deno.emit() - graph errors as diagnostics`, + ignore: Deno.build.os === "windows", + async fn() { + const { diagnostics } = await Deno.emit("/a.ts", { + sources: { + "/a.ts": `import { b } from "./b.ts"; + console.log(b);`, + }, + }); + assert(diagnostics); + assertEquals(diagnostics, [ + { + category: 1, + code: 2305, + start: { line: 0, character: 9 }, + end: { line: 0, character: 10 }, + messageText: + `Module '"deno:///missing_dependency.d.ts"' has no exported member 'b'.`, + messageChain: null, + source: null, + sourceLine: 'import { b } from "./b.ts";', + fileName: "file:///a.ts", + relatedInformation: null, + }, + { + category: 1, + code: 900001, + start: null, + end: null, + messageText: "Unable to find specifier in sources: file:///b.ts", + messageChain: null, + source: null, + sourceLine: null, + fileName: "file:///b.ts", + relatedInformation: null, + }, + ]); + assert( + Deno.formatDiagnostics(diagnostics).includes( + "Unable to find specifier in sources: file:///b.ts", + ), + ); + }, +}); diff --git a/cli/tests/testdata/complex_permissions_test.ts b/cli/tests/testdata/complex_permissions_test.ts new file mode 100644 index 000000000..bae157246 --- /dev/null +++ b/cli/tests/testdata/complex_permissions_test.ts @@ -0,0 +1,53 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +const name = Deno.args[0]; +// deno-lint-ignore no-explicit-any +const test: { [key: string]: (...args: any[]) => void | Promise<void> } = { + read(files: string[]) { + files.forEach((file) => Deno.readFileSync(file)); + }, + write(files: string[]) { + files.forEach((file) => + Deno.writeFileSync(file, new Uint8Array(0), { append: true }) + ); + }, + netFetch(urls: string[]) { + urls.forEach((url) => fetch(url)); + }, + netListen(endpoints: string[]) { + endpoints.forEach((endpoint) => { + const index = endpoint.lastIndexOf(":"); + const [hostname, port] = [ + endpoint.substr(0, index), + endpoint.substr(index + 1), + ]; + const listener = Deno.listen({ + transport: "tcp", + hostname, + port: parseInt(port, 10), + }); + listener.close(); + }); + }, + async netConnect(endpoints: string[]) { + for (const endpoint of endpoints) { + const index = endpoint.lastIndexOf(":"); + const [hostname, port] = [ + endpoint.substr(0, index), + endpoint.substr(index + 1), + ]; + const listener = await Deno.connect({ + transport: "tcp", + hostname, + port: parseInt(port, 10), + }); + listener.close(); + } + }, +}; + +if (!test[name]) { + console.log("Unknown test:", name); + Deno.exit(1); +} + +test[name](Deno.args.slice(1)); diff --git a/cli/tests/testdata/config.ts b/cli/tests/testdata/config.ts new file mode 100644 index 000000000..cd7a1b33f --- /dev/null +++ b/cli/tests/testdata/config.ts @@ -0,0 +1,18 @@ +// deno-lint-ignore-file + +function b() { + return function ( + _target: any, + _propertyKey: string, + _descriptor: PropertyDescriptor, + ) { + console.log("b"); + }; +} + +class A { + @b() + a() { + console.log("a"); + } +} diff --git a/cli/tests/testdata/config.ts.out b/cli/tests/testdata/config.ts.out new file mode 100644 index 000000000..9f8a8ddd1 --- /dev/null +++ b/cli/tests/testdata/config.ts.out @@ -0,0 +1,7 @@ +[WILDCARD]Unsupported compiler options in "[WILDCARD]config.tsconfig.json". + The following options were ignored: + module, target +error: TS1219 [ERROR]: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning. + a() { + ^ + at file:///[WILDCARD]/config.ts:[WILDCARD] diff --git a/cli/tests/testdata/config.tsconfig.json b/cli/tests/testdata/config.tsconfig.json new file mode 100644 index 000000000..dcabb50a4 --- /dev/null +++ b/cli/tests/testdata/config.tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "experimentalDecorators": false, + "module": "amd", + "target": "es5" + } +} diff --git a/cli/tests/testdata/config_types.ts b/cli/tests/testdata/config_types.ts new file mode 100644 index 000000000..f1a8d6583 --- /dev/null +++ b/cli/tests/testdata/config_types.ts @@ -0,0 +1 @@ +console.log(globalThis.a); diff --git a/cli/tests/testdata/config_types.ts.out b/cli/tests/testdata/config_types.ts.out new file mode 100644 index 000000000..417b7b537 --- /dev/null +++ b/cli/tests/testdata/config_types.ts.out @@ -0,0 +1 @@ +undefined diff --git a/cli/tests/testdata/config_types.tsconfig.json b/cli/tests/testdata/config_types.tsconfig.json new file mode 100644 index 000000000..3810d4534 --- /dev/null +++ b/cli/tests/testdata/config_types.tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "types": [ + "./subdir/types.d.ts" + ] + } +} diff --git a/cli/tests/testdata/config_types_remote.tsconfig.json b/cli/tests/testdata/config_types_remote.tsconfig.json new file mode 100644 index 000000000..f40d5b1c4 --- /dev/null +++ b/cli/tests/testdata/config_types_remote.tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "types": [ + "http://localhost:4545/subdir/types.d.ts" + ] + } +} diff --git a/cli/tests/testdata/coverage/branch.ts b/cli/tests/testdata/coverage/branch.ts new file mode 100644 index 000000000..352167109 --- /dev/null +++ b/cli/tests/testdata/coverage/branch.ts @@ -0,0 +1,15 @@ +export function branch(condition: boolean): boolean { + if (condition) { + return true; + } else { + return false; + } +} + +export function unused(condition: boolean): boolean { + if (condition) { + return false; + } else { + return true; + } +} diff --git a/cli/tests/testdata/coverage/branch_test.ts b/cli/tests/testdata/coverage/branch_test.ts new file mode 100644 index 000000000..2a44c8071 --- /dev/null +++ b/cli/tests/testdata/coverage/branch_test.ts @@ -0,0 +1,5 @@ +import { branch } from "./branch.ts"; + +Deno.test("branch", function () { + branch(true); +}); diff --git a/cli/tests/testdata/coverage/complex.ts b/cli/tests/testdata/coverage/complex.ts new file mode 100644 index 000000000..47d4ffa79 --- /dev/null +++ b/cli/tests/testdata/coverage/complex.ts @@ -0,0 +1,71 @@ +// This entire interface should be completely ignored by the coverage tool. +export interface Complex { + // These comments should be ignored. + foo: string; + + // But this is a stub, so this isn't really documentation. + bar: string; + + // Really all these are doing is padding the line count. + baz: string; +} + +// Lets add some wide characters to ensure that the absolute byte offsets are +// being matched properly. +// +// íŒ¨ë”©ì— ëŒ€í•œ ë” ë§Žì€ ë¬¸ìž. +function dependency( + foo: string, + bar: string, + baz: string, +): Complex { + return { + foo, + bar, + baz, + }; +} + +// Again just more wide characters for padding. +// +// 良ã„対ç–ã®ãŸã‚ã«ã„ãã¤ã‹ã®ãƒ¦ãƒ‹ã‚³ãƒ¼ãƒ‰æ–‡å—を投ã’る。 +export function complex( + foo: string, + bar: string, + baz: string, +): Complex { + return dependency( + foo, + bar, + baz, + ); +} + +// And yet again for good measure. +// 更多用於填充的å—元。 +export function unused( + foo: string, + bar: string, + baz: string, +): Complex { + return complex( + foo, + bar, + baz, + ); +} + +// Using a non-ascii name again to ensure that the byte offsets match up +// correctly. +export const Ï€ = Math.PI; + +// And same applies for this one, this one is unused and will show up in +// lacking coverage. +export function Æ’(): number { + return ( + 0 + ); +} + +// This arrow function should also show up as uncovered. +console.log("%s", () => 1); diff --git a/cli/tests/testdata/coverage/complex_test.ts b/cli/tests/testdata/coverage/complex_test.ts new file mode 100644 index 000000000..fda948bc3 --- /dev/null +++ b/cli/tests/testdata/coverage/complex_test.ts @@ -0,0 +1,5 @@ +import { complex } from "./complex.ts"; + +Deno.test("complex", function () { + complex("foo", "bar", "baz"); +}); diff --git a/cli/tests/testdata/coverage/expected_branch.lcov b/cli/tests/testdata/coverage/expected_branch.lcov new file mode 100644 index 000000000..07e29cca5 --- /dev/null +++ b/cli/tests/testdata/coverage/expected_branch.lcov @@ -0,0 +1,27 @@ +SF:[WILDCARD]branch.ts +FN:2,branch +FN:10,unused +FNDA:1,branch +FNDA:0,unused +FNF:2 +FNH:1 +BRDA:4,1,0,0 +BRF:1 +BRH:0 +DA:1,1 +DA:2,2 +DA:3,2 +DA:4,0 +DA:5,0 +DA:6,0 +DA:7,1 +DA:9,0 +DA:10,0 +DA:11,0 +DA:12,0 +DA:13,0 +DA:14,0 +DA:15,0 +LH:4 +LF:14 +end_of_record diff --git a/cli/tests/testdata/coverage/expected_branch.out b/cli/tests/testdata/coverage/expected_branch.out new file mode 100644 index 000000000..630ea93b2 --- /dev/null +++ b/cli/tests/testdata/coverage/expected_branch.out @@ -0,0 +1,12 @@ +cover [WILDCARD]/coverage/branch.ts ... 28.571% (4/14) + 4 | } else { + 5 | return false; + 6 | } +-----|----- + 9 | export function unused(condition: boolean): boolean { + 10 | if (condition) { + 11 | return false; + 12 | } else { + 13 | return true; + 14 | } + 15 | } diff --git a/cli/tests/testdata/coverage/expected_complex.lcov b/cli/tests/testdata/coverage/expected_complex.lcov new file mode 100644 index 000000000..962ebee96 --- /dev/null +++ b/cli/tests/testdata/coverage/expected_complex.lcov @@ -0,0 +1,53 @@ +SF:[WILDCARD]complex.ts +FN:22,dependency +FN:37,complex +FN:51,unused +FN:65,Æ’ +FNDA:1,dependency +FNDA:1,complex +FNDA:0,unused +FNDA:0,Æ’ +FNF:4 +FNH:2 +BRF:0 +BRH:0 +DA:17,2 +DA:18,2 +DA:19,2 +DA:20,2 +DA:22,2 +DA:23,2 +DA:24,2 +DA:25,2 +DA:26,2 +DA:27,1 +DA:32,1 +DA:33,1 +DA:34,1 +DA:35,1 +DA:37,2 +DA:38,2 +DA:39,2 +DA:40,2 +DA:41,2 +DA:42,1 +DA:46,0 +DA:47,0 +DA:48,0 +DA:49,0 +DA:51,0 +DA:52,0 +DA:53,0 +DA:54,0 +DA:55,0 +DA:56,0 +DA:60,1 +DA:64,0 +DA:65,0 +DA:66,0 +DA:67,0 +DA:68,1 +DA:71,0 +LH:22 +LF:37 +end_of_record diff --git a/cli/tests/testdata/coverage/expected_complex.out b/cli/tests/testdata/coverage/expected_complex.out new file mode 100644 index 000000000..e9f9a453f --- /dev/null +++ b/cli/tests/testdata/coverage/expected_complex.out @@ -0,0 +1,19 @@ +cover [WILDCARD]/coverage/complex.ts ... 59.459% (22/37) + 46 | export function unused( + 47 | foo: string, + 48 | bar: string, + 49 | baz: string, +-----|----- + 51 | return complex( + 52 | foo, + 53 | bar, + 54 | baz, + 55 | ); + 56 | } +-----|----- + 64 | export function Æ’(): number { + 65 | return ( + 66 | 0 + 67 | ); +-----|----- + 71 | console.log("%s", () => 1); diff --git a/cli/tests/testdata/delayed_error.ts b/cli/tests/testdata/delayed_error.ts new file mode 100644 index 000000000..76057e627 --- /dev/null +++ b/cli/tests/testdata/delayed_error.ts @@ -0,0 +1,2 @@ +await new Promise((r) => setTimeout(r, 100)); +throw new Error("foo"); diff --git a/cli/tests/testdata/deno_doc.out b/cli/tests/testdata/deno_doc.out new file mode 100644 index 000000000..86a77a9cc --- /dev/null +++ b/cli/tests/testdata/deno_doc.out @@ -0,0 +1,2 @@ +[WILDCARD] +function foo[WILDCARD]
\ No newline at end of file diff --git a/cli/tests/testdata/deno_doc.ts b/cli/tests/testdata/deno_doc.ts new file mode 100644 index 000000000..fb3c50957 --- /dev/null +++ b/cli/tests/testdata/deno_doc.ts @@ -0,0 +1,3 @@ +/** Some JSDoc */ +export function foo() { +} diff --git a/cli/tests/testdata/deno_doc_builtin.out b/cli/tests/testdata/deno_doc_builtin.out new file mode 100644 index 000000000..b4a90d6bc --- /dev/null +++ b/cli/tests/testdata/deno_doc_builtin.out @@ -0,0 +1,3 @@ +[WILDCARD] +namespace Deno +[WILDCARD]
\ No newline at end of file diff --git a/cli/tests/testdata/deno_dom_0.1.3-alpha2.wasm b/cli/tests/testdata/deno_dom_0.1.3-alpha2.wasm Binary files differnew file mode 100644 index 000000000..6dd9d0e91 --- /dev/null +++ b/cli/tests/testdata/deno_dom_0.1.3-alpha2.wasm diff --git a/cli/tests/testdata/deno_land_unsafe_ssl.ts b/cli/tests/testdata/deno_land_unsafe_ssl.ts new file mode 100644 index 000000000..f5e8dcc80 --- /dev/null +++ b/cli/tests/testdata/deno_land_unsafe_ssl.ts @@ -0,0 +1,2 @@ +const r = await fetch("https://google.com"); +console.log(r.status); diff --git a/cli/tests/testdata/deno_land_unsafe_ssl.ts.out b/cli/tests/testdata/deno_land_unsafe_ssl.ts.out new file mode 100644 index 000000000..cbf52b076 --- /dev/null +++ b/cli/tests/testdata/deno_land_unsafe_ssl.ts.out @@ -0,0 +1,2 @@ +DANGER: TLS certificate validation is disabled for: deno.land +200 diff --git a/cli/tests/testdata/disallow_http_from_https.js b/cli/tests/testdata/disallow_http_from_https.js new file mode 100644 index 000000000..bff407b5e --- /dev/null +++ b/cli/tests/testdata/disallow_http_from_https.js @@ -0,0 +1,2 @@ +// Trying to import "http://", while this file is accessed by "https://" +import "http://localhost:4545/001_hello.js"; diff --git a/cli/tests/testdata/disallow_http_from_https.ts b/cli/tests/testdata/disallow_http_from_https.ts new file mode 100644 index 000000000..bff407b5e --- /dev/null +++ b/cli/tests/testdata/disallow_http_from_https.ts @@ -0,0 +1,2 @@ +// Trying to import "http://", while this file is accessed by "https://" +import "http://localhost:4545/001_hello.js"; diff --git a/cli/tests/testdata/disallow_http_from_https_js.out b/cli/tests/testdata/disallow_http_from_https_js.out new file mode 100644 index 000000000..3219b7d35 --- /dev/null +++ b/cli/tests/testdata/disallow_http_from_https_js.out @@ -0,0 +1,3 @@ +error: Modules imported via https are not allowed to import http modules. + Importing: http://localhost:4545/001_hello.js + at https://localhost:5545/disallow_http_from_https.js:2:0 diff --git a/cli/tests/testdata/disallow_http_from_https_ts.out b/cli/tests/testdata/disallow_http_from_https_ts.out new file mode 100644 index 000000000..d1ab64394 --- /dev/null +++ b/cli/tests/testdata/disallow_http_from_https_ts.out @@ -0,0 +1,3 @@ +error: Modules imported via https are not allowed to import http modules. + Importing: http://localhost:4545/001_hello.js + at https://localhost:5545/disallow_http_from_https.ts:2:0 diff --git a/cli/tests/testdata/doc/import_map.json b/cli/tests/testdata/doc/import_map.json new file mode 100644 index 000000000..244a30296 --- /dev/null +++ b/cli/tests/testdata/doc/import_map.json @@ -0,0 +1,5 @@ +{ + "imports": { + "rex/": "./module/" + } +} diff --git a/cli/tests/testdata/doc/invalid_url.out b/cli/tests/testdata/doc/invalid_url.out new file mode 100644 index 000000000..8be787e90 --- /dev/null +++ b/cli/tests/testdata/doc/invalid_url.out @@ -0,0 +1,4 @@ +error: invalid URL: invalid domain character + +Caused by: + invalid domain character diff --git a/cli/tests/testdata/doc/module/fun.js b/cli/tests/testdata/doc/module/fun.js new file mode 100644 index 000000000..28901d945 --- /dev/null +++ b/cli/tests/testdata/doc/module/fun.js @@ -0,0 +1,2 @@ +/** This is some documentation */ +export function fun(_a, _b) {} diff --git a/cli/tests/testdata/doc/types_header.out b/cli/tests/testdata/doc/types_header.out new file mode 100644 index 000000000..ccff1a373 --- /dev/null +++ b/cli/tests/testdata/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/testdata/doc/types_header.ts b/cli/tests/testdata/doc/types_header.ts new file mode 100644 index 000000000..b64c8d000 --- /dev/null +++ b/cli/tests/testdata/doc/types_header.ts @@ -0,0 +1 @@ +export * from "http://127.0.0.1:4545/xTypeScriptTypes.js"; diff --git a/cli/tests/testdata/doc/types_hint.out b/cli/tests/testdata/doc/types_hint.out new file mode 100644 index 000000000..7eb05faed --- /dev/null +++ b/cli/tests/testdata/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/testdata/doc/types_hint.ts b/cli/tests/testdata/doc/types_hint.ts new file mode 100644 index 000000000..bacea46db --- /dev/null +++ b/cli/tests/testdata/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/testdata/doc/types_ref.js b/cli/tests/testdata/doc/types_ref.js new file mode 100644 index 000000000..03d8b5570 --- /dev/null +++ b/cli/tests/testdata/doc/types_ref.js @@ -0,0 +1,2 @@ +/// <reference types="../type_definitions/foo.d.ts" /> +export const foo = "foo"; diff --git a/cli/tests/testdata/doc/types_ref.out b/cli/tests/testdata/doc/types_ref.out new file mode 100644 index 000000000..7eb05faed --- /dev/null +++ b/cli/tests/testdata/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/testdata/doc/use_import_map.js b/cli/tests/testdata/doc/use_import_map.js new file mode 100644 index 000000000..672a7a7bd --- /dev/null +++ b/cli/tests/testdata/doc/use_import_map.js @@ -0,0 +1 @@ +export { fun } from "rex/fun.js"; diff --git a/cli/tests/testdata/doc/use_import_map.out b/cli/tests/testdata/doc/use_import_map.out new file mode 100644 index 000000000..0b27ccf18 --- /dev/null +++ b/cli/tests/testdata/doc/use_import_map.out @@ -0,0 +1,5 @@ +Defined in [WILDCARD]/doc/module/fun.js:2:0 + +function fun(_a, _b) + This is some documentation + diff --git a/cli/tests/testdata/dynamic_import/b.js b/cli/tests/testdata/dynamic_import/b.js new file mode 100644 index 000000000..6ea50d360 --- /dev/null +++ b/cli/tests/testdata/dynamic_import/b.js @@ -0,0 +1,2 @@ +import "./bad.mjs"; +export default () => "error"; diff --git a/cli/tests/testdata/dynamic_import/c.js b/cli/tests/testdata/dynamic_import/c.js new file mode 100644 index 000000000..20546455e --- /dev/null +++ b/cli/tests/testdata/dynamic_import/c.js @@ -0,0 +1,2 @@ +await import("./bad2.mjs"); +export default () => "error"; diff --git a/cli/tests/testdata/dynamic_import/permissions_blob_local.ts b/cli/tests/testdata/dynamic_import/permissions_blob_local.ts new file mode 100644 index 000000000..9ef4158ce --- /dev/null +++ b/cli/tests/testdata/dynamic_import/permissions_blob_local.ts @@ -0,0 +1,6 @@ +// This file doesn't really exist, but it doesn't matter, a "PermissionsDenied" error should be thrown. +const code = `import "file:///${ + Deno.build.os == "windows" ? "C:/" : "" +}local_file.ts";`; +const blob = new Blob([code]); +await import(URL.createObjectURL(blob)); diff --git a/cli/tests/testdata/dynamic_import/permissions_blob_local.ts.out b/cli/tests/testdata/dynamic_import/permissions_blob_local.ts.out new file mode 100644 index 000000000..6dfa8e527 --- /dev/null +++ b/cli/tests/testdata/dynamic_import/permissions_blob_local.ts.out @@ -0,0 +1,5 @@ +error: Uncaught (in promise) TypeError: Requires read access to "[WILDCARD]local_file.ts", run again with the --allow-read flag + at blob:null/[WILDCARD]:1:0 +await import(URL.createObjectURL(blob)); +^ + at async file:///[WILDCARD]/dynamic_import/permissions_blob_local.ts:6:1 diff --git a/cli/tests/testdata/dynamic_import/permissions_blob_remote.ts b/cli/tests/testdata/dynamic_import/permissions_blob_remote.ts new file mode 100644 index 000000000..1e2c8c21a --- /dev/null +++ b/cli/tests/testdata/dynamic_import/permissions_blob_remote.ts @@ -0,0 +1,4 @@ +// This file doesn't really exist, but it doesn't matter, a "PermissionsDenied" error should be thrown. +const code = `import "https://example.com/some/file.ts";`; +const blob = new Blob([code]); +await import(URL.createObjectURL(blob)); diff --git a/cli/tests/testdata/dynamic_import/permissions_blob_remote.ts.out b/cli/tests/testdata/dynamic_import/permissions_blob_remote.ts.out new file mode 100644 index 000000000..60d71ed6d --- /dev/null +++ b/cli/tests/testdata/dynamic_import/permissions_blob_remote.ts.out @@ -0,0 +1,5 @@ +error: Uncaught (in promise) TypeError: Requires net access to "example.com", run again with the --allow-net flag + at blob:null/[WILDCARD]:1:0 +await import(URL.createObjectURL(blob)); +^ + at async file:///[WILDCARD]/dynamic_import/permissions_blob_remote.ts:4:1 diff --git a/cli/tests/testdata/dynamic_import/permissions_data_local.ts b/cli/tests/testdata/dynamic_import/permissions_data_local.ts new file mode 100644 index 000000000..be4fc1c34 --- /dev/null +++ b/cli/tests/testdata/dynamic_import/permissions_data_local.ts @@ -0,0 +1,5 @@ +// This file doesn't really exist, but it doesn't matter, a "PermissionsDenied" error should be thrown. +const code = `import "file:///${ + Deno.build.os == "windows" ? "C:/" : "" +}local_file.ts";`; +await import(`data:application/javascript;base64,${btoa(code)}`); diff --git a/cli/tests/testdata/dynamic_import/permissions_data_local.ts.out b/cli/tests/testdata/dynamic_import/permissions_data_local.ts.out new file mode 100644 index 000000000..c9fcb0a17 --- /dev/null +++ b/cli/tests/testdata/dynamic_import/permissions_data_local.ts.out @@ -0,0 +1,5 @@ +error: Uncaught (in promise) TypeError: Requires read access to "[WILDCARD]local_file.ts", run again with the --allow-read flag + at data:application/javascript;base64,[WILDCARD]:1:0 +await import(`data:application/javascript;base64,${btoa(code)}`); +^ + at async file:///[WILDCARD]/dynamic_import/permissions_data_local.ts:5:1 diff --git a/cli/tests/testdata/dynamic_import/permissions_data_remote.ts b/cli/tests/testdata/dynamic_import/permissions_data_remote.ts new file mode 100644 index 000000000..b0a9540c3 --- /dev/null +++ b/cli/tests/testdata/dynamic_import/permissions_data_remote.ts @@ -0,0 +1,3 @@ +// This file doesn't really exist, but it doesn't matter, a "PermissionsDenied" error should be thrown. +const code = `import "https://example.com/some/file.ts";`; +await import(`data:application/javascript;base64,${btoa(code)}`); diff --git a/cli/tests/testdata/dynamic_import/permissions_data_remote.ts.out b/cli/tests/testdata/dynamic_import/permissions_data_remote.ts.out new file mode 100644 index 000000000..772f0b51e --- /dev/null +++ b/cli/tests/testdata/dynamic_import/permissions_data_remote.ts.out @@ -0,0 +1,5 @@ +error: Uncaught (in promise) TypeError: Requires net access to "example.com", run again with the --allow-net flag + at data:application/javascript;base64,aW1wb3J0ICJodHRwczovL2V4YW1wbGUuY29tL3NvbWUvZmlsZS50cyI7:1:0 +await import(`data:application/javascript;base64,${btoa(code)}`); +^ + at async file:///[WILDCARD]/dynamic_import/permissions_data_remote.ts:3:1 diff --git a/cli/tests/testdata/dynamic_import/permissions_remote_remote.ts b/cli/tests/testdata/dynamic_import/permissions_remote_remote.ts new file mode 100644 index 000000000..0033bcccc --- /dev/null +++ b/cli/tests/testdata/dynamic_import/permissions_remote_remote.ts @@ -0,0 +1,3 @@ +await import( + "http://localhost:4545/dynamic_import/static_remote.ts" +); diff --git a/cli/tests/testdata/dynamic_import/permissions_remote_remote.ts.out b/cli/tests/testdata/dynamic_import/permissions_remote_remote.ts.out new file mode 100644 index 000000000..cd7f58bb9 --- /dev/null +++ b/cli/tests/testdata/dynamic_import/permissions_remote_remote.ts.out @@ -0,0 +1,5 @@ +error: Uncaught (in promise) TypeError: Requires net access to "example.com", run again with the --allow-net flag + at http://localhost:4545/dynamic_import/static_remote.ts:2:0 +await import( +^ + at async file:///[WILDCARD]/dynamic_import/permissions_remote_remote.ts:1:1 diff --git a/cli/tests/testdata/dynamic_import/static_remote.ts b/cli/tests/testdata/dynamic_import/static_remote.ts new file mode 100644 index 000000000..2d6e820fd --- /dev/null +++ b/cli/tests/testdata/dynamic_import/static_remote.ts @@ -0,0 +1,2 @@ +// This file doesn't really exist, but it doesn't matter, a "PermissionsDenied" error should be thrown. +import "https://example.com/some/file.ts"; diff --git a/cli/tests/testdata/dynamic_import_conditional.js b/cli/tests/testdata/dynamic_import_conditional.js new file mode 100644 index 000000000..1b4193e3e --- /dev/null +++ b/cli/tests/testdata/dynamic_import_conditional.js @@ -0,0 +1,3 @@ +const Worker = globalThis.Worker ?? (await import("worker_threads")).Worker; + +console.log(!!Worker); diff --git a/cli/tests/testdata/dynamic_import_conditional.js.out b/cli/tests/testdata/dynamic_import_conditional.js.out new file mode 100644 index 000000000..27ba77dda --- /dev/null +++ b/cli/tests/testdata/dynamic_import_conditional.js.out @@ -0,0 +1 @@ +true diff --git a/cli/tests/testdata/echo.ts b/cli/tests/testdata/echo.ts new file mode 100644 index 000000000..84a645433 --- /dev/null +++ b/cli/tests/testdata/echo.ts @@ -0,0 +1,6 @@ +function echo(args: string[]) { + const msg = args.join(", "); + Deno.stdout.write(new TextEncoder().encode(msg)); +} + +echo(Deno.args); diff --git a/cli/tests/testdata/echo_server.ts b/cli/tests/testdata/echo_server.ts new file mode 100644 index 000000000..b23867cdd --- /dev/null +++ b/cli/tests/testdata/echo_server.ts @@ -0,0 +1,12 @@ +import { copy } from "../../../test_util/std/io/util.ts"; +const addr = Deno.args[0] || "0.0.0.0:4544"; +const [hostname, port] = addr.split(":"); +const listener = Deno.listen({ hostname, port: Number(port) }); +console.log("listening on", addr); +listener.accept().then( + async (conn) => { + console.log("received bytes:", await copy(conn, conn)); + conn.close(); + listener.close(); + }, +); diff --git a/cli/tests/testdata/encoding/utf-16be.ts b/cli/tests/testdata/encoding/utf-16be.ts Binary files differnew file mode 100644 index 000000000..3d0144d7c --- /dev/null +++ b/cli/tests/testdata/encoding/utf-16be.ts diff --git a/cli/tests/testdata/encoding/utf-16le.ts b/cli/tests/testdata/encoding/utf-16le.ts Binary files differnew file mode 100644 index 000000000..6f0e415f2 --- /dev/null +++ b/cli/tests/testdata/encoding/utf-16le.ts diff --git a/cli/tests/testdata/encoding/utf-8.ts b/cli/tests/testdata/encoding/utf-8.ts new file mode 100644 index 000000000..bf889aeb7 --- /dev/null +++ b/cli/tests/testdata/encoding/utf-8.ts @@ -0,0 +1 @@ +console.log("Hello World"); diff --git a/cli/tests/testdata/encoding/windows-1255 b/cli/tests/testdata/encoding/windows-1255 new file mode 100644 index 000000000..ec5cad7fd --- /dev/null +++ b/cli/tests/testdata/encoding/windows-1255 @@ -0,0 +1 @@ +console.log("ùìåí òåìí"); diff --git a/cli/tests/testdata/error_001.ts b/cli/tests/testdata/error_001.ts new file mode 100644 index 000000000..b01068bc0 --- /dev/null +++ b/cli/tests/testdata/error_001.ts @@ -0,0 +1,9 @@ +function foo(): never { + throw Error("bad"); +} + +function bar() { + foo(); +} + +bar(); diff --git a/cli/tests/testdata/error_001.ts.out b/cli/tests/testdata/error_001.ts.out new file mode 100644 index 000000000..25664a9a4 --- /dev/null +++ b/cli/tests/testdata/error_001.ts.out @@ -0,0 +1,6 @@ +[WILDCARD]error: Uncaught Error: bad + throw Error("bad"); + ^ + at foo ([WILDCARD]/error_001.ts:2:9) + at bar ([WILDCARD]/error_001.ts:6:3) + at [WILDCARD]/error_001.ts:9:1 diff --git a/cli/tests/testdata/error_002.ts b/cli/tests/testdata/error_002.ts new file mode 100644 index 000000000..6aa0fcc3b --- /dev/null +++ b/cli/tests/testdata/error_002.ts @@ -0,0 +1,7 @@ +import { throwsError } from "./subdir/mod1.ts"; + +function foo() { + throwsError(); +} + +foo(); diff --git a/cli/tests/testdata/error_002.ts.out b/cli/tests/testdata/error_002.ts.out new file mode 100644 index 000000000..96b9e602a --- /dev/null +++ b/cli/tests/testdata/error_002.ts.out @@ -0,0 +1,6 @@ +[WILDCARD]error: Uncaught Error: exception from mod1 + throw Error("exception from mod1"); + ^ + at throwsError ([WILDCARD]/subdir/mod1.ts:16:9) + at foo ([WILDCARD]/error_002.ts:4:3) + at [WILDCARD]/error_002.ts:7:1 diff --git a/cli/tests/testdata/error_003_typescript.ts b/cli/tests/testdata/error_003_typescript.ts new file mode 100644 index 000000000..e1f882123 --- /dev/null +++ b/cli/tests/testdata/error_003_typescript.ts @@ -0,0 +1,20 @@ +// deno-lint-ignore-file +let x = { + a: { + b: { + c() { + return { d: "hello" }; + }, + }, + }, +}; +let y = { + a: { + b: { + c() { + return { d: 1234 }; + }, + }, + }, +}; +x = y; diff --git a/cli/tests/testdata/error_003_typescript.ts.out b/cli/tests/testdata/error_003_typescript.ts.out new file mode 100644 index 000000000..bbb2ec470 --- /dev/null +++ b/cli/tests/testdata/error_003_typescript.ts.out @@ -0,0 +1,7 @@ +[WILDCARD] +error: TS2322 [ERROR]: Type '{ a: { b: { c(): { d: number; }; }; }; }' is not assignable to type '{ a: { b: { c(): { d: string; }; }; }; }'. + The types of 'a.b.c().d' are incompatible between these types. + Type 'number' is not assignable to type 'string'. +x = y; +^ + at [WILDCARD]/error_003_typescript.ts:20:1 diff --git a/cli/tests/testdata/error_004_missing_module.ts b/cli/tests/testdata/error_004_missing_module.ts new file mode 100644 index 000000000..82b281181 --- /dev/null +++ b/cli/tests/testdata/error_004_missing_module.ts @@ -0,0 +1,3 @@ +import * as badModule from "./bad-module.ts"; + +console.log(badModule); diff --git a/cli/tests/testdata/error_004_missing_module.ts.out b/cli/tests/testdata/error_004_missing_module.ts.out new file mode 100644 index 000000000..8521f4424 --- /dev/null +++ b/cli/tests/testdata/error_004_missing_module.ts.out @@ -0,0 +1,2 @@ +[WILDCARD]error: Cannot resolve module "file:///[WILDCARD]/bad-module.ts" from "file:///[WILDCARD]/error_004_missing_module.ts". + at file:///[WILDCARD]/error_004_missing_module.ts:1:0 diff --git a/cli/tests/testdata/error_005_missing_dynamic_import.ts b/cli/tests/testdata/error_005_missing_dynamic_import.ts new file mode 100644 index 000000000..8ea8ff94e --- /dev/null +++ b/cli/tests/testdata/error_005_missing_dynamic_import.ts @@ -0,0 +1,3 @@ +(async () => { + const _badModule = await import("./bad-module.ts"); +})(); diff --git a/cli/tests/testdata/error_005_missing_dynamic_import.ts.out b/cli/tests/testdata/error_005_missing_dynamic_import.ts.out new file mode 100644 index 000000000..e8647a44e --- /dev/null +++ b/cli/tests/testdata/error_005_missing_dynamic_import.ts.out @@ -0,0 +1,4 @@ +error: Uncaught (in promise) TypeError: Cannot resolve module "[WILDCARD]/bad-module.ts". + const _badModule = await import("./bad-module.ts"); + ^ + at async file://[WILDCARD]/error_005_missing_dynamic_import.ts:2:22 diff --git a/cli/tests/testdata/error_006_import_ext_failure.ts b/cli/tests/testdata/error_006_import_ext_failure.ts new file mode 100644 index 000000000..3c32303a3 --- /dev/null +++ b/cli/tests/testdata/error_006_import_ext_failure.ts @@ -0,0 +1 @@ +import "./non-existent"; diff --git a/cli/tests/testdata/error_006_import_ext_failure.ts.out b/cli/tests/testdata/error_006_import_ext_failure.ts.out new file mode 100644 index 000000000..24d819e5d --- /dev/null +++ b/cli/tests/testdata/error_006_import_ext_failure.ts.out @@ -0,0 +1,2 @@ +[WILDCARD]error: Cannot resolve module "[WILDCARD]/non-existent" from "[WILDCARD]/error_006_import_ext_failure.ts". + at file:///[WILDCARD]/error_006_import_ext_failure.ts:1:0 diff --git a/cli/tests/testdata/error_007_any.ts b/cli/tests/testdata/error_007_any.ts new file mode 100644 index 000000000..778886fcb --- /dev/null +++ b/cli/tests/testdata/error_007_any.ts @@ -0,0 +1 @@ +throw {}; diff --git a/cli/tests/testdata/error_007_any.ts.out b/cli/tests/testdata/error_007_any.ts.out new file mode 100644 index 000000000..45dbffd04 --- /dev/null +++ b/cli/tests/testdata/error_007_any.ts.out @@ -0,0 +1 @@ +[WILDCARD]error: Uncaught #<Object> diff --git a/cli/tests/testdata/error_008_checkjs.js b/cli/tests/testdata/error_008_checkjs.js new file mode 100644 index 000000000..f0856d94c --- /dev/null +++ b/cli/tests/testdata/error_008_checkjs.js @@ -0,0 +1,5 @@ +// console.log intentionally misspelled to trigger a type error +consol.log("hello world!"); + +// the following error should be ignored and not output to the console +const foo = new Foo(); diff --git a/cli/tests/testdata/error_008_checkjs.js.out b/cli/tests/testdata/error_008_checkjs.js.out new file mode 100644 index 000000000..e43187382 --- /dev/null +++ b/cli/tests/testdata/error_008_checkjs.js.out @@ -0,0 +1,4 @@ +[WILDCARD]error: Uncaught ReferenceError: consol is not defined +consol.log("hello world!"); +^ + at [WILDCARD]/error_008_checkjs.js:2:1 diff --git a/cli/tests/testdata/error_009_extensions_error.js b/cli/tests/testdata/error_009_extensions_error.js new file mode 100644 index 000000000..01b97ea38 --- /dev/null +++ b/cli/tests/testdata/error_009_extensions_error.js @@ -0,0 +1,2 @@ +// Missing arg. +new Event(); diff --git a/cli/tests/testdata/error_009_extensions_error.js.out b/cli/tests/testdata/error_009_extensions_error.js.out new file mode 100644 index 000000000..8510980f6 --- /dev/null +++ b/cli/tests/testdata/error_009_extensions_error.js.out @@ -0,0 +1,6 @@ +[WILDCARD]error: Uncaught TypeError: Failed to construct 'Event': 1 argument required, but only 0 present. +new Event(); +^ + at [WILDCARD] + at new Event (deno:ext/web/[WILDCARD]) + at [WILDCARD] diff --git a/cli/tests/testdata/error_009_missing_js_module.disabled b/cli/tests/testdata/error_009_missing_js_module.disabled new file mode 100644 index 000000000..3156fc94b --- /dev/null +++ b/cli/tests/testdata/error_009_missing_js_module.disabled @@ -0,0 +1,4 @@ +args: tests/error_009_missing_js_module.js +check_stderr: true +exit_code: 1 +output: tests/error_009_missing_js_module.js.out diff --git a/cli/tests/testdata/error_009_missing_js_module.js b/cli/tests/testdata/error_009_missing_js_module.js new file mode 100644 index 000000000..e6ca88934 --- /dev/null +++ b/cli/tests/testdata/error_009_missing_js_module.js @@ -0,0 +1 @@ +import "./bad-module.js"; diff --git a/cli/tests/testdata/error_009_missing_js_module.js.out b/cli/tests/testdata/error_009_missing_js_module.js.out new file mode 100644 index 000000000..edb08da1c --- /dev/null +++ b/cli/tests/testdata/error_009_missing_js_module.js.out @@ -0,0 +1 @@ +Cannot resolve module "./bad-module.js" from "[WILDCARD]error_009_missing_js_module.js" diff --git a/cli/tests/testdata/error_010_nonexistent_arg.disabled b/cli/tests/testdata/error_010_nonexistent_arg.disabled new file mode 100644 index 000000000..9d183107c --- /dev/null +++ b/cli/tests/testdata/error_010_nonexistent_arg.disabled @@ -0,0 +1,4 @@ +args: not-a-valid-filename.ts +output: tests/error_010_nonexistent_arg.out +exit_code: 1 +check_stderr: true diff --git a/cli/tests/testdata/error_010_nonexistent_arg.out b/cli/tests/testdata/error_010_nonexistent_arg.out new file mode 100644 index 000000000..ef4f7b041 --- /dev/null +++ b/cli/tests/testdata/error_010_nonexistent_arg.out @@ -0,0 +1 @@ +[WILDCARD]Cannot resolve module "file:[WILDCARD]not-a-valid-filename.ts" from "." diff --git a/cli/tests/testdata/error_011_bad_module_specifier.ts b/cli/tests/testdata/error_011_bad_module_specifier.ts new file mode 100644 index 000000000..1c57e37a5 --- /dev/null +++ b/cli/tests/testdata/error_011_bad_module_specifier.ts @@ -0,0 +1,3 @@ +import * as badModule from "bad-module.ts"; + +console.log(badModule); diff --git a/cli/tests/testdata/error_011_bad_module_specifier.ts.out b/cli/tests/testdata/error_011_bad_module_specifier.ts.out new file mode 100644 index 000000000..713072191 --- /dev/null +++ b/cli/tests/testdata/error_011_bad_module_specifier.ts.out @@ -0,0 +1 @@ +[WILDCARD]error: Relative import path "bad-module.ts" not prefixed with / or ./ or ../ from "[WILDCARD]/error_011_bad_module_specifier.ts" diff --git a/cli/tests/testdata/error_012_bad_dynamic_import_specifier.ts b/cli/tests/testdata/error_012_bad_dynamic_import_specifier.ts new file mode 100644 index 000000000..5f39f407c --- /dev/null +++ b/cli/tests/testdata/error_012_bad_dynamic_import_specifier.ts @@ -0,0 +1,3 @@ +(async () => { + const _badModule = await import("bad-module.ts"); +})(); diff --git a/cli/tests/testdata/error_012_bad_dynamic_import_specifier.ts.out b/cli/tests/testdata/error_012_bad_dynamic_import_specifier.ts.out new file mode 100644 index 000000000..0d0b168a4 --- /dev/null +++ b/cli/tests/testdata/error_012_bad_dynamic_import_specifier.ts.out @@ -0,0 +1,5 @@ +Check [WILDCARD]error_012_bad_dynamic_import_specifier.ts +error: Uncaught (in promise) TypeError: Relative import path "bad-module.ts" not prefixed with / or ./ or ../ from "[WILDCARD]/error_012_bad_dynamic_import_specifier.ts" + const _badModule = await import("bad-module.ts"); + ^ + at async file:///[WILDCARD]/error_012_bad_dynamic_import_specifier.ts:2:22 diff --git a/cli/tests/testdata/error_013_missing_script.out b/cli/tests/testdata/error_013_missing_script.out new file mode 100644 index 000000000..d1c257bdb --- /dev/null +++ b/cli/tests/testdata/error_013_missing_script.out @@ -0,0 +1 @@ +error: Cannot resolve module "[WILDCARD]missing_file_name". diff --git a/cli/tests/testdata/error_014_catch_dynamic_import_error.js b/cli/tests/testdata/error_014_catch_dynamic_import_error.js new file mode 100644 index 000000000..483be7b1a --- /dev/null +++ b/cli/tests/testdata/error_014_catch_dynamic_import_error.js @@ -0,0 +1,31 @@ +(async () => { + try { + await import("does not exist"); + } catch (err) { + console.log("Caught direct dynamic import error."); + console.log(err); + } + + try { + await import("./subdir/indirect_import_error.js"); + } catch (err) { + console.log("Caught indirect direct dynamic import error."); + console.log(err); + } + + try { + await import("./subdir/throws.js"); + } catch (err) { + console.log("Caught error thrown by dynamically imported module."); + console.log(err); + } + + try { + await import("./subdir/indirect_throws.js"); + } catch (err) { + console.log( + "Caught error thrown indirectly by dynamically imported module.", + ); + console.log(err); + } +})(); diff --git a/cli/tests/testdata/error_014_catch_dynamic_import_error.js.out b/cli/tests/testdata/error_014_catch_dynamic_import_error.js.out new file mode 100644 index 000000000..8f2d695f7 --- /dev/null +++ b/cli/tests/testdata/error_014_catch_dynamic_import_error.js.out @@ -0,0 +1,12 @@ +Caught direct dynamic import error. +TypeError: Relative import path "does not exist" not prefixed with / or ./ or ../ from "[WILDCARD]/error_014_catch_dynamic_import_error.js" + at async file:///[WILDCARD]/error_014_catch_dynamic_import_error.js:3:5 +Caught indirect direct dynamic import error. +TypeError: Relative import path "does not exist either" not prefixed with / or ./ or ../ from "[WILDCARD]/indirect_import_error.js" + at async file:///[WILDCARD]/error_014_catch_dynamic_import_error.js:10:5 +Caught error thrown by dynamically imported module. +Error: An error + at file:///[WILDCARD]/subdir/throws.js:6:7 +Caught error thrown indirectly by dynamically imported module. +Error: An error + at file:///[WILDCARD]/subdir/throws.js:6:7 diff --git a/cli/tests/testdata/error_015_dynamic_import_permissions.js b/cli/tests/testdata/error_015_dynamic_import_permissions.js new file mode 100644 index 000000000..73da56fd8 --- /dev/null +++ b/cli/tests/testdata/error_015_dynamic_import_permissions.js @@ -0,0 +1,3 @@ +(async () => { + await import("http://localhost:4545/subdir/mod4.js"); +})(); diff --git a/cli/tests/testdata/error_015_dynamic_import_permissions.out b/cli/tests/testdata/error_015_dynamic_import_permissions.out new file mode 100644 index 000000000..a509cfdab --- /dev/null +++ b/cli/tests/testdata/error_015_dynamic_import_permissions.out @@ -0,0 +1,4 @@ +error: Uncaught (in promise) TypeError: Requires net access to "localhost:4545", run again with the --allow-net flag + await import("http://localhost:4545/subdir/mod4.js"); + ^ + at async file:///[WILDCARD]/error_015_dynamic_import_permissions.js:2:3 diff --git a/cli/tests/testdata/error_016_dynamic_import_permissions2.js b/cli/tests/testdata/error_016_dynamic_import_permissions2.js new file mode 100644 index 000000000..f018d4a2e --- /dev/null +++ b/cli/tests/testdata/error_016_dynamic_import_permissions2.js @@ -0,0 +1,5 @@ +// If this is executed with --allow-net but not --allow-read the following +// import should cause a permission denied error. +(async () => { + await import("http://localhost:4545/subdir/evil_remote_import.js"); +})(); diff --git a/cli/tests/testdata/error_016_dynamic_import_permissions2.out b/cli/tests/testdata/error_016_dynamic_import_permissions2.out new file mode 100644 index 000000000..0b43c5b91 --- /dev/null +++ b/cli/tests/testdata/error_016_dynamic_import_permissions2.out @@ -0,0 +1,4 @@ +[WILDCARD] +error: Remote modules are not allowed to import local modules. Consider using a dynamic import instead. + Importing: file:///c:/etc/passwd + at http://localhost:4545/subdir/evil_remote_import.js:3:0 diff --git a/cli/tests/testdata/error_017_hide_long_source_ts.ts b/cli/tests/testdata/error_017_hide_long_source_ts.ts new file mode 100644 index 000000000..d61cb1277 --- /dev/null +++ b/cli/tests/testdata/error_017_hide_long_source_ts.ts @@ -0,0 +1,3 @@ +// deno-fmt-ignore-file +const LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG = undefined; +LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG.a; diff --git a/cli/tests/testdata/error_017_hide_long_source_ts.ts.out b/cli/tests/testdata/error_017_hide_long_source_ts.ts.out new file mode 100644 index 000000000..917061ab9 --- /dev/null +++ b/cli/tests/testdata/error_017_hide_long_source_ts.ts.out @@ -0,0 +1,3 @@ +[WILDCARD] +error: TS2532 [ERROR]: Object is possibly 'undefined'. + at [WILDCARD]/error_017_hide_long_source_ts.ts:3:1 diff --git a/cli/tests/testdata/error_018_hide_long_source_js.js b/cli/tests/testdata/error_018_hide_long_source_js.js new file mode 100644 index 000000000..d61cb1277 --- /dev/null +++ b/cli/tests/testdata/error_018_hide_long_source_js.js @@ -0,0 +1,3 @@ +// deno-fmt-ignore-file +const LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG = undefined; +LONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONGLONG.a; diff --git a/cli/tests/testdata/error_018_hide_long_source_js.js.out b/cli/tests/testdata/error_018_hide_long_source_js.js.out new file mode 100644 index 000000000..cc98669a7 --- /dev/null +++ b/cli/tests/testdata/error_018_hide_long_source_js.js.out @@ -0,0 +1,2 @@ +error: Uncaught TypeError: Cannot read properties of undefined (reading 'a') + at file:///[WILDCARD]/error_018_hide_long_source_js.js:3:206 diff --git a/cli/tests/testdata/error_019_stack_function.ts b/cli/tests/testdata/error_019_stack_function.ts new file mode 100644 index 000000000..c5eeae8f4 --- /dev/null +++ b/cli/tests/testdata/error_019_stack_function.ts @@ -0,0 +1,10 @@ +function foo(): never { + throw new Error("function"); +} + +try { + foo(); +} catch (error) { + console.log(error.stack); + throw error; +} diff --git a/cli/tests/testdata/error_019_stack_function.ts.out b/cli/tests/testdata/error_019_stack_function.ts.out new file mode 100644 index 000000000..03967d12b --- /dev/null +++ b/cli/tests/testdata/error_019_stack_function.ts.out @@ -0,0 +1,8 @@ +[WILDCARD]Error: function + at foo ([WILDCARD]/error_019_stack_function.ts:[WILDCARD]) + at [WILDCARD]/error_019_stack_function.ts:[WILDCARD] +error: Uncaught Error: function + throw new Error("function"); + ^ + at foo ([WILDCARD]/error_019_stack_function.ts:[WILDCARD]) + at [WILDCARD]/error_019_stack_function.ts:[WILDCARD] diff --git a/cli/tests/testdata/error_020_stack_constructor.ts b/cli/tests/testdata/error_020_stack_constructor.ts new file mode 100644 index 000000000..49988280b --- /dev/null +++ b/cli/tests/testdata/error_020_stack_constructor.ts @@ -0,0 +1,12 @@ +class A { + constructor() { + throw new Error("constructor"); + } +} + +try { + new A(); +} catch (error) { + console.log(error.stack); + throw error; +} diff --git a/cli/tests/testdata/error_020_stack_constructor.ts.out b/cli/tests/testdata/error_020_stack_constructor.ts.out new file mode 100644 index 000000000..01fdfb3c4 --- /dev/null +++ b/cli/tests/testdata/error_020_stack_constructor.ts.out @@ -0,0 +1,8 @@ +[WILDCARD]Error: constructor + at new A ([WILDCARD]/error_020_stack_constructor.ts:[WILDCARD]) + at [WILDCARD]/error_020_stack_constructor.ts:[WILDCARD] +error: Uncaught Error: constructor + throw new Error("constructor"); + ^ + at new A ([WILDCARD]/error_020_stack_constructor.ts:[WILDCARD]) + at [WILDCARD]/error_020_stack_constructor.ts:[WILDCARD] diff --git a/cli/tests/testdata/error_021_stack_method.ts b/cli/tests/testdata/error_021_stack_method.ts new file mode 100644 index 000000000..a52d00deb --- /dev/null +++ b/cli/tests/testdata/error_021_stack_method.ts @@ -0,0 +1,12 @@ +class A { + m(): never { + throw new Error("method"); + } +} + +try { + new A().m(); +} catch (error) { + console.log(error.stack); + throw error; +} diff --git a/cli/tests/testdata/error_021_stack_method.ts.out b/cli/tests/testdata/error_021_stack_method.ts.out new file mode 100644 index 000000000..999f0aaa0 --- /dev/null +++ b/cli/tests/testdata/error_021_stack_method.ts.out @@ -0,0 +1,8 @@ +[WILDCARD]Error: method + at A.m ([WILDCARD]/error_021_stack_method.ts:[WILDCARD]) + at [WILDCARD]/error_021_stack_method.ts:[WILDCARD] +error: Uncaught Error: method + throw new Error("method"); + ^ + at A.m ([WILDCARD]/error_021_stack_method.ts:[WILDCARD]) + at [WILDCARD]/error_021_stack_method.ts:[WILDCARD] diff --git a/cli/tests/testdata/error_022_stack_custom_error.ts b/cli/tests/testdata/error_022_stack_custom_error.ts new file mode 100644 index 000000000..b95743503 --- /dev/null +++ b/cli/tests/testdata/error_022_stack_custom_error.ts @@ -0,0 +1,14 @@ +class CustomError extends Error { + constructor() { + super(); + this.name = "CustomError"; + } + + get message(): string { + return "custom error"; + } +} + +const error = new CustomError(); +console.log(error.stack); +throw error; diff --git a/cli/tests/testdata/error_022_stack_custom_error.ts.out b/cli/tests/testdata/error_022_stack_custom_error.ts.out new file mode 100644 index 000000000..78b0dcaea --- /dev/null +++ b/cli/tests/testdata/error_022_stack_custom_error.ts.out @@ -0,0 +1,6 @@ +[WILDCARD]CustomError: custom error + at [WILDCARD]/error_022_stack_custom_error.ts:[WILDCARD] +error: Uncaught CustomError: custom error +const error = new CustomError(); + ^ + at [WILDCARD]/error_022_stack_custom_error.ts:[WILDCARD] diff --git a/cli/tests/testdata/error_023_stack_async.ts b/cli/tests/testdata/error_023_stack_async.ts new file mode 100644 index 000000000..99e676e26 --- /dev/null +++ b/cli/tests/testdata/error_023_stack_async.ts @@ -0,0 +1,12 @@ +const p = (async () => { + await Promise.resolve().then((): never => { + throw new Error("async"); + }); +})(); + +try { + await p; +} catch (error) { + console.log(error.stack); + throw error; +} diff --git a/cli/tests/testdata/error_023_stack_async.ts.out b/cli/tests/testdata/error_023_stack_async.ts.out new file mode 100644 index 000000000..95f0eae64 --- /dev/null +++ b/cli/tests/testdata/error_023_stack_async.ts.out @@ -0,0 +1,10 @@ +[WILDCARD]Error: async + at [WILDCARD]/error_023_stack_async.ts:[WILDCARD] + at async [WILDCARD]/error_023_stack_async.ts:[WILDCARD] + at async [WILDCARD]/error_023_stack_async.ts:[WILDCARD] +error: Uncaught Error: async + throw new Error("async"); + ^ + at [WILDCARD]/error_023_stack_async.ts:[WILDCARD] + at async [WILDCARD]/error_023_stack_async.ts:[WILDCARD] + at async [WILDCARD]/error_023_stack_async.ts:[WILDCARD] diff --git a/cli/tests/testdata/error_024_stack_promise_all.ts b/cli/tests/testdata/error_024_stack_promise_all.ts new file mode 100644 index 000000000..ddaf0dbaa --- /dev/null +++ b/cli/tests/testdata/error_024_stack_promise_all.ts @@ -0,0 +1,14 @@ +const p = Promise.all([ + Promise.resolve(), + (async (): Promise<never> => { + await Promise.resolve(); + throw new Error("Promise.all()"); + })(), +]); + +try { + await p; +} catch (error) { + console.log(error.stack); + throw error; +} diff --git a/cli/tests/testdata/error_024_stack_promise_all.ts.out b/cli/tests/testdata/error_024_stack_promise_all.ts.out new file mode 100644 index 000000000..6cd88715c --- /dev/null +++ b/cli/tests/testdata/error_024_stack_promise_all.ts.out @@ -0,0 +1,10 @@ +[WILDCARD]Error: Promise.all() + at [WILDCARD]/error_024_stack_promise_all.ts:[WILDCARD] + at async Promise.all (index 1) + at async [WILDCARD]/error_024_stack_promise_all.ts:[WILDCARD] +error: Uncaught Error: Promise.all() + throw new Error("Promise.all()"); + ^ + at [WILDCARD]/error_024_stack_promise_all.ts:[WILDCARD] + at async Promise.all (index 1) + at async [WILDCARD]/error_024_stack_promise_all.ts:[WILDCARD] diff --git a/cli/tests/testdata/error_025_tab_indent b/cli/tests/testdata/error_025_tab_indent new file mode 100644 index 000000000..35a25bcea --- /dev/null +++ b/cli/tests/testdata/error_025_tab_indent @@ -0,0 +1,9 @@ +function foo() { + throw Error("bad"); +} + +function bar() { + foo(); +} + +bar(); diff --git a/cli/tests/testdata/error_025_tab_indent.out b/cli/tests/testdata/error_025_tab_indent.out new file mode 100644 index 000000000..f1466ce3f --- /dev/null +++ b/cli/tests/testdata/error_025_tab_indent.out @@ -0,0 +1,6 @@ +[WILDCARD]error: Uncaught Error: bad + throw Error("bad"); + ^ + at foo ([WILDCARD]/error_025_tab_indent:2:8) + at bar ([WILDCARD]/error_025_tab_indent:6:2) + at [WILDCARD]/error_025_tab_indent:9:1 diff --git a/cli/tests/testdata/error_026_remote_import_error.ts b/cli/tests/testdata/error_026_remote_import_error.ts new file mode 100644 index 000000000..2718e768a --- /dev/null +++ b/cli/tests/testdata/error_026_remote_import_error.ts @@ -0,0 +1 @@ +import "http://localhost:4545/error_001.ts"; diff --git a/cli/tests/testdata/error_026_remote_import_error.ts.out b/cli/tests/testdata/error_026_remote_import_error.ts.out new file mode 100644 index 000000000..bec0cf1c5 --- /dev/null +++ b/cli/tests/testdata/error_026_remote_import_error.ts.out @@ -0,0 +1,7 @@ +[WILDCARD]error: Uncaught Error: bad + throw Error("bad"); + ^ + at foo (http://localhost:4545/error_001.ts:2:9) + at bar (http://localhost:4545/error_001.ts:6:3) + at http://localhost:4545/error_001.ts:9:1 +[WILDCARD] diff --git a/cli/tests/testdata/error_027_bundle_with_bare_import.ts b/cli/tests/testdata/error_027_bundle_with_bare_import.ts new file mode 100644 index 000000000..c0748305d --- /dev/null +++ b/cli/tests/testdata/error_027_bundle_with_bare_import.ts @@ -0,0 +1 @@ +import "foo"; diff --git a/cli/tests/testdata/error_027_bundle_with_bare_import.ts.out b/cli/tests/testdata/error_027_bundle_with_bare_import.ts.out new file mode 100644 index 000000000..3aa4a42a2 --- /dev/null +++ b/cli/tests/testdata/error_027_bundle_with_bare_import.ts.out @@ -0,0 +1 @@ +[WILDCARD]error: Relative import path "foo" not prefixed with / or ./ or ../ from "file:///[WILDCARD]/error_027_bundle_with_bare_import.ts" diff --git a/cli/tests/testdata/error_import_map_unable_to_load.out b/cli/tests/testdata/error_import_map_unable_to_load.out new file mode 100644 index 000000000..50760e438 --- /dev/null +++ b/cli/tests/testdata/error_import_map_unable_to_load.out @@ -0,0 +1,4 @@ +error: Unable to load '[WILDCARD]' import map + +Caused by: + [WILDCARD]
\ No newline at end of file diff --git a/cli/tests/testdata/error_local_static_import_from_remote.js b/cli/tests/testdata/error_local_static_import_from_remote.js new file mode 100644 index 000000000..eb7fd23ba --- /dev/null +++ b/cli/tests/testdata/error_local_static_import_from_remote.js @@ -0,0 +1 @@ +import "file:///some/dir/file.js"; diff --git a/cli/tests/testdata/error_local_static_import_from_remote.js.out b/cli/tests/testdata/error_local_static_import_from_remote.js.out new file mode 100644 index 000000000..44b676532 --- /dev/null +++ b/cli/tests/testdata/error_local_static_import_from_remote.js.out @@ -0,0 +1,4 @@ +[WILDCARD] +error: Remote modules are not allowed to import local modules. Consider using a dynamic import instead. + Importing: file:///some/dir/file.js + at http://localhost:4545/error_local_static_import_from_remote.js:1:0 diff --git a/cli/tests/testdata/error_local_static_import_from_remote.ts b/cli/tests/testdata/error_local_static_import_from_remote.ts new file mode 100644 index 000000000..a831db0c4 --- /dev/null +++ b/cli/tests/testdata/error_local_static_import_from_remote.ts @@ -0,0 +1 @@ +import "file:///some/dir/file.ts"; diff --git a/cli/tests/testdata/error_local_static_import_from_remote.ts.out b/cli/tests/testdata/error_local_static_import_from_remote.ts.out new file mode 100644 index 000000000..f8f409de0 --- /dev/null +++ b/cli/tests/testdata/error_local_static_import_from_remote.ts.out @@ -0,0 +1,4 @@ +[WILDCARD] +error: Remote modules are not allowed to import local modules. Consider using a dynamic import instead. + Importing: file:///some/dir/file.ts + at http://localhost:4545/error_local_static_import_from_remote.ts:1:0 diff --git a/cli/tests/testdata/error_missing_module_named_import.ts b/cli/tests/testdata/error_missing_module_named_import.ts new file mode 100644 index 000000000..9eb5239ff --- /dev/null +++ b/cli/tests/testdata/error_missing_module_named_import.ts @@ -0,0 +1,3 @@ +import { a } from "./does_not_exist.js"; + +console.log(a); diff --git a/cli/tests/testdata/error_missing_module_named_import.ts.out b/cli/tests/testdata/error_missing_module_named_import.ts.out new file mode 100644 index 000000000..6f09f0c0d --- /dev/null +++ b/cli/tests/testdata/error_missing_module_named_import.ts.out @@ -0,0 +1,2 @@ +error: Cannot resolve module "[WILDCARD]/does_not_exist.js" from "[WILDCARD]/error_missing_module_named_import.ts". + at [WILDCARD]/error_missing_module_named_import.ts:1:0 diff --git a/cli/tests/testdata/error_no_check.ts b/cli/tests/testdata/error_no_check.ts new file mode 100644 index 000000000..db9257a1d --- /dev/null +++ b/cli/tests/testdata/error_no_check.ts @@ -0,0 +1 @@ +export { AnInterface, isAnInterface } from "./subdir/type_and_code.ts"; diff --git a/cli/tests/testdata/error_no_check.ts.out b/cli/tests/testdata/error_no_check.ts.out new file mode 100644 index 000000000..cac1367ba --- /dev/null +++ b/cli/tests/testdata/error_no_check.ts.out @@ -0,0 +1,2 @@ +error: Uncaught SyntaxError: The requested module './subdir/type_and_code.ts' does not provide an export named 'AnInterface' +[WILDCARD]
\ No newline at end of file diff --git a/cli/tests/testdata/error_syntax.js b/cli/tests/testdata/error_syntax.js new file mode 100644 index 000000000..c0414c356 --- /dev/null +++ b/cli/tests/testdata/error_syntax.js @@ -0,0 +1,3 @@ + +// deno-fmt-ignore-file +(the following is a syntax error ^^ ! ) diff --git a/cli/tests/testdata/error_syntax.js.out b/cli/tests/testdata/error_syntax.js.out new file mode 100644 index 000000000..4c2a007f1 --- /dev/null +++ b/cli/tests/testdata/error_syntax.js.out @@ -0,0 +1 @@ +error: Expected ,, got following at [WILDCARD]/error_syntax.js:3:5 diff --git a/cli/tests/testdata/error_syntax_empty_trailing_line.mjs b/cli/tests/testdata/error_syntax_empty_trailing_line.mjs new file mode 100644 index 000000000..864dfb0c7 --- /dev/null +++ b/cli/tests/testdata/error_syntax_empty_trailing_line.mjs @@ -0,0 +1,2 @@ +// Deliberately using .mjs to avoid triggering dprint +setTimeout(() => {}), diff --git a/cli/tests/testdata/error_syntax_empty_trailing_line.mjs.out b/cli/tests/testdata/error_syntax_empty_trailing_line.mjs.out new file mode 100644 index 000000000..daa37818d --- /dev/null +++ b/cli/tests/testdata/error_syntax_empty_trailing_line.mjs.out @@ -0,0 +1 @@ +error: Unexpected eof at [WILDCARD]/error_syntax_empty_trailing_line.mjs:2:21 diff --git a/cli/tests/testdata/error_type_definitions.ts b/cli/tests/testdata/error_type_definitions.ts new file mode 100644 index 000000000..ceb11787e --- /dev/null +++ b/cli/tests/testdata/error_type_definitions.ts @@ -0,0 +1,5 @@ +// @deno-types="./type_definitions/bar.d.ts" +import { Bar } from "./type_definitions/bar.js"; + +const bar = new Bar(); +console.log(bar); diff --git a/cli/tests/testdata/error_type_definitions.ts.out b/cli/tests/testdata/error_type_definitions.ts.out new file mode 100644 index 000000000..304ec1bdf --- /dev/null +++ b/cli/tests/testdata/error_type_definitions.ts.out @@ -0,0 +1 @@ +[WILDCARD]error: Relative import path "baz" not prefixed with / or ./ or ../ from "[WILDCARD]/type_definitions/bar.d.ts" diff --git a/cli/tests/testdata/error_worker_permissions_local.ts b/cli/tests/testdata/error_worker_permissions_local.ts new file mode 100644 index 000000000..b43c8fe94 --- /dev/null +++ b/cli/tests/testdata/error_worker_permissions_local.ts @@ -0,0 +1,4 @@ +new Worker( + new URL("./subdeb/worker_types.ts", import.meta.url).toString(), + { type: "module" }, +); diff --git a/cli/tests/testdata/error_worker_permissions_local.ts.out b/cli/tests/testdata/error_worker_permissions_local.ts.out new file mode 100644 index 000000000..e6404e8e3 --- /dev/null +++ b/cli/tests/testdata/error_worker_permissions_local.ts.out @@ -0,0 +1,3 @@ +[WILDCARD] +error: Uncaught (in worker "") Requires read access to "[WILDCARD]worker_types.ts", run again with the --allow-read flag +[WILDCARD] diff --git a/cli/tests/testdata/error_worker_permissions_remote.ts b/cli/tests/testdata/error_worker_permissions_remote.ts new file mode 100644 index 000000000..878c7080a --- /dev/null +++ b/cli/tests/testdata/error_worker_permissions_remote.ts @@ -0,0 +1,4 @@ +new Worker( + "http://localhost:4545/subdir/worker_types.ts", + { type: "module" }, +); diff --git a/cli/tests/testdata/error_worker_permissions_remote.ts.out b/cli/tests/testdata/error_worker_permissions_remote.ts.out new file mode 100644 index 000000000..74c7c3974 --- /dev/null +++ b/cli/tests/testdata/error_worker_permissions_remote.ts.out @@ -0,0 +1,3 @@ +[WILDCARD] +error: Uncaught (in worker "") Requires net access to "localhost:4545", run again with the --allow-net flag +[WILDCARD] diff --git a/cli/tests/testdata/es_private_fields.js b/cli/tests/testdata/es_private_fields.js new file mode 100644 index 000000000..b5f83e39c --- /dev/null +++ b/cli/tests/testdata/es_private_fields.js @@ -0,0 +1,15 @@ +class Foo { + #field = "field"; + + setValue(val) { + this.#field = val; + } + + getValue() { + return this.#field; + } +} + +const bar = new Foo(); +bar.setValue("PRIVATE"); +console.log(bar.getValue()); diff --git a/cli/tests/testdata/es_private_fields.js.out b/cli/tests/testdata/es_private_fields.js.out new file mode 100644 index 000000000..be1970b05 --- /dev/null +++ b/cli/tests/testdata/es_private_fields.js.out @@ -0,0 +1 @@ +PRIVATE diff --git a/cli/tests/testdata/esm_imports_a.js b/cli/tests/testdata/esm_imports_a.js new file mode 100644 index 000000000..673cd9aa3 --- /dev/null +++ b/cli/tests/testdata/esm_imports_a.js @@ -0,0 +1,3 @@ +import { retb } from "./esm_imports_b.js"; + +if (retb() != "b") throw Error(); diff --git a/cli/tests/testdata/esm_imports_b.js b/cli/tests/testdata/esm_imports_b.js new file mode 100644 index 000000000..840121368 --- /dev/null +++ b/cli/tests/testdata/esm_imports_b.js @@ -0,0 +1,4 @@ +// deno-lint-ignore-file +export function retb() { + return "b"; +} diff --git a/cli/tests/testdata/exec_path.ts b/cli/tests/testdata/exec_path.ts new file mode 100644 index 000000000..b70b23237 --- /dev/null +++ b/cli/tests/testdata/exec_path.ts @@ -0,0 +1 @@ +console.log(Deno.execPath()); diff --git a/cli/tests/testdata/exit_error42.ts b/cli/tests/testdata/exit_error42.ts new file mode 100644 index 000000000..e4db41f3a --- /dev/null +++ b/cli/tests/testdata/exit_error42.ts @@ -0,0 +1,3 @@ +console.log("before"); +Deno.exit(42); +console.log("after"); diff --git a/cli/tests/testdata/exit_error42.ts.out b/cli/tests/testdata/exit_error42.ts.out new file mode 100644 index 000000000..90be1f305 --- /dev/null +++ b/cli/tests/testdata/exit_error42.ts.out @@ -0,0 +1 @@ +before diff --git a/cli/tests/testdata/export_type_def.ts b/cli/tests/testdata/export_type_def.ts new file mode 100644 index 000000000..e33b70a64 --- /dev/null +++ b/cli/tests/testdata/export_type_def.ts @@ -0,0 +1,2 @@ +// @deno-types="./type_definitions/foo.d.ts" +export { foo } from "./type_definitions/foo.js"; diff --git a/cli/tests/testdata/fetch/hello.txt b/cli/tests/testdata/fetch/hello.txt new file mode 100644 index 000000000..af5626b4a --- /dev/null +++ b/cli/tests/testdata/fetch/hello.txt @@ -0,0 +1 @@ +Hello, world! diff --git a/cli/tests/testdata/fetch/other.ts b/cli/tests/testdata/fetch/other.ts new file mode 100644 index 000000000..91fe376b3 --- /dev/null +++ b/cli/tests/testdata/fetch/other.ts @@ -0,0 +1 @@ +import "http://localhost:4545/subdir/mt_text_typescript.t1.ts"; diff --git a/cli/tests/testdata/fetch/test.ts b/cli/tests/testdata/fetch/test.ts new file mode 100644 index 000000000..baa52775d --- /dev/null +++ b/cli/tests/testdata/fetch/test.ts @@ -0,0 +1 @@ +import "http://localhost:4545/subdir/mod2.ts"; diff --git a/cli/tests/testdata/fetch_response_finalization.js b/cli/tests/testdata/fetch_response_finalization.js new file mode 100644 index 000000000..dd7c355eb --- /dev/null +++ b/cli/tests/testdata/fetch_response_finalization.js @@ -0,0 +1,16 @@ +async function doAFetch() { + const resp = await fetch("http://localhost:4545/README.md"); + console.log(Deno.resources()); // print the current resources + const _resp = resp; + // at this point resp can be GC'ed +} + +await doAFetch(); // create a resource + +globalThis.gc(); // force GC + +// It is very important that there is a yield here, otherwise the finalizer for +// the response body is not called and the resource is not closed. +await new Promise((resolve) => setTimeout(resolve, 0)); + +console.log(Deno.resources()); // print the current resources diff --git a/cli/tests/testdata/fetch_response_finalization.js.out b/cli/tests/testdata/fetch_response_finalization.js.out new file mode 100644 index 000000000..844a4e4b2 --- /dev/null +++ b/cli/tests/testdata/fetch_response_finalization.js.out @@ -0,0 +1,2 @@ +{ "0": "stdin", "1": "stdout", "2": "stderr", "5": "fetchResponseBody" } +{ "0": "stdin", "1": "stdout", "2": "stderr" } diff --git a/cli/tests/testdata/file_exists.ts b/cli/tests/testdata/file_exists.ts new file mode 100644 index 000000000..20de4d4f2 --- /dev/null +++ b/cli/tests/testdata/file_exists.ts @@ -0,0 +1,6 @@ +try { + await Deno.open(Deno.args[0]); + Deno.exit(0); +} catch (_e) { + Deno.exit(1); +} diff --git a/cli/tests/testdata/finalization_registry.js b/cli/tests/testdata/finalization_registry.js new file mode 100644 index 000000000..f75979358 --- /dev/null +++ b/cli/tests/testdata/finalization_registry.js @@ -0,0 +1,20 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +"use strict"; + +function assertEquals(a, b) { + if (a === b) return; + throw a + " does not equal " + b; +} + +const registry = new FinalizationRegistry((value) => { + assertEquals(value, "called!"); + Deno.core.print("FinalizationRegistry called!\n"); +}); + +(function () { + let x = {}; + registry.register(x, "called!"); + x = null; +})(); + +gc(); diff --git a/cli/tests/testdata/finalization_registry.js.out b/cli/tests/testdata/finalization_registry.js.out new file mode 100644 index 000000000..fee61413a --- /dev/null +++ b/cli/tests/testdata/finalization_registry.js.out @@ -0,0 +1 @@ +FinalizationRegistry called! diff --git a/cli/tests/testdata/fix_dynamic_import_errors.js b/cli/tests/testdata/fix_dynamic_import_errors.js new file mode 100644 index 000000000..317047ccb --- /dev/null +++ b/cli/tests/testdata/fix_dynamic_import_errors.js @@ -0,0 +1,7 @@ +import("./dynamic_import/b.js").catch(() => { + console.log("caught import error from b.js"); +}); + +import("./dynamic_import/c.js").catch(() => { + console.log("caught import error from c.js"); +}); diff --git a/cli/tests/testdata/fix_dynamic_import_errors.js.out b/cli/tests/testdata/fix_dynamic_import_errors.js.out new file mode 100644 index 000000000..e7856fb9c --- /dev/null +++ b/cli/tests/testdata/fix_dynamic_import_errors.js.out @@ -0,0 +1,2 @@ +caught import error from [WILDCARD].js +caught import error from [WILDCARD].js diff --git a/cli/tests/testdata/fix_emittable_skipped.js b/cli/tests/testdata/fix_emittable_skipped.js new file mode 100644 index 000000000..f61907b06 --- /dev/null +++ b/cli/tests/testdata/fix_emittable_skipped.js @@ -0,0 +1,7 @@ +/// <reference types="./subdir/emittable.d.ts" /> + +import "./subdir/polyfill.ts"; + +export const a = "a"; + +console.log(globalThis.polyfill); diff --git a/cli/tests/testdata/fix_emittable_skipped.ts.out b/cli/tests/testdata/fix_emittable_skipped.ts.out new file mode 100644 index 000000000..108c2d67f --- /dev/null +++ b/cli/tests/testdata/fix_emittable_skipped.ts.out @@ -0,0 +1,2 @@ +[WILDCARD] +[Function] diff --git a/cli/tests/testdata/fix_exotic_specifiers.ts b/cli/tests/testdata/fix_exotic_specifiers.ts new file mode 100644 index 000000000..101667b2a --- /dev/null +++ b/cli/tests/testdata/fix_exotic_specifiers.ts @@ -0,0 +1,3 @@ +import clone from "https://jspm.dev/lodash@4/clone"; + +console.log(clone); diff --git a/cli/tests/testdata/fix_exotic_specifiers.ts.out b/cli/tests/testdata/fix_exotic_specifiers.ts.out new file mode 100644 index 000000000..7afdb808d --- /dev/null +++ b/cli/tests/testdata/fix_exotic_specifiers.ts.out @@ -0,0 +1 @@ +[Function: clone] diff --git a/cli/tests/testdata/fix_js_import_js.ts b/cli/tests/testdata/fix_js_import_js.ts new file mode 100644 index 000000000..c9f341748 --- /dev/null +++ b/cli/tests/testdata/fix_js_import_js.ts @@ -0,0 +1,3 @@ +import { isMod4 } from "./subdir/mod6.js"; + +console.log(isMod4); diff --git a/cli/tests/testdata/fix_js_import_js.ts.out b/cli/tests/testdata/fix_js_import_js.ts.out new file mode 100644 index 000000000..27ba77dda --- /dev/null +++ b/cli/tests/testdata/fix_js_import_js.ts.out @@ -0,0 +1 @@ +true diff --git a/cli/tests/testdata/fix_js_imports.ts b/cli/tests/testdata/fix_js_imports.ts new file mode 100644 index 000000000..4770b1ab6 --- /dev/null +++ b/cli/tests/testdata/fix_js_imports.ts @@ -0,0 +1,3 @@ +import * as amdLike from "./subdir/amd_like.js"; + +console.log(amdLike); diff --git a/cli/tests/testdata/fix_js_imports.ts.out b/cli/tests/testdata/fix_js_imports.ts.out new file mode 100644 index 000000000..5e45122de --- /dev/null +++ b/cli/tests/testdata/fix_js_imports.ts.out @@ -0,0 +1 @@ +Module {} diff --git a/cli/tests/testdata/fix_tsc_file_exists.out b/cli/tests/testdata/fix_tsc_file_exists.out new file mode 100644 index 000000000..ce0136250 --- /dev/null +++ b/cli/tests/testdata/fix_tsc_file_exists.out @@ -0,0 +1 @@ +hello diff --git a/cli/tests/testdata/fix_worker_dispatchevent.ts b/cli/tests/testdata/fix_worker_dispatchevent.ts new file mode 100644 index 000000000..1b73b52dc --- /dev/null +++ b/cli/tests/testdata/fix_worker_dispatchevent.ts @@ -0,0 +1,43 @@ +const code = ` +addEventListener("message", () => { + postMessage("pong"); +}); + +const context = new EventTarget(); + +Object.defineProperty(globalThis, "dispatchEvent", { + value: context.dispatchEvent.bind(context), + writable: true, + enumerable: true, + configurable: true, +}); + +postMessage("start"); +`; + +const blob = new Blob([code], { type: "application/javascript" }); + +const url = URL.createObjectURL(blob); + +const worker = new Worker(url, { type: "module" }); + +let terminated = false; + +worker.addEventListener("message", (evt) => { + if (evt.data === "start") { + worker.postMessage("ping"); + } else if (evt.data === "pong") { + worker.terminate(); + terminated = true; + console.log("success"); + } else { + throw new Error("unexpected message from worker"); + } +}); + +setTimeout(() => { + if (!terminated) { + worker.terminate(); + throw new Error("did not receive message from worker in time"); + } +}, 2000); diff --git a/cli/tests/testdata/fix_worker_dispatchevent.ts.out b/cli/tests/testdata/fix_worker_dispatchevent.ts.out new file mode 100644 index 000000000..2e9ba477f --- /dev/null +++ b/cli/tests/testdata/fix_worker_dispatchevent.ts.out @@ -0,0 +1 @@ +success diff --git a/cli/tests/testdata/fixture.json b/cli/tests/testdata/fixture.json new file mode 100644 index 000000000..56e056b6a --- /dev/null +++ b/cli/tests/testdata/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/testdata/fmt/expected_fmt_check_formatted_files.out b/cli/tests/testdata/fmt/expected_fmt_check_formatted_files.out new file mode 100644 index 000000000..5a4833dd4 --- /dev/null +++ b/cli/tests/testdata/fmt/expected_fmt_check_formatted_files.out @@ -0,0 +1 @@ +Checked 4 files diff --git a/cli/tests/testdata/fmt/expected_fmt_check_ignore.out b/cli/tests/testdata/fmt/expected_fmt_check_ignore.out new file mode 100644 index 000000000..7c1e471b9 --- /dev/null +++ b/cli/tests/testdata/fmt/expected_fmt_check_ignore.out @@ -0,0 +1 @@ +Checked 3 files diff --git a/cli/tests/testdata/fmt/expected_fmt_check_tests_dir.out b/cli/tests/testdata/fmt/expected_fmt_check_tests_dir.out new file mode 100644 index 000000000..e2dc2b4ae --- /dev/null +++ b/cli/tests/testdata/fmt/expected_fmt_check_tests_dir.out @@ -0,0 +1,2 @@ +[WILDCARD] +error: Found 6 not formatted files in [WILDCARD] files diff --git a/cli/tests/testdata/fmt/expected_fmt_check_verbose_formatted_files.out b/cli/tests/testdata/fmt/expected_fmt_check_verbose_formatted_files.out new file mode 100644 index 000000000..158c556c2 --- /dev/null +++ b/cli/tests/testdata/fmt/expected_fmt_check_verbose_formatted_files.out @@ -0,0 +1 @@ +Checked 2 files diff --git a/cli/tests/testdata/fmt/expected_fmt_check_verbose_tests_dir.out b/cli/tests/testdata/fmt/expected_fmt_check_verbose_tests_dir.out new file mode 100644 index 000000000..04cd5ec64 --- /dev/null +++ b/cli/tests/testdata/fmt/expected_fmt_check_verbose_tests_dir.out @@ -0,0 +1,2 @@ +[WILDCARD] +error: Found 1 not formatted file in [WILDCARD] files diff --git a/cli/tests/testdata/fmt/formatted1.js b/cli/tests/testdata/fmt/formatted1.js new file mode 100644 index 000000000..587aa5b96 --- /dev/null +++ b/cli/tests/testdata/fmt/formatted1.js @@ -0,0 +1,5 @@ +function foo() { + return 42; +} + +foo(); diff --git a/cli/tests/testdata/fmt/formatted2.ts b/cli/tests/testdata/fmt/formatted2.ts new file mode 100644 index 000000000..4a8036806 --- /dev/null +++ b/cli/tests/testdata/fmt/formatted2.ts @@ -0,0 +1,5 @@ +function bar(): number { + return 42; +} + +bar(); diff --git a/cli/tests/testdata/fmt/formatted3.md b/cli/tests/testdata/fmt/formatted3.md new file mode 100644 index 000000000..e6e616584 --- /dev/null +++ b/cli/tests/testdata/fmt/formatted3.md @@ -0,0 +1,17 @@ +# Hello + +```js +function foo() { + return 42; +} + +foo(); +``` + +```ts +function bar(): number { + return 42; +} + +bar(); +``` diff --git a/cli/tests/testdata/fmt/formatted4.jsonc b/cli/tests/testdata/fmt/formatted4.jsonc new file mode 100644 index 000000000..f0f72a6ed --- /dev/null +++ b/cli/tests/testdata/fmt/formatted4.jsonc @@ -0,0 +1,4 @@ +{ + // Comment + "key": "value" +} diff --git a/cli/tests/testdata/heapstats.js b/cli/tests/testdata/heapstats.js new file mode 100644 index 000000000..675fac2d6 --- /dev/null +++ b/cli/tests/testdata/heapstats.js @@ -0,0 +1,37 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +"use strict"; + +function allocTest(alloc, allocAssert, deallocAssert) { + // Helper func that GCs then returns memory usage + const sample = () => { + // deno-lint-ignore no-undef + gc(); + return Deno.memoryUsage(); + }; + const delta = (t1, t2) => t2.heapUsed - t1.heapUsed; + + // Sample "clean" heap usage + const t1 = sample(); + + // Alloc + // deno-lint-ignore no-unused-vars + let x = alloc(); + const t2 = sample(); + allocAssert(delta(t1, t2)); + + // Free + x = null; + const t3 = sample(); + deallocAssert(delta(t2, t3)); +} + +function main() { + // Large-array test, 1M slot array consumes ~4MB (4B per slot) + allocTest( + () => new Array(1e6), + (delta) => console.log("Allocated:", Math.round(delta / 1e6) + "MB"), + (delta) => console.log("Freed:", Math.round(delta / 1e6) + "MB"), + ); +} + +main(); diff --git a/cli/tests/testdata/heapstats.js.out b/cli/tests/testdata/heapstats.js.out new file mode 100644 index 000000000..b75a755f8 --- /dev/null +++ b/cli/tests/testdata/heapstats.js.out @@ -0,0 +1,2 @@ +Allocated: 4MB +Freed: -4MB diff --git a/cli/tests/testdata/hello.txt b/cli/tests/testdata/hello.txt new file mode 100644 index 000000000..6769dd60b --- /dev/null +++ b/cli/tests/testdata/hello.txt @@ -0,0 +1 @@ +Hello world!
\ No newline at end of file diff --git a/cli/tests/testdata/https_import.ts b/cli/tests/testdata/https_import.ts new file mode 100644 index 000000000..3bcc90326 --- /dev/null +++ b/cli/tests/testdata/https_import.ts @@ -0,0 +1,3 @@ +import { printHello } from "https://localhost:5545/subdir/print_hello.ts"; + +printHello(); diff --git a/cli/tests/testdata/https_import.ts.out b/cli/tests/testdata/https_import.ts.out new file mode 100644 index 000000000..e965047ad --- /dev/null +++ b/cli/tests/testdata/https_import.ts.out @@ -0,0 +1 @@ +Hello diff --git a/cli/tests/testdata/if_main.ts b/cli/tests/testdata/if_main.ts new file mode 100644 index 000000000..4dcfecea0 --- /dev/null +++ b/cli/tests/testdata/if_main.ts @@ -0,0 +1,6 @@ +if (import.meta.main) { + console.log("main"); +} else { + console.log("import.meta.url", import.meta.url); + throw Error("not main"); +} diff --git a/cli/tests/testdata/if_main.ts.out b/cli/tests/testdata/if_main.ts.out new file mode 100644 index 000000000..ba2906d06 --- /dev/null +++ b/cli/tests/testdata/if_main.ts.out @@ -0,0 +1 @@ +main diff --git a/cli/tests/testdata/ignore_require.js b/cli/tests/testdata/ignore_require.js new file mode 100644 index 000000000..a8ef15021 --- /dev/null +++ b/cli/tests/testdata/ignore_require.js @@ -0,0 +1,2 @@ +// deno-lint-ignore-file +require("invalid module specifier"); diff --git a/cli/tests/testdata/import_blob_url.ts b/cli/tests/testdata/import_blob_url.ts new file mode 100644 index 000000000..86bb634e1 --- /dev/null +++ b/cli/tests/testdata/import_blob_url.ts @@ -0,0 +1,13 @@ +const blob = new Blob( + ['export const a = "a";\n\nexport enum A {\n A,\n B,\n C,\n}\n'], + { + type: "application/typescript", + }, +); +const url = URL.createObjectURL(blob); + +const a = await import(url); + +console.log(a.a); +console.log(a.A); +console.log(a.A.A); diff --git a/cli/tests/testdata/import_blob_url.ts.out b/cli/tests/testdata/import_blob_url.ts.out new file mode 100644 index 000000000..bfa0b9d94 --- /dev/null +++ b/cli/tests/testdata/import_blob_url.ts.out @@ -0,0 +1,3 @@ +a +{ "0": "A", "1": "B", "2": "C", A: 0, B: 1, C: 2 } +0 diff --git a/cli/tests/testdata/import_blob_url_error_stack.ts b/cli/tests/testdata/import_blob_url_error_stack.ts new file mode 100644 index 000000000..f9c4f2e9d --- /dev/null +++ b/cli/tests/testdata/import_blob_url_error_stack.ts @@ -0,0 +1,13 @@ +const blob = new Blob( + [ + "enum A {\n A,\n B,\n C,\n }\n \n export function a() {\n throw new Error(`Hello ${A.C}`);\n }\n ", + ], + { + type: "application/typescript", + }, +); +const url = URL.createObjectURL(blob); + +const { a } = await import(url); + +a(); diff --git a/cli/tests/testdata/import_blob_url_error_stack.ts.out b/cli/tests/testdata/import_blob_url_error_stack.ts.out new file mode 100644 index 000000000..52b76fd5c --- /dev/null +++ b/cli/tests/testdata/import_blob_url_error_stack.ts.out @@ -0,0 +1,6 @@ +[WILDCARD]error: Uncaught (in promise) Error: Hello 2 + throw new Error(`Hello ${A.C}`); + ^ + at a (blob:null/[WILDCARD]:8:10) + at file:///[WILDCARD]/import_blob_url_error_stack.ts:13:1 +[WILDCARD] diff --git a/cli/tests/testdata/import_blob_url_import_relative.ts b/cli/tests/testdata/import_blob_url_import_relative.ts new file mode 100644 index 000000000..ad130bdac --- /dev/null +++ b/cli/tests/testdata/import_blob_url_import_relative.ts @@ -0,0 +1,8 @@ +const blob = new Blob(['export { a } from "./a.ts";'], { + type: "application/javascript", +}); +const url = URL.createObjectURL(blob); + +const a = await import(url); + +console.log(a); diff --git a/cli/tests/testdata/import_blob_url_import_relative.ts.out b/cli/tests/testdata/import_blob_url_import_relative.ts.out new file mode 100644 index 000000000..77f399763 --- /dev/null +++ b/cli/tests/testdata/import_blob_url_import_relative.ts.out @@ -0,0 +1,4 @@ +error: Uncaught (in promise) TypeError: invalid URL: relative URL with a cannot-be-a-base base +const a = await import(url); + ^ + at async file://[WILDCARD]/import_blob_url_import_relative.ts:6:11 diff --git a/cli/tests/testdata/import_blob_url_imports.ts b/cli/tests/testdata/import_blob_url_imports.ts new file mode 100644 index 000000000..a7c639152 --- /dev/null +++ b/cli/tests/testdata/import_blob_url_imports.ts @@ -0,0 +1,11 @@ +const blob = new Blob( + [ + 'export { printHello } from "http://localhost:4545/subdir/mod2.ts"', + ], + { type: "application/javascript" }, +); +const url = URL.createObjectURL(blob); + +const { printHello } = await import(url); + +printHello(); diff --git a/cli/tests/testdata/import_blob_url_imports.ts.out b/cli/tests/testdata/import_blob_url_imports.ts.out new file mode 100644 index 000000000..e965047ad --- /dev/null +++ b/cli/tests/testdata/import_blob_url_imports.ts.out @@ -0,0 +1 @@ +Hello diff --git a/cli/tests/testdata/import_blob_url_jsx.ts b/cli/tests/testdata/import_blob_url_jsx.ts new file mode 100644 index 000000000..8d645796a --- /dev/null +++ b/cli/tests/testdata/import_blob_url_jsx.ts @@ -0,0 +1,16 @@ +const blob = new Blob( + ["export default function() {\n return <div>Hello Deno!</div>\n}\n"], + { type: "text/jsx" }, +); +const url = URL.createObjectURL(blob); + +const { default: render } = await import(url); + +// deno-lint-ignore no-explicit-any +(globalThis as any).React = { + createElement(...args: unknown[]) { + console.log(...args); + }, +}; + +render(); diff --git a/cli/tests/testdata/import_blob_url_jsx.ts.out b/cli/tests/testdata/import_blob_url_jsx.ts.out new file mode 100644 index 000000000..c1c85f250 --- /dev/null +++ b/cli/tests/testdata/import_blob_url_jsx.ts.out @@ -0,0 +1 @@ +div null Hello Deno! diff --git a/cli/tests/testdata/import_data_url.ts b/cli/tests/testdata/import_data_url.ts new file mode 100644 index 000000000..258514a5e --- /dev/null +++ b/cli/tests/testdata/import_data_url.ts @@ -0,0 +1,12 @@ +// export const a = "a"; + +// export enum A { +// A, +// B, +// C, +// } +import * as a from "data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo="; + +console.log(a.a); +console.log(a.A); +console.log(a.A.A); diff --git a/cli/tests/testdata/import_data_url.ts.out b/cli/tests/testdata/import_data_url.ts.out new file mode 100644 index 000000000..bfa0b9d94 --- /dev/null +++ b/cli/tests/testdata/import_data_url.ts.out @@ -0,0 +1,3 @@ +a +{ "0": "A", "1": "B", "2": "C", A: 0, B: 1, C: 2 } +0 diff --git a/cli/tests/testdata/import_data_url_error_stack.ts b/cli/tests/testdata/import_data_url_error_stack.ts new file mode 100644 index 000000000..022e49fe1 --- /dev/null +++ b/cli/tests/testdata/import_data_url_error_stack.ts @@ -0,0 +1,3 @@ +import { a } from "data:application/typescript;base64,ZW51bSBBIHsKICBBLAogIEIsCiAgQywKIH0KIAogZXhwb3J0IGZ1bmN0aW9uIGEoKSB7CiAgIHRocm93IG5ldyBFcnJvcihgSGVsbG8gJHtBLkN9YCk7CiB9CiA="; + +a(); diff --git a/cli/tests/testdata/import_data_url_error_stack.ts.out b/cli/tests/testdata/import_data_url_error_stack.ts.out new file mode 100644 index 000000000..d456ad0ea --- /dev/null +++ b/cli/tests/testdata/import_data_url_error_stack.ts.out @@ -0,0 +1,6 @@ +[WILDCARD]error: Uncaught Error: Hello 2 + throw new Error(`Hello ${A.C}`); + ^ + at a (data:application/typescript;base64,ZW51bSBBIHsKICBBLAogIEIsCiAgQywKIH0KIAogZXhwb3J0IGZ1bmN0aW9uIGEoKSB7CiAgIHRocm93IG5ldyBFcnJvcihgSGVsbG8gJHtBLkN9YCk7CiB9CiA=:8:10) + at file:///[WILDCARD]/import_data_url_error_stack.ts:3:1 +[WILDCARD] diff --git a/cli/tests/testdata/import_data_url_import_relative.ts b/cli/tests/testdata/import_data_url_import_relative.ts new file mode 100644 index 000000000..23947fe60 --- /dev/null +++ b/cli/tests/testdata/import_data_url_import_relative.ts @@ -0,0 +1,4 @@ +// export { a } from "./a.ts"; +import * as a from "data:application/javascript;base64,ZXhwb3J0IHsgYSB9IGZyb20gIi4vYS50cyI7Cg=="; + +console.log(a); diff --git a/cli/tests/testdata/import_data_url_import_relative.ts.out b/cli/tests/testdata/import_data_url_import_relative.ts.out new file mode 100644 index 000000000..1f4f3e9ef --- /dev/null +++ b/cli/tests/testdata/import_data_url_import_relative.ts.out @@ -0,0 +1,4 @@ +error: invalid URL: relative URL with a cannot-be-a-base base + +Caused by: + relative URL with a cannot-be-a-base base diff --git a/cli/tests/testdata/import_data_url_imports.ts b/cli/tests/testdata/import_data_url_imports.ts new file mode 100644 index 000000000..df7dae727 --- /dev/null +++ b/cli/tests/testdata/import_data_url_imports.ts @@ -0,0 +1,4 @@ +// export { printHello } from "http://localhost:4545/subdir/mod2.ts"; +import { printHello } from "data:application/typescript;base64,ZXhwb3J0IHsgcHJpbnRIZWxsbyB9IGZyb20gImh0dHA6Ly9sb2NhbGhvc3Q6NDU0NS9zdWJkaXIvbW9kMi50cyI7"; + +printHello(); diff --git a/cli/tests/testdata/import_data_url_imports.ts.out b/cli/tests/testdata/import_data_url_imports.ts.out new file mode 100644 index 000000000..e965047ad --- /dev/null +++ b/cli/tests/testdata/import_data_url_imports.ts.out @@ -0,0 +1 @@ +Hello diff --git a/cli/tests/testdata/import_data_url_jsx.ts b/cli/tests/testdata/import_data_url_jsx.ts new file mode 100644 index 000000000..1881211f9 --- /dev/null +++ b/cli/tests/testdata/import_data_url_jsx.ts @@ -0,0 +1,10 @@ +import render from "data:text/jsx;base64,ZXhwb3J0IGRlZmF1bHQgZnVuY3Rpb24oKSB7CiAgcmV0dXJuIDxkaXY+SGVsbG8gRGVubyE8L2Rpdj4KfQo="; + +// deno-lint-ignore no-explicit-any +(globalThis as any).React = { + createElement(...args: unknown[]) { + console.log(...args); + }, +}; + +render(); diff --git a/cli/tests/testdata/import_data_url_jsx.ts.out b/cli/tests/testdata/import_data_url_jsx.ts.out new file mode 100644 index 000000000..c1c85f250 --- /dev/null +++ b/cli/tests/testdata/import_data_url_jsx.ts.out @@ -0,0 +1 @@ +div null Hello Deno! diff --git a/cli/tests/testdata/import_dynamic_data_url.ts b/cli/tests/testdata/import_dynamic_data_url.ts new file mode 100644 index 000000000..53a0fbcd3 --- /dev/null +++ b/cli/tests/testdata/import_dynamic_data_url.ts @@ -0,0 +1,14 @@ +// export const a = "a"; + +// export enum A { +// A, +// B, +// C, +// } +const a = await import( + "data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=" +); + +console.log(a.a); +console.log(a.A); +console.log(a.A.A); diff --git a/cli/tests/testdata/import_dynamic_data_url.ts.out b/cli/tests/testdata/import_dynamic_data_url.ts.out new file mode 100644 index 000000000..bfa0b9d94 --- /dev/null +++ b/cli/tests/testdata/import_dynamic_data_url.ts.out @@ -0,0 +1,3 @@ +a +{ "0": "A", "1": "B", "2": "C", A: 0, B: 1, C: 2 } +0 diff --git a/cli/tests/testdata/import_file_with_colon.ts b/cli/tests/testdata/import_file_with_colon.ts new file mode 100644 index 000000000..619bdd66d --- /dev/null +++ b/cli/tests/testdata/import_file_with_colon.ts @@ -0,0 +1 @@ +import "http://localhost:4545/subdir/file_with_:_in_name.ts"; diff --git a/cli/tests/testdata/import_file_with_colon.ts.out b/cli/tests/testdata/import_file_with_colon.ts.out new file mode 100644 index 000000000..f60bbf4b1 --- /dev/null +++ b/cli/tests/testdata/import_file_with_colon.ts.out @@ -0,0 +1 @@ +Hello from file_with_:_in_name.ts diff --git a/cli/tests/testdata/import_maps/import_map.json b/cli/tests/testdata/import_maps/import_map.json new file mode 100644 index 000000000..601874aab --- /dev/null +++ b/cli/tests/testdata/import_maps/import_map.json @@ -0,0 +1,14 @@ +{ + "imports": { + "moment": "./moment/moment.ts", + "moment/": "./moment/", + "lodash": "./lodash/lodash.ts", + "lodash/": "./lodash/", + "https://www.unpkg.com/vue/dist/vue.runtime.esm.js": "./vue.ts" + }, + "scopes": { + "scope/": { + "moment": "./scoped_moment.ts" + } + } +} diff --git a/cli/tests/testdata/import_maps/import_map_remote.json b/cli/tests/testdata/import_maps/import_map_remote.json new file mode 100644 index 000000000..51f90f69c --- /dev/null +++ b/cli/tests/testdata/import_maps/import_map_remote.json @@ -0,0 +1,9 @@ +{ + "imports": { + "moment": "./moment/moment.ts", + "moment/": "./moment/", + "lodash": "./lodash/lodash.ts", + "lodash/": "./lodash/", + "https://www.unpkg.com/vue/dist/vue.runtime.esm.js": "./vue.ts" + } +} diff --git a/cli/tests/testdata/import_maps/lodash/lodash.ts b/cli/tests/testdata/import_maps/lodash/lodash.ts new file mode 100644 index 000000000..2ec04ed3c --- /dev/null +++ b/cli/tests/testdata/import_maps/lodash/lodash.ts @@ -0,0 +1 @@ +console.log("Hello from remapped lodash!"); diff --git a/cli/tests/testdata/import_maps/lodash/other_file.ts b/cli/tests/testdata/import_maps/lodash/other_file.ts new file mode 100644 index 000000000..714adae3f --- /dev/null +++ b/cli/tests/testdata/import_maps/lodash/other_file.ts @@ -0,0 +1 @@ +console.log("Hello from remapped lodash dir!"); diff --git a/cli/tests/testdata/import_maps/moment/moment.ts b/cli/tests/testdata/import_maps/moment/moment.ts new file mode 100644 index 000000000..2b54a431e --- /dev/null +++ b/cli/tests/testdata/import_maps/moment/moment.ts @@ -0,0 +1 @@ +console.log("Hello from remapped moment!"); diff --git a/cli/tests/testdata/import_maps/moment/other_file.ts b/cli/tests/testdata/import_maps/moment/other_file.ts new file mode 100644 index 000000000..24f3a0226 --- /dev/null +++ b/cli/tests/testdata/import_maps/moment/other_file.ts @@ -0,0 +1 @@ +console.log("Hello from remapped moment dir!"); diff --git a/cli/tests/testdata/import_maps/scope/scoped.ts b/cli/tests/testdata/import_maps/scope/scoped.ts new file mode 100644 index 000000000..9a0b5d8e3 --- /dev/null +++ b/cli/tests/testdata/import_maps/scope/scoped.ts @@ -0,0 +1,2 @@ +import "moment"; +console.log("Hello from scoped!"); diff --git a/cli/tests/testdata/import_maps/scoped_moment.ts b/cli/tests/testdata/import_maps/scoped_moment.ts new file mode 100644 index 000000000..9f67f88d4 --- /dev/null +++ b/cli/tests/testdata/import_maps/scoped_moment.ts @@ -0,0 +1 @@ +console.log("Hello from scoped moment!"); diff --git a/cli/tests/testdata/import_maps/test.ts b/cli/tests/testdata/import_maps/test.ts new file mode 100644 index 000000000..9b09e9953 --- /dev/null +++ b/cli/tests/testdata/import_maps/test.ts @@ -0,0 +1,6 @@ +import "moment"; +import "moment/other_file.ts"; +import "lodash"; +import "lodash/other_file.ts"; +import "https://www.unpkg.com/vue/dist/vue.runtime.esm.js"; +import "./scope/scoped.ts"; diff --git a/cli/tests/testdata/import_maps/test_remote.ts b/cli/tests/testdata/import_maps/test_remote.ts new file mode 100644 index 000000000..206bdbd5f --- /dev/null +++ b/cli/tests/testdata/import_maps/test_remote.ts @@ -0,0 +1,5 @@ +import "moment"; +import "moment/other_file.ts"; +import "lodash"; +import "lodash/other_file.ts"; +import "https://www.unpkg.com/vue/dist/vue.runtime.esm.js"; diff --git a/cli/tests/testdata/import_maps/vue.ts b/cli/tests/testdata/import_maps/vue.ts new file mode 100644 index 000000000..76dbe1917 --- /dev/null +++ b/cli/tests/testdata/import_maps/vue.ts @@ -0,0 +1 @@ +console.log("Hello from remapped Vue!"); diff --git a/cli/tests/testdata/import_meta.ts b/cli/tests/testdata/import_meta.ts new file mode 100644 index 000000000..d111059ea --- /dev/null +++ b/cli/tests/testdata/import_meta.ts @@ -0,0 +1,3 @@ +console.log("import_meta", import.meta.url, import.meta.main); + +import "./import_meta2.ts"; diff --git a/cli/tests/testdata/import_meta.ts.out b/cli/tests/testdata/import_meta.ts.out new file mode 100644 index 000000000..f38aa98ea --- /dev/null +++ b/cli/tests/testdata/import_meta.ts.out @@ -0,0 +1,2 @@ +import_meta2 [WILDCARD]import_meta2.ts false +import_meta [WILDCARD]import_meta.ts true diff --git a/cli/tests/testdata/import_meta2.ts b/cli/tests/testdata/import_meta2.ts new file mode 100644 index 000000000..7f59a5a46 --- /dev/null +++ b/cli/tests/testdata/import_meta2.ts @@ -0,0 +1 @@ +console.log("import_meta2", import.meta.url, import.meta.main); diff --git a/cli/tests/testdata/info/data_null_error/data_null_error.out b/cli/tests/testdata/info/data_null_error/data_null_error.out new file mode 100644 index 000000000..89961be65 --- /dev/null +++ b/cli/tests/testdata/info/data_null_error/data_null_error.out @@ -0,0 +1,6 @@ +local: [WILDCARD]mod.ts +type: TypeScript +dependencies: 1 unique (total [WILDCARD]) + +file://[WILDCARD]/mod.ts ([WILDCARD]) +└── file://[WILDCARD]/types.d.ts ([WILDCARD]) diff --git a/cli/tests/testdata/info/data_null_error/mod.ts b/cli/tests/testdata/info/data_null_error/mod.ts new file mode 100644 index 000000000..6e3e99bd4 --- /dev/null +++ b/cli/tests/testdata/info/data_null_error/mod.ts @@ -0,0 +1 @@ +/// <reference path="./types.d.ts" /> diff --git a/cli/tests/testdata/info/data_null_error/types.d.ts b/cli/tests/testdata/info/data_null_error/types.d.ts new file mode 100644 index 000000000..6ecc85676 --- /dev/null +++ b/cli/tests/testdata/info/data_null_error/types.d.ts @@ -0,0 +1 @@ +declare class Test {} diff --git a/cli/tests/testdata/info/types_header.out b/cli/tests/testdata/info/types_header.out new file mode 100644 index 000000000..d3b6e8c4e --- /dev/null +++ b/cli/tests/testdata/info/types_header.out @@ -0,0 +1,8 @@ +[WILDCARD] +local: [WILDCARD]type_directives_01.ts +type: TypeScript +dependencies: 2 unique (total [WILDCARD]) + +[WILDCARD]/type_directives_01.ts ([WILDCARD]) +└─┬ http://127.0.0.1:4545/xTypeScriptTypes.js ([WILDCARD]) + └── http://127.0.0.1:4545/xTypeScriptTypes.d.ts ([WILDCARD]) diff --git a/cli/tests/testdata/info_json.out b/cli/tests/testdata/info_json.out new file mode 100644 index 000000000..4ba5a95f4 --- /dev/null +++ b/cli/tests/testdata/info_json.out @@ -0,0 +1,7 @@ +{ + "denoDir": "[WILDCARD]", + "modulesCache": "[WILDCARD]deps", + "typescriptCache": "[WILDCARD]gen", + "registryCache": "[WILDCARD]registries", + "originStorage": "[WILDCARD]location_data" +} diff --git a/cli/tests/testdata/info_json_location.out b/cli/tests/testdata/info_json_location.out new file mode 100644 index 000000000..6c4cddefb --- /dev/null +++ b/cli/tests/testdata/info_json_location.out @@ -0,0 +1,8 @@ +{ + "denoDir": "[WILDCARD]", + "modulesCache": "[WILDCARD]deps", + "typescriptCache": "[WILDCARD]gen", + "registryCache": "[WILDCARD]registries", + "originStorage": "[WILDCARD]location_data[WILDCARD]", + "localStorage": "[WILDCARD]location_data[WILDCARD]local_storage" +} diff --git a/cli/tests/testdata/info_missing_module.out b/cli/tests/testdata/info_missing_module.out new file mode 100644 index 000000000..75b077407 --- /dev/null +++ b/cli/tests/testdata/info_missing_module.out @@ -0,0 +1,6 @@ +local: [WILDCARD]error_009_missing_js_module.js +type: JavaScript +dependencies: 1 unique (total 26B) + +file://[WILDCARD]/error_009_missing_js_module.js (26B) +└── file://[WILDCARD]/bad-module.js (error) diff --git a/cli/tests/testdata/info_recursive_imports_test.out b/cli/tests/testdata/info_recursive_imports_test.out new file mode 100644 index 000000000..10ee54534 --- /dev/null +++ b/cli/tests/testdata/info_recursive_imports_test.out @@ -0,0 +1,12 @@ +local: [WILDCARD]info_recursive_imports_test.ts +type: TypeScript +dependencies: 4 unique (total [WILDCARD]) + +file://[WILDCARD]/info_recursive_imports_test.ts ([WILDCARD]) +└─┬ file://[WILDCARD]/recursive_imports/A.ts ([WILDCARD]) + ├─┬ file://[WILDCARD]/recursive_imports/B.ts ([WILDCARD]) + │ ├─┬ file://[WILDCARD]/recursive_imports/C.ts ([WILDCARD]) + │ │ ├── file://[WILDCARD]/recursive_imports/A.ts * + │ │ └── file://[WILDCARD]/recursive_imports/common.ts ([WILDCARD]) + │ └── file://[WILDCARD]/recursive_imports/common.ts * + └── file://[WILDCARD]/recursive_imports/common.ts * diff --git a/cli/tests/testdata/info_recursive_imports_test.ts b/cli/tests/testdata/info_recursive_imports_test.ts new file mode 100644 index 000000000..c9ba44755 --- /dev/null +++ b/cli/tests/testdata/info_recursive_imports_test.ts @@ -0,0 +1,5 @@ +import { A } from "./recursive_imports/A.ts"; + +export function test() { + A(); +} diff --git a/cli/tests/testdata/info_type_import.out b/cli/tests/testdata/info_type_import.out new file mode 100644 index 000000000..6b9869f1f --- /dev/null +++ b/cli/tests/testdata/info_type_import.out @@ -0,0 +1,5 @@ +local: [WILDCARD]info_type_import.ts +type: TypeScript +dependencies: 1 unique (total [WILDCARD]) +[WILDCARD]info_type_import.ts ([WILDCARD]) +└── [WILDCARD]type_and_code.ts ([WILDCARD]) diff --git a/cli/tests/testdata/info_type_import.ts b/cli/tests/testdata/info_type_import.ts new file mode 100644 index 000000000..eeef46c89 --- /dev/null +++ b/cli/tests/testdata/info_type_import.ts @@ -0,0 +1,3 @@ +import { AnInterface as _, isAnInterface } from "./subdir/type_and_code.ts"; + +isAnInterface({}); diff --git a/cli/tests/testdata/inline_js_source_map.ts b/cli/tests/testdata/inline_js_source_map.ts new file mode 100644 index 000000000..5ae7c226a --- /dev/null +++ b/cli/tests/testdata/inline_js_source_map.ts @@ -0,0 +1,6 @@ +1 + 1; +interface Test { + hello: string; +} + +// throw new Error("Hello world!" as string); diff --git a/cli/tests/testdata/inline_js_source_map_2.js b/cli/tests/testdata/inline_js_source_map_2.js new file mode 100644 index 000000000..036f351b9 --- /dev/null +++ b/cli/tests/testdata/inline_js_source_map_2.js @@ -0,0 +1,4 @@ +"use strict"; +1 + 1; +throw new Error("Hello world!"); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiaHR0cDovL2xvY2FsaG9zdDo0NTQ1L2lubGluZV9qc19zb3VyY2VfbWFwXzIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLENBQUMsR0FBQyxDQUFDLENBQUM7QUFLSixNQUFNLElBQUksS0FBSyxDQUFDLGNBQStCLENBQUMsQ0FBQyJ9
\ No newline at end of file diff --git a/cli/tests/testdata/inline_js_source_map_2.js.out b/cli/tests/testdata/inline_js_source_map_2.js.out new file mode 100644 index 000000000..4f9127da6 --- /dev/null +++ b/cli/tests/testdata/inline_js_source_map_2.js.out @@ -0,0 +1,2 @@ +error: Uncaught Error: Hello world! + at http://localhost:4545/inline_js_source_map_2.ts:6:7 diff --git a/cli/tests/testdata/inline_js_source_map_2.ts b/cli/tests/testdata/inline_js_source_map_2.ts new file mode 100644 index 000000000..fa50586e6 --- /dev/null +++ b/cli/tests/testdata/inline_js_source_map_2.ts @@ -0,0 +1,6 @@ +1 + 1; +interface Test { + hello: string; +} + +throw new Error("Hello world!" as unknown as string); diff --git a/cli/tests/testdata/inline_js_source_map_2_with_inline_contents.js b/cli/tests/testdata/inline_js_source_map_2_with_inline_contents.js new file mode 100644 index 000000000..5bea615b8 --- /dev/null +++ b/cli/tests/testdata/inline_js_source_map_2_with_inline_contents.js @@ -0,0 +1,4 @@ +"use strict"; + +throw new Error("Hello world!"); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiaHR0cDovL2xvY2FsaG9zdDo0NTQ1L2lubGluZV9qc19zb3VyY2VfbWFwXzIudHMiXSwic291cmNlc0NvbnRlbnQiOlsiMSsxO1xuaW50ZXJmYWNlIFRlc3Qge1xuICBoZWxsbzogc3RyaW5nO1xufVxuXG50aHJvdyBuZXcgRXJyb3IoXCJIZWxsbyB3b3JsZCFcIiBhcyB1bmtub3duIGFzIHN0cmluZyk7XG4iXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLENBQUMsR0FBQyxDQUFDLENBQUM7QUFLSixNQUFNLElBQUksS0FBSyxDQUFDLGNBQStCLENBQUMsQ0FBQyJ9
\ No newline at end of file diff --git a/cli/tests/testdata/inline_js_source_map_2_with_inline_contents.js.out b/cli/tests/testdata/inline_js_source_map_2_with_inline_contents.js.out new file mode 100644 index 000000000..9280361f7 --- /dev/null +++ b/cli/tests/testdata/inline_js_source_map_2_with_inline_contents.js.out @@ -0,0 +1,4 @@ +error: Uncaught Error: Hello world! +throw new Error("Hello world!" as unknown as string); + ^ + at http://localhost:4545/inline_js_source_map_2.ts:6:7 diff --git a/cli/tests/testdata/inline_js_source_map_with_contents_from_graph.js b/cli/tests/testdata/inline_js_source_map_with_contents_from_graph.js new file mode 100644 index 000000000..decf47bdc --- /dev/null +++ b/cli/tests/testdata/inline_js_source_map_with_contents_from_graph.js @@ -0,0 +1,4 @@ +"use strict"; +import "http://localhost:4545/inline_js_source_map.ts"; +throw new Error("Hello world!"); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiaHR0cDovL2xvY2FsaG9zdDo0NTQ1L2lubGluZV9qc19zb3VyY2VfbWFwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxDQUFDLEdBQUMsQ0FBQyxDQUFDO0FBS0osTUFBTSxJQUFJLEtBQUssQ0FBQyxjQUErQixDQUFDLENBQUMifQ==
\ No newline at end of file diff --git a/cli/tests/testdata/inline_js_source_map_with_contents_from_graph.js.out b/cli/tests/testdata/inline_js_source_map_with_contents_from_graph.js.out new file mode 100644 index 000000000..7304fc5f6 --- /dev/null +++ b/cli/tests/testdata/inline_js_source_map_with_contents_from_graph.js.out @@ -0,0 +1,4 @@ +error: Uncaught Error: Hello world! +// throw new Error("Hello world!" as string); + ^ + at http://localhost:4545/inline_js_source_map.ts:6:7 diff --git a/cli/tests/testdata/inspector1.js b/cli/tests/testdata/inspector1.js new file mode 100644 index 000000000..5cb059def --- /dev/null +++ b/cli/tests/testdata/inspector1.js @@ -0,0 +1,3 @@ +setInterval(() => { + console.log("hello"); +}, 1000); diff --git a/cli/tests/testdata/inspector2.js b/cli/tests/testdata/inspector2.js new file mode 100644 index 000000000..57f80ef94 --- /dev/null +++ b/cli/tests/testdata/inspector2.js @@ -0,0 +1,4 @@ +console.log("hello from the script"); + +// This process will be killed before the timeout is over. +await new Promise((res, _) => setTimeout(res, 1000)); diff --git a/cli/tests/testdata/inspector3.js b/cli/tests/testdata/inspector3.js new file mode 100644 index 000000000..b1b00b5a0 --- /dev/null +++ b/cli/tests/testdata/inspector3.js @@ -0,0 +1,7 @@ +// deno-lint-ignore-file +for (let i = 0; i < 128; i++) { + console.log(i); + debugger; +} +await new Promise((res, _) => setTimeout(res, 100)); +console.log("done"); diff --git a/cli/tests/testdata/inspector4.js b/cli/tests/testdata/inspector4.js new file mode 100644 index 000000000..1bf419650 --- /dev/null +++ b/cli/tests/testdata/inspector4.js @@ -0,0 +1,5 @@ +console.log("hello"); + +setInterval(() => { + console.log("hello from interval"); +}, 1000); diff --git a/cli/tests/testdata/js_import_detect.ts b/cli/tests/testdata/js_import_detect.ts new file mode 100644 index 000000000..751741996 --- /dev/null +++ b/cli/tests/testdata/js_import_detect.ts @@ -0,0 +1,3 @@ +function define(_foo: string[]) {} +define(["long"]); +console.log("ok"); diff --git a/cli/tests/testdata/js_import_detect.ts.out b/cli/tests/testdata/js_import_detect.ts.out new file mode 100644 index 000000000..9766475a4 --- /dev/null +++ b/cli/tests/testdata/js_import_detect.ts.out @@ -0,0 +1 @@ +ok diff --git a/cli/tests/testdata/jsx_import_from_ts.App.jsx b/cli/tests/testdata/jsx_import_from_ts.App.jsx new file mode 100644 index 000000000..649230613 --- /dev/null +++ b/cli/tests/testdata/jsx_import_from_ts.App.jsx @@ -0,0 +1,11 @@ +const React = { + createElement() {}, +}; + +export default function app() { + return ( + <div> + <h2>asdf</h2> + </div> + ); +} diff --git a/cli/tests/testdata/jsx_import_from_ts.ts b/cli/tests/testdata/jsx_import_from_ts.ts new file mode 100644 index 000000000..3cc916698 --- /dev/null +++ b/cli/tests/testdata/jsx_import_from_ts.ts @@ -0,0 +1,3 @@ +import app from "./jsx_import_from_ts.App.jsx"; + +console.log(app); diff --git a/cli/tests/testdata/jsx_import_from_ts.ts.out b/cli/tests/testdata/jsx_import_from_ts.ts.out new file mode 100644 index 000000000..d449b8c9a --- /dev/null +++ b/cli/tests/testdata/jsx_import_from_ts.ts.out @@ -0,0 +1 @@ +[Function: app] diff --git a/cli/tests/testdata/lib_dom_asynciterable.ts b/cli/tests/testdata/lib_dom_asynciterable.ts new file mode 100644 index 000000000..d932011f4 --- /dev/null +++ b/cli/tests/testdata/lib_dom_asynciterable.ts @@ -0,0 +1,23 @@ +const { diagnostics, files } = await Deno.emit("/main.ts", { + compilerOptions: { + target: "esnext", + lib: ["esnext", "dom", "dom.iterable", "dom.asynciterable"], + }, + sources: { + "/main.ts": `const rs = new ReadableStream<string>({ + start(c) { + c.enqueue("hello"); + c.enqueue("deno"); + c.close(); + } + }); + + for await (const s of rs) { + console.log("s"); + } + `, + }, +}); + +console.log(diagnostics); +console.log(Object.keys(files).sort()); diff --git a/cli/tests/testdata/lib_dom_asynciterable.ts.out b/cli/tests/testdata/lib_dom_asynciterable.ts.out new file mode 100644 index 000000000..8b5e7adb6 --- /dev/null +++ b/cli/tests/testdata/lib_dom_asynciterable.ts.out @@ -0,0 +1,2 @@ +[] +[ "[WILDCARD]/main.ts.js", "[WILDCARD]/main.ts.js.map" ] diff --git a/cli/tests/testdata/lib_ref.ts b/cli/tests/testdata/lib_ref.ts new file mode 100644 index 000000000..2454f8b5d --- /dev/null +++ b/cli/tests/testdata/lib_ref.ts @@ -0,0 +1,16 @@ +const { diagnostics, files } = await Deno.emit( + "/main.ts", + { + sources: { + "/main.ts": + `/// <reference lib="dom" />\n\ndocument.getElementById("foo");\nDeno.args;`, + }, + compilerOptions: { + target: "es2018", + lib: ["es2018", "deno.ns"], + }, + }, +); + +console.log(diagnostics); +console.log(Object.keys(files).sort()); diff --git a/cli/tests/testdata/lib_ref.ts.out b/cli/tests/testdata/lib_ref.ts.out new file mode 100644 index 000000000..4e0f933fc --- /dev/null +++ b/cli/tests/testdata/lib_ref.ts.out @@ -0,0 +1,2 @@ +[] +[ "file:///[WILDCARD]main.ts.js", "file:///[WILDCARD]main.ts.js.map" ] diff --git a/cli/tests/testdata/lib_runtime_api.ts b/cli/tests/testdata/lib_runtime_api.ts new file mode 100644 index 000000000..450d9480b --- /dev/null +++ b/cli/tests/testdata/lib_runtime_api.ts @@ -0,0 +1,14 @@ +const { diagnostics, files } = await Deno.emit( + "/main.ts", + { + sources: { + "/main.ts": `document.getElementById("foo");`, + }, + compilerOptions: { + lib: ["dom", "esnext"], + }, + }, +); + +console.log(diagnostics); +console.log(Object.keys(files).sort()); diff --git a/cli/tests/testdata/lib_runtime_api.ts.out b/cli/tests/testdata/lib_runtime_api.ts.out new file mode 100644 index 000000000..4e0f933fc --- /dev/null +++ b/cli/tests/testdata/lib_runtime_api.ts.out @@ -0,0 +1,2 @@ +[] +[ "file:///[WILDCARD]main.ts.js", "file:///[WILDCARD]main.ts.js.map" ] diff --git a/cli/tests/testdata/lint/expected.out b/cli/tests/testdata/lint/expected.out new file mode 100644 index 000000000..eb8a2651a --- /dev/null +++ b/cli/tests/testdata/lint/expected.out @@ -0,0 +1,3 @@ +[WILDCARD] +Found 3 problems +Checked 3 files diff --git a/cli/tests/testdata/lint/expected_from_stdin.out b/cli/tests/testdata/lint/expected_from_stdin.out new file mode 100644 index 000000000..90f455fdc --- /dev/null +++ b/cli/tests/testdata/lint/expected_from_stdin.out @@ -0,0 +1,3 @@ +[WILDCARD] +Found 1 problem +Checked 1 file diff --git a/cli/tests/testdata/lint/expected_from_stdin_json.out b/cli/tests/testdata/lint/expected_from_stdin_json.out new file mode 100644 index 000000000..7ea40e957 --- /dev/null +++ b/cli/tests/testdata/lint/expected_from_stdin_json.out @@ -0,0 +1,23 @@ +{ + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "col": 8, + "bytePos": 8 + }, + "end": { + "line": 1, + "col": 11, + "bytePos": 11 + } + }, + "filename": "_stdin.ts", + "message": "`any` type is not allowed", + "code": "no-explicit-any", + "hint": [WILDCARD] + } + ], + "errors": [] +} diff --git a/cli/tests/testdata/lint/expected_glob.out b/cli/tests/testdata/lint/expected_glob.out new file mode 100644 index 000000000..eb8a2651a --- /dev/null +++ b/cli/tests/testdata/lint/expected_glob.out @@ -0,0 +1,3 @@ +[WILDCARD] +Found 3 problems +Checked 3 files diff --git a/cli/tests/testdata/lint/expected_ignore.out b/cli/tests/testdata/lint/expected_ignore.out new file mode 100644 index 000000000..b5f78ee04 --- /dev/null +++ b/cli/tests/testdata/lint/expected_ignore.out @@ -0,0 +1,3 @@ +[WILDCARD] +Found 1 problem +Checked 2 files diff --git a/cli/tests/testdata/lint/expected_json.out b/cli/tests/testdata/lint/expected_json.out new file mode 100644 index 000000000..dbeb8039b --- /dev/null +++ b/cli/tests/testdata/lint/expected_json.out @@ -0,0 +1,64 @@ +{ + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "col": 0, + "bytePos": 0 + }, + "end": { + "line": 1, + "col": 19, + "bytePos": 19 + } + }, + "filename": "[WILDCARD]file1.js", + "message": "Ignore directive requires lint rule name(s)", + "code": "ban-untagged-ignore", + "hint": [WILDCARD] + }, + { + "range": { + "start": { + "line": 2, + "col": 14, + "bytePos": 34 + }, + "end": { + "line": 2, + "col": 16, + "bytePos": 36 + } + }, + "filename": "[WILDCARD]file1.js", + "message": "Empty block statement", + "code": "no-empty", + "hint": [WILDCARD] + }, + { + "range": { + "start": { + "line": 3, + "col": 13, + "bytePos": 57 + }, + "end": { + "line": 3, + "col": 15, + "bytePos": 59 + } + }, + "filename": "[WILDCARD]file2.ts", + "message": "Empty block statement", + "code": "no-empty", + "hint": [WILDCARD] + } + ], + "errors": [ + { + "file_path": "[WILDCARD]malformed.js", + "message": "Expected }, got <eof> at [WILDCARD]malformed.js:4:15" + } + ] +} diff --git a/cli/tests/testdata/lint/expected_quiet.out b/cli/tests/testdata/lint/expected_quiet.out new file mode 100644 index 000000000..d7c9d7bb9 --- /dev/null +++ b/cli/tests/testdata/lint/expected_quiet.out @@ -0,0 +1,14 @@ +(ban-untagged-ignore) Ignore directive requires lint rule name(s) +// deno-lint-ignore +^^^^^^^^^^^^^^^^^^^ + at [WILDCARD]file1.js:1:0 + + hint: [WILDCARD] + +(no-empty) Empty block statement +while (false) {} + ^^ + at [WILDCARD]file1.js:2:14 + + hint: [WILDCARD] + diff --git a/cli/tests/testdata/lint/expected_rules.out b/cli/tests/testdata/lint/expected_rules.out new file mode 100644 index 000000000..4afab7b9b --- /dev/null +++ b/cli/tests/testdata/lint/expected_rules.out @@ -0,0 +1,2 @@ +Available rules: +[WILDCARD] diff --git a/cli/tests/testdata/lint/expected_verbose.out b/cli/tests/testdata/lint/expected_verbose.out new file mode 100644 index 000000000..eb8a2651a --- /dev/null +++ b/cli/tests/testdata/lint/expected_verbose.out @@ -0,0 +1,3 @@ +[WILDCARD] +Found 3 problems +Checked 3 files diff --git a/cli/tests/testdata/lint/file1.js b/cli/tests/testdata/lint/file1.js new file mode 100644 index 000000000..737f26818 --- /dev/null +++ b/cli/tests/testdata/lint/file1.js @@ -0,0 +1,2 @@ +// deno-lint-ignore +while (false) {} diff --git a/cli/tests/testdata/lint/file2.ts b/cli/tests/testdata/lint/file2.ts new file mode 100644 index 000000000..73c612c35 --- /dev/null +++ b/cli/tests/testdata/lint/file2.ts @@ -0,0 +1,6 @@ +try { + await Deno.open("./some/file.txt"); +} catch (_e) {} + +// deno-lint-ignore no-explicit-any +function _foo(): any {} diff --git a/cli/tests/testdata/lint/ignored_file.ts b/cli/tests/testdata/lint/ignored_file.ts new file mode 100644 index 000000000..97befafa3 --- /dev/null +++ b/cli/tests/testdata/lint/ignored_file.ts @@ -0,0 +1,3 @@ +// deno-lint-ignore-file + +function foo(): any {} diff --git a/cli/tests/testdata/lint/malformed.js b/cli/tests/testdata/lint/malformed.js new file mode 100644 index 000000000..5ad4650d6 --- /dev/null +++ b/cli/tests/testdata/lint/malformed.js @@ -0,0 +1,4 @@ +// deno-fmt-ignore-file + +// intentionally malformed file +export class A {
\ No newline at end of file diff --git a/cli/tests/testdata/listen_tls_alpn.ts b/cli/tests/testdata/listen_tls_alpn.ts new file mode 100644 index 000000000..5d58065d9 --- /dev/null +++ b/cli/tests/testdata/listen_tls_alpn.ts @@ -0,0 +1,12 @@ +const listener = Deno.listenTls({ + port: Number(Deno.args[0]), + certFile: "./tls/localhost.crt", + keyFile: "./tls/localhost.key", + alpnProtocols: ["h2", "http/1.1", "foobar"], +}); + +console.log("READY"); + +for await (const conn of listener) { + conn.close(); +} diff --git a/cli/tests/testdata/localhost_unsafe_ssl.ts.out b/cli/tests/testdata/localhost_unsafe_ssl.ts.out new file mode 100644 index 000000000..c482bd81c --- /dev/null +++ b/cli/tests/testdata/localhost_unsafe_ssl.ts.out @@ -0,0 +1,3 @@ +DANGER: TLS certificate validation is disabled for: deno.land +error: error sending request for url (https://localhost:5545/subdir/mod2.ts): error trying to connect: invalid certificate: UnknownIssuer + at [WILDCARD]/cafile_url_imports.ts:1:0 diff --git a/cli/tests/testdata/lock_check_err.json b/cli/tests/testdata/lock_check_err.json new file mode 100644 index 000000000..9bf52adca --- /dev/null +++ b/cli/tests/testdata/lock_check_err.json @@ -0,0 +1,4 @@ +{ + "http://127.0.0.1:4545/subdir/print_hello.ts": "fa6692c8f9ff3fb107e773c3ece5274e9d08be282867a1e3ded1d9c00fcaa63c", + "http://127.0.0.1:4545/003_relative_import.ts": "bad" +} diff --git a/cli/tests/testdata/lock_check_err.out b/cli/tests/testdata/lock_check_err.out new file mode 100644 index 000000000..3c5eceb8c --- /dev/null +++ b/cli/tests/testdata/lock_check_err.out @@ -0,0 +1,3 @@ +[WILDCARD]The source code is invalid, as it does not match the expected hash in the lock file. + Specifier: http://127.0.0.1:4545/003_relative_import.ts + Lock file: lock_check_err.json diff --git a/cli/tests/testdata/lock_check_err2.json b/cli/tests/testdata/lock_check_err2.json new file mode 100644 index 000000000..a59cbc9e3 --- /dev/null +++ b/cli/tests/testdata/lock_check_err2.json @@ -0,0 +1,10 @@ +{ + "http://localhost:4545/subdir/mt_application_ecmascript.j2.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_application_x_javascript.j4.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_application_x_typescript.t4.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_text_ecmascript.j3.js": "bad", + "http://localhost:4545/subdir/mt_text_javascript.j1.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_text_typescript.t1.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_video_mp2t.t3.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_video_vdn.t2.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18" +} diff --git a/cli/tests/testdata/lock_check_err2.out b/cli/tests/testdata/lock_check_err2.out new file mode 100644 index 000000000..958c01654 --- /dev/null +++ b/cli/tests/testdata/lock_check_err2.out @@ -0,0 +1,3 @@ +[WILDCARD]The source code is invalid, as it does not match the expected hash in the lock file. + Specifier: http://localhost:4545/subdir/mt_text_ecmascript.j3.js + Lock file: lock_check_err2.json diff --git a/cli/tests/testdata/lock_check_err_with_bundle.json b/cli/tests/testdata/lock_check_err_with_bundle.json new file mode 100644 index 000000000..a218d7000 --- /dev/null +++ b/cli/tests/testdata/lock_check_err_with_bundle.json @@ -0,0 +1,5 @@ +{ + "http://127.0.0.1:4545/subdir/mod1.ts": "bfc1037b02c99abc20367f739bca7455813a5950066abd77965bff33b6eece0f", + "http://127.0.0.1:4545/subdir/print_hello.ts": "fa6692c8f9ff3fb107e773c3ece5274e9d08be282867a1e3ded1d9c00fcaa63c", + "http://127.0.0.1:4545/subdir/subdir2/mod2.ts": "bad" +} diff --git a/cli/tests/testdata/lock_check_err_with_bundle.out b/cli/tests/testdata/lock_check_err_with_bundle.out new file mode 100644 index 000000000..a47cbc606 --- /dev/null +++ b/cli/tests/testdata/lock_check_err_with_bundle.out @@ -0,0 +1,4 @@ +[WILDCARD] +The source code is invalid, as it does not match the expected hash in the lock file. + Specifier: http://127.0.0.1:4545/subdir/subdir2/mod2.ts + Lock file: lock_check_err_with_bundle.json diff --git a/cli/tests/testdata/lock_check_ok.json b/cli/tests/testdata/lock_check_ok.json new file mode 100644 index 000000000..9dd5b0548 --- /dev/null +++ b/cli/tests/testdata/lock_check_ok.json @@ -0,0 +1,4 @@ +{ + "http://127.0.0.1:4545/subdir/print_hello.ts": "fa6692c8f9ff3fb107e773c3ece5274e9d08be282867a1e3ded1d9c00fcaa63c", + "http://127.0.0.1:4545/003_relative_import.ts": "aa9e16de824f81871a1c7164d5bd6857df7db2e18621750bd66b0bde4df07f21" +} diff --git a/cli/tests/testdata/lock_check_ok2.json b/cli/tests/testdata/lock_check_ok2.json new file mode 100644 index 000000000..162c755e2 --- /dev/null +++ b/cli/tests/testdata/lock_check_ok2.json @@ -0,0 +1,10 @@ +{ + "http://localhost:4545/subdir/mt_application_ecmascript.j2.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_application_x_javascript.j4.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_application_x_typescript.t4.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_text_ecmascript.j3.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_text_javascript.j1.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_text_typescript.t1.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_video_mp2t.t3.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_video_vdn.t2.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18" +} diff --git a/cli/tests/testdata/lock_dynamic_imports.json b/cli/tests/testdata/lock_dynamic_imports.json new file mode 100644 index 000000000..57263bc85 --- /dev/null +++ b/cli/tests/testdata/lock_dynamic_imports.json @@ -0,0 +1,6 @@ +{ + "http://127.0.0.1:4545/013_dynamic_import.ts": "f0d2d108c100e769cda9f26b74326f21e44cab81611aa7f6cd2b731d4cbc1995", + "http://127.0.0.1:4545/subdir/mod1.ts": "bfc1037b02c99abc20367f739bca7455813a5950066abd77965bff33b6eece0f", + "http://127.0.0.1:4545/subdir/print_hello.ts": "fa6692c8f9ff3fb107e773c3ece5274e9d08be282867a1e3ded1d9c00fcaa63c", + "http://127.0.0.1:4545/subdir/subdir2/mod2.ts": "bad" +} diff --git a/cli/tests/testdata/lock_dynamic_imports.out b/cli/tests/testdata/lock_dynamic_imports.out new file mode 100644 index 000000000..e5c76c8f0 --- /dev/null +++ b/cli/tests/testdata/lock_dynamic_imports.out @@ -0,0 +1,4 @@ +[WILDCARD] +The source code is invalid, as it does not match the expected hash in the lock file. + Specifier: http://127.0.0.1:4545/subdir/subdir2/mod2.ts + Lock file: lock_dynamic_imports.json diff --git a/cli/tests/testdata/lock_write_fetch.ts b/cli/tests/testdata/lock_write_fetch.ts new file mode 100644 index 000000000..b6ecf4747 --- /dev/null +++ b/cli/tests/testdata/lock_write_fetch.ts @@ -0,0 +1,58 @@ +try { + Deno.removeSync("./lock_write_fetch.json"); +} catch { + // pass +} + +const fetchProc = Deno.run({ + stdout: "null", + stderr: "null", + cmd: [ + Deno.execPath(), + "cache", + "--reload", + "--lock=lock_write_fetch.json", + "--lock-write", + "--cert=tls/RootCA.pem", + "https_import.ts", + ], +}); + +const fetchCode = (await fetchProc.status()).code; +console.log(`fetch code: ${fetchCode}`); + +const fetchCheckProc = Deno.run({ + stdout: "null", + stderr: "null", + cmd: [ + Deno.execPath(), + "cache", + "--lock=lock_write_fetch.json", + "--cert=tls/RootCA.pem", + "https_import.ts", + ], +}); + +const fetchCheckProcCode = (await fetchCheckProc.status()).code; +console.log(`fetch check code: ${fetchCheckProcCode}`); + +Deno.removeSync("./lock_write_fetch.json"); + +const runProc = Deno.run({ + stdout: "null", + stderr: "null", + cmd: [ + Deno.execPath(), + "run", + "--lock=lock_write_fetch.json", + "--lock-write", + "--allow-read", + "file_exists.ts", + "lock_write_fetch.json", + ], +}); + +const runCode = (await runProc.status()).code; +console.log(`run code: ${runCode}`); + +Deno.removeSync("./lock_write_fetch.json"); diff --git a/cli/tests/testdata/lock_write_fetch.ts.out b/cli/tests/testdata/lock_write_fetch.ts.out new file mode 100644 index 000000000..bfdb952f9 --- /dev/null +++ b/cli/tests/testdata/lock_write_fetch.ts.out @@ -0,0 +1,3 @@ +fetch code: 0 +fetch check code: 0 +run code: 0 diff --git a/cli/tests/testdata/lock_write_requires_lock.out b/cli/tests/testdata/lock_write_requires_lock.out new file mode 100644 index 000000000..7cc5906f6 --- /dev/null +++ b/cli/tests/testdata/lock_write_requires_lock.out @@ -0,0 +1,3 @@ +error: The following required arguments were not provided: + --lock <FILE> +[WILDCARD]
\ No newline at end of file diff --git a/cli/tests/testdata/lsp/a.d.ts b/cli/tests/testdata/lsp/a.d.ts new file mode 100644 index 000000000..7f587e144 --- /dev/null +++ b/cli/tests/testdata/lsp/a.d.ts @@ -0,0 +1 @@ +declare var a: string; diff --git a/cli/tests/testdata/lsp/b.d.ts b/cli/tests/testdata/lsp/b.d.ts new file mode 100644 index 000000000..9d4b96cb8 --- /dev/null +++ b/cli/tests/testdata/lsp/b.d.ts @@ -0,0 +1 @@ +declare var b: string; diff --git a/cli/tests/testdata/lsp/code_action_ignore_lint_params.json b/cli/tests/testdata/lsp/code_action_ignore_lint_params.json new file mode 100644 index 000000000..7711812fd --- /dev/null +++ b/cli/tests/testdata/lsp/code_action_ignore_lint_params.json @@ -0,0 +1,39 @@ +{ + "textDocument": { + "uri": "file:///a/file.ts" + }, + "range": { + "start": { + "line": 1, + "character": 5 + }, + "end": { + "line": 1, + "character": 12 + } + }, + "context": { + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 5 + }, + "end": { + "line": 1, + "character": 12 + } + }, + "severity": 1, + "code": "prefer-const", + "source": "deno-lint", + "message": "'message' is never reassigned\nUse 'const' instead", + "relatedInformation": [] + } + ], + "only": [ + "quickfix" + ] + } +} diff --git a/cli/tests/testdata/lsp/code_action_ignore_lint_response.json b/cli/tests/testdata/lsp/code_action_ignore_lint_response.json new file mode 100644 index 000000000..f5c24ec21 --- /dev/null +++ b/cli/tests/testdata/lsp/code_action_ignore_lint_response.json @@ -0,0 +1,62 @@ +[ + { + "title": "Disable prefer-const for this line", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { "line": 1, "character": 5 }, + "end": { "line": 1, "character": 12 } + }, + "severity": 1, + "code": "prefer-const", + "source": "deno-lint", + "message": "'message' is never reassigned\nUse 'const' instead", + "relatedInformation": [] + } + ], + "edit": { + "changes": { + "file:///a/file.ts": [ + { + "range": { + "start": { "line": 1, "character": 0 }, + "end": { "line": 1, "character": 0 } + }, + "newText": "// deno-lint-ignore prefer-const\n" + } + ] + } + } + }, + { + "title": "Ignore lint errors for the entire file", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { "line": 1, "character": 5 }, + "end": { "line": 1, "character": 12 } + }, + "severity": 1, + "code": "prefer-const", + "source": "deno-lint", + "message": "'message' is never reassigned\nUse 'const' instead", + "relatedInformation": [] + } + ], + "edit": { + "changes": { + "file:///a/file.ts": [ + { + "range": { + "start": { "line": 0, "character": 0 }, + "end": { "line": 0, "character": 0 } + }, + "newText": "// deno-lint-ignore-file\n" + } + ] + } + } + } +] diff --git a/cli/tests/testdata/lsp/code_action_params.json b/cli/tests/testdata/lsp/code_action_params.json new file mode 100644 index 000000000..d026d61f6 --- /dev/null +++ b/cli/tests/testdata/lsp/code_action_params.json @@ -0,0 +1,39 @@ +{ + "textDocument": { + "uri": "file:///a/file.ts" + }, + "range": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 7 + } + }, + "context": { + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 7 + } + }, + "severity": 1, + "code": 1308, + "source": "deno-ts", + "message": "'await' expressions are only allowed within async functions and at the top levels of modules.", + "relatedInformation": [] + } + ], + "only": [ + "quickfix" + ] + } +} diff --git a/cli/tests/testdata/lsp/code_action_params_cache.json b/cli/tests/testdata/lsp/code_action_params_cache.json new file mode 100644 index 000000000..61ae555a3 --- /dev/null +++ b/cli/tests/testdata/lsp/code_action_params_cache.json @@ -0,0 +1,41 @@ +{ + "textDocument": { + "uri": "file:///a/file.ts" + }, + "range": { + "start": { + "line": 0, + "character": 19 + }, + "end": { + "line": 0, + "character": 49 + } + }, + "context": { + "diagnostics": [ + { + "range": { + "start": { + "line": 0, + "character": 19 + }, + "end": { + "line": 0, + "character": 49 + } + }, + "severity": 1, + "code": "no-cache", + "source": "deno", + "message": "Unable to load the remote module: \"https://deno.land/x/a/mod.ts\".", + "data": { + "specifier": "https://deno.land/x/a/mod.ts" + } + } + ], + "only": [ + "quickfix" + ] + } +} diff --git a/cli/tests/testdata/lsp/code_action_params_deadlock.json b/cli/tests/testdata/lsp/code_action_params_deadlock.json new file mode 100644 index 000000000..be0e317e1 --- /dev/null +++ b/cli/tests/testdata/lsp/code_action_params_deadlock.json @@ -0,0 +1,38 @@ +{ + "textDocument": { + "uri": "file:///a/file.ts" + }, + "range": { + "start": { + "line": 441, + "character": 33 + }, + "end": { + "line": 441, + "character": 42 + } + }, + "context": { + "diagnostics": [ + { + "range": { + "start": { + "line": 441, + "character": 33 + }, + "end": { + "line": 441, + "character": 42 + } + }, + "severity": 1, + "code": 7031, + "source": "deno-ts", + "message": "Binding element 'debugFlag' implicitly has an 'any' type." + } + ], + "only": [ + "quickfix" + ] + } +} diff --git a/cli/tests/testdata/lsp/code_action_params_imports.json b/cli/tests/testdata/lsp/code_action_params_imports.json new file mode 100644 index 000000000..7a5824923 --- /dev/null +++ b/cli/tests/testdata/lsp/code_action_params_imports.json @@ -0,0 +1,54 @@ +{ + "textDocument": { + "uri": "file:///a/file01.ts" + }, + "range": { + "start": { + "line": 1, + "character": 12 + }, + "end": { + "line": 1, + "character": 15 + } + }, + "context": { + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 12 + }, + "end": { + "line": 1, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'abc'." + }, + { + "range": { + "start": { + "line": 2, + "character": 12 + }, + "end": { + "line": 2, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'def'." + } + ], + "only": [ + "quickfix" + ] + } +} diff --git a/cli/tests/testdata/lsp/code_action_params_refactor.json b/cli/tests/testdata/lsp/code_action_params_refactor.json new file mode 100644 index 000000000..121c400ed --- /dev/null +++ b/cli/tests/testdata/lsp/code_action_params_refactor.json @@ -0,0 +1,21 @@ +{ + "textDocument": { + "uri": "file:///a/file.ts" + }, + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 1, + "character": 0 + } + }, + "context": { + "diagnostics": [], + "only": [ + "refactor" + ] + } +} diff --git a/cli/tests/testdata/lsp/code_action_resolve_params.json b/cli/tests/testdata/lsp/code_action_resolve_params.json new file mode 100644 index 000000000..50c1f9a43 --- /dev/null +++ b/cli/tests/testdata/lsp/code_action_resolve_params.json @@ -0,0 +1,27 @@ +{ + "title": "Add all missing 'async' modifiers", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 7 + } + }, + "severity": 1, + "code": 1308, + "source": "deno-ts", + "message": "'await' expressions are only allowed within async functions and at the top levels of modules.", + "relatedInformation": [] + } + ], + "data": { + "specifier": "file:///a/file.ts", + "fixId": "fixAwaitInSyncFunction" + } +} diff --git a/cli/tests/testdata/lsp/code_action_resolve_params_imports.json b/cli/tests/testdata/lsp/code_action_resolve_params_imports.json new file mode 100644 index 000000000..60178bbfe --- /dev/null +++ b/cli/tests/testdata/lsp/code_action_resolve_params_imports.json @@ -0,0 +1,26 @@ +{ + "title": "Add all missing imports", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 12 + }, + "end": { + "line": 1, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'abc'." + } + ], + "data": { + "specifier": "file:///a/file01.ts", + "fixId": "fixMissingImport" + } +} diff --git a/cli/tests/testdata/lsp/code_action_resolve_params_refactor.json b/cli/tests/testdata/lsp/code_action_resolve_params_refactor.json new file mode 100644 index 000000000..d4bb3bd81 --- /dev/null +++ b/cli/tests/testdata/lsp/code_action_resolve_params_refactor.json @@ -0,0 +1,20 @@ +{ + "title": "Extract to interface", + "kind": "refactor.extract.interface", + "isPreferred": true, + "data": { + "specifier": "file:///a/file.ts", + "range": { + "start": { + "line": 0, + "character": 7 + }, + "end": { + "line": 0, + "character": 33 + } + }, + "refactorName": "Extract type", + "actionName": "Extract to interface" + } +} diff --git a/cli/tests/testdata/lsp/code_action_resolve_response.json b/cli/tests/testdata/lsp/code_action_resolve_response.json new file mode 100644 index 000000000..e3f5b3f0e --- /dev/null +++ b/cli/tests/testdata/lsp/code_action_resolve_response.json @@ -0,0 +1,91 @@ +{ + "title": "Add all missing 'async' modifiers", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 7 + } + }, + "severity": 1, + "code": 1308, + "source": "deno-ts", + "message": "'await' expressions are only allowed within async functions and at the top levels of modules.", + "relatedInformation": [] + } + ], + "edit": { + "documentChanges": [ + { + "textDocument": { + "uri": "file:///a/file.ts", + "version": 1 + }, + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 7 + }, + "end": { + "line": 0, + "character": 7 + } + }, + "newText": "async " + }, + { + "range": { + "start": { + "line": 0, + "character": 21 + }, + "end": { + "line": 0, + "character": 25 + } + }, + "newText": "Promise<void>" + }, + { + "range": { + "start": { + "line": 4, + "character": 7 + }, + "end": { + "line": 4, + "character": 7 + } + }, + "newText": "async " + }, + { + "range": { + "start": { + "line": 4, + "character": 21 + }, + "end": { + "line": 4, + "character": 25 + } + }, + "newText": "Promise<void>" + } + ] + } + ] + }, + "data": { + "specifier": "file:///a/file.ts", + "fixId": "fixAwaitInSyncFunction" + } +} diff --git a/cli/tests/testdata/lsp/code_action_resolve_response_imports.json b/cli/tests/testdata/lsp/code_action_resolve_response_imports.json new file mode 100644 index 000000000..6621c501f --- /dev/null +++ b/cli/tests/testdata/lsp/code_action_resolve_response_imports.json @@ -0,0 +1,51 @@ +{ + "title": "Add all missing imports", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 12 + }, + "end": { + "line": 1, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'abc'." + } + ], + "edit": { + "documentChanges": [ + { + "textDocument": { + "uri": "file:///a/file01.ts", + "version": 1 + }, + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "newText": "import { abc,def } from \"./file00.ts\";\n" + } + ] + } + ] + }, + "data": { + "specifier": "file:///a/file01.ts", + "fixId": "fixMissingImport" + } +} diff --git a/cli/tests/testdata/lsp/code_action_resolve_response_refactor.json b/cli/tests/testdata/lsp/code_action_resolve_response_refactor.json new file mode 100644 index 000000000..721a76a6b --- /dev/null +++ b/cli/tests/testdata/lsp/code_action_resolve_response_refactor.json @@ -0,0 +1,58 @@ +{ + "title": "Extract to interface", + "kind": "refactor.extract.interface", + "edit": { + "documentChanges": [ + { + "textDocument": { + "uri": "file:///a/file.ts", + "version": 1 + }, + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "newText": "interface NewType {\n a?: number;\n b?: string;\n}\n\n" + }, + { + "range": { + "start": { + "line": 0, + "character": 7 + }, + "end": { + "line": 0, + "character": 33 + } + }, + "newText": "NewType" + } + ] + } + ] + }, + "isPreferred": true, + "data": { + "specifier": "file:///a/file.ts", + "range": { + "start": { + "line": 0, + "character": 7 + }, + "end": { + "line": 0, + "character": 33 + } + }, + "refactorName": "Extract type", + "actionName": "Extract to interface" + } +} diff --git a/cli/tests/testdata/lsp/code_action_response.json b/cli/tests/testdata/lsp/code_action_response.json new file mode 100644 index 000000000..ab30898f8 --- /dev/null +++ b/cli/tests/testdata/lsp/code_action_response.json @@ -0,0 +1,90 @@ +[ + { + "title": "Add async modifier to containing function", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 7 + } + }, + "severity": 1, + "code": 1308, + "source": "deno-ts", + "message": "'await' expressions are only allowed within async functions and at the top levels of modules.", + "relatedInformation": [] + } + ], + "edit": { + "documentChanges": [ + { + "textDocument": { + "uri": "file:///a/file.ts", + "version": 1 + }, + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 7 + }, + "end": { + "line": 0, + "character": 7 + } + }, + "newText": "async " + }, + { + "range": { + "start": { + "line": 0, + "character": 21 + }, + "end": { + "line": 0, + "character": 25 + } + }, + "newText": "Promise<void>" + } + ] + } + ] + } + }, + { + "title": "Add all missing 'async' modifiers", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 7 + } + }, + "severity": 1, + "code": 1308, + "source": "deno-ts", + "message": "'await' expressions are only allowed within async functions and at the top levels of modules.", + "relatedInformation": [] + } + ], + "data": { + "specifier": "file:///a/file.ts", + "fixId": "fixAwaitInSyncFunction" + } + } +] diff --git a/cli/tests/testdata/lsp/code_action_response_cache.json b/cli/tests/testdata/lsp/code_action_response_cache.json new file mode 100644 index 000000000..c56b35023 --- /dev/null +++ b/cli/tests/testdata/lsp/code_action_response_cache.json @@ -0,0 +1,36 @@ +[ + { + "title": "Cache \"https://deno.land/x/a/mod.ts\" and its dependencies.", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 0, + "character": 19 + }, + "end": { + "line": 0, + "character": 49 + } + }, + "severity": 1, + "code": "no-cache", + "source": "deno", + "message": "Unable to load the remote module: \"https://deno.land/x/a/mod.ts\".", + "data": { + "specifier": "https://deno.land/x/a/mod.ts" + } + } + ], + "command": { + "title": "", + "command": "deno.cache", + "arguments": [ + [ + "https://deno.land/x/a/mod.ts" + ] + ] + } + } +] diff --git a/cli/tests/testdata/lsp/code_action_response_imports.json b/cli/tests/testdata/lsp/code_action_response_imports.json new file mode 100644 index 000000000..e4d926bdd --- /dev/null +++ b/cli/tests/testdata/lsp/code_action_response_imports.json @@ -0,0 +1,242 @@ +[ + { + "title": "Import 'abc' from module \"./file00.ts\"", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 12 + }, + "end": { + "line": 1, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'abc'." + } + ], + "edit": { + "documentChanges": [ + { + "textDocument": { + "uri": "file:///a/file01.ts", + "version": 1 + }, + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "newText": "import { abc } from \"./file00.ts\";\n" + } + ] + } + ] + } + }, + { + "title": "Add all missing imports", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 12 + }, + "end": { + "line": 1, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'abc'." + } + ], + "data": { + "specifier": "file:///a/file01.ts", + "fixId": "fixMissingImport" + } + }, + { + "title": "Add missing function declaration 'abc'", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 12 + }, + "end": { + "line": 1, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'abc'." + } + ], + "edit": { + "documentChanges": [ + { + "textDocument": { + "uri": "file:///a/file01.ts", + "version": 1 + }, + "edits": [ + { + "range": { + "start": { + "line": 3, + "character": 0 + }, + "end": { + "line": 3, + "character": 0 + } + }, + "newText": "\nfunction abc(abc: any) {\nthrow new Error(\"Function not implemented.\");\n}\n" + } + ] + } + ] + } + }, + { + "title": "Import 'def' from module \"./file00.ts\"", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 2, + "character": 12 + }, + "end": { + "line": 2, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'def'." + } + ], + "edit": { + "documentChanges": [ + { + "textDocument": { + "uri": "file:///a/file01.ts", + "version": 1 + }, + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "newText": "import { def } from \"./file00.ts\";\n" + } + ] + } + ] + } + }, + { + "title": "Add missing function declaration 'def'", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 2, + "character": 12 + }, + "end": { + "line": 2, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'def'." + } + ], + "edit": { + "documentChanges": [ + { + "textDocument": { + "uri": "file:///a/file01.ts", + "version": 1 + }, + "edits": [ + { + "range": { + "start": { + "line": 3, + "character": 0 + }, + "end": { + "line": 3, + "character": 0 + } + }, + "newText": "\nfunction def(def: any) {\nthrow new Error(\"Function not implemented.\");\n}\n" + } + ] + } + ] + } + }, + { + "title": "Add all missing function declarations", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 12 + }, + "end": { + "line": 1, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'abc'." + } + ], + "data": { + "specifier": "file:///a/file01.ts", + "fixId": "fixMissingFunctionDeclaration" + } + } +] diff --git a/cli/tests/testdata/lsp/code_action_response_no_disabled.json b/cli/tests/testdata/lsp/code_action_response_no_disabled.json new file mode 100644 index 000000000..c69bd1120 --- /dev/null +++ b/cli/tests/testdata/lsp/code_action_response_no_disabled.json @@ -0,0 +1,22 @@ +[ + { + "title": "Move to a new file", + "kind": "refactor.move.newFile", + "isPreferred": false, + "data": { + "specifier": "file:///a/file.ts", + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 14, + "character": 0 + } + }, + "refactorName": "Move to a new file", + "actionName": "Move to a new file" + } + } +] diff --git a/cli/tests/testdata/lsp/code_action_response_refactor.json b/cli/tests/testdata/lsp/code_action_response_refactor.json new file mode 100644 index 000000000..a9fbd2827 --- /dev/null +++ b/cli/tests/testdata/lsp/code_action_response_refactor.json @@ -0,0 +1,177 @@ +[ + { + "title": "Extract to function in global scope", + "kind": "refactor.extract.function", + "isPreferred": false, + "data": { + "specifier": "file:///a/file.ts", + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 1, + "character": 0 + } + }, + "refactorName": "Extract Symbol", + "actionName": "function_scope_0" + } + }, + { + "title": "Extract to constant in enclosing scope", + "kind": "refactor.extract.constant", + "isPreferred": false, + "data": { + "specifier": "file:///a/file.ts", + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 1, + "character": 0 + } + }, + "refactorName": "Extract Symbol", + "actionName": "constant_scope_0" + } + }, + { + "title": "Move to a new file", + "kind": "refactor.move.newFile", + "isPreferred": false, + "data": { + "specifier": "file:///a/file.ts", + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 1, + "character": 0 + } + }, + "refactorName": "Move to a new file", + "actionName": "Move to a new file" + } + }, + { + "title": "Convert default export to named export", + "kind": "refactor.rewrite.export.named", + "isPreferred": false, + "disabled": { + "reason": "This file already has a default export" + }, + "data": { + "specifier": "file:///a/file.ts", + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 1, + "character": 0 + } + }, + "refactorName": "Convert export", + "actionName": "Convert default export to named export" + } + }, + { + "title": "Convert named export to default export", + "kind": "refactor.rewrite.export.default", + "isPreferred": false, + "disabled": { + "reason": "This file already has a default export" + }, + "data": { + "specifier": "file:///a/file.ts", + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 1, + "character": 0 + } + }, + "refactorName": "Convert export", + "actionName": "Convert named export to default export" + } + }, + { + "title": "Convert namespace import to named imports", + "kind": "refactor.rewrite.import.named", + "isPreferred": false, + "disabled": { + "reason": "Selection is not an import declaration." + }, + "data": { + "specifier": "file:///a/file.ts", + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 1, + "character": 0 + } + }, + "refactorName": "Convert import", + "actionName": "Convert namespace import to named imports" + } + }, + { + "title": "Convert named imports to namespace import", + "kind": "refactor.rewrite.import.namespace", + "isPreferred": false, + "disabled": { + "reason": "Selection is not an import declaration." + }, + "data": { + "specifier": "file:///a/file.ts", + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 1, + "character": 0 + } + }, + "refactorName": "Convert import", + "actionName": "Convert named imports to namespace import" + } + }, + { + "title": "Convert to optional chain expression", + "kind": "refactor.rewrite.expression.optionalChain", + "isPreferred": false, + "disabled": { + "reason": "Could not find convertible access expression" + }, + "data": { + "specifier": "file:///a/file.ts", + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 1, + "character": 0 + } + }, + "refactorName": "Convert to optional chain expression", + "actionName": "Convert to optional chain expression" + } + } +] diff --git a/cli/tests/testdata/lsp/code_lens_resolve_response.json b/cli/tests/testdata/lsp/code_lens_resolve_response.json new file mode 100644 index 000000000..1400eb4e6 --- /dev/null +++ b/cli/tests/testdata/lsp/code_lens_resolve_response.json @@ -0,0 +1,38 @@ +{ + "range": { + "start": { + "line": 0, + "character": 6 + }, + "end": { + "line": 0, + "character": 7 + } + }, + "command": { + "title": "1 reference", + "command": "deno.showReferences", + "arguments": [ + "file:///a/file.ts", + { + "line": 0, + "character": 6 + }, + [ + { + "uri": "file:///a/file.ts", + "range": { + "start": { + "line": 12, + "character": 14 + }, + "end": { + "line": 12, + "character": 15 + } + } + } + ] + ] + } +} diff --git a/cli/tests/testdata/lsp/code_lens_resolve_response_impl.json b/cli/tests/testdata/lsp/code_lens_resolve_response_impl.json new file mode 100644 index 000000000..cabf2f833 --- /dev/null +++ b/cli/tests/testdata/lsp/code_lens_resolve_response_impl.json @@ -0,0 +1,38 @@ +{ + "range": { + "start": { + "line": 0, + "character": 10 + }, + "end": { + "line": 0, + "character": 11 + } + }, + "command": { + "title": "1 implementation", + "command": "deno.showReferences", + "arguments": [ + "file:///a/file.ts", + { + "line": 0, + "character": 10 + }, + [ + { + "uri": "file:///a/file.ts", + "range": { + "start": { + "line": 4, + "character": 6 + }, + "end": { + "line": 4, + "character": 7 + } + } + } + ] + ] + } +} diff --git a/cli/tests/testdata/lsp/code_lens_response.json b/cli/tests/testdata/lsp/code_lens_response.json new file mode 100644 index 000000000..e3a87e4be --- /dev/null +++ b/cli/tests/testdata/lsp/code_lens_response.json @@ -0,0 +1,34 @@ +[ + { + "range": { + "start": { + "line": 0, + "character": 6 + }, + "end": { + "line": 0, + "character": 7 + } + }, + "data": { + "specifier": "file:///a/file.ts", + "source": "references" + } + }, + { + "range": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 3 + } + }, + "data": { + "specifier": "file:///a/file.ts", + "source": "references" + } + } +] diff --git a/cli/tests/testdata/lsp/code_lens_response_changed.json b/cli/tests/testdata/lsp/code_lens_response_changed.json new file mode 100644 index 000000000..b0073a23f --- /dev/null +++ b/cli/tests/testdata/lsp/code_lens_response_changed.json @@ -0,0 +1,50 @@ +[ + { + "range": { + "start": { + "line": 0, + "character": 10 + }, + "end": { + "line": 0, + "character": 11 + } + }, + "data": { + "specifier": "file:///a/file.ts", + "source": "implementations" + } + }, + { + "range": { + "start": { + "line": 0, + "character": 10 + }, + "end": { + "line": 0, + "character": 11 + } + }, + "data": { + "specifier": "file:///a/file.ts", + "source": "references" + } + }, + { + "range": { + "start": { + "line": 4, + "character": 6 + }, + "end": { + "line": 4, + "character": 7 + } + }, + "data": { + "specifier": "file:///a/file.ts", + "source": "references" + } + } +] diff --git a/cli/tests/testdata/lsp/code_lens_response_impl.json b/cli/tests/testdata/lsp/code_lens_response_impl.json new file mode 100644 index 000000000..c6e5bd92d --- /dev/null +++ b/cli/tests/testdata/lsp/code_lens_response_impl.json @@ -0,0 +1,98 @@ +[ + { + "range": { + "start": { + "line": 0, + "character": 10 + }, + "end": { + "line": 0, + "character": 11 + } + }, + "data": { + "specifier": "file:///a/file.ts", + "source": "implementations" + } + }, + { + "range": { + "start": { + "line": 0, + "character": 10 + }, + "end": { + "line": 0, + "character": 11 + } + }, + "data": { + "specifier": "file:///a/file.ts", + "source": "references" + } + }, + { + "range": { + "start": { + "line": 4, + "character": 6 + }, + "end": { + "line": 4, + "character": 7 + } + }, + "data": { + "specifier": "file:///a/file.ts", + "source": "references" + } + }, + { + "range": { + "start": { + "line": 10, + "character": 10 + }, + "end": { + "line": 10, + "character": 11 + } + }, + "data": { + "specifier": "file:///a/file.ts", + "source": "implementations" + } + }, + { + "range": { + "start": { + "line": 10, + "character": 10 + }, + "end": { + "line": 10, + "character": 11 + } + }, + "data": { + "specifier": "file:///a/file.ts", + "source": "references" + } + }, + { + "range": { + "start": { + "line": 11, + "character": 2 + }, + "end": { + "line": 11, + "character": 3 + } + }, + "data": { + "specifier": "file:///a/file.ts", + "source": "references" + } + } +] diff --git a/cli/tests/testdata/lsp/code_lens_response_test.json b/cli/tests/testdata/lsp/code_lens_response_test.json new file mode 100644 index 000000000..b2cb4588a --- /dev/null +++ b/cli/tests/testdata/lsp/code_lens_response_test.json @@ -0,0 +1,162 @@ +[ + { + "range": { + "start": { + "line": 4, + "character": 5 + }, + "end": { + "line": 4, + "character": 9 + } + }, + "command": { + "title": "▶︎ Run Test", + "command": "deno.test", + "arguments": [ + "file:///a/file.ts", + "test a" + ] + } + }, + { + "range": { + "start": { + "line": 5, + "character": 5 + }, + "end": { + "line": 5, + "character": 9 + } + }, + "command": { + "title": "▶︎ Run Test", + "command": "deno.test", + "arguments": [ + "file:///a/file.ts", + "test b" + ] + } + }, + { + "range": { + "start": { + "line": 9, + "character": 0 + }, + "end": { + "line": 9, + "character": 4 + } + }, + "command": { + "title": "▶︎ Run Test", + "command": "deno.test", + "arguments": [ + "file:///a/file.ts", + "test c" + ] + } + }, + { + "range": { + "start": { + "line": 13, + "character": 0 + }, + "end": { + "line": 13, + "character": 4 + } + }, + "command": { + "title": "▶︎ Run Test", + "command": "deno.test", + "arguments": [ + "file:///a/file.ts", + "test d" + ] + } + }, + { + "range": { + "start": { + "line": 14, + "character": 0 + }, + "end": { + "line": 14, + "character": 5 + } + }, + "command": { + "title": "▶︎ Run Test", + "command": "deno.test", + "arguments": [ + "file:///a/file.ts", + "test e" + ] + } + }, + { + "range": { + "start": { + "line": 18, + "character": 0 + }, + "end": { + "line": 18, + "character": 5 + } + }, + "command": { + "title": "▶︎ Run Test", + "command": "deno.test", + "arguments": [ + "file:///a/file.ts", + "test f" + ] + } + }, + { + "range": { + "start": { + "line": 19, + "character": 0 + }, + "end": { + "line": 19, + "character": 5 + } + }, + "command": { + "title": "▶︎ Run Test", + "command": "deno.test", + "arguments": [ + "file:///a/file.ts", + "test g" + ] + } + }, + { + "range": { + "start": { + "line": 23, + "character": 0 + }, + "end": { + "line": 23, + "character": 5 + } + }, + "command": { + "title": "▶︎ Run Test", + "command": "deno.test", + "arguments": [ + "file:///a/file.ts", + "test h" + ] + } + } +] diff --git a/cli/tests/testdata/lsp/completion_request_params_optional.json b/cli/tests/testdata/lsp/completion_request_params_optional.json new file mode 100644 index 000000000..1f3c079c7 --- /dev/null +++ b/cli/tests/testdata/lsp/completion_request_params_optional.json @@ -0,0 +1,13 @@ +{ + "textDocument": { + "uri": "file:///a/file.ts" + }, + "position": { + "line": 8, + "character": 4 + }, + "context": { + "triggerKind": 2, + "triggerCharacter": "." + } +} diff --git a/cli/tests/testdata/lsp/completion_request_response_empty.json b/cli/tests/testdata/lsp/completion_request_response_empty.json new file mode 100644 index 000000000..272dfb475 --- /dev/null +++ b/cli/tests/testdata/lsp/completion_request_response_empty.json @@ -0,0 +1,38 @@ +{ + "isIncomplete": false, + "items": [ + { + "label": ".", + "kind": 19, + "detail": "(local)", + "sortText": "1", + "insertText": "." + }, + { + "label": "..", + "kind": 19, + "detail": "(local)", + "sortText": "1", + "insertText": ".." + }, + { + "label": "http://localhost:4545", + "kind": 19, + "detail": "(registry)", + "sortText": "2", + "textEdit": { + "range": { + "start": { + "line": 0, + "character": 20 + }, + "end": { + "line": 0, + "character": 20 + } + }, + "newText": "http://localhost:4545" + } + } + ] +} diff --git a/cli/tests/testdata/lsp/completion_resolve_params.json b/cli/tests/testdata/lsp/completion_resolve_params.json new file mode 100644 index 000000000..26231036d --- /dev/null +++ b/cli/tests/testdata/lsp/completion_resolve_params.json @@ -0,0 +1,14 @@ +{ + "label": "build", + "kind": 6, + "sortText": "1", + "insertTextFormat": 1, + "data": { + "tsc": { + "specifier": "file:///a/file.ts", + "position": 5, + "name": "build", + "useCodeSnippet": false + } + } +} diff --git a/cli/tests/testdata/lsp/completion_resolve_params_optional.json b/cli/tests/testdata/lsp/completion_resolve_params_optional.json new file mode 100644 index 000000000..cb99bf960 --- /dev/null +++ b/cli/tests/testdata/lsp/completion_resolve_params_optional.json @@ -0,0 +1,15 @@ +{ + "label": "b?", + "kind": 5, + "sortText": "1", + "filterText": "b", + "insertText": "b", + "data": { + "tsc": { + "specifier": "file:///a/file.ts", + "position": 79, + "name": "b", + "useCodeSnippet": false + } + } +} diff --git a/cli/tests/testdata/lsp/completion_resolve_params_registry.json b/cli/tests/testdata/lsp/completion_resolve_params_registry.json new file mode 100644 index 000000000..99a4a048e --- /dev/null +++ b/cli/tests/testdata/lsp/completion_resolve_params_registry.json @@ -0,0 +1,20 @@ +{ + "label": "v2.0.0", + "kind": 19, + "detail": "(version)", + "sortText": "0000000003", + "filterText": "http://localhost:4545/x/a@v2.0.0", + "textEdit": { + "range": { + "start": { + "line": 0, + "character": 20 + }, + "end": { + "line": 0, + "character": 46 + } + }, + "newText": "http://localhost:4545/x/a@v2.0.0" + } +} diff --git a/cli/tests/testdata/lsp/completion_resolve_response.json b/cli/tests/testdata/lsp/completion_resolve_response.json new file mode 100644 index 000000000..0edbc14ef --- /dev/null +++ b/cli/tests/testdata/lsp/completion_resolve_response.json @@ -0,0 +1,11 @@ +{ + "label": "build", + "kind": 6, + "detail": "const Deno.build: {\n target: string;\n arch: \"x86_64\" | \"aarch64\";\n os: \"darwin\" | \"linux\" | \"windows\";\n vendor: string;\n env?: string | undefined;\n}", + "documentation": { + "kind": "markdown", + "value": "Build related information." + }, + "sortText": "1", + "insertTextFormat": 1 +} diff --git a/cli/tests/testdata/lsp/completion_resolve_response_registry.json b/cli/tests/testdata/lsp/completion_resolve_response_registry.json new file mode 100644 index 000000000..99a4a048e --- /dev/null +++ b/cli/tests/testdata/lsp/completion_resolve_response_registry.json @@ -0,0 +1,20 @@ +{ + "label": "v2.0.0", + "kind": 19, + "detail": "(version)", + "sortText": "0000000003", + "filterText": "http://localhost:4545/x/a@v2.0.0", + "textEdit": { + "range": { + "start": { + "line": 0, + "character": 20 + }, + "end": { + "line": 0, + "character": 46 + } + }, + "newText": "http://localhost:4545/x/a@v2.0.0" + } +} diff --git a/cli/tests/testdata/lsp/diagnostics_deno_deps.json b/cli/tests/testdata/lsp/diagnostics_deno_deps.json new file mode 100644 index 000000000..ec6cc4f51 --- /dev/null +++ b/cli/tests/testdata/lsp/diagnostics_deno_deps.json @@ -0,0 +1,25 @@ +{ + "uri": "file:///a/file.ts", + "diagnostics": [ + { + "range": { + "start": { + "line": 0, + "character": 19 + }, + "end": { + "line": 0, + "character": 49 + } + }, + "severity": 1, + "code": "no-cache", + "source": "deno", + "message": "Uncached or missing remote URL: \"https://deno.land/x/a/mod.ts\".", + "data": { + "specifier": "https://deno.land/x/a/mod.ts" + } + } + ], + "version": 1 +} diff --git a/cli/tests/testdata/lsp/diagnostics_deno_types.json b/cli/tests/testdata/lsp/diagnostics_deno_types.json new file mode 100644 index 000000000..f33945a59 --- /dev/null +++ b/cli/tests/testdata/lsp/diagnostics_deno_types.json @@ -0,0 +1,101 @@ +{ + "uri": "file:///a/file.ts", + "diagnostics": [ + { + "range": { + "start": { + "line": 0, + "character": 21 + }, + "end": { + "line": 0, + "character": 51 + } + }, + "severity": 1, + "code": "no-cache", + "source": "deno", + "message": "Uncached or missing remote URL: \"https://example.com/a/b.d.ts\".", + "data": { + "specifier": "https://example.com/a/b.d.ts" + } + }, + { + "range": { + "start": { + "line": 7, + "character": 19 + }, + "end": { + "line": 7, + "character": 47 + } + }, + "severity": 1, + "code": "no-cache", + "source": "deno", + "message": "Uncached or missing remote URL: \"https://example.com/a/e.js\".", + "data": { + "specifier": "https://example.com/a/e.js" + } + }, + { + "range": { + "start": { + "line": 6, + "character": 16 + }, + "end": { + "line": 6, + "character": 44 + } + }, + "severity": 1, + "code": "no-cache", + "source": "deno", + "message": "Uncached or missing remote URL: \"https://example.com/a/e.d.ts\".", + "data": { + "specifier": "https://example.com/a/e.d.ts" + } + }, + { + "range": { + "start": { + "line": 4, + "character": 19 + }, + "end": { + "line": 4, + "character": 47 + } + }, + "severity": 1, + "code": "no-cache", + "source": "deno", + "message": "Uncached or missing remote URL: \"https://example.com/a/d.js\".", + "data": { + "specifier": "https://example.com/a/d.js" + } + }, + { + "range": { + "start": { + "line": 3, + "character": 15 + }, + "end": { + "line": 3, + "character": 43 + } + }, + "severity": 1, + "code": "no-cache", + "source": "deno", + "message": "Uncached or missing remote URL: \"https://example.com/a/d.d.ts\".", + "data": { + "specifier": "https://example.com/a/d.d.ts" + } + } + ], + "version": 1 +} diff --git a/cli/tests/testdata/lsp/did_open_params_deno_types.json b/cli/tests/testdata/lsp/did_open_params_deno_types.json new file mode 100644 index 000000000..6f085d045 --- /dev/null +++ b/cli/tests/testdata/lsp/did_open_params_deno_types.json @@ -0,0 +1,8 @@ +{ + "textDocument": { + "uri": "file:///a/file.ts", + "languageId": "typescript", + "version": 1, + "text": "/// <reference types=\"https://example.com/a/b.d.ts\" />\n/// <reference path=\"https://example.com/a/c.ts\"\n\n// @deno-types=https://example.com/a/d.d.ts\nimport * as d from \"https://example.com/a/d.js\";\n\n// @deno-types=\"https://example.com/a/e.d.ts\"\nimport * as e from \"https://example.com/a/e.js\";\n\nconsole.log(d, e);\n" + } +} diff --git a/cli/tests/testdata/lsp/did_open_params_doc_symbol.json b/cli/tests/testdata/lsp/did_open_params_doc_symbol.json new file mode 100644 index 000000000..c74877191 --- /dev/null +++ b/cli/tests/testdata/lsp/did_open_params_doc_symbol.json @@ -0,0 +1,8 @@ +{ + "textDocument": { + "uri": "file:///a/file.ts", + "languageId": "typescript", + "version": 1, + "text": "interface IFoo {\n foo(): boolean;\n}\n\nclass Bar implements IFoo {\n constructor(public x: number) { }\n foo() { return true; }\n /** @deprecated */\n baz() { return false; }\n get value(): number { return 0; }\n set value(newVavlue: number) { return; }\n static staticBar = new Bar(0);\n private static getStaticBar() { return Bar.staticBar; }\n}\n\nenum Values { value1, value2 }\n\nvar bar: IFoo = new Bar(3);" + } +} diff --git a/cli/tests/testdata/lsp/did_open_params_import_hover.json b/cli/tests/testdata/lsp/did_open_params_import_hover.json new file mode 100644 index 000000000..e054eef3e --- /dev/null +++ b/cli/tests/testdata/lsp/did_open_params_import_hover.json @@ -0,0 +1,8 @@ +{ + "textDocument": { + "uri": "file:///a/file.ts", + "languageId": "typescript", + "version": 1, + "text": "import * as a from \"http://127.0.0.1:4545/xTypeScriptTypes.js\";\n// @deno-types=\"http://127.0.0.1:4545/type_definitions/foo.d.ts\"\nimport * as b from \"http://127.0.0.1:4545/type_definitions/foo.js\";\nimport * as c from \"http://127.0.0.1:4545/subdir/type_reference.js\";\nimport * as d from \"http://127.0.0.1:4545/subdir/mod1.ts\";\nimport * as e from \"data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=\";\nimport * as f from \"./file_01.ts\";\n\nconsole.log(a, b, c, d, e, f);\n" + } +} diff --git a/cli/tests/testdata/lsp/did_open_params_large.json b/cli/tests/testdata/lsp/did_open_params_large.json new file mode 100644 index 000000000..996434c0c --- /dev/null +++ b/cli/tests/testdata/lsp/did_open_params_large.json @@ -0,0 +1,8 @@ +{ + "textDocument": { + "uri": "file:///a/file.ts", + "languageId": "javascript", + "version": 1, + "text": "// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.\n\n// @ts-check\n/// <reference path=\"./compiler.d.ts\" />\n// deno-lint-ignore-file no-undef\n\n// This module is the entry point for \"compiler\" isolate, ie. the one\n// that is created when Deno needs to type check TypeScript, and in some\n// instances convert TypeScript to JavaScript.\n\n// Removes the `__proto__` for security reasons. This intentionally makes\n// Deno non compliant with ECMA-262 Annex B.2.2.1\ndelete Object.prototype.__proto__;\n\n((window) => {\n /** @type {DenoCore} */\n const core = window.Deno.core;\n\n let logDebug = false;\n let logSource = \"JS\";\n\n function setLogDebug(debug, source) {\n logDebug = debug;\n if (source) {\n logSource = source;\n }\n }\n\n function debug(...args) {\n if (logDebug) {\n const stringifiedArgs = args.map((arg) =>\n typeof arg === \"string\" ? arg : JSON.stringify(arg)\n ).join(\" \");\n // adding a non-zero integer value to the end of the debug string causes\n // the message to be printed to stderr instead of stdout, which is better\n // aligned to the behaviour of debug messages\n core.print(`DEBUG ${logSource} - ${stringifiedArgs}\\n`, 1);\n }\n }\n\n function error(...args) {\n const stringifiedArgs = args.map((arg) =>\n typeof arg === \"string\" || arg instanceof Error\n ? String(arg)\n : JSON.stringify(arg)\n ).join(\" \");\n core.print(`ERROR ${logSource} = ${stringifiedArgs}\\n`, 1);\n }\n\n class AssertionError extends Error {\n constructor(msg) {\n super(msg);\n this.name = \"AssertionError\";\n }\n }\n\n function assert(cond, msg = \"Assertion failed.\") {\n if (!cond) {\n throw new AssertionError(msg);\n }\n }\n\n /** @type {Map<string, ts.SourceFile>} */\n const sourceFileCache = new Map();\n\n /** @param {ts.DiagnosticRelatedInformation} diagnostic */\n function fromRelatedInformation({\n start,\n length,\n file,\n messageText: msgText,\n ...ri\n }) {\n let messageText;\n let messageChain;\n if (typeof msgText === \"object\") {\n messageChain = msgText;\n } else {\n messageText = msgText;\n }\n if (start !== undefined && length !== undefined && file) {\n const startPos = file.getLineAndCharacterOfPosition(start);\n const sourceLine = file.getFullText().split(\"\\n\")[startPos.line];\n const fileName = file.fileName;\n return {\n start: startPos,\n end: file.getLineAndCharacterOfPosition(start + length),\n fileName,\n messageChain,\n messageText,\n sourceLine,\n ...ri,\n };\n } else {\n return {\n messageChain,\n messageText,\n ...ri,\n };\n }\n }\n\n /** @param {ts.Diagnostic[]} diagnostics */\n function fromTypeScriptDiagnostic(diagnostics) {\n return diagnostics.map(({ relatedInformation: ri, source, ...diag }) => {\n /** @type {any} */\n const value = fromRelatedInformation(diag);\n value.relatedInformation = ri\n ? ri.map(fromRelatedInformation)\n : undefined;\n value.source = source;\n return value;\n });\n }\n\n // Using incremental compile APIs requires that all\n // paths must be either relative or absolute. Since\n // analysis in Rust operates on fully resolved URLs,\n // it makes sense to use the same scheme here.\n const ASSETS = \"asset:///\";\n const CACHE = \"cache:///\";\n\n /** Diagnostics that are intentionally ignored when compiling TypeScript in\n * Deno, as they provide misleading or incorrect information. */\n const IGNORED_DIAGNOSTICS = [\n // TS1208: All files must be modules when the '--isolatedModules' flag is\n // provided. We can ignore because we guarantee that all files are\n // modules.\n 1208,\n // TS1375: 'await' expressions are only allowed at the top level of a file\n // when that file is a module, but this file has no imports or exports.\n // Consider adding an empty 'export {}' to make this file a module.\n 1375,\n // TS1103: 'for-await-of' statement is only allowed within an async function\n // or async generator.\n 1103,\n // TS2306: File 'file:///Users/rld/src/deno/subdir/amd_like.js' is\n // not a module.\n 2306,\n // TS2691: An import path cannot end with a '.ts' extension. Consider\n // importing 'bad-module' instead.\n 2691,\n // TS2792: Cannot find module. Did you mean to set the 'moduleResolution'\n // option to 'node', or to add aliases to the 'paths' option?\n 2792,\n // TS5009: Cannot find the common subdirectory path for the input files.\n 5009,\n // TS5055: Cannot write file\n // 'http://localhost:4545/subdir/mt_application_x_javascript.j4.js'\n // because it would overwrite input file.\n 5055,\n // TypeScript is overly opinionated that only CommonJS modules kinds can\n // support JSON imports. Allegedly this was fixed in\n // Microsoft/TypeScript#26825 but that doesn't seem to be working here,\n // so we will ignore complaints about this compiler setting.\n 5070,\n // TS7016: Could not find a declaration file for module '...'. '...'\n // implicitly has an 'any' type. This is due to `allowJs` being off by\n // default but importing of a JavaScript module.\n 7016,\n ];\n\n const SNAPSHOT_COMPILE_OPTIONS = {\n esModuleInterop: true,\n jsx: ts.JsxEmit.React,\n module: ts.ModuleKind.ESNext,\n noEmit: true,\n strict: true,\n target: ts.ScriptTarget.ESNext,\n };\n\n class ScriptSnapshot {\n /** @type {string} */\n specifier;\n /** @type {string} */\n version;\n /**\n * @param {string} specifier\n * @param {string} version \n */\n constructor(specifier, version) {\n this.specifier = specifier;\n this.version = version;\n }\n /**\n * @param {number} start \n * @param {number} end \n * @returns {string}\n */\n getText(start, end) {\n const { specifier, version } = this;\n debug(\n `snapshot.getText(${start}, ${end}) specifier: ${specifier} version: ${version}`,\n );\n return core.jsonOpSync(\"op_get_text\", { specifier, version, start, end });\n }\n /**\n * @returns {number}\n */\n getLength() {\n const { specifier, version } = this;\n debug(`snapshot.getLength() specifier: ${specifier} version: ${version}`);\n return core.jsonOpSync(\"op_get_length\", { specifier, version });\n }\n /**\n * @param {ScriptSnapshot} oldSnapshot\n * @returns {ts.TextChangeRange | undefined}\n */\n getChangeRange(oldSnapshot) {\n const { specifier, version } = this;\n const { version: oldVersion } = oldSnapshot;\n const oldLength = oldSnapshot.getLength();\n debug(\n `snapshot.getLength() specifier: ${specifier} oldVersion: ${oldVersion} version: ${version}`,\n );\n return core.jsonOpSync(\n \"op_get_change_range\",\n { specifier, oldLength, oldVersion, version },\n );\n }\n dispose() {\n const { specifier, version } = this;\n debug(`snapshot.dispose() specifier: ${specifier} version: ${version}`);\n core.jsonOpSync(\"op_dispose\", { specifier, version });\n }\n }\n\n /** @type {ts.CompilerOptions} */\n let compilationSettings = {};\n\n /** @type {ts.LanguageService} */\n let languageService;\n\n /** An object literal of the incremental compiler host, which provides the\n * specific \"bindings\" to the Deno environment that tsc needs to work.\n *\n * @type {ts.CompilerHost & ts.LanguageServiceHost} */\n const host = {\n fileExists(fileName) {\n debug(`host.fileExists(\"${fileName}\")`);\n return false;\n },\n readFile(specifier) {\n debug(`host.readFile(\"${specifier}\")`);\n return core.jsonOpSync(\"op_load\", { specifier }).data;\n },\n getSourceFile(\n specifier,\n languageVersion,\n _onError,\n _shouldCreateNewSourceFile,\n ) {\n debug(\n `host.getSourceFile(\"${specifier}\", ${\n ts.ScriptTarget[languageVersion]\n })`,\n );\n let sourceFile = sourceFileCache.get(specifier);\n if (sourceFile) {\n return sourceFile;\n }\n\n /** @type {{ data: string; hash?: string; scriptKind: ts.ScriptKind }} */\n const { data, hash, scriptKind } = core.jsonOpSync(\n \"op_load\",\n { specifier },\n );\n assert(\n data != null,\n `\"data\" is unexpectedly null for \"${specifier}\".`,\n );\n sourceFile = ts.createSourceFile(\n specifier,\n data,\n languageVersion,\n false,\n scriptKind,\n );\n sourceFile.moduleName = specifier;\n sourceFile.version = hash;\n sourceFileCache.set(specifier, sourceFile);\n return sourceFile;\n },\n getDefaultLibFileName() {\n return `${ASSETS}/lib.esnext.d.ts`;\n },\n getDefaultLibLocation() {\n return ASSETS;\n },\n writeFile(fileName, data, _writeByteOrderMark, _onError, sourceFiles) {\n debug(`host.writeFile(\"${fileName}\")`);\n let maybeSpecifiers;\n if (sourceFiles) {\n maybeSpecifiers = sourceFiles.map((sf) => sf.moduleName);\n }\n return core.jsonOpSync(\n \"op_emit\",\n { maybeSpecifiers, fileName, data },\n );\n },\n getCurrentDirectory() {\n return CACHE;\n },\n getCanonicalFileName(fileName) {\n return fileName;\n },\n useCaseSensitiveFileNames() {\n return true;\n },\n getNewLine() {\n return \"\\n\";\n },\n resolveModuleNames(specifiers, base) {\n debug(`host.resolveModuleNames()`);\n debug(` base: ${base}`);\n debug(` specifiers: ${specifiers.join(\", \")}`);\n /** @type {Array<[string, ts.Extension] | undefined>} */\n const resolved = core.jsonOpSync(\"op_resolve\", {\n specifiers,\n base,\n });\n if (resolved) {\n const result = resolved.map((item) => {\n if (item) {\n const [resolvedFileName, extension] = item;\n return {\n resolvedFileName,\n extension,\n isExternalLibraryImport: false,\n };\n }\n return undefined;\n });\n result.length = specifiers.length;\n return result;\n } else {\n return new Array(specifiers.length);\n }\n },\n createHash(data) {\n return core.jsonOpSync(\"op_create_hash\", { data }).hash;\n },\n\n // LanguageServiceHost\n getCompilationSettings() {\n debug(\"host.getCompilationSettings()\");\n return compilationSettings;\n },\n getScriptFileNames() {\n debug(\"host.getScriptFileNames()\");\n return core.jsonOpSync(\"op_script_names\", undefined);\n },\n getScriptVersion(specifier) {\n debug(`host.getScriptVersion(\"${specifier}\")`);\n const sourceFile = sourceFileCache.get(specifier);\n if (sourceFile) {\n return sourceFile.version ?? \"1\";\n }\n return core.jsonOpSync(\"op_script_version\", { specifier });\n },\n getScriptSnapshot(specifier) {\n debug(`host.getScriptSnapshot(\"${specifier}\")`);\n const sourceFile = sourceFileCache.get(specifier);\n if (sourceFile) {\n return {\n getText(start, end) {\n return sourceFile.text.substring(start, end);\n },\n getLength() {\n return sourceFile.text.length;\n },\n getChangeRange() {\n return undefined;\n },\n };\n }\n /** @type {string | undefined} */\n const version = core.jsonOpSync(\"op_script_version\", { specifier });\n if (version != null) {\n return new ScriptSnapshot(specifier, version);\n }\n return undefined;\n },\n };\n\n /** @type {Array<[string, number]>} */\n const stats = [];\n let statsStart = 0;\n\n function performanceStart() {\n stats.length = 0;\n statsStart = Date.now();\n ts.performance.enable();\n }\n\n /**\n * @param {{ program: ts.Program | ts.EmitAndSemanticDiagnosticsBuilderProgram, fileCount?: number }} options \n */\n function performanceProgram({ program, fileCount }) {\n if (program) {\n if (\"getProgram\" in program) {\n program = program.getProgram();\n }\n stats.push([\"Files\", program.getSourceFiles().length]);\n stats.push([\"Nodes\", program.getNodeCount()]);\n stats.push([\"Identifiers\", program.getIdentifierCount()]);\n stats.push([\"Symbols\", program.getSymbolCount()]);\n stats.push([\"Types\", program.getTypeCount()]);\n stats.push([\"Instantiations\", program.getInstantiationCount()]);\n } else if (fileCount != null) {\n stats.push([\"Files\", fileCount]);\n }\n const programTime = ts.performance.getDuration(\"Program\");\n const bindTime = ts.performance.getDuration(\"Bind\");\n const checkTime = ts.performance.getDuration(\"Check\");\n const emitTime = ts.performance.getDuration(\"Emit\");\n stats.push([\"Parse time\", programTime]);\n stats.push([\"Bind time\", bindTime]);\n stats.push([\"Check time\", checkTime]);\n stats.push([\"Emit time\", emitTime]);\n stats.push(\n [\"Total TS time\", programTime + bindTime + checkTime + emitTime],\n );\n }\n\n function performanceEnd() {\n const duration = Date.now() - statsStart;\n stats.push([\"Compile time\", duration]);\n return stats;\n }\n\n /**\n * @typedef {object} Request\n * @property {Record<string, any>} config\n * @property {boolean} debug\n * @property {string[]} rootNames\n */\n\n /** The API that is called by Rust when executing a request.\n * @param {Request} request\n */\n function exec({ config, debug: debugFlag, rootNames }) {\n setLogDebug(debugFlag, \"TS\");\n performanceStart();\n debug(\">>> exec start\", { rootNames });\n debug(config);\n\n const { options, errors: configFileParsingDiagnostics } = ts\n .convertCompilerOptionsFromJson(config, \"\");\n // The `allowNonTsExtensions` is a \"hidden\" compiler option used in VSCode\n // which is not allowed to be passed in JSON, we need it to allow special\n // URLs which Deno supports. So we need to either ignore the diagnostic, or\n // inject it ourselves.\n Object.assign(options, { allowNonTsExtensions: true });\n const program = ts.createIncrementalProgram({\n rootNames,\n options,\n host,\n configFileParsingDiagnostics,\n });\n\n const { diagnostics: emitDiagnostics } = program.emit();\n\n const diagnostics = [\n ...program.getConfigFileParsingDiagnostics(),\n ...program.getSyntacticDiagnostics(),\n ...program.getOptionsDiagnostics(),\n ...program.getGlobalDiagnostics(),\n ...program.getSemanticDiagnostics(),\n ...emitDiagnostics,\n ].filter(({ code }) => !IGNORED_DIAGNOSTICS.includes(code));\n performanceProgram({ program });\n\n core.jsonOpSync(\"op_respond\", {\n diagnostics: fromTypeScriptDiagnostic(diagnostics),\n stats: performanceEnd(),\n });\n debug(\"<<< exec stop\");\n }\n\n /**\n * @param {number} id \n * @param {any} data \n */\n function respond(id, data = null) {\n core.jsonOpSync(\"op_respond\", { id, data });\n }\n\n /**\n * @param {LanguageServerRequest} request \n */\n function serverRequest({ id, ...request }) {\n debug(`serverRequest()`, { id, ...request });\n switch (request.method) {\n case \"configure\": {\n const { options, errors } = ts\n .convertCompilerOptionsFromJson(request.compilerOptions, \"\");\n Object.assign(options, { allowNonTsExtensions: true });\n if (errors.length) {\n debug(ts.formatDiagnostics(errors, host));\n }\n compilationSettings = options;\n return respond(id, true);\n }\n case \"getAsset\": {\n const sourceFile = host.getSourceFile(\n request.specifier,\n ts.ScriptTarget.ESNext,\n );\n return respond(id, sourceFile && sourceFile.text);\n }\n case \"getDiagnostics\": {\n try {\n /** @type {Record<string, any[]>} */\n const diagnosticMap = {};\n for (const specifier of request.specifiers) {\n diagnosticMap[specifier] = fromTypeScriptDiagnostic([\n ...languageService.getSemanticDiagnostics(specifier),\n ...languageService.getSuggestionDiagnostics(specifier),\n ...languageService.getSyntacticDiagnostics(specifier),\n ].filter(({ code }) => !IGNORED_DIAGNOSTICS.includes(code)));\n }\n return respond(id, diagnosticMap);\n } catch (e) {\n if (\"stack\" in e) {\n error(e.stack);\n } else {\n error(e);\n }\n return respond(id, {});\n }\n }\n case \"getQuickInfo\": {\n return respond(\n id,\n languageService.getQuickInfoAtPosition(\n request.specifier,\n request.position,\n ),\n );\n }\n case \"getCompletions\": {\n return respond(\n id,\n languageService.getCompletionsAtPosition(\n request.specifier,\n request.position,\n request.preferences,\n ),\n );\n }\n case \"getDocumentHighlights\": {\n return respond(\n id,\n languageService.getDocumentHighlights(\n request.specifier,\n request.position,\n request.filesToSearch,\n ),\n );\n }\n case \"getReferences\": {\n return respond(\n id,\n languageService.getReferencesAtPosition(\n request.specifier,\n request.position,\n ),\n );\n }\n case \"getDefinition\": {\n return respond(\n id,\n languageService.getDefinitionAndBoundSpan(\n request.specifier,\n request.position,\n ),\n );\n }\n case \"getImplementation\": {\n return respond(\n id,\n languageService.getImplementationAtPosition(\n request.specifier,\n request.position,\n ),\n );\n }\n case \"findRenameLocations\": {\n return respond(\n id,\n languageService.findRenameLocations(\n request.specifier,\n request.position,\n request.findInStrings,\n request.findInComments,\n request.providePrefixAndSuffixTextForRename,\n ),\n );\n }\n default:\n throw new TypeError(\n // @ts-ignore exhausted case statement sets type to never\n `Invalid request method for request: \"${request.method}\" (${id})`,\n );\n }\n }\n\n /** @param {{ debug: boolean; }} init */\n function serverInit({ debug: debugFlag }) {\n if (hasStarted) {\n throw new Error(\"The language server has already been initialized.\");\n }\n hasStarted = true;\n languageService = ts.createLanguageService(host);\n core.ops();\n setLogDebug(debugFlag, \"TSLS\");\n debug(\"serverInit()\");\n }\n\n let hasStarted = false;\n\n /** Startup the runtime environment, setting various flags.\n * @param {{ debugFlag?: boolean; legacyFlag?: boolean; }} msg\n */\n function startup({ debugFlag = false }) {\n if (hasStarted) {\n throw new Error(\"The compiler runtime already started.\");\n }\n hasStarted = true;\n core.ops();\n setLogDebug(!!debugFlag, \"TS\");\n }\n\n // Setup the compiler runtime during the build process.\n core.ops();\n core.registerErrorClass(\"Error\", Error);\n\n // A build time only op that provides some setup information that is used to\n // ensure the snapshot is setup properly.\n /** @type {{ buildSpecifier: string; libs: string[] }} */\n const { buildSpecifier, libs } = core.jsonOpSync(\"op_build_info\", {});\n for (const lib of libs) {\n const specifier = `lib.${lib}.d.ts`;\n // we are using internal APIs here to \"inject\" our custom libraries into\n // tsc, so things like `\"lib\": [ \"deno.ns\" ]` are supported.\n if (!ts.libs.includes(lib)) {\n ts.libs.push(lib);\n ts.libMap.set(lib, `lib.${lib}.d.ts`);\n }\n // we are caching in memory common type libraries that will be re-used by\n // tsc on when the snapshot is restored\n assert(\n host.getSourceFile(`${ASSETS}${specifier}`, ts.ScriptTarget.ESNext),\n );\n }\n // this helps ensure as much as possible is in memory that is re-usable\n // before the snapshotting is done, which helps unsure fast \"startup\" for\n // subsequent uses of tsc in Deno.\n const TS_SNAPSHOT_PROGRAM = ts.createProgram({\n rootNames: [buildSpecifier],\n options: SNAPSHOT_COMPILE_OPTIONS,\n host,\n });\n ts.getPreEmitDiagnostics(TS_SNAPSHOT_PROGRAM);\n\n // exposes the two functions that are called by `tsc::exec()` when type\n // checking TypeScript.\n globalThis.startup = startup;\n globalThis.exec = exec;\n\n // exposes the functions that are called when the compiler is used as a\n // language service.\n globalThis.serverInit = serverInit;\n globalThis.serverRequest = serverRequest;\n})(this);\n" + } +} diff --git a/cli/tests/testdata/lsp/did_open_params_semantic_tokens.json b/cli/tests/testdata/lsp/did_open_params_semantic_tokens.json new file mode 100644 index 000000000..5cf48ae05 --- /dev/null +++ b/cli/tests/testdata/lsp/did_open_params_semantic_tokens.json @@ -0,0 +1,8 @@ +{ + "textDocument": { + "uri": "file:///a/file.ts", + "languageId": "typescript", + "version": 1, + "text": "enum Values { value1, value2 }\n\nasync function baz(s: string): Promise<string> {\n const r = s.slice(0);\n return r;\n}\n\ninterface IFoo {\n readonly x: number;\n foo(): boolean;\n}\n\nclass Bar implements IFoo {\n constructor(public readonly x: number) { }\n foo() { return true; }\n static staticBar = new Bar(0);\n private static getStaticBar() { return Bar.staticBar; }\n}\n" + } +} diff --git a/cli/tests/testdata/lsp/did_open_params_test_code_lens.json b/cli/tests/testdata/lsp/did_open_params_test_code_lens.json new file mode 100644 index 000000000..dcb9e11f3 --- /dev/null +++ b/cli/tests/testdata/lsp/did_open_params_test_code_lens.json @@ -0,0 +1,8 @@ +{ + "textDocument": { + "uri": "file:///a/file.ts", + "languageId": "typescript", + "version": 1, + "text": "const { test } = Deno;\nconst { test: test2 } = Deno;\nconst test3 = Deno.test;\n\nDeno.test(\"test a\", () => {});\nDeno.test({\n name: \"test b\",\n fn() {},\n});\ntest({\n name: \"test c\",\n fn() {},\n});\ntest(\"test d\", () => {});\ntest2({\n name: \"test e\",\n fn() {},\n});\ntest2(\"test f\", () => {});\ntest3({\n name: \"test g\",\n fn() {},\n});\ntest3(\"test h\", () => {});\n" + } +} diff --git a/cli/tests/testdata/lsp/document_symbol_response.json b/cli/tests/testdata/lsp/document_symbol_response.json new file mode 100644 index 000000000..89d56ef70 --- /dev/null +++ b/cli/tests/testdata/lsp/document_symbol_response.json @@ -0,0 +1,371 @@ +[ + { + "name": "bar", + "kind": 13, + "range": { + "start": { + "line": 17, + "character": 4 + }, + "end": { + "line": 17, + "character": 26 + } + }, + "selectionRange": { + "start": { + "line": 17, + "character": 4 + }, + "end": { + "line": 17, + "character": 7 + } + } + }, + { + "name": "Bar", + "kind": 5, + "range": { + "start": { + "line": 4, + "character": 0 + }, + "end": { + "line": 13, + "character": 1 + } + }, + "selectionRange": { + "start": { + "line": 4, + "character": 6 + }, + "end": { + "line": 4, + "character": 9 + } + }, + "children": [ + { + "name": "constructor", + "kind": 9, + "range": { + "start": { + "line": 5, + "character": 2 + }, + "end": { + "line": 5, + "character": 35 + } + }, + "selectionRange": { + "start": { + "line": 5, + "character": 2 + }, + "end": { + "line": 5, + "character": 35 + } + } + }, + { + "name": "baz", + "kind": 6, + "tags": [ + 1 + ], + "range": { + "start": { + "line": 8, + "character": 2 + }, + "end": { + "line": 8, + "character": 25 + } + }, + "selectionRange": { + "start": { + "line": 8, + "character": 2 + }, + "end": { + "line": 8, + "character": 5 + } + } + }, + { + "name": "foo", + "kind": 6, + "range": { + "start": { + "line": 6, + "character": 2 + }, + "end": { + "line": 6, + "character": 24 + } + }, + "selectionRange": { + "start": { + "line": 6, + "character": 2 + }, + "end": { + "line": 6, + "character": 5 + } + } + }, + { + "name": "getStaticBar", + "kind": 6, + "range": { + "start": { + "line": 12, + "character": 2 + }, + "end": { + "line": 12, + "character": 57 + } + }, + "selectionRange": { + "start": { + "line": 12, + "character": 17 + }, + "end": { + "line": 12, + "character": 29 + } + } + }, + { + "name": "staticBar", + "kind": 7, + "range": { + "start": { + "line": 11, + "character": 2 + }, + "end": { + "line": 11, + "character": 32 + } + }, + "selectionRange": { + "start": { + "line": 11, + "character": 9 + }, + "end": { + "line": 11, + "character": 18 + } + } + }, + { + "name": "value", + "kind": 7, + "range": { + "start": { + "line": 9, + "character": 2 + }, + "end": { + "line": 9, + "character": 35 + } + }, + "selectionRange": { + "start": { + "line": 9, + "character": 6 + }, + "end": { + "line": 9, + "character": 11 + } + } + }, + { + "name": "value", + "kind": 7, + "range": { + "start": { + "line": 10, + "character": 2 + }, + "end": { + "line": 10, + "character": 42 + } + }, + "selectionRange": { + "start": { + "line": 10, + "character": 6 + }, + "end": { + "line": 10, + "character": 11 + } + } + }, + { + "name": "x", + "kind": 7, + "range": { + "start": { + "line": 5, + "character": 14 + }, + "end": { + "line": 5, + "character": 30 + } + }, + "selectionRange": { + "start": { + "line": 5, + "character": 21 + }, + "end": { + "line": 5, + "character": 22 + } + } + } + ] + }, + { + "name": "IFoo", + "kind": 11, + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 1 + } + }, + "selectionRange": { + "start": { + "line": 0, + "character": 10 + }, + "end": { + "line": 0, + "character": 14 + } + }, + "children": [ + { + "name": "foo", + "kind": 6, + "range": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 17 + } + }, + "selectionRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 5 + } + } + } + ] + }, + { + "name": "Values", + "kind": 10, + "range": { + "start": { + "line": 15, + "character": 0 + }, + "end": { + "line": 15, + "character": 30 + } + }, + "selectionRange": { + "start": { + "line": 15, + "character": 5 + }, + "end": { + "line": 15, + "character": 11 + } + }, + "children": [ + { + "name": "value1", + "kind": 13, + "range": { + "start": { + "line": 15, + "character": 14 + }, + "end": { + "line": 15, + "character": 20 + } + }, + "selectionRange": { + "start": { + "line": 15, + "character": 14 + }, + "end": { + "line": 15, + "character": 20 + } + } + }, + { + "name": "value2", + "kind": 13, + "range": { + "start": { + "line": 15, + "character": 22 + }, + "end": { + "line": 15, + "character": 28 + } + }, + "selectionRange": { + "start": { + "line": 15, + "character": 22 + }, + "end": { + "line": 15, + "character": 28 + } + } + } + ] + } +] diff --git a/cli/tests/testdata/lsp/formatting_mbc_response.json b/cli/tests/testdata/lsp/formatting_mbc_response.json new file mode 100644 index 000000000..1c0b9f8e8 --- /dev/null +++ b/cli/tests/testdata/lsp/formatting_mbc_response.json @@ -0,0 +1,54 @@ +[ + { + "range": { + "start": { + "line": 0, + "character": 12 + }, + "end": { + "line": 0, + "character": 13 + } + }, + "newText": "\"" + }, + { + "range": { + "start": { + "line": 0, + "character": 21 + }, + "end": { + "line": 0, + "character": 22 + } + }, + "newText": "\";" + }, + { + "range": { + "start": { + "line": 1, + "character": 12 + }, + "end": { + "line": 1, + "character": 13 + } + }, + "newText": "\"" + }, + { + "range": { + "start": { + "line": 1, + "character": 23 + }, + "end": { + "line": 1, + "character": 25 + } + }, + "newText": "\");" + } +] diff --git a/cli/tests/testdata/lsp/import-map.json b/cli/tests/testdata/lsp/import-map.json new file mode 100644 index 000000000..75d5d0849 --- /dev/null +++ b/cli/tests/testdata/lsp/import-map.json @@ -0,0 +1,5 @@ +{ + "imports": { + "/~/": "./lib/" + } +} diff --git a/cli/tests/testdata/lsp/incoming_calls_params.json b/cli/tests/testdata/lsp/incoming_calls_params.json new file mode 100644 index 000000000..6b38d26ee --- /dev/null +++ b/cli/tests/testdata/lsp/incoming_calls_params.json @@ -0,0 +1,28 @@ +{ + "item": { + "name": "baz", + "kind": 6, + "detail": "Bar", + "uri": "file:///a/file.ts", + "range": { + "start": { + "line": 5, + "character": 2 + }, + "end": { + "line": 7, + "character": 3 + } + }, + "selectionRange": { + "start": { + "line": 5, + "character": 2 + }, + "end": { + "line": 5, + "character": 5 + } + } + } +} diff --git a/cli/tests/testdata/lsp/incoming_calls_response.json b/cli/tests/testdata/lsp/incoming_calls_response.json new file mode 100644 index 000000000..231919a8c --- /dev/null +++ b/cli/tests/testdata/lsp/incoming_calls_response.json @@ -0,0 +1,42 @@ +[ + { + "from": { + "name": "main", + "kind": 12, + "detail": "", + "uri": "file:///a/file.ts", + "range": { + "start": { + "line": 10, + "character": 0 + }, + "end": { + "line": 13, + "character": 1 + } + }, + "selectionRange": { + "start": { + "line": 10, + "character": 9 + }, + "end": { + "line": 10, + "character": 13 + } + } + }, + "fromRanges": [ + { + "start": { + "line": 12, + "character": 6 + }, + "end": { + "line": 12, + "character": 9 + } + } + ] + } +] diff --git a/cli/tests/testdata/lsp/initialize_params.json b/cli/tests/testdata/lsp/initialize_params.json new file mode 100644 index 000000000..3b99be4f0 --- /dev/null +++ b/cli/tests/testdata/lsp/initialize_params.json @@ -0,0 +1,65 @@ +{ + "processId": 0, + "clientInfo": { + "name": "test-harness", + "version": "1.0.0" + }, + "rootUri": null, + "initializationOptions": { + "enable": true, + "cache": null, + "codeLens": { + "implementations": true, + "references": true, + "test": true + }, + "config": "", + "importMap": null, + "lint": true, + "suggest": { + "autoImports": true, + "completeFunctionCalls": false, + "names": true, + "paths": true, + "imports": { + "hosts": {} + } + }, + "unstable": false + }, + "capabilities": { + "textDocument": { + "codeAction": { + "codeActionLiteralSupport": { + "codeActionKind": { + "valueSet": [ + "quickfix", + "refactor" + ] + } + }, + "isPreferredSupport": true, + "dataSupport": true, + "disabledSupport": true, + "resolveSupport": { + "properties": [ + "edit" + ] + } + }, + "foldingRange": { + "lineFoldingOnly": true + }, + "synchronization": { + "dynamicRegistration": true, + "willSave": true, + "willSaveWaitUntil": true, + "didSave": true + } + }, + "workspace": { + "configuration": true, + "workspaceFolders": true + } + } +} diff --git a/cli/tests/testdata/lsp/initialize_params_bad_config_option.json b/cli/tests/testdata/lsp/initialize_params_bad_config_option.json new file mode 100644 index 000000000..053cb70f3 --- /dev/null +++ b/cli/tests/testdata/lsp/initialize_params_bad_config_option.json @@ -0,0 +1,65 @@ +{ + "processId": 0, + "clientInfo": { + "name": "test-harness", + "version": "1.0.0" + }, + "rootUri": null, + "initializationOptions": { + "enable": true, + "cache": null, + "codeLens": { + "implementations": true, + "references": true, + "test": true + }, + "config": "bad_tsconfig.json", + "importMap": null, + "lint": true, + "suggest": { + "autoImports": true, + "completeFunctionCalls": false, + "names": true, + "paths": true, + "imports": { + "hosts": {} + } + }, + "unstable": false + }, + "capabilities": { + "textDocument": { + "codeAction": { + "codeActionLiteralSupport": { + "codeActionKind": { + "valueSet": [ + "quickfix", + "refactor" + ] + } + }, + "isPreferredSupport": true, + "dataSupport": true, + "disabledSupport": true, + "resolveSupport": { + "properties": [ + "edit" + ] + } + }, + "foldingRange": { + "lineFoldingOnly": true + }, + "synchronization": { + "dynamicRegistration": true, + "willSave": true, + "willSaveWaitUntil": true, + "didSave": true + } + }, + "workspace": { + "configuration": true, + "workspaceFolders": true + } + } +} diff --git a/cli/tests/testdata/lsp/initialize_params_ca_no_disabled.json b/cli/tests/testdata/lsp/initialize_params_ca_no_disabled.json new file mode 100644 index 000000000..3df87aded --- /dev/null +++ b/cli/tests/testdata/lsp/initialize_params_ca_no_disabled.json @@ -0,0 +1,64 @@ +{ + "processId": 0, + "clientInfo": { + "name": "test-harness", + "version": "1.0.0" + }, + "rootUri": null, + "initializationOptions": { + "enable": true, + "cache": null, + "codeLens": { + "implementations": true, + "references": true, + "test": true + }, + "config": "", + "importMap": null, + "lint": true, + "suggest": { + "autoImports": true, + "completeFunctionCalls": false, + "names": true, + "paths": true, + "imports": { + "hosts": {} + } + }, + "unstable": false + }, + "capabilities": { + "textDocument": { + "codeAction": { + "codeActionLiteralSupport": { + "codeActionKind": { + "valueSet": [ + "quickfix", + "refactor" + ] + } + }, + "isPreferredSupport": true, + "dataSupport": true, + "resolveSupport": { + "properties": [ + "edit" + ] + } + }, + "foldingRange": { + "lineFoldingOnly": true + }, + "synchronization": { + "dynamicRegistration": true, + "willSave": true, + "willSaveWaitUntil": true, + "didSave": true + } + }, + "workspace": { + "configuration": true, + "workspaceFolders": true + } + } +} diff --git a/cli/tests/testdata/lsp/initialize_params_code_lens_test.json b/cli/tests/testdata/lsp/initialize_params_code_lens_test.json new file mode 100644 index 000000000..bdd01bfca --- /dev/null +++ b/cli/tests/testdata/lsp/initialize_params_code_lens_test.json @@ -0,0 +1,59 @@ +{ + "processId": 0, + "clientInfo": { + "name": "test-harness", + "version": "1.0.0" + }, + "rootUri": null, + "initializationOptions": { + "enable": true, + "cache": null, + "importMap": null, + "lint": true, + "suggest": { + "autoImports": true, + "completeFunctionCalls": false, + "names": true, + "paths": true, + "imports": { + "hosts": {} + } + }, + "unstable": false + }, + "capabilities": { + "textDocument": { + "codeAction": { + "codeActionLiteralSupport": { + "codeActionKind": { + "valueSet": [ + "quickfix", + "refactor" + ] + } + }, + "isPreferredSupport": true, + "dataSupport": true, + "disabledSupport": true, + "resolveSupport": { + "properties": [ + "edit" + ] + } + }, + "foldingRange": { + "lineFoldingOnly": true + }, + "synchronization": { + "dynamicRegistration": true, + "willSave": true, + "willSaveWaitUntil": true, + "didSave": true + } + }, + "workspace": { + "configuration": true, + "workspaceFolders": true + } + } +} diff --git a/cli/tests/testdata/lsp/initialize_params_code_lens_test_disabled.json b/cli/tests/testdata/lsp/initialize_params_code_lens_test_disabled.json new file mode 100644 index 000000000..1d18934ae --- /dev/null +++ b/cli/tests/testdata/lsp/initialize_params_code_lens_test_disabled.json @@ -0,0 +1,64 @@ +{ + "processId": 0, + "clientInfo": { + "name": "test-harness", + "version": "1.0.0" + }, + "rootUri": null, + "initializationOptions": { + "enable": true, + "cache": null, + "codeLens": { + "implementations": true, + "references": true, + "test": false + }, + "importMap": null, + "lint": true, + "suggest": { + "autoImports": true, + "completeFunctionCalls": false, + "names": true, + "paths": true, + "imports": { + "hosts": {} + } + }, + "unstable": false + }, + "capabilities": { + "textDocument": { + "codeAction": { + "codeActionLiteralSupport": { + "codeActionKind": { + "valueSet": [ + "quickfix", + "refactor" + ] + } + }, + "isPreferredSupport": true, + "dataSupport": true, + "disabledSupport": true, + "resolveSupport": { + "properties": [ + "edit" + ] + } + }, + "foldingRange": { + "lineFoldingOnly": true + }, + "synchronization": { + "dynamicRegistration": true, + "willSave": true, + "willSaveWaitUntil": true, + "didSave": true + } + }, + "workspace": { + "configuration": true, + "workspaceFolders": true + } + } +} diff --git a/cli/tests/testdata/lsp/initialize_params_did_config_change.json b/cli/tests/testdata/lsp/initialize_params_did_config_change.json new file mode 100644 index 000000000..870ad6e0f --- /dev/null +++ b/cli/tests/testdata/lsp/initialize_params_did_config_change.json @@ -0,0 +1,65 @@ +{ + "processId": 0, + "clientInfo": { + "name": "test-harness", + "version": "1.0.0" + }, + "rootUri": null, + "initializationOptions": { + "enable": true, + "cache": null, + "codeLens": { + "implementations": true, + "references": true + }, + "importMap": null, + "lint": true, + "suggest": { + "autoImports": true, + "completeFunctionCalls": false, + "names": true, + "paths": true, + "imports": { + "hosts": { + "http://localhost:4545/": false + } + } + }, + "unstable": false + }, + "capabilities": { + "textDocument": { + "codeAction": { + "codeActionLiteralSupport": { + "codeActionKind": { + "valueSet": [ + "quickfix", + "refactor" + ] + } + }, + "isPreferredSupport": true, + "dataSupport": true, + "disabledSupport": true, + "resolveSupport": { + "properties": [ + "edit" + ] + } + }, + "foldingRange": { + "lineFoldingOnly": true + }, + "synchronization": { + "dynamicRegistration": true, + "willSave": true, + "willSaveWaitUntil": true, + "didSave": true + } + }, + "workspace": { + "configuration": true, + "workspaceFolders": true + } + } +} diff --git a/cli/tests/testdata/lsp/initialize_params_disabled.json b/cli/tests/testdata/lsp/initialize_params_disabled.json new file mode 100644 index 000000000..879b1181c --- /dev/null +++ b/cli/tests/testdata/lsp/initialize_params_disabled.json @@ -0,0 +1,63 @@ +{ + "processId": 0, + "clientInfo": { + "name": "test-harness", + "version": "1.0.0" + }, + "rootUri": null, + "initializationOptions": { + "enable": false, + "cache": null, + "codeLens": { + "implementations": true, + "references": true + }, + "importMap": null, + "lint": true, + "suggest": { + "autoImports": true, + "completeFunctionCalls": false, + "names": true, + "paths": true, + "imports": { + "hosts": {} + } + }, + "unstable": false + }, + "capabilities": { + "textDocument": { + "codeAction": { + "codeActionLiteralSupport": { + "codeActionKind": { + "valueSet": [ + "quickfix", + "refactor" + ] + } + }, + "isPreferredSupport": true, + "dataSupport": true, + "disabledSupport": true, + "resolveSupport": { + "properties": [ + "edit" + ] + } + }, + "foldingRange": { + "lineFoldingOnly": true + }, + "synchronization": { + "dynamicRegistration": true, + "willSave": true, + "willSaveWaitUntil": true, + "didSave": true + } + }, + "workspace": { + "configuration": true, + "workspaceFolders": true + } + } +} diff --git a/cli/tests/testdata/lsp/initialize_params_registry.json b/cli/tests/testdata/lsp/initialize_params_registry.json new file mode 100644 index 000000000..67559ebb3 --- /dev/null +++ b/cli/tests/testdata/lsp/initialize_params_registry.json @@ -0,0 +1,65 @@ +{ + "processId": 0, + "clientInfo": { + "name": "test-harness", + "version": "1.0.0" + }, + "rootUri": null, + "initializationOptions": { + "enable": true, + "cache": null, + "codeLens": { + "implementations": true, + "references": true + }, + "importMap": null, + "lint": true, + "suggest": { + "autoImports": true, + "completeFunctionCalls": false, + "names": true, + "paths": true, + "imports": { + "hosts": { + "http://localhost:4545/": true + } + } + }, + "unstable": false + }, + "capabilities": { + "textDocument": { + "codeAction": { + "codeActionLiteralSupport": { + "codeActionKind": { + "valueSet": [ + "quickfix", + "refactor" + ] + } + }, + "isPreferredSupport": true, + "dataSupport": true, + "disabledSupport": true, + "resolveSupport": { + "properties": [ + "edit" + ] + } + }, + "foldingRange": { + "lineFoldingOnly": true + }, + "synchronization": { + "dynamicRegistration": true, + "willSave": true, + "willSaveWaitUntil": true, + "didSave": true + } + }, + "workspace": { + "configuration": true, + "workspaceFolders": true + } + } +} diff --git a/cli/tests/testdata/lsp/initialize_params_unstable.json b/cli/tests/testdata/lsp/initialize_params_unstable.json new file mode 100644 index 000000000..104db16f2 --- /dev/null +++ b/cli/tests/testdata/lsp/initialize_params_unstable.json @@ -0,0 +1,63 @@ +{ + "processId": 0, + "clientInfo": { + "name": "test-harness", + "version": "1.0.0" + }, + "rootUri": null, + "initializationOptions": { + "enable": true, + "cache": null, + "codeLens": { + "implementations": true, + "references": true + }, + "importMap": null, + "lint": true, + "suggest": { + "autoImports": true, + "completeFunctionCalls": false, + "names": true, + "paths": true, + "imports": { + "hosts": {} + } + }, + "unstable": true + }, + "capabilities": { + "textDocument": { + "codeAction": { + "codeActionLiteralSupport": { + "codeActionKind": { + "valueSet": [ + "quickfix", + "refactor" + ] + } + }, + "isPreferredSupport": true, + "dataSupport": true, + "disabledSupport": true, + "resolveSupport": { + "properties": [ + "edit" + ] + } + }, + "foldingRange": { + "lineFoldingOnly": true + }, + "synchronization": { + "dynamicRegistration": true, + "willSave": true, + "willSaveWaitUntil": true, + "didSave": true + } + }, + "workspace": { + "configuration": true, + "workspaceFolders": true + } + } +} diff --git a/cli/tests/testdata/lsp/lib.tsconfig.json b/cli/tests/testdata/lsp/lib.tsconfig.json new file mode 100644 index 000000000..8d2ae8a8b --- /dev/null +++ b/cli/tests/testdata/lsp/lib.tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "lib": ["deno.ns", "deno.unstable", "dom"] + } +} diff --git a/cli/tests/testdata/lsp/outgoing_calls_params.json b/cli/tests/testdata/lsp/outgoing_calls_params.json new file mode 100644 index 000000000..6b38d26ee --- /dev/null +++ b/cli/tests/testdata/lsp/outgoing_calls_params.json @@ -0,0 +1,28 @@ +{ + "item": { + "name": "baz", + "kind": 6, + "detail": "Bar", + "uri": "file:///a/file.ts", + "range": { + "start": { + "line": 5, + "character": 2 + }, + "end": { + "line": 7, + "character": 3 + } + }, + "selectionRange": { + "start": { + "line": 5, + "character": 2 + }, + "end": { + "line": 5, + "character": 5 + } + } + } +} diff --git a/cli/tests/testdata/lsp/outgoing_calls_response.json b/cli/tests/testdata/lsp/outgoing_calls_response.json new file mode 100644 index 000000000..c7cf85cf8 --- /dev/null +++ b/cli/tests/testdata/lsp/outgoing_calls_response.json @@ -0,0 +1,42 @@ +[ + { + "to": { + "name": "foo", + "kind": 12, + "detail": "", + "uri": "file:///a/file.ts", + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 2, + "character": 1 + } + }, + "selectionRange": { + "start": { + "line": 0, + "character": 9 + }, + "end": { + "line": 0, + "character": 12 + } + } + }, + "fromRanges": [ + { + "start": { + "line": 6, + "character": 11 + }, + "end": { + "line": 6, + "character": 14 + } + } + ] + } +] diff --git a/cli/tests/testdata/lsp/prepare_call_hierarchy_response.json b/cli/tests/testdata/lsp/prepare_call_hierarchy_response.json new file mode 100644 index 000000000..93a7d4f1b --- /dev/null +++ b/cli/tests/testdata/lsp/prepare_call_hierarchy_response.json @@ -0,0 +1,28 @@ +[ + { + "name": "baz", + "kind": 6, + "detail": "Bar", + "uri": "file:///a/file.ts", + "range": { + "start": { + "line": 5, + "character": 2 + }, + "end": { + "line": 7, + "character": 3 + } + }, + "selectionRange": { + "start": { + "line": 5, + "character": 2 + }, + "end": { + "line": 5, + "character": 5 + } + } + } +] diff --git a/cli/tests/testdata/lsp/registries/a_latest.json b/cli/tests/testdata/lsp/registries/a_latest.json new file mode 100644 index 000000000..f9f9d111e --- /dev/null +++ b/cli/tests/testdata/lsp/registries/a_latest.json @@ -0,0 +1,4 @@ +[ + "b/c.ts", + "d/e.js" +] diff --git a/cli/tests/testdata/lsp/registries/a_v1.0.0.json b/cli/tests/testdata/lsp/registries/a_v1.0.0.json new file mode 100644 index 000000000..f9f9d111e --- /dev/null +++ b/cli/tests/testdata/lsp/registries/a_v1.0.0.json @@ -0,0 +1,4 @@ +[ + "b/c.ts", + "d/e.js" +] diff --git a/cli/tests/testdata/lsp/registries/a_v1.0.1.json b/cli/tests/testdata/lsp/registries/a_v1.0.1.json new file mode 100644 index 000000000..f9f9d111e --- /dev/null +++ b/cli/tests/testdata/lsp/registries/a_v1.0.1.json @@ -0,0 +1,4 @@ +[ + "b/c.ts", + "d/e.js" +] diff --git a/cli/tests/testdata/lsp/registries/a_v2.0.0.json b/cli/tests/testdata/lsp/registries/a_v2.0.0.json new file mode 100644 index 000000000..f9f9d111e --- /dev/null +++ b/cli/tests/testdata/lsp/registries/a_v2.0.0.json @@ -0,0 +1,4 @@ +[ + "b/c.ts", + "d/e.js" +] diff --git a/cli/tests/testdata/lsp/registries/a_versions.json b/cli/tests/testdata/lsp/registries/a_versions.json new file mode 100644 index 000000000..930e38323 --- /dev/null +++ b/cli/tests/testdata/lsp/registries/a_versions.json @@ -0,0 +1,5 @@ +[ + "v1.0.0", + "v1.0.1", + "v2.0.0" +] diff --git a/cli/tests/testdata/lsp/registries/b_latest.json b/cli/tests/testdata/lsp/registries/b_latest.json new file mode 100644 index 000000000..f9f9d111e --- /dev/null +++ b/cli/tests/testdata/lsp/registries/b_latest.json @@ -0,0 +1,4 @@ +[ + "b/c.ts", + "d/e.js" +] diff --git a/cli/tests/testdata/lsp/registries/b_v0.0.1.json b/cli/tests/testdata/lsp/registries/b_v0.0.1.json new file mode 100644 index 000000000..f9f9d111e --- /dev/null +++ b/cli/tests/testdata/lsp/registries/b_v0.0.1.json @@ -0,0 +1,4 @@ +[ + "b/c.ts", + "d/e.js" +] diff --git a/cli/tests/testdata/lsp/registries/b_v0.0.2.json b/cli/tests/testdata/lsp/registries/b_v0.0.2.json new file mode 100644 index 000000000..f9f9d111e --- /dev/null +++ b/cli/tests/testdata/lsp/registries/b_v0.0.2.json @@ -0,0 +1,4 @@ +[ + "b/c.ts", + "d/e.js" +] diff --git a/cli/tests/testdata/lsp/registries/b_v0.0.3.json b/cli/tests/testdata/lsp/registries/b_v0.0.3.json new file mode 100644 index 000000000..f9f9d111e --- /dev/null +++ b/cli/tests/testdata/lsp/registries/b_v0.0.3.json @@ -0,0 +1,4 @@ +[ + "b/c.ts", + "d/e.js" +] diff --git a/cli/tests/testdata/lsp/registries/b_versions.json b/cli/tests/testdata/lsp/registries/b_versions.json new file mode 100644 index 000000000..9532fbb85 --- /dev/null +++ b/cli/tests/testdata/lsp/registries/b_versions.json @@ -0,0 +1,5 @@ +[ + "v0.0.1", + "v0.0.2", + "v0.0.3" +] diff --git a/cli/tests/testdata/lsp/registries/deno-import-intellisense.json b/cli/tests/testdata/lsp/registries/deno-import-intellisense.json new file mode 100644 index 000000000..8aa4a4eca --- /dev/null +++ b/cli/tests/testdata/lsp/registries/deno-import-intellisense.json @@ -0,0 +1,35 @@ +{ + "version": 1, + "registries": [ + { + "schema": "/x/:module([a-z0-9_]*)@:version?/:path*", + "variables": [ + { + "key": "module", + "url": "http://localhost:4545/lsp/registries/modules.json" + }, + { + "key": "version", + "url": "http://localhost:4545/lsp/registries/${module}_versions.json" + }, + { + "key": "path", + "url": "http://localhost:4545/lsp/registries/${module}_${{version}}.json" + } + ] + }, + { + "schema": "/x/:module([a-z0-9_]*)/:path*", + "variables": [ + { + "key": "module", + "url": "http://localhost:4545/lsp/registries/modules.json" + }, + { + "key": "path", + "url": "http://localhost:4545/lsp/registries/${module}_latest.json" + } + ] + } + ] +} diff --git a/cli/tests/testdata/lsp/registries/modules.json b/cli/tests/testdata/lsp/registries/modules.json new file mode 100644 index 000000000..517c9d68e --- /dev/null +++ b/cli/tests/testdata/lsp/registries/modules.json @@ -0,0 +1,4 @@ +[ + "a", + "b" +] diff --git a/cli/tests/testdata/lsp/rename_response.json b/cli/tests/testdata/lsp/rename_response.json new file mode 100644 index 000000000..5e0e28e4c --- /dev/null +++ b/cli/tests/testdata/lsp/rename_response.json @@ -0,0 +1,38 @@ +{ + "documentChanges": [ + { + "textDocument": { + "uri": "file:///a/file.ts", + "version": 1 + }, + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 4 + }, + "end": { + "line": 0, + "character": 12 + } + }, + "newText": "variable_modified" + }, + { + "range": { + "start": { + "line": 1, + "character": 12 + }, + "end": { + "line": 1, + "character": 20 + } + }, + "newText": "variable_modified" + } + ] + } + ] +} diff --git a/cli/tests/testdata/lsp/selection_range_response.json b/cli/tests/testdata/lsp/selection_range_response.json new file mode 100644 index 000000000..b5eef5ddc --- /dev/null +++ b/cli/tests/testdata/lsp/selection_range_response.json @@ -0,0 +1,86 @@ +[ + { + "range": { + "start": { + "line": 2, + "character": 8 + }, + "end": { + "line": 2, + "character": 9 + } + }, + "parent": { + "range": { + "start": { + "line": 2, + "character": 8 + }, + "end": { + "line": 2, + "character": 15 + } + }, + "parent": { + "range": { + "start": { + "line": 2, + "character": 4 + }, + "end": { + "line": 4, + "character": 5 + } + }, + "parent": { + "range": { + "start": { + "line": 1, + "character": 13 + }, + "end": { + "line": 6, + "character": 2 + } + }, + "parent": { + "range": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 6, + "character": 3 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 11 + }, + "end": { + "line": 7, + "character": 0 + } + }, + "parent": { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 7, + "character": 1 + } + } + } + } + } + } + } + } + } +] diff --git a/cli/tests/testdata/lsp/types.tsconfig.json b/cli/tests/testdata/lsp/types.tsconfig.json new file mode 100644 index 000000000..ba7f3344d --- /dev/null +++ b/cli/tests/testdata/lsp/types.tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "types": [ + "./a.d.ts" + ] + } +} diff --git a/cli/tests/testdata/main_module.ts b/cli/tests/testdata/main_module.ts new file mode 100644 index 000000000..19988f4bf --- /dev/null +++ b/cli/tests/testdata/main_module.ts @@ -0,0 +1,3 @@ +console.log("main_module", Deno.mainModule); + +import "./main_module2.ts"; diff --git a/cli/tests/testdata/main_module.ts.out b/cli/tests/testdata/main_module.ts.out new file mode 100644 index 000000000..817bb6b8c --- /dev/null +++ b/cli/tests/testdata/main_module.ts.out @@ -0,0 +1,2 @@ +main_module2 [WILDCARD]/main_module.ts +main_module [WILDCARD]/main_module.ts diff --git a/cli/tests/testdata/main_module2.ts b/cli/tests/testdata/main_module2.ts new file mode 100644 index 000000000..585615c7f --- /dev/null +++ b/cli/tests/testdata/main_module2.ts @@ -0,0 +1 @@ +console.log("main_module2", Deno.mainModule); diff --git a/cli/tests/testdata/module_graph/file_tests-a.mjs b/cli/tests/testdata/module_graph/file_tests-a.mjs new file mode 100644 index 000000000..72b3a67bc --- /dev/null +++ b/cli/tests/testdata/module_graph/file_tests-a.mjs @@ -0,0 +1,3 @@ +import * as b from "./b.ts"; + +console.log(b); diff --git a/cli/tests/testdata/module_graph/file_tests-b-mod.js b/cli/tests/testdata/module_graph/file_tests-b-mod.js new file mode 100644 index 000000000..59d168993 --- /dev/null +++ b/cli/tests/testdata/module_graph/file_tests-b-mod.js @@ -0,0 +1 @@ +export const b = "b"; diff --git a/cli/tests/testdata/module_graph/file_tests-b.ts b/cli/tests/testdata/module_graph/file_tests-b.ts new file mode 100644 index 000000000..59d168993 --- /dev/null +++ b/cli/tests/testdata/module_graph/file_tests-b.ts @@ -0,0 +1 @@ +export const b = "b"; diff --git a/cli/tests/testdata/module_graph/file_tests-c-mod.ts b/cli/tests/testdata/module_graph/file_tests-c-mod.ts new file mode 100644 index 000000000..7f2cfac77 --- /dev/null +++ b/cli/tests/testdata/module_graph/file_tests-c-mod.ts @@ -0,0 +1 @@ +export const c = "c"; diff --git a/cli/tests/testdata/module_graph/file_tests-checkwithconfig.ts b/cli/tests/testdata/module_graph/file_tests-checkwithconfig.ts new file mode 100644 index 000000000..e7af5fa19 --- /dev/null +++ b/cli/tests/testdata/module_graph/file_tests-checkwithconfig.ts @@ -0,0 +1,5 @@ +import { ServerRequest } from "https://deno.land/std/http/server.ts"; + +export default (req: ServerRequest) => { + req.respond({ body: `Hello, from Deno v${Deno.version.deno}!` }); +}; diff --git a/cli/tests/testdata/module_graph/file_tests-diag.ts b/cli/tests/testdata/module_graph/file_tests-diag.ts new file mode 100644 index 000000000..ba365234a --- /dev/null +++ b/cli/tests/testdata/module_graph/file_tests-diag.ts @@ -0,0 +1,4 @@ +import * as c from "./c/mod.ts"; + +// deno-lint-ignore no-undef +consol.log(c); diff --git a/cli/tests/testdata/module_graph/file_tests-dynamicimport.ts b/cli/tests/testdata/module_graph/file_tests-dynamicimport.ts new file mode 100644 index 000000000..b5c9f080f --- /dev/null +++ b/cli/tests/testdata/module_graph/file_tests-dynamicimport.ts @@ -0,0 +1,5 @@ +try { + await import("bare_module_specifier"); +} catch (err) { + console.log(err); +} diff --git a/cli/tests/testdata/module_graph/file_tests-importjson.ts b/cli/tests/testdata/module_graph/file_tests-importjson.ts new file mode 100644 index 000000000..c2bc2bca7 --- /dev/null +++ b/cli/tests/testdata/module_graph/file_tests-importjson.ts @@ -0,0 +1,3 @@ +import * as config from "./some.json"; + +console.log(config); diff --git a/cli/tests/testdata/module_graph/file_tests-importremap.ts b/cli/tests/testdata/module_graph/file_tests-importremap.ts new file mode 100644 index 000000000..17f012673 --- /dev/null +++ b/cli/tests/testdata/module_graph/file_tests-importremap.ts @@ -0,0 +1,3 @@ +import * as a from "https://deno.land/x/a/mod.ts"; + +console.log(a); diff --git a/cli/tests/testdata/module_graph/file_tests-main.ts b/cli/tests/testdata/module_graph/file_tests-main.ts new file mode 100644 index 000000000..aa8eef1b8 --- /dev/null +++ b/cli/tests/testdata/module_graph/file_tests-main.ts @@ -0,0 +1,4 @@ +// @deno-types="https://deno.land/x/lib/mod.d.ts" +import * as lib from "https://deno.land/x/lib/mod.js"; + +console.log(lib); diff --git a/cli/tests/testdata/module_graph/file_tests-some.json b/cli/tests/testdata/module_graph/file_tests-some.json new file mode 100644 index 000000000..567c4ba21 --- /dev/null +++ b/cli/tests/testdata/module_graph/file_tests-some.json @@ -0,0 +1,5 @@ +{ + "config": { + "debug": true + } +} diff --git a/cli/tests/testdata/module_graph/file_typesref.d.ts b/cli/tests/testdata/module_graph/file_typesref.d.ts new file mode 100644 index 000000000..8ae31dde3 --- /dev/null +++ b/cli/tests/testdata/module_graph/file_typesref.d.ts @@ -0,0 +1 @@ +export const a: "a"; diff --git a/cli/tests/testdata/module_graph/file_typesref.js b/cli/tests/testdata/module_graph/file_typesref.js new file mode 100644 index 000000000..79da24cae --- /dev/null +++ b/cli/tests/testdata/module_graph/file_typesref.js @@ -0,0 +1,3 @@ +/// <reference types="./typesref.d.ts" /> + +export const a = "a"; diff --git a/cli/tests/testdata/module_graph/https_deno.land-std-http-server.ts b/cli/tests/testdata/module_graph/https_deno.land-std-http-server.ts new file mode 100644 index 000000000..0b3c995ec --- /dev/null +++ b/cli/tests/testdata/module_graph/https_deno.land-std-http-server.ts @@ -0,0 +1,5 @@ +export class ServerRequest { + respond(value: { body: string }) { + console.log(value); + } +} diff --git a/cli/tests/testdata/module_graph/https_deno.land-x-a-mod.ts b/cli/tests/testdata/module_graph/https_deno.land-x-a-mod.ts new file mode 100644 index 000000000..1e334d399 --- /dev/null +++ b/cli/tests/testdata/module_graph/https_deno.land-x-a-mod.ts @@ -0,0 +1 @@ +export * as b from "../b/mod.js"; diff --git a/cli/tests/testdata/module_graph/https_deno.land-x-a.ts b/cli/tests/testdata/module_graph/https_deno.land-x-a.ts new file mode 100644 index 000000000..a6e3cea80 --- /dev/null +++ b/cli/tests/testdata/module_graph/https_deno.land-x-a.ts @@ -0,0 +1 @@ +export const a = "hello"; diff --git a/cli/tests/testdata/module_graph/https_deno.land-x-import_map.ts b/cli/tests/testdata/module_graph/https_deno.land-x-import_map.ts new file mode 100644 index 000000000..e285d863a --- /dev/null +++ b/cli/tests/testdata/module_graph/https_deno.land-x-import_map.ts @@ -0,0 +1,4 @@ +import * as $ from "jquery"; +import * as _ from "lodash"; + +console.log($, _); diff --git a/cli/tests/testdata/module_graph/https_deno.land-x-jquery.js b/cli/tests/testdata/module_graph/https_deno.land-x-jquery.js new file mode 100644 index 000000000..71896157a --- /dev/null +++ b/cli/tests/testdata/module_graph/https_deno.land-x-jquery.js @@ -0,0 +1,3 @@ +const $ = {}; + +export default $; diff --git a/cli/tests/testdata/module_graph/https_deno.land-x-lib-a.ts b/cli/tests/testdata/module_graph/https_deno.land-x-lib-a.ts new file mode 100644 index 000000000..a0a6f8e94 --- /dev/null +++ b/cli/tests/testdata/module_graph/https_deno.land-x-lib-a.ts @@ -0,0 +1 @@ +export const a: string[] = []; diff --git a/cli/tests/testdata/module_graph/https_deno.land-x-lib-b.js b/cli/tests/testdata/module_graph/https_deno.land-x-lib-b.js new file mode 100644 index 000000000..13cacdd8b --- /dev/null +++ b/cli/tests/testdata/module_graph/https_deno.land-x-lib-b.js @@ -0,0 +1 @@ +export const b = []; diff --git a/cli/tests/testdata/module_graph/https_deno.land-x-lib-c.d.ts b/cli/tests/testdata/module_graph/https_deno.land-x-lib-c.d.ts new file mode 100644 index 000000000..fac988e49 --- /dev/null +++ b/cli/tests/testdata/module_graph/https_deno.land-x-lib-c.d.ts @@ -0,0 +1 @@ +export const c: string[]; diff --git a/cli/tests/testdata/module_graph/https_deno.land-x-lib-c.js b/cli/tests/testdata/module_graph/https_deno.land-x-lib-c.js new file mode 100644 index 000000000..620ca0b66 --- /dev/null +++ b/cli/tests/testdata/module_graph/https_deno.land-x-lib-c.js @@ -0,0 +1,3 @@ +/// <reference types="./c.d.ts" /> + +export const c = []; diff --git a/cli/tests/testdata/module_graph/https_deno.land-x-lib-mod.d.ts b/cli/tests/testdata/module_graph/https_deno.land-x-lib-mod.d.ts new file mode 100644 index 000000000..76ed81df0 --- /dev/null +++ b/cli/tests/testdata/module_graph/https_deno.land-x-lib-mod.d.ts @@ -0,0 +1,9 @@ +export * as a from "./a.ts"; +export * as b from "./b.js"; +export * as c from "./c.js"; + +export interface A { + a: string; +} + +export const mod: A[]; diff --git a/cli/tests/testdata/module_graph/https_deno.land-x-lib-mod.js b/cli/tests/testdata/module_graph/https_deno.land-x-lib-mod.js new file mode 100644 index 000000000..505162094 --- /dev/null +++ b/cli/tests/testdata/module_graph/https_deno.land-x-lib-mod.js @@ -0,0 +1,5 @@ +export * as a from "./a.ts"; +export * as b from "./b.js"; +export * as c from "./c.js"; + +export const mod = []; diff --git a/cli/tests/testdata/module_graph/https_deno.land-x-mod.ts b/cli/tests/testdata/module_graph/https_deno.land-x-mod.ts new file mode 100644 index 000000000..35d76ef75 --- /dev/null +++ b/cli/tests/testdata/module_graph/https_deno.land-x-mod.ts @@ -0,0 +1,3 @@ +import * as a from "./a.ts"; + +console.log(a); diff --git a/cli/tests/testdata/module_graph/https_deno.land-x-transpile.tsx b/cli/tests/testdata/module_graph/https_deno.land-x-transpile.tsx new file mode 100644 index 000000000..02955bad8 --- /dev/null +++ b/cli/tests/testdata/module_graph/https_deno.land-x-transpile.tsx @@ -0,0 +1,5 @@ +export default class A { + render() { + return <div>Hello world!</div>; + } +} diff --git a/cli/tests/testdata/module_graph/https_unpkg.com-lodash-index.js b/cli/tests/testdata/module_graph/https_unpkg.com-lodash-index.js new file mode 100644 index 000000000..d16c126a6 --- /dev/null +++ b/cli/tests/testdata/module_graph/https_unpkg.com-lodash-index.js @@ -0,0 +1,3 @@ +const _ = {}; + +export default _; diff --git a/cli/tests/testdata/module_graph/lockfile.json b/cli/tests/testdata/module_graph/lockfile.json new file mode 100644 index 000000000..03cfe1185 --- /dev/null +++ b/cli/tests/testdata/module_graph/lockfile.json @@ -0,0 +1,8 @@ +{ + "https://deno.land/x/lib/a.ts": "4437fee72a750d9540a9575ea6426761d0aa1beedfa308fb1bc38701d97011b8", + "https://deno.land/x/lib/b.js": "093cc4164ca7a9adb11597ad291e021634f0b2d8c048137f7e9fb0d709499028", + "https://deno.land/x/lib/c.d.ts": "a95647377477cc663559f5e857bf318c584622ed1295a8ccb0c091d06bee0456", + "https://deno.land/x/lib/c.js": "4ff934f4b3b06f320c3130326376d9f2435e2ecedd582940ca90938137d004e1", + "https://deno.land/x/lib/mod.d.ts": "e54b994fbf63cb7f01076ea54f2ed67b185f2a48e8ff71d74bd9c8180a338eb7", + "https://deno.land/x/lib/mod.js": "3f6fcb8ef83ed6c66e71774d5079d14d22a6948dc6e5358ac30e0ab55e1a6404" +} diff --git a/cli/tests/testdata/module_graph/lockfile_fail.json b/cli/tests/testdata/module_graph/lockfile_fail.json new file mode 100644 index 000000000..c0019fba4 --- /dev/null +++ b/cli/tests/testdata/module_graph/lockfile_fail.json @@ -0,0 +1,8 @@ +{ + "https://deno.land/x/lib/a.ts": "4437fee72a750d9540a9575ea6426761d0aa1beedfa308fb1bc38701d97011b8", + "https://deno.land/x/lib/b.js": "093cc4164ca7a9adb11597ad291e021634f0b2d8c048137f7e9fb0d709499028", + "https://deno.land/x/lib/c.d.ts": "a95647377477cc663559f5e857bf318c584622ed1295a8ccb0c091d06bee0456", + "https://deno.land/x/lib/c.js": "4ff934f4b3b06f320c3130326376d9f2435e2ecedd582940ca90938137d004e1", + "https://deno.land/x/lib/mod.d.ts": "e54b994fbf63cb7f01076ea54f2ed67b185f2a48e8ff71d74bd9c8180a338eb7", + "https://deno.land/x/lib/mod.js": "3f6fcb8ef83fd6c66e71774d5079d14d22a6948dc6e5358ac30e0ab55e1a6404" +} diff --git a/cli/tests/testdata/module_graph/tsconfig.json b/cli/tests/testdata/module_graph/tsconfig.json new file mode 100644 index 000000000..a4c5f4f33 --- /dev/null +++ b/cli/tests/testdata/module_graph/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "target": "ES5", + "jsx": "preserve" + } +} diff --git a/cli/tests/testdata/module_graph/tsconfig_01.json b/cli/tests/testdata/module_graph/tsconfig_01.json new file mode 100644 index 000000000..f7496d475 --- /dev/null +++ b/cli/tests/testdata/module_graph/tsconfig_01.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "strict": false, + "noImplicitAny": false, + "noImplicitThis": false, + "alwaysStrict": false, + "strictNullChecks": false, + "strictFunctionTypes": true, + "strictPropertyInitialization": false, + "experimentalDecorators": true, + "emitDecoratorMetadata": true + } +} diff --git a/cli/tests/testdata/no_check_decorators.ts b/cli/tests/testdata/no_check_decorators.ts new file mode 100644 index 000000000..9f7ec550d --- /dev/null +++ b/cli/tests/testdata/no_check_decorators.ts @@ -0,0 +1,21 @@ +// deno-lint-ignore-file +function a() { + console.log("a(): evaluated"); + return ( + _target: any, + _propertyKey: string, + _descriptor: PropertyDescriptor, + ) => { + console.log("a(): called"); + }; +} + +class B { + @a() + method() { + console.log("method"); + } +} + +const b = new B(); +b.method(); diff --git a/cli/tests/testdata/no_check_decorators.ts.out b/cli/tests/testdata/no_check_decorators.ts.out new file mode 100644 index 000000000..015f7076e --- /dev/null +++ b/cli/tests/testdata/no_check_decorators.ts.out @@ -0,0 +1,3 @@ +a(): evaluated +a(): called +method diff --git a/cli/tests/testdata/no_color.js b/cli/tests/testdata/no_color.js new file mode 100644 index 000000000..cea11a52f --- /dev/null +++ b/cli/tests/testdata/no_color.js @@ -0,0 +1 @@ +console.log("noColor", Deno.noColor); diff --git a/cli/tests/testdata/no_mem_cache.js b/cli/tests/testdata/no_mem_cache.js new file mode 100644 index 000000000..a486732b6 --- /dev/null +++ b/cli/tests/testdata/no_mem_cache.js @@ -0,0 +1,33 @@ +const fixtureFile = await Deno.makeTempFile(); +let prefix = "file://"; +if (Deno.build.os == "windows") { + prefix += "/"; +} +const fixtureUrl = new URL(`${prefix}${fixtureFile}`); +let resolve; + +let p = new Promise((res) => resolve = res); + +await Deno.writeTextFile(fixtureUrl, `self.postMessage("hello");\n`); + +const workerA = new Worker(fixtureUrl.href, { type: "module" }); +workerA.onmessage = (msg) => { + console.log(msg.data); + resolve(); +}; + +await p; +workerA.terminate(); + +p = new Promise((res) => resolve = res); + +await Deno.writeTextFile(fixtureUrl, `self.postMessage("goodbye");\n`); + +const workerB = new Worker(fixtureUrl.href, { type: "module" }); +workerB.onmessage = (msg) => { + console.log(msg.data); + resolve(); +}; + +await p; +workerB.terminate(); diff --git a/cli/tests/testdata/no_mem_cache.js.out b/cli/tests/testdata/no_mem_cache.js.out new file mode 100644 index 000000000..a32119c8a --- /dev/null +++ b/cli/tests/testdata/no_mem_cache.js.out @@ -0,0 +1,2 @@ +hello +goodbye diff --git a/cli/tests/testdata/no_validate_asm.js b/cli/tests/testdata/no_validate_asm.js new file mode 100644 index 000000000..ef999e080 --- /dev/null +++ b/cli/tests/testdata/no_validate_asm.js @@ -0,0 +1,20 @@ +// V8 logs any asmjs validation errors to stdout, but it shows line numbers that +// are non-existent in the source. + +const _asmJsModule = function () { + "use asm"; + + function func( + x, + ) { + x = +x; // cast to float + + ~x; + // asmjs error: `~` is only valid on integers + // should not log to stdout with --no-validate-asm + } + + return { + f: func, + }; +}(); diff --git a/cli/tests/testdata/performance_stats.out b/cli/tests/testdata/performance_stats.out new file mode 100644 index 000000000..141829ee6 --- /dev/null +++ b/cli/tests/testdata/performance_stats.out @@ -0,0 +1,16 @@ +[WILDCARD] +DEBUG RS - [WILDCARD] - Compilation statistics: + Files: [WILDCARD] + Nodes: [WILDCARD] + Identifiers: [WILDCARD] + Symbols: [WILDCARD] + Types: [WILDCARD] + Instantiations: [WILDCARD] + Parse time: [WILDCARD] + Bind time: [WILDCARD] + Check time: [WILDCARD] + Emit time: [WILDCARD] + Total TS time: [WILDCARD] + Compile time: [WILDCARD] + +[WILDCARD] diff --git a/cli/tests/testdata/permission_test.ts b/cli/tests/testdata/permission_test.ts new file mode 100644 index 000000000..a3a38f2a0 --- /dev/null +++ b/cli/tests/testdata/permission_test.ts @@ -0,0 +1,33 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +const name = Deno.args[0]; +// deno-lint-ignore no-explicit-any +const test: { [key: string]: (...args: any[]) => void | Promise<void> } = { + readRequired() { + Deno.readFileSync("hello.txt"); + return Promise.resolve(); + }, + writeRequired() { + Deno.makeTempDirSync(); + }, + envRequired() { + Deno.env.get("home"); + }, + netRequired() { + Deno.listen({ transport: "tcp", port: 4541 }); + }, + runRequired() { + const p = Deno.run({ + cmd: Deno.build.os === "windows" + ? ["cmd.exe", "/c", "echo hello"] + : ["printf", "hello"], + }); + p.close(); + }, +}; + +if (!test[name]) { + console.log("Unknown test:", name); + Deno.exit(1); +} + +test[name](); diff --git a/cli/tests/testdata/preserve_imports.tsconfig.json b/cli/tests/testdata/preserve_imports.tsconfig.json new file mode 100644 index 000000000..9b19291aa --- /dev/null +++ b/cli/tests/testdata/preserve_imports.tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "importsNotUsedAsValues": "preserve" + } +} diff --git a/cli/tests/testdata/proto_exploit.js b/cli/tests/testdata/proto_exploit.js new file mode 100644 index 000000000..8bd22cfe5 --- /dev/null +++ b/cli/tests/testdata/proto_exploit.js @@ -0,0 +1,5 @@ +const payload = `{ "__proto__": null }`; +const obj = {}; +console.log("Before: " + obj); +Object.assign(obj, JSON.parse(payload)); +console.log("After: " + obj); diff --git a/cli/tests/testdata/proto_exploit.js.out b/cli/tests/testdata/proto_exploit.js.out new file mode 100644 index 000000000..fde881dc5 --- /dev/null +++ b/cli/tests/testdata/proto_exploit.js.out @@ -0,0 +1,2 @@ +Before: [object Object] +After: [object Object] diff --git a/cli/tests/testdata/raw_mode.ts b/cli/tests/testdata/raw_mode.ts new file mode 100644 index 000000000..87502e7d9 --- /dev/null +++ b/cli/tests/testdata/raw_mode.ts @@ -0,0 +1,18 @@ +Deno.setRaw(0, true); +Deno.setRaw(0, true); // Can be called multiple times + +Deno.stdout.writeSync(new TextEncoder().encode("S")); + +const buf = new Uint8Array(3); +for (let i = 0; i < 3; i++) { + const nread = await Deno.stdin.read(buf); + if (nread === null) { + break; + } else { + const data = new TextDecoder().decode(buf.subarray(0, nread)); + Deno.stdout.writeSync(new TextEncoder().encode(data.toUpperCase())); + } +} + +Deno.setRaw(0, false); // restores old mode. +Deno.setRaw(0, false); // Can be safely called multiple times diff --git a/cli/tests/testdata/raw_mode_cbreak.ts b/cli/tests/testdata/raw_mode_cbreak.ts new file mode 100644 index 000000000..b1c6d324b --- /dev/null +++ b/cli/tests/testdata/raw_mode_cbreak.ts @@ -0,0 +1,17 @@ +Deno.setRaw(0, true); +Deno.setRaw(0, true, { cbreak: true }); // Can be called multiple times + +const signal = Deno.signals.interrupt(); + +Deno.stdout.writeSync(new TextEncoder().encode("S")); + +signal.then(() => { + Deno.stdout.writeSync(new TextEncoder().encode("A")); + + signal.dispose(); + + Deno.setRaw(0, false); // restores old mode. + Deno.setRaw(0, false); // Can be safely called multiple times +}); + +setTimeout(() => {}, 10000); // Keep the program running diff --git a/cli/tests/testdata/recursive_imports/A.ts b/cli/tests/testdata/recursive_imports/A.ts new file mode 100644 index 000000000..43ecdbe5e --- /dev/null +++ b/cli/tests/testdata/recursive_imports/A.ts @@ -0,0 +1,7 @@ +import { B } from "./B.ts"; +import { thing } from "./common.ts"; + +export function A() { + thing(); + B(); +} diff --git a/cli/tests/testdata/recursive_imports/B.ts b/cli/tests/testdata/recursive_imports/B.ts new file mode 100644 index 000000000..9fff0fdc9 --- /dev/null +++ b/cli/tests/testdata/recursive_imports/B.ts @@ -0,0 +1,7 @@ +import { C } from "./C.ts"; +import { thing } from "./common.ts"; + +export function B() { + thing(); + C(); +} diff --git a/cli/tests/testdata/recursive_imports/C.ts b/cli/tests/testdata/recursive_imports/C.ts new file mode 100644 index 000000000..e47e77b41 --- /dev/null +++ b/cli/tests/testdata/recursive_imports/C.ts @@ -0,0 +1,8 @@ +import { A } from "./A.ts"; +import { thing } from "./common.ts"; + +export function C() { + if (A != null) { + thing(); + } +} diff --git a/cli/tests/testdata/recursive_imports/common.ts b/cli/tests/testdata/recursive_imports/common.ts new file mode 100644 index 000000000..2b16a7bf1 --- /dev/null +++ b/cli/tests/testdata/recursive_imports/common.ts @@ -0,0 +1,2 @@ +export function thing() { +} diff --git a/cli/tests/testdata/redirect_cache.out b/cli/tests/testdata/redirect_cache.out new file mode 100644 index 000000000..8905c4529 --- /dev/null +++ b/cli/tests/testdata/redirect_cache.out @@ -0,0 +1,5 @@ +Download http://localhost:4548/subdir/redirects/a.ts +Download http://localhost:4546/subdir/redirects/a.ts +Download http://localhost:4545/subdir/redirects/a.ts +Download http://localhost:4545/subdir/redirects/b.ts +Check http://localhost:4548/subdir/redirects/a.ts diff --git a/cli/tests/testdata/reference_types.ts b/cli/tests/testdata/reference_types.ts new file mode 100644 index 000000000..105e23b37 --- /dev/null +++ b/cli/tests/testdata/reference_types.ts @@ -0,0 +1,3 @@ +/// <reference types="./subdir/types.d.ts" /> + +console.log(globalThis.a); diff --git a/cli/tests/testdata/reference_types.ts.out b/cli/tests/testdata/reference_types.ts.out new file mode 100644 index 000000000..417b7b537 --- /dev/null +++ b/cli/tests/testdata/reference_types.ts.out @@ -0,0 +1 @@ +undefined diff --git a/cli/tests/testdata/reference_types_remote.ts b/cli/tests/testdata/reference_types_remote.ts new file mode 100644 index 000000000..e7fa81b2c --- /dev/null +++ b/cli/tests/testdata/reference_types_remote.ts @@ -0,0 +1,3 @@ +/// <reference types="http://localhost:4545/subdir/types.d.ts" /> + +console.log(globalThis.a); diff --git a/cli/tests/testdata/reference_types_remote.ts.out b/cli/tests/testdata/reference_types_remote.ts.out new file mode 100644 index 000000000..417b7b537 --- /dev/null +++ b/cli/tests/testdata/reference_types_remote.ts.out @@ -0,0 +1 @@ +undefined diff --git a/cli/tests/testdata/resolve_dns.ts b/cli/tests/testdata/resolve_dns.ts new file mode 100644 index 000000000..d765e0536 --- /dev/null +++ b/cli/tests/testdata/resolve_dns.ts @@ -0,0 +1,42 @@ +const nameServer = { nameServer: { ipAddr: "127.0.0.1", port: 4553 } }; + +const [a, aaaa, aname, cname, mx, ptr, srv, txt] = await Promise.all([ + Deno.resolveDns("www.example.com", "A", nameServer), + Deno.resolveDns("www.example.com", "AAAA", nameServer), + Deno.resolveDns("www.example.com", "ANAME", nameServer), + Deno.resolveDns("foo", "CNAME", nameServer), + Deno.resolveDns("www.example.com", "MX", nameServer), + Deno.resolveDns("5.6.7.8", "PTR", nameServer), + Deno.resolveDns("_Service._TCP.example.com", "SRV", nameServer), + Deno.resolveDns("www.example.com", "TXT", nameServer), +]); + +console.log("A"); +console.log(JSON.stringify(a)); + +console.log("AAAA"); +console.log(JSON.stringify(aaaa)); + +console.log("ANAME"); +console.log(JSON.stringify(aname)); + +console.log("CNAME"); +console.log(JSON.stringify(cname)); + +console.log("MX"); +console.log(JSON.stringify(mx)); + +console.log("PTR"); +console.log(JSON.stringify(ptr)); + +console.log("SRV"); +console.log(JSON.stringify(srv)); + +console.log("TXT"); +console.log(JSON.stringify(txt)); + +try { + await Deno.resolveDns("not-found-example.com", "A", nameServer); +} catch (_e) { + console.log("Error thrown for not-found-example.com"); +} diff --git a/cli/tests/testdata/resolve_dns.ts.out b/cli/tests/testdata/resolve_dns.ts.out new file mode 100644 index 000000000..78381e6c6 --- /dev/null +++ b/cli/tests/testdata/resolve_dns.ts.out @@ -0,0 +1,17 @@ +A +["1.2.3.4"] +AAAA +["1:2:3:4:5:6:7:8"] +ANAME +["aname.com."] +CNAME +["cname.com."] +MX +[{"preference":0,"exchange":"mx.com."}] +PTR +["ptr.com."] +SRV +[{"priority":0,"weight":100,"port":1234,"target":"srv.com."}] +TXT +[["foo","bar"]] +Error thrown for not-found-example.com diff --git a/cli/tests/testdata/runtime_decorators.ts b/cli/tests/testdata/runtime_decorators.ts new file mode 100644 index 000000000..5da109110 --- /dev/null +++ b/cli/tests/testdata/runtime_decorators.ts @@ -0,0 +1,42 @@ +// deno-lint-ignore-file +function A() { + console.log("@A evaluated"); + return function ( + target: any, + propertyKey: string, + descriptor: PropertyDescriptor, + ) { + console.log("@A called"); + const fn = descriptor.value; + descriptor.value = function () { + console.log("fn() called from @A"); + fn(); + }; + }; +} + +function B() { + console.log("@B evaluated"); + return function ( + target: any, + propertyKey: string, + descriptor: PropertyDescriptor, + ) { + console.log("@B called"); + const fn = descriptor.value; + descriptor.value = function () { + console.log("fn() called from @B"); + fn(); + }; + }; +} + +class C { + @A() + @B() + static test() { + console.log("C.test() called"); + } +} + +C.test(); diff --git a/cli/tests/testdata/runtime_decorators.ts.out b/cli/tests/testdata/runtime_decorators.ts.out new file mode 100644 index 000000000..0fc1d4590 --- /dev/null +++ b/cli/tests/testdata/runtime_decorators.ts.out @@ -0,0 +1,7 @@ +@A evaluated +@B evaluated +@B called +@A called +fn() called from @A +fn() called from @B +C.test() called diff --git a/cli/tests/testdata/seed_random.js b/cli/tests/testdata/seed_random.js new file mode 100644 index 000000000..7f6e336df --- /dev/null +++ b/cli/tests/testdata/seed_random.js @@ -0,0 +1,11 @@ +for (let i = 0; i < 10; ++i) { + console.log(Math.random()); +} + +const arr = new Uint8Array(32); + +crypto.getRandomValues(arr); +console.log(arr); + +crypto.getRandomValues(arr); +console.log(arr); diff --git a/cli/tests/testdata/seed_random.js.out b/cli/tests/testdata/seed_random.js.out new file mode 100644 index 000000000..4d1ebd081 --- /dev/null +++ b/cli/tests/testdata/seed_random.js.out @@ -0,0 +1,22 @@ +0.858562739044346 +0.8973397944553141 +0.15335012655691727 +0.36867387434349963 +0.3591039342838782 +0.7044499748617652 +0.7461423057751548 +0.3824611207183364 +0.5950178237266042 +0.22440633214343908 +Uint8Array(32) [ + 153, 221, 127, 193, 173, 88, 77, 155, + 23, 66, 117, 239, 157, 231, 189, 160, + 79, 198, 30, 56, 137, 159, 220, 226, + 47, 211, 26, 73, 243, 252, 71, 214 +] +Uint8Array(32) [ + 18, 98, 66, 131, 76, 87, 93, 76, + 205, 81, 250, 112, 129, 119, 92, 9, + 116, 99, 5, 171, 8, 137, 132, 79, + 255, 9, 194, 1, 138, 85, 72, 189 +] diff --git a/cli/tests/testdata/single_compile_with_reload.ts b/cli/tests/testdata/single_compile_with_reload.ts new file mode 100644 index 000000000..f84e91f2f --- /dev/null +++ b/cli/tests/testdata/single_compile_with_reload.ts @@ -0,0 +1,18 @@ +await import("./single_compile_with_reload_dyn.ts"); +console.log("1"); +await import("./single_compile_with_reload_dyn.ts"); +console.log("2"); +await new Promise((r) => + new Worker( + new URL("single_compile_with_reload_worker.ts", import.meta.url).href, + { type: "module" }, + ).onmessage = r +); +console.log("3"); +await new Promise((r) => + new Worker( + new URL("single_compile_with_reload_worker.ts", import.meta.url).href, + { type: "module" }, + ).onmessage = r +); +console.log("4"); diff --git a/cli/tests/testdata/single_compile_with_reload.ts.out b/cli/tests/testdata/single_compile_with_reload.ts.out new file mode 100644 index 000000000..b0b2fcaf1 --- /dev/null +++ b/cli/tests/testdata/single_compile_with_reload.ts.out @@ -0,0 +1,9 @@ +Check [WILDCARD]single_compile_with_reload.ts +Hello +1 +2 +Check [WILDCARD]single_compile_with_reload_worker.ts +Hello from worker +3 +Hello from worker +4 diff --git a/cli/tests/testdata/single_compile_with_reload_dyn.ts b/cli/tests/testdata/single_compile_with_reload_dyn.ts new file mode 100644 index 000000000..0266bf46c --- /dev/null +++ b/cli/tests/testdata/single_compile_with_reload_dyn.ts @@ -0,0 +1,11 @@ +import { printHello3, returnsFoo2, returnsHi } from "./subdir/mod1.ts"; + +printHello3(); + +if (returnsHi() !== "Hi") { + throw Error("Unexpected"); +} + +if (returnsFoo2() !== "Foo") { + throw Error("Unexpected"); +} diff --git a/cli/tests/testdata/single_compile_with_reload_worker.ts b/cli/tests/testdata/single_compile_with_reload_worker.ts new file mode 100644 index 000000000..103cafe20 --- /dev/null +++ b/cli/tests/testdata/single_compile_with_reload_worker.ts @@ -0,0 +1,3 @@ +console.log("Hello from worker"); +postMessage(null); +close(); diff --git a/cli/tests/testdata/standalone_compiler_ops.ts b/cli/tests/testdata/standalone_compiler_ops.ts new file mode 100644 index 000000000..b95e1222e --- /dev/null +++ b/cli/tests/testdata/standalone_compiler_ops.ts @@ -0,0 +1,12 @@ +const { files } = await Deno.emit("/mod.ts", { + bundle: "classic", + sources: { + "/mod.ts": `import { hello } from "/hello.ts"; console.log(hello);`, + "/hello.ts": `export const hello: string = "Hello, Compiler API!"`, + }, + compilerOptions: { + sourceMap: false, + }, +}); + +eval(files["deno:///bundle.js"]); diff --git a/cli/tests/testdata/standalone_error.ts b/cli/tests/testdata/standalone_error.ts new file mode 100644 index 000000000..279398113 --- /dev/null +++ b/cli/tests/testdata/standalone_error.ts @@ -0,0 +1,9 @@ +function boom() { + throw new Error("boom!"); +} + +function foo() { + boom(); +} + +foo(); diff --git a/cli/tests/testdata/standalone_import.ts b/cli/tests/testdata/standalone_import.ts new file mode 100644 index 000000000..804102a53 --- /dev/null +++ b/cli/tests/testdata/standalone_import.ts @@ -0,0 +1,2 @@ +console.log("start"); +await import("./001_hello.js"); diff --git a/cli/tests/testdata/standalone_import_datauri.ts b/cli/tests/testdata/standalone_import_datauri.ts new file mode 100644 index 000000000..68f348828 --- /dev/null +++ b/cli/tests/testdata/standalone_import_datauri.ts @@ -0,0 +1,4 @@ +const c = await import( + "data:text/javascript;base64,ZXhwb3J0IGRlZmF1bHQgJ0hlbGxvIERlbm8hJw==" +); +console.log(c.default); // Output: "Hello Deno!" diff --git a/cli/tests/testdata/standalone_runtime_flags.ts b/cli/tests/testdata/standalone_runtime_flags.ts new file mode 100644 index 000000000..0154c7f4e --- /dev/null +++ b/cli/tests/testdata/standalone_runtime_flags.ts @@ -0,0 +1,3 @@ +console.log(Math.random()); +await Deno.stat("."); +await Deno.create("foo.txt"); diff --git a/cli/tests/testdata/std_lint.out b/cli/tests/testdata/std_lint.out new file mode 100644 index 000000000..9d62fcc67 --- /dev/null +++ b/cli/tests/testdata/std_lint.out @@ -0,0 +1,3 @@ +[WILDCARD] + +Found [WILDCARD] problems
\ No newline at end of file diff --git a/cli/tests/testdata/stdout_write_all.out b/cli/tests/testdata/stdout_write_all.out new file mode 100644 index 000000000..af5626b4a --- /dev/null +++ b/cli/tests/testdata/stdout_write_all.out @@ -0,0 +1 @@ +Hello, world! diff --git a/cli/tests/testdata/stdout_write_all.ts b/cli/tests/testdata/stdout_write_all.ts new file mode 100644 index 000000000..623bd8f53 --- /dev/null +++ b/cli/tests/testdata/stdout_write_all.ts @@ -0,0 +1,8 @@ +const encoder = new TextEncoder(); +const pending = [ + Deno.stdout.write(encoder.encode("Hello, ")), + Deno.stdout.write(encoder.encode("world!")), +]; + +await Promise.all(pending); +await Deno.stdout.write(encoder.encode("\n")); diff --git a/cli/tests/testdata/subdir/amd_like.js b/cli/tests/testdata/subdir/amd_like.js new file mode 100644 index 000000000..f27e505e4 --- /dev/null +++ b/cli/tests/testdata/subdir/amd_like.js @@ -0,0 +1,3 @@ +// looks like an AMD module, but isn't +const define = () => {}; +define(["fake_module"], () => {}); diff --git a/cli/tests/testdata/subdir/auto_print_hello.ts b/cli/tests/testdata/subdir/auto_print_hello.ts new file mode 100644 index 000000000..5efa72e03 --- /dev/null +++ b/cli/tests/testdata/subdir/auto_print_hello.ts @@ -0,0 +1,2 @@ +console.log("hello!"); +export default {}; diff --git a/cli/tests/testdata/subdir/circular1.ts b/cli/tests/testdata/subdir/circular1.ts new file mode 100644 index 000000000..06fdb3373 --- /dev/null +++ b/cli/tests/testdata/subdir/circular1.ts @@ -0,0 +1,7 @@ +import * as circular2 from "./circular2.ts"; + +export function f1() { + console.log("f1"); +} + +circular2.f2(); diff --git a/cli/tests/testdata/subdir/circular2.ts b/cli/tests/testdata/subdir/circular2.ts new file mode 100644 index 000000000..0864b7adf --- /dev/null +++ b/cli/tests/testdata/subdir/circular2.ts @@ -0,0 +1,7 @@ +import * as circular1 from "./circular1.ts"; + +export function f2() { + console.log("f2"); +} + +circular1.f1(); diff --git a/cli/tests/testdata/subdir/comment.ts b/cli/tests/testdata/subdir/comment.ts new file mode 100644 index 000000000..ea7e630c0 --- /dev/null +++ b/cli/tests/testdata/subdir/comment.ts @@ -0,0 +1,4 @@ +// This is a comment. +export function comment(): string { + return "comment"; +} diff --git a/cli/tests/testdata/subdir/config.json b/cli/tests/testdata/subdir/config.json new file mode 100644 index 000000000..01c3b5e79 --- /dev/null +++ b/cli/tests/testdata/subdir/config.json @@ -0,0 +1,6 @@ +{ + "foo": { + "bar": true, + "baz": ["qat", 1] + } +} diff --git a/cli/tests/testdata/subdir/emittable.d.ts b/cli/tests/testdata/subdir/emittable.d.ts new file mode 100644 index 000000000..425b80f24 --- /dev/null +++ b/cli/tests/testdata/subdir/emittable.d.ts @@ -0,0 +1 @@ +export const a: string; diff --git a/cli/tests/testdata/subdir/empty.ts b/cli/tests/testdata/subdir/empty.ts new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/cli/tests/testdata/subdir/empty.ts diff --git a/cli/tests/testdata/subdir/evil_remote_import.js b/cli/tests/testdata/subdir/evil_remote_import.js new file mode 100644 index 000000000..4ff7d1b97 --- /dev/null +++ b/cli/tests/testdata/subdir/evil_remote_import.js @@ -0,0 +1,4 @@ +// We expect to get a permission denied error if we dynamically +// import this module without --allow-read. +export * from "file:///c:/etc/passwd"; +console.log("Hello from evil_remote_import.js"); diff --git a/cli/tests/testdata/subdir/foo_types.d.ts b/cli/tests/testdata/subdir/foo_types.d.ts new file mode 100644 index 000000000..c489584b9 --- /dev/null +++ b/cli/tests/testdata/subdir/foo_types.d.ts @@ -0,0 +1,3 @@ +declare namespace Foo { + const bar: string; +} diff --git a/cli/tests/testdata/subdir/form_urlencoded.txt b/cli/tests/testdata/subdir/form_urlencoded.txt new file mode 100644 index 000000000..70e087c20 --- /dev/null +++ b/cli/tests/testdata/subdir/form_urlencoded.txt @@ -0,0 +1 @@ +field_1=Hi&field_2=%3CDeno%3E
\ No newline at end of file diff --git a/cli/tests/testdata/subdir/indirect_import_error.js b/cli/tests/testdata/subdir/indirect_import_error.js new file mode 100644 index 000000000..84011d291 --- /dev/null +++ b/cli/tests/testdata/subdir/indirect_import_error.js @@ -0,0 +1 @@ +export * from "does not exist either"; diff --git a/cli/tests/testdata/subdir/indirect_throws.js b/cli/tests/testdata/subdir/indirect_throws.js new file mode 100644 index 000000000..e1810a66c --- /dev/null +++ b/cli/tests/testdata/subdir/indirect_throws.js @@ -0,0 +1 @@ +export * from "./throws.js"; diff --git a/cli/tests/testdata/subdir/json_1.json b/cli/tests/testdata/subdir/json_1.json new file mode 100644 index 000000000..754d16b84 --- /dev/null +++ b/cli/tests/testdata/subdir/json_1.json @@ -0,0 +1,5 @@ +{ + "$var": { "a": 123, "b": [1, 2, 3], "c": null }, + "with space": "invalid variable name", + "function": "reserved word" +} diff --git a/cli/tests/testdata/subdir/json_2.json b/cli/tests/testdata/subdir/json_2.json new file mode 100644 index 000000000..7deb8b173 --- /dev/null +++ b/cli/tests/testdata/subdir/json_2.json @@ -0,0 +1 @@ +"just a string" diff --git a/cli/tests/testdata/subdir/main.ts b/cli/tests/testdata/subdir/main.ts new file mode 100644 index 000000000..29acf42e0 --- /dev/null +++ b/cli/tests/testdata/subdir/main.ts @@ -0,0 +1,3 @@ +if (import.meta.main) { + console.log("Hello, world!"); +} diff --git a/cli/tests/testdata/subdir/mismatch_ext.ts b/cli/tests/testdata/subdir/mismatch_ext.ts new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/testdata/subdir/mismatch_ext.ts @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/testdata/subdir/mod1.ts b/cli/tests/testdata/subdir/mod1.ts new file mode 100644 index 000000000..5e58f432e --- /dev/null +++ b/cli/tests/testdata/subdir/mod1.ts @@ -0,0 +1,17 @@ +import { printHello2, returnsFoo } from "./subdir2/mod2.ts"; + +export function returnsHi(): string { + return "Hi"; +} + +export function returnsFoo2(): string { + return returnsFoo(); +} + +export function printHello3() { + printHello2(); +} + +export function throwsError() { + throw Error("exception from mod1"); +} diff --git a/cli/tests/testdata/subdir/mod2.ts b/cli/tests/testdata/subdir/mod2.ts new file mode 100644 index 000000000..ce1adc0e8 --- /dev/null +++ b/cli/tests/testdata/subdir/mod2.ts @@ -0,0 +1 @@ +export { printHello } from "./print_hello.ts"; diff --git a/cli/tests/testdata/subdir/mod3.js b/cli/tests/testdata/subdir/mod3.js new file mode 100644 index 000000000..ce534f570 --- /dev/null +++ b/cli/tests/testdata/subdir/mod3.js @@ -0,0 +1 @@ +export const isTSFile = false; diff --git a/cli/tests/testdata/subdir/mod4.js b/cli/tests/testdata/subdir/mod4.js new file mode 100644 index 000000000..71332dbc4 --- /dev/null +++ b/cli/tests/testdata/subdir/mod4.js @@ -0,0 +1 @@ +export const isMod4 = true; diff --git a/cli/tests/testdata/subdir/mod5.mjs b/cli/tests/testdata/subdir/mod5.mjs new file mode 100644 index 000000000..f21d8862b --- /dev/null +++ b/cli/tests/testdata/subdir/mod5.mjs @@ -0,0 +1 @@ +export const isMod5 = true; diff --git a/cli/tests/testdata/subdir/mod6.js b/cli/tests/testdata/subdir/mod6.js new file mode 100644 index 000000000..5e17c9ee0 --- /dev/null +++ b/cli/tests/testdata/subdir/mod6.js @@ -0,0 +1 @@ +export { isMod4 } from "./mod4.js"; diff --git a/cli/tests/testdata/subdir/more_decorators.ts b/cli/tests/testdata/subdir/more_decorators.ts new file mode 100644 index 000000000..674705d56 --- /dev/null +++ b/cli/tests/testdata/subdir/more_decorators.ts @@ -0,0 +1,18 @@ +// deno-lint-ignore-file +function a() { + console.log("a(): evaluated"); + return ( + _target: any, + _propertyKey: string, + _descriptor: PropertyDescriptor, + ) => { + console.log("a(): called"); + }; +} + +export class B { + @a() + method() { + console.log("method"); + } +} diff --git a/cli/tests/testdata/subdir/mt_application_ecmascript.j2.js b/cli/tests/testdata/subdir/mt_application_ecmascript.j2.js new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/testdata/subdir/mt_application_ecmascript.j2.js @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/testdata/subdir/mt_application_ecmascript_jsx.j2.jsx b/cli/tests/testdata/subdir/mt_application_ecmascript_jsx.j2.jsx new file mode 100644 index 000000000..c5c27f9f9 --- /dev/null +++ b/cli/tests/testdata/subdir/mt_application_ecmascript_jsx.j2.jsx @@ -0,0 +1,5 @@ +const React = { + createElement() {}, +}; +const temp = <div></div>; +export const loaded = true; diff --git a/cli/tests/testdata/subdir/mt_application_x_javascript.j4.js b/cli/tests/testdata/subdir/mt_application_x_javascript.j4.js new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/testdata/subdir/mt_application_x_javascript.j4.js @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/testdata/subdir/mt_application_x_javascript_jsx.j4.jsx b/cli/tests/testdata/subdir/mt_application_x_javascript_jsx.j4.jsx new file mode 100644 index 000000000..c5c27f9f9 --- /dev/null +++ b/cli/tests/testdata/subdir/mt_application_x_javascript_jsx.j4.jsx @@ -0,0 +1,5 @@ +const React = { + createElement() {}, +}; +const temp = <div></div>; +export const loaded = true; diff --git a/cli/tests/testdata/subdir/mt_application_x_typescript.t4.ts b/cli/tests/testdata/subdir/mt_application_x_typescript.t4.ts new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/testdata/subdir/mt_application_x_typescript.t4.ts @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/testdata/subdir/mt_application_x_typescript_tsx.t4.tsx b/cli/tests/testdata/subdir/mt_application_x_typescript_tsx.t4.tsx new file mode 100644 index 000000000..c5c27f9f9 --- /dev/null +++ b/cli/tests/testdata/subdir/mt_application_x_typescript_tsx.t4.tsx @@ -0,0 +1,5 @@ +const React = { + createElement() {}, +}; +const temp = <div></div>; +export const loaded = true; diff --git a/cli/tests/testdata/subdir/mt_javascript.js b/cli/tests/testdata/subdir/mt_javascript.js new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/testdata/subdir/mt_javascript.js @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/testdata/subdir/mt_javascript_jsx.jsx b/cli/tests/testdata/subdir/mt_javascript_jsx.jsx new file mode 100644 index 000000000..c5c27f9f9 --- /dev/null +++ b/cli/tests/testdata/subdir/mt_javascript_jsx.jsx @@ -0,0 +1,5 @@ +const React = { + createElement() {}, +}; +const temp = <div></div>; +export const loaded = true; diff --git a/cli/tests/testdata/subdir/mt_text_ecmascript.j3.js b/cli/tests/testdata/subdir/mt_text_ecmascript.j3.js new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/testdata/subdir/mt_text_ecmascript.j3.js @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/testdata/subdir/mt_text_ecmascript_jsx.j3.jsx b/cli/tests/testdata/subdir/mt_text_ecmascript_jsx.j3.jsx new file mode 100644 index 000000000..c5c27f9f9 --- /dev/null +++ b/cli/tests/testdata/subdir/mt_text_ecmascript_jsx.j3.jsx @@ -0,0 +1,5 @@ +const React = { + createElement() {}, +}; +const temp = <div></div>; +export const loaded = true; diff --git a/cli/tests/testdata/subdir/mt_text_javascript.j1.js b/cli/tests/testdata/subdir/mt_text_javascript.j1.js new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/testdata/subdir/mt_text_javascript.j1.js @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/testdata/subdir/mt_text_javascript_jsx.j1.jsx b/cli/tests/testdata/subdir/mt_text_javascript_jsx.j1.jsx new file mode 100644 index 000000000..c5c27f9f9 --- /dev/null +++ b/cli/tests/testdata/subdir/mt_text_javascript_jsx.j1.jsx @@ -0,0 +1,5 @@ +const React = { + createElement() {}, +}; +const temp = <div></div>; +export const loaded = true; diff --git a/cli/tests/testdata/subdir/mt_text_typescript.t1.ts b/cli/tests/testdata/subdir/mt_text_typescript.t1.ts new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/testdata/subdir/mt_text_typescript.t1.ts @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/testdata/subdir/mt_text_typescript_tsx.t1.tsx b/cli/tests/testdata/subdir/mt_text_typescript_tsx.t1.tsx new file mode 100644 index 000000000..c5c27f9f9 --- /dev/null +++ b/cli/tests/testdata/subdir/mt_text_typescript_tsx.t1.tsx @@ -0,0 +1,5 @@ +const React = { + createElement() {}, +}; +const temp = <div></div>; +export const loaded = true; diff --git a/cli/tests/testdata/subdir/mt_video_mp2t.t3.ts b/cli/tests/testdata/subdir/mt_video_mp2t.t3.ts new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/testdata/subdir/mt_video_mp2t.t3.ts @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/testdata/subdir/mt_video_mp2t_tsx.t3.tsx b/cli/tests/testdata/subdir/mt_video_mp2t_tsx.t3.tsx new file mode 100644 index 000000000..c5c27f9f9 --- /dev/null +++ b/cli/tests/testdata/subdir/mt_video_mp2t_tsx.t3.tsx @@ -0,0 +1,5 @@ +const React = { + createElement() {}, +}; +const temp = <div></div>; +export const loaded = true; diff --git a/cli/tests/testdata/subdir/mt_video_vdn.t2.ts b/cli/tests/testdata/subdir/mt_video_vdn.t2.ts new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/testdata/subdir/mt_video_vdn.t2.ts @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/testdata/subdir/mt_video_vdn_tsx.t2.tsx b/cli/tests/testdata/subdir/mt_video_vdn_tsx.t2.tsx new file mode 100644 index 000000000..c5c27f9f9 --- /dev/null +++ b/cli/tests/testdata/subdir/mt_video_vdn_tsx.t2.tsx @@ -0,0 +1,5 @@ +const React = { + createElement() {}, +}; +const temp = <div></div>; +export const loaded = true; diff --git a/cli/tests/testdata/subdir/no_ext b/cli/tests/testdata/subdir/no_ext new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/testdata/subdir/no_ext @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/testdata/subdir/no_js_ext b/cli/tests/testdata/subdir/no_js_ext new file mode 100644 index 000000000..8322a106f --- /dev/null +++ b/cli/tests/testdata/subdir/no_js_ext @@ -0,0 +1,3 @@ +// @ts-check +import { printHello } from "./mod2.ts"; +printHello(); diff --git a/cli/tests/testdata/subdir/polyfill.ts b/cli/tests/testdata/subdir/polyfill.ts new file mode 100644 index 000000000..e1cd923cb --- /dev/null +++ b/cli/tests/testdata/subdir/polyfill.ts @@ -0,0 +1,10 @@ +declare global { + const polyfill: () => void; +} + +export {}; + +// deno-lint-ignore no-explicit-any +(globalThis as any).polyfill = () => { + console.log("polyfill"); +}; diff --git a/cli/tests/testdata/subdir/print_hello.ts b/cli/tests/testdata/subdir/print_hello.ts new file mode 100644 index 000000000..b9c0ad527 --- /dev/null +++ b/cli/tests/testdata/subdir/print_hello.ts @@ -0,0 +1,3 @@ +export function printHello() { + console.log("Hello"); +} diff --git a/cli/tests/testdata/subdir/redirects/a.ts b/cli/tests/testdata/subdir/redirects/a.ts new file mode 100644 index 000000000..071ee4728 --- /dev/null +++ b/cli/tests/testdata/subdir/redirects/a.ts @@ -0,0 +1,9 @@ +import { createA } from "./b.ts"; + +export class A { + private _a = "a"; +} + +export function start(): A { + return createA(); +} diff --git a/cli/tests/testdata/subdir/redirects/b.ts b/cli/tests/testdata/subdir/redirects/b.ts new file mode 100644 index 000000000..cdb71eaae --- /dev/null +++ b/cli/tests/testdata/subdir/redirects/b.ts @@ -0,0 +1,5 @@ +import { A } from "./a.ts"; + +export function createA(): A { + return new A(); +} diff --git a/cli/tests/testdata/subdir/redirects/redirect1.js b/cli/tests/testdata/subdir/redirects/redirect1.js new file mode 100644 index 000000000..d674be88c --- /dev/null +++ b/cli/tests/testdata/subdir/redirects/redirect1.js @@ -0,0 +1 @@ +export const redirect = 1; diff --git a/cli/tests/testdata/subdir/redirects/redirect1.ts b/cli/tests/testdata/subdir/redirects/redirect1.ts new file mode 100644 index 000000000..d674be88c --- /dev/null +++ b/cli/tests/testdata/subdir/redirects/redirect1.ts @@ -0,0 +1 @@ +export const redirect = 1; diff --git a/cli/tests/testdata/subdir/redirects/redirect2.js b/cli/tests/testdata/subdir/redirects/redirect2.js new file mode 100644 index 000000000..e4244f638 --- /dev/null +++ b/cli/tests/testdata/subdir/redirects/redirect2.js @@ -0,0 +1 @@ +import "./redirect1.js"; diff --git a/cli/tests/testdata/subdir/redirects/redirect3.js b/cli/tests/testdata/subdir/redirects/redirect3.js new file mode 100644 index 000000000..e24f2af32 --- /dev/null +++ b/cli/tests/testdata/subdir/redirects/redirect3.js @@ -0,0 +1,2 @@ +import { redirect } from "./redirect1.js"; +export const value = `3 imports ${redirect}`; diff --git a/cli/tests/testdata/subdir/redirects/redirect4.ts b/cli/tests/testdata/subdir/redirects/redirect4.ts new file mode 100644 index 000000000..45c65c5eb --- /dev/null +++ b/cli/tests/testdata/subdir/redirects/redirect4.ts @@ -0,0 +1,2 @@ +import { redirect } from "./redirect1.ts"; +export const value = `4 imports ${redirect}`; diff --git a/cli/tests/testdata/subdir/single_module.ts b/cli/tests/testdata/subdir/single_module.ts new file mode 100644 index 000000000..f41b0a4b5 --- /dev/null +++ b/cli/tests/testdata/subdir/single_module.ts @@ -0,0 +1,2 @@ +console.log("Hello world!"); +export {}; // TODO(ry) This shouldn't be necessary. diff --git a/cli/tests/testdata/subdir/subdir2/dynamic_import.ts b/cli/tests/testdata/subdir/subdir2/dynamic_import.ts new file mode 100644 index 000000000..573887b71 --- /dev/null +++ b/cli/tests/testdata/subdir/subdir2/dynamic_import.ts @@ -0,0 +1,6 @@ +(async () => { + const { printHello } = await import("../mod2.ts"); + printHello(); +})(); + +export {}; diff --git a/cli/tests/testdata/subdir/subdir2/mod2.ts b/cli/tests/testdata/subdir/subdir2/mod2.ts new file mode 100644 index 000000000..9071d0aeb --- /dev/null +++ b/cli/tests/testdata/subdir/subdir2/mod2.ts @@ -0,0 +1,9 @@ +import { printHello } from "../print_hello.ts"; + +export function returnsFoo(): string { + return "Foo"; +} + +export function printHello2() { + printHello(); +} diff --git a/cli/tests/testdata/subdir/test_worker_basic.js b/cli/tests/testdata/subdir/test_worker_basic.js new file mode 100644 index 000000000..b960128b4 --- /dev/null +++ b/cli/tests/testdata/subdir/test_worker_basic.js @@ -0,0 +1,14 @@ +console.log("hello from test_worker_basic.js"); + +if (self.name !== "jsWorker") { + throw Error(`Bad worker name: ${self.name}, expected jsWorker`); +} + +onmessage = function (e) { + postMessage(e.data); + close(); +}; + +onerror = function () { + return false; +}; diff --git a/cli/tests/testdata/subdir/throws.js b/cli/tests/testdata/subdir/throws.js new file mode 100644 index 000000000..abdf29156 --- /dev/null +++ b/cli/tests/testdata/subdir/throws.js @@ -0,0 +1,6 @@ +// deno-lint-ignore-file +export function boo() { + console.log("Boo!"); +} + +throw new Error("An error"); diff --git a/cli/tests/testdata/subdir/tla.ts b/cli/tests/testdata/subdir/tla.ts new file mode 100644 index 000000000..713dbfca0 --- /dev/null +++ b/cli/tests/testdata/subdir/tla.ts @@ -0,0 +1 @@ +export const foo = await Promise.resolve("Hello"); diff --git a/cli/tests/testdata/subdir/type_and_code.ts b/cli/tests/testdata/subdir/type_and_code.ts new file mode 100644 index 000000000..b14713419 --- /dev/null +++ b/cli/tests/testdata/subdir/type_and_code.ts @@ -0,0 +1,7 @@ +export interface AnInterface { + a: string; +} + +export function isAnInterface(value: unknown): value is AnInterface { + return value && typeof value === "object" && "a" in value; +} diff --git a/cli/tests/testdata/subdir/type_reference.d.ts b/cli/tests/testdata/subdir/type_reference.d.ts new file mode 100644 index 000000000..f9b8de5ed --- /dev/null +++ b/cli/tests/testdata/subdir/type_reference.d.ts @@ -0,0 +1 @@ +export const foo: "foo"; diff --git a/cli/tests/testdata/subdir/type_reference.js b/cli/tests/testdata/subdir/type_reference.js new file mode 100644 index 000000000..917d89198 --- /dev/null +++ b/cli/tests/testdata/subdir/type_reference.js @@ -0,0 +1,3 @@ +/// <reference types="./type_reference.d.ts" /> + +export const foo = "foo"; diff --git a/cli/tests/testdata/subdir/types.d.ts b/cli/tests/testdata/subdir/types.d.ts new file mode 100644 index 000000000..7f587e144 --- /dev/null +++ b/cli/tests/testdata/subdir/types.d.ts @@ -0,0 +1 @@ +declare var a: string; diff --git a/cli/tests/testdata/subdir/unknown_ext.deno b/cli/tests/testdata/subdir/unknown_ext.deno new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/testdata/subdir/unknown_ext.deno @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/testdata/swc_syntax_error.ts b/cli/tests/testdata/swc_syntax_error.ts new file mode 100644 index 000000000..991ca9214 --- /dev/null +++ b/cli/tests/testdata/swc_syntax_error.ts @@ -0,0 +1,4 @@ +// deno-fmt-ignore-file +for await (const req of s) { + let something: +} diff --git a/cli/tests/testdata/swc_syntax_error.ts.out b/cli/tests/testdata/swc_syntax_error.ts.out new file mode 100644 index 000000000..53ed29cb6 --- /dev/null +++ b/cli/tests/testdata/swc_syntax_error.ts.out @@ -0,0 +1 @@ +error: Unexpected token `}`. Expected an identifier, void, yield, null, await, break, a string literal, a numeric literal, true, false, `, -, import, this, typeof, {, [, ( at [WILDCARD]syntax_error.ts:4:0 diff --git a/cli/tests/testdata/symlink_to_subdir b/cli/tests/testdata/symlink_to_subdir new file mode 120000 index 000000000..fe0c45aa4 --- /dev/null +++ b/cli/tests/testdata/symlink_to_subdir @@ -0,0 +1 @@ +subdir/
\ No newline at end of file diff --git a/cli/tests/testdata/test/allow_all.out b/cli/tests/testdata/test/allow_all.out new file mode 100644 index 000000000..9b7367b94 --- /dev/null +++ b/cli/tests/testdata/test/allow_all.out @@ -0,0 +1,18 @@ +[WILDCARD] +running 14 tests from [WILDCARD] +test read false ... ok [WILDCARD] +test read true ... ok [WILDCARD] +test write false ... ok [WILDCARD] +test write true ... ok [WILDCARD] +test net false ... ok [WILDCARD] +test net true ... ok [WILDCARD] +test env false ... ok [WILDCARD] +test env true ... ok [WILDCARD] +test run false ... ok [WILDCARD] +test run true ... ok [WILDCARD] +test ffi false ... ok [WILDCARD] +test ffi true ... ok [WILDCARD] +test hrtime false ... ok [WILDCARD] +test hrtime true ... ok [WILDCARD] + +test result: ok. 14 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out [WILDCARD] diff --git a/cli/tests/testdata/test/allow_all.ts b/cli/tests/testdata/test/allow_all.ts new file mode 100644 index 000000000..abe55a8d5 --- /dev/null +++ b/cli/tests/testdata/test/allow_all.ts @@ -0,0 +1,35 @@ +import { assertEquals } from "../../../../test_util/std/testing/asserts.ts"; + +const permissions: Deno.PermissionName[] = [ + "read", + "write", + "net", + "env", + "run", + "ffi", + "hrtime", +]; + +for (const name of permissions) { + Deno.test({ + name: `${name} false`, + permissions: { + [name]: false, + }, + async fn() { + const status = await Deno.permissions.query({ name }); + assertEquals(status.state, "denied"); + }, + }); + + Deno.test({ + name: `${name} true`, + permissions: { + [name]: true, + }, + async fn() { + const status = await Deno.permissions.query({ name }); + assertEquals(status.state, "granted"); + }, + }); +} diff --git a/cli/tests/testdata/test/allow_none.out b/cli/tests/testdata/test/allow_none.out new file mode 100644 index 000000000..b79c7e6bf --- /dev/null +++ b/cli/tests/testdata/test/allow_none.out @@ -0,0 +1,51 @@ +[WILDCARD] +running 7 tests from [WILDCARD] +test read ... FAILED [WILDCARD] +test write ... FAILED [WILDCARD] +test net ... FAILED [WILDCARD] +test env ... FAILED [WILDCARD] +test run ... FAILED [WILDCARD] +test ffi ... FAILED [WILDCARD] +test hrtime ... FAILED [WILDCARD] + +failures: + +read +PermissionDenied: Can't escalate parent thread permissions +[WILDCARD] + +write +PermissionDenied: Can't escalate parent thread permissions +[WILDCARD] + +net +PermissionDenied: Can't escalate parent thread permissions +[WILDCARD] + +env +PermissionDenied: Can't escalate parent thread permissions +[WILDCARD] + +run +PermissionDenied: Can't escalate parent thread permissions +[WILDCARD] + +ffi +PermissionDenied: Can't escalate parent thread permissions +[WILDCARD] + +hrtime +PermissionDenied: Can't escalate parent thread permissions +[WILDCARD] + +failures: + + read + write + net + env + run + ffi + hrtime + +test result: FAILED. 0 passed; 7 failed; 0 ignored; 0 measured; 0 filtered out [WILDCARD] diff --git a/cli/tests/testdata/test/allow_none.ts b/cli/tests/testdata/test/allow_none.ts new file mode 100644 index 000000000..3153b9755 --- /dev/null +++ b/cli/tests/testdata/test/allow_none.ts @@ -0,0 +1,23 @@ +import { unreachable } from "../../../../test_util/std/testing/asserts.ts"; + +const permissions: Deno.PermissionName[] = [ + "read", + "write", + "net", + "env", + "run", + "ffi", + "hrtime", +]; + +for (const name of permissions) { + Deno.test({ + name, + permissions: { + [name]: true, + }, + fn() { + unreachable(); + }, + }); +} diff --git a/cli/tests/testdata/test/clear_timeout.out b/cli/tests/testdata/test/clear_timeout.out new file mode 100644 index 000000000..c9f459dbe --- /dev/null +++ b/cli/tests/testdata/test/clear_timeout.out @@ -0,0 +1,8 @@ +Check [WILDCARD]/test/clear_timeout.ts +running 3 tests from [WILDCARD]/test/clear_timeout.ts +test test 1 ... ok ([WILDCARD]) +test test 2 ... ok ([WILDCARD]) +test test 3 ... ok ([WILDCARD]) + +test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + diff --git a/cli/tests/testdata/test/clear_timeout.ts b/cli/tests/testdata/test/clear_timeout.ts new file mode 100644 index 000000000..00056e853 --- /dev/null +++ b/cli/tests/testdata/test/clear_timeout.ts @@ -0,0 +1,5 @@ +clearTimeout(setTimeout(() => {}, 1000)); + +Deno.test("test 1", () => {}); +Deno.test("test 2", () => {}); +Deno.test("test 3", () => {}); diff --git a/cli/tests/testdata/test/doc.out b/cli/tests/testdata/test/doc.out new file mode 100644 index 000000000..91ecbd4d4 --- /dev/null +++ b/cli/tests/testdata/test/doc.out @@ -0,0 +1,10 @@ +Check [WILDCARD]/doc.ts$2-5.ts +Check [WILDCARD]/doc.ts$6-9.js +Check [WILDCARD]/doc.ts$10-13.jsx +Check [WILDCARD]/doc.ts$14-17.ts +Check [WILDCARD]/doc.ts$18-21.tsx +Check [WILDCARD]/doc.ts$30-35.ts +error: TS2367 [ERROR]: This condition will always return 'false' since the types 'string' and 'number' have no overlap. +console.assert(check() == 42); + ~~~~~~~~~~~~~ + at [WILDCARD]/doc.ts$30-35.ts:3:16 diff --git a/cli/tests/testdata/test/doc.ts b/cli/tests/testdata/test/doc.ts new file mode 100644 index 000000000..52fe6bdf0 --- /dev/null +++ b/cli/tests/testdata/test/doc.ts @@ -0,0 +1,38 @@ +/** + * ``` + * import * as doc from "./doc.ts"; + * ``` + * + * ```js + * import * as doc from "./doc.ts"; + * ``` + * + * ```jsx + * import * as doc from "./doc.ts"; + * ``` + * + * ```ts + * import * as doc from "./doc.ts"; + * ``` + * + * ```tsx + * import * as doc from "./doc.ts"; + * ``` + * + * ```text + * import * as doc from "./doc.ts"; + * ``` + * + * @module doc + */ + +/** + * ``` + * import { check } from "./doc.ts"; + * + * console.assert(check() == 42); + * ``` + */ +export function check(): string { + return "check"; +} diff --git a/cli/tests/testdata/test/doc_markdown.out b/cli/tests/testdata/test/doc_markdown.out new file mode 100644 index 000000000..9d2c35974 --- /dev/null +++ b/cli/tests/testdata/test/doc_markdown.out @@ -0,0 +1,7 @@ +Check [WILDCARD]/test/doc_markdown/doc.md$11-14.js +Check [WILDCARD]/test/doc_markdown/doc.md$17-20.ts +Check [WILDCARD]/test/doc_markdown/doc.md$23-26.ts +error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'. +const a: string = 42; + ^ + at [WILDCARD]/test/doc_markdown/doc.md$23-26.ts:1:7 diff --git a/cli/tests/testdata/test/doc_markdown/doc.md b/cli/tests/testdata/test/doc_markdown/doc.md new file mode 100644 index 000000000..e5afb841b --- /dev/null +++ b/cli/tests/testdata/test/doc_markdown/doc.md @@ -0,0 +1,25 @@ +# Documentation + +The following block does not have a language attribute and should be ignored: + +``` +This is a fenced block without attributes, it's invalid and it should be ignored. +``` + +The following block should be given a js extension on extraction: + +```js +console.log("js"); +``` + +The following block should be given a ts extension on extraction: + +```ts +console.log("ts"); +``` + +The following example will trigger the type-checker to fail: + +```ts +const a: string = 42; +``` diff --git a/cli/tests/testdata/test/exit_sanitizer.out b/cli/tests/testdata/test/exit_sanitizer.out new file mode 100644 index 000000000..f331d7a70 --- /dev/null +++ b/cli/tests/testdata/test/exit_sanitizer.out @@ -0,0 +1,35 @@ +Check [WILDCARD]/test/exit_sanitizer.ts +running 3 tests from [WILDCARD]/test/exit_sanitizer.ts +test exit(0) ... FAILED ([WILDCARD]) +test exit(1) ... FAILED ([WILDCARD]) +test exit(2) ... FAILED ([WILDCARD]) + +failures: + +exit(0) +AssertionError: Test case attempted to exit with exit code: 0 + at [WILDCARD] + at [WILDCARD]/test/exit_sanitizer.ts:2:8 + at [WILDCARD] + +exit(1) +AssertionError: Test case attempted to exit with exit code: 1 + at [WILDCARD] + at [WILDCARD]/test/exit_sanitizer.ts:6:8 + at [WILDCARD] + +exit(2) +AssertionError: Test case attempted to exit with exit code: 2 + at [WILDCARD] + at [WILDCARD]/test/exit_sanitizer.ts:10:8 + at [WILDCARD] + +failures: + + exit(0) + exit(1) + exit(2) + +test result: FAILED. 0 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + +error: Test failed diff --git a/cli/tests/testdata/test/exit_sanitizer.ts b/cli/tests/testdata/test/exit_sanitizer.ts new file mode 100644 index 000000000..186406a9d --- /dev/null +++ b/cli/tests/testdata/test/exit_sanitizer.ts @@ -0,0 +1,11 @@ +Deno.test("exit(0)", function () { + Deno.exit(0); +}); + +Deno.test("exit(1)", function () { + Deno.exit(1); +}); + +Deno.test("exit(2)", function () { + Deno.exit(2); +}); diff --git a/cli/tests/testdata/test/fail.out b/cli/tests/testdata/test/fail.out new file mode 100644 index 000000000..66d471cdf --- /dev/null +++ b/cli/tests/testdata/test/fail.out @@ -0,0 +1,81 @@ +Check [WILDCARD]/test/fail.ts +running 10 tests from [WILDCARD]/test/fail.ts +test test 0 ... FAILED ([WILDCARD]) +test test 1 ... FAILED ([WILDCARD]) +test test 2 ... FAILED ([WILDCARD]) +test test 3 ... FAILED ([WILDCARD]) +test test 4 ... FAILED ([WILDCARD]) +test test 5 ... FAILED ([WILDCARD]) +test test 6 ... FAILED ([WILDCARD]) +test test 7 ... FAILED ([WILDCARD]) +test test 8 ... FAILED ([WILDCARD]) +test test 9 ... FAILED ([WILDCARD]) + +failures: + +test 0 +Error + at [WILDCARD]/test/fail.ts:2:9 + at [WILDCARD] + +test 1 +Error + at [WILDCARD]/test/fail.ts:5:9 + at [WILDCARD] + +test 2 +Error + at [WILDCARD]/test/fail.ts:8:9 + at [WILDCARD] + +test 3 +Error + at [WILDCARD]/test/fail.ts:11:9 + at [WILDCARD] + +test 4 +Error + at [WILDCARD]/test/fail.ts:14:9 + at [WILDCARD] + +test 5 +Error + at [WILDCARD]/test/fail.ts:17:9 + at [WILDCARD] + +test 6 +Error + at [WILDCARD]/test/fail.ts:20:9 + at [WILDCARD] + +test 7 +Error + at [WILDCARD]/test/fail.ts:23:9 + at [WILDCARD] + +test 8 +Error + at [WILDCARD]/test/fail.ts:26:9 + at [WILDCARD] + +test 9 +Error + at [WILDCARD]/test/fail.ts:29:9 + at [WILDCARD] + +failures: + + test 0 + test 1 + test 2 + test 3 + test 4 + test 5 + test 6 + test 7 + test 8 + test 9 + +test result: FAILED. 0 passed; 10 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + +error: Test failed diff --git a/cli/tests/testdata/test/fail.ts b/cli/tests/testdata/test/fail.ts new file mode 100644 index 000000000..9340db556 --- /dev/null +++ b/cli/tests/testdata/test/fail.ts @@ -0,0 +1,30 @@ +Deno.test("test 0", () => { + throw new Error(); +}); +Deno.test("test 1", () => { + throw new Error(); +}); +Deno.test("test 2", () => { + throw new Error(); +}); +Deno.test("test 3", () => { + throw new Error(); +}); +Deno.test("test 4", () => { + throw new Error(); +}); +Deno.test("test 5", () => { + throw new Error(); +}); +Deno.test("test 6", () => { + throw new Error(); +}); +Deno.test("test 7", () => { + throw new Error(); +}); +Deno.test("test 8", () => { + throw new Error(); +}); +Deno.test("test 9", () => { + throw new Error(); +}); diff --git a/cli/tests/testdata/test/fail_fast.out b/cli/tests/testdata/test/fail_fast.out new file mode 100644 index 000000000..c97f854fa --- /dev/null +++ b/cli/tests/testdata/test/fail_fast.out @@ -0,0 +1,18 @@ +Check [WILDCARD]/test/fail_fast.ts +running 10 tests from [WILDCARD]/test/fail_fast.ts +test test 1 ... FAILED ([WILDCARD]) + +failures: + +test 1 +Error + at [WILDCARD]/test/fail_fast.ts:2:9 + at [WILDCARD] + +failures: + + test 1 + +test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + +error: Test failed diff --git a/cli/tests/testdata/test/fail_fast.ts b/cli/tests/testdata/test/fail_fast.ts new file mode 100644 index 000000000..637e825ec --- /dev/null +++ b/cli/tests/testdata/test/fail_fast.ts @@ -0,0 +1,30 @@ +Deno.test("test 1", () => { + throw new Error(); +}); +Deno.test("test 2", () => { + throw new Error(); +}); +Deno.test("test 3", () => { + throw new Error(); +}); +Deno.test("test 4", () => { + throw new Error(); +}); +Deno.test("test 5", () => { + throw new Error(); +}); +Deno.test("test 6", () => { + throw new Error(); +}); +Deno.test("test 7", () => { + throw new Error(); +}); +Deno.test("test 8", () => { + throw new Error(); +}); +Deno.test("test 9", () => { + throw new Error(); +}); +Deno.test("test 0", () => { + throw new Error(); +}); diff --git a/cli/tests/testdata/test/fail_fast_with_val.out b/cli/tests/testdata/test/fail_fast_with_val.out new file mode 100644 index 000000000..a902e4c7b --- /dev/null +++ b/cli/tests/testdata/test/fail_fast_with_val.out @@ -0,0 +1,23 @@ +[WILDCARD] +running 10 tests from [WILDCARD]/test/fail_fast_with_val.ts +test test 1 ... FAILED ([WILDCARD]) +test test 2 ... FAILED ([WILDCARD]) + +failures: + +test 1 +Error + at [WILDCARD]/test/fail_fast_with_val.ts:2:9 + at [WILDCARD] + +test 2 +Error + at [WILDCARD]/test/fail_fast_with_val.ts:5:9 + at [WILDCARD] + +failures: + + test 1 + test 2 + +test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) diff --git a/cli/tests/testdata/test/fail_fast_with_val.ts b/cli/tests/testdata/test/fail_fast_with_val.ts new file mode 100644 index 000000000..637e825ec --- /dev/null +++ b/cli/tests/testdata/test/fail_fast_with_val.ts @@ -0,0 +1,30 @@ +Deno.test("test 1", () => { + throw new Error(); +}); +Deno.test("test 2", () => { + throw new Error(); +}); +Deno.test("test 3", () => { + throw new Error(); +}); +Deno.test("test 4", () => { + throw new Error(); +}); +Deno.test("test 5", () => { + throw new Error(); +}); +Deno.test("test 6", () => { + throw new Error(); +}); +Deno.test("test 7", () => { + throw new Error(); +}); +Deno.test("test 8", () => { + throw new Error(); +}); +Deno.test("test 9", () => { + throw new Error(); +}); +Deno.test("test 0", () => { + throw new Error(); +}); diff --git a/cli/tests/testdata/test/finally_timeout.out b/cli/tests/testdata/test/finally_timeout.out new file mode 100644 index 000000000..570e9108f --- /dev/null +++ b/cli/tests/testdata/test/finally_timeout.out @@ -0,0 +1,19 @@ +Check [WILDCARD]/test/finally_timeout.ts +running 2 tests from [WILDCARD]/test/finally_timeout.ts +test error ... FAILED ([WILDCARD]) +test success ... ok ([WILDCARD]) + +failures: + +error +Error: fail + at [WILDCARD]/test/finally_timeout.ts:4:11 + at [WILDCARD] + +failures: + + error + +test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + +error: Test failed diff --git a/cli/tests/testdata/test/finally_timeout.ts b/cli/tests/testdata/test/finally_timeout.ts new file mode 100644 index 000000000..dcc0a4d64 --- /dev/null +++ b/cli/tests/testdata/test/finally_timeout.ts @@ -0,0 +1,11 @@ +Deno.test("error", function () { + const timer = setTimeout(() => null, 10000); + try { + throw new Error("fail"); + } finally { + clearTimeout(timer); + } +}); + +Deno.test("success", function () { +}); diff --git a/cli/tests/testdata/test/ignore.out b/cli/tests/testdata/test/ignore.out new file mode 100644 index 000000000..a7c68261d --- /dev/null +++ b/cli/tests/testdata/test/ignore.out @@ -0,0 +1,15 @@ +Check [WILDCARD]/test/ignore.ts +running 10 tests from [WILDCARD]/test/ignore.ts +test test 0 ... ignored ([WILDCARD]) +test test 1 ... ignored ([WILDCARD]) +test test 2 ... ignored ([WILDCARD]) +test test 3 ... ignored ([WILDCARD]) +test test 4 ... ignored ([WILDCARD]) +test test 5 ... ignored ([WILDCARD]) +test test 6 ... ignored ([WILDCARD]) +test test 7 ... ignored ([WILDCARD]) +test test 8 ... ignored ([WILDCARD]) +test test 9 ... ignored ([WILDCARD]) + +test result: ok. 0 passed; 0 failed; 10 ignored; 0 measured; 0 filtered out ([WILDCARD]) + diff --git a/cli/tests/testdata/test/ignore.ts b/cli/tests/testdata/test/ignore.ts new file mode 100644 index 000000000..01113a129 --- /dev/null +++ b/cli/tests/testdata/test/ignore.ts @@ -0,0 +1,9 @@ +for (let i = 0; i < 10; i++) { + Deno.test({ + name: `test ${i}`, + ignore: true, + fn() { + throw new Error("unreachable"); + }, + }); +} diff --git a/cli/tests/testdata/test/ignore_permissions.out b/cli/tests/testdata/test/ignore_permissions.out new file mode 100644 index 000000000..c4d273d8f --- /dev/null +++ b/cli/tests/testdata/test/ignore_permissions.out @@ -0,0 +1,6 @@ +Check [WILDCARD]/test/ignore_permissions.ts +running 1 test from [WILDCARD]/test/ignore_permissions.ts +test ignore ... ignored ([WILDCARD]) + +test result: ok. 0 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out ([WILDCARD]) + diff --git a/cli/tests/testdata/test/ignore_permissions.ts b/cli/tests/testdata/test/ignore_permissions.ts new file mode 100644 index 000000000..ff3084441 --- /dev/null +++ b/cli/tests/testdata/test/ignore_permissions.ts @@ -0,0 +1,16 @@ +Deno.test({ + name: "ignore", + permissions: { + read: true, + write: true, + net: true, + env: true, + run: true, + ffi: true, + hrtime: true, + }, + ignore: true, + fn() { + throw new Error("unreachable"); + }, +}); diff --git a/cli/tests/testdata/test/meta.out b/cli/tests/testdata/test/meta.out new file mode 100644 index 000000000..a8c7acd63 --- /dev/null +++ b/cli/tests/testdata/test/meta.out @@ -0,0 +1,7 @@ +Check [WILDCARD]/test/meta.ts +import.meta.main: false +import.meta.url: [WILDCARD]/test/meta.ts +running 0 tests from [WILDCARD]/test/meta.ts + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + diff --git a/cli/tests/testdata/test/meta.ts b/cli/tests/testdata/test/meta.ts new file mode 100644 index 000000000..e32fdeea6 --- /dev/null +++ b/cli/tests/testdata/test/meta.ts @@ -0,0 +1,2 @@ +console.log("import.meta.main: %s", import.meta.main); +console.log("import.meta.url: %s", import.meta.url); diff --git a/cli/tests/testdata/test/no_check.out b/cli/tests/testdata/test/no_check.out new file mode 100644 index 000000000..9daab7ac4 --- /dev/null +++ b/cli/tests/testdata/test/no_check.out @@ -0,0 +1,8 @@ + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + +error: Uncaught TypeError: Cannot read properties of undefined (reading 'fn') +Deno.test(); + ^ + at [WILDCARD] + at [WILDCARD]/test/no_check.ts:1:6 diff --git a/cli/tests/testdata/test/no_check.ts b/cli/tests/testdata/test/no_check.ts new file mode 100644 index 000000000..79d75f989 --- /dev/null +++ b/cli/tests/testdata/test/no_check.ts @@ -0,0 +1 @@ +Deno.test(); diff --git a/cli/tests/testdata/test/no_color.ts b/cli/tests/testdata/test/no_color.ts new file mode 100644 index 000000000..38c531ee9 --- /dev/null +++ b/cli/tests/testdata/test/no_color.ts @@ -0,0 +1,17 @@ +Deno.test({ + name: "success", + fn() {}, +}); + +Deno.test({ + name: "fail", + fn() { + throw new Error("fail"); + }, +}); + +Deno.test({ + name: "ignored", + ignore: true, + fn() {}, +}); diff --git a/cli/tests/testdata/test/no_run.out b/cli/tests/testdata/test/no_run.out new file mode 100644 index 000000000..5edf03fe0 --- /dev/null +++ b/cli/tests/testdata/test/no_run.out @@ -0,0 +1,5 @@ +Check [WILDCARD]/test/no_run.ts +error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'. +const _value: string = 1; + ~~~~~~ + at [WILDCARD]/test/no_run.ts:1:7 diff --git a/cli/tests/testdata/test/no_run.ts b/cli/tests/testdata/test/no_run.ts new file mode 100644 index 000000000..b75915753 --- /dev/null +++ b/cli/tests/testdata/test/no_run.ts @@ -0,0 +1 @@ +const _value: string = 1; diff --git a/cli/tests/testdata/test/only.out b/cli/tests/testdata/test/only.out new file mode 100644 index 000000000..dc78cae80 --- /dev/null +++ b/cli/tests/testdata/test/only.out @@ -0,0 +1,7 @@ +Check [WILDCARD]/test/only.ts +running 1 test from [WILDCARD]/test/only.ts +test only ... ok ([WILDCARD]) + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 2 filtered out ([WILDCARD]) + +error: Test failed because the "only" option was used diff --git a/cli/tests/testdata/test/only.ts b/cli/tests/testdata/test/only.ts new file mode 100644 index 000000000..03c4dcac3 --- /dev/null +++ b/cli/tests/testdata/test/only.ts @@ -0,0 +1,15 @@ +Deno.test({ + name: "before", + fn() {}, +}); + +Deno.test({ + only: true, + name: "only", + fn() {}, +}); + +Deno.test({ + name: "after", + fn() {}, +}); diff --git a/cli/tests/testdata/test/pass.out b/cli/tests/testdata/test/pass.out new file mode 100644 index 000000000..cf81ac2e7 --- /dev/null +++ b/cli/tests/testdata/test/pass.out @@ -0,0 +1,15 @@ +Check [WILDCARD]/test/pass.ts +running 10 tests from [WILDCARD]/test/pass.ts +test test 0 ... ok ([WILDCARD]) +test test 1 ... ok ([WILDCARD]) +test test 2 ... ok ([WILDCARD]) +test test 3 ... ok ([WILDCARD]) +test test 4 ... ok ([WILDCARD]) +test test 5 ... ok ([WILDCARD]) +test test 6 ... ok ([WILDCARD]) +test test 7 ... ok ([WILDCARD]) +test test 8 ... ok ([WILDCARD]) +test test 9 ... ok ([WILDCARD]) + +test result: ok. 10 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + diff --git a/cli/tests/testdata/test/pass.ts b/cli/tests/testdata/test/pass.ts new file mode 100644 index 000000000..288cc7c83 --- /dev/null +++ b/cli/tests/testdata/test/pass.ts @@ -0,0 +1,10 @@ +Deno.test("test 0", () => {}); +Deno.test("test 1", () => {}); +Deno.test("test 2", () => {}); +Deno.test("test 3", () => {}); +Deno.test("test 4", () => {}); +Deno.test("test 5", () => {}); +Deno.test("test 6", () => {}); +Deno.test("test 7", () => {}); +Deno.test("test 8", () => {}); +Deno.test("test 9", () => {}); diff --git a/cli/tests/testdata/test/quiet.out b/cli/tests/testdata/test/quiet.out new file mode 100644 index 000000000..05302fb2c --- /dev/null +++ b/cli/tests/testdata/test/quiet.out @@ -0,0 +1,8 @@ +running 4 tests from [WILDCARD]/test/quiet.ts +test console.log ... ok ([WILDCARD]) +test console.error ... ok ([WILDCARD]) +test console.info ... ok ([WILDCARD]) +test console.warn ... ok ([WILDCARD]) + +test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + diff --git a/cli/tests/testdata/test/quiet.ts b/cli/tests/testdata/test/quiet.ts new file mode 100644 index 000000000..f40805bfb --- /dev/null +++ b/cli/tests/testdata/test/quiet.ts @@ -0,0 +1,15 @@ +Deno.test("console.log", function () { + console.log("log"); +}); + +Deno.test("console.error", function () { + console.error("error"); +}); + +Deno.test("console.info", function () { + console.info("info"); +}); + +Deno.test("console.warn", function () { + console.info("warn"); +}); diff --git a/cli/tests/testdata/test/shuffle.out b/cli/tests/testdata/test/shuffle.out new file mode 100644 index 000000000..04dd08ee2 --- /dev/null +++ b/cli/tests/testdata/test/shuffle.out @@ -0,0 +1,39 @@ +Check [WILDCARD]/test/shuffle/foo_test.ts +Check [WILDCARD]/test/shuffle/baz_test.ts +Check [WILDCARD]/test/shuffle/bar_test.ts +running 10 tests from [WILDCARD]/test/shuffle/foo_test.ts +test test 2 ... ok ([WILDCARD]) +test test 3 ... ok ([WILDCARD]) +test test 6 ... ok ([WILDCARD]) +test test 9 ... ok ([WILDCARD]) +test test 8 ... ok ([WILDCARD]) +test test 7 ... ok ([WILDCARD]) +test test 5 ... ok ([WILDCARD]) +test test 4 ... ok ([WILDCARD]) +test test 1 ... ok ([WILDCARD]) +test test 0 ... ok ([WILDCARD]) +running 10 tests from [WILDCARD]/test/shuffle/baz_test.ts +test test 2 ... ok ([WILDCARD]) +test test 3 ... ok ([WILDCARD]) +test test 6 ... ok ([WILDCARD]) +test test 9 ... ok ([WILDCARD]) +test test 8 ... ok ([WILDCARD]) +test test 7 ... ok ([WILDCARD]) +test test 5 ... ok ([WILDCARD]) +test test 4 ... ok ([WILDCARD]) +test test 1 ... ok ([WILDCARD]) +test test 0 ... ok ([WILDCARD]) +running 10 tests from [WILDCARD]/test/shuffle/bar_test.ts +test test 2 ... ok ([WILDCARD]) +test test 3 ... ok ([WILDCARD]) +test test 6 ... ok ([WILDCARD]) +test test 9 ... ok ([WILDCARD]) +test test 8 ... ok ([WILDCARD]) +test test 7 ... ok ([WILDCARD]) +test test 5 ... ok ([WILDCARD]) +test test 4 ... ok ([WILDCARD]) +test test 1 ... ok ([WILDCARD]) +test test 0 ... ok ([WILDCARD]) + +test result: ok. 30 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + diff --git a/cli/tests/testdata/test/shuffle/bar_test.ts b/cli/tests/testdata/test/shuffle/bar_test.ts new file mode 100644 index 000000000..ca118dc0d --- /dev/null +++ b/cli/tests/testdata/test/shuffle/bar_test.ts @@ -0,0 +1,3 @@ +for (let i = 0; i < 10; i++) { + Deno.test(`test ${i}`, () => {}); +} diff --git a/cli/tests/testdata/test/shuffle/baz_test.ts b/cli/tests/testdata/test/shuffle/baz_test.ts new file mode 100644 index 000000000..ca118dc0d --- /dev/null +++ b/cli/tests/testdata/test/shuffle/baz_test.ts @@ -0,0 +1,3 @@ +for (let i = 0; i < 10; i++) { + Deno.test(`test ${i}`, () => {}); +} diff --git a/cli/tests/testdata/test/shuffle/foo_test.ts b/cli/tests/testdata/test/shuffle/foo_test.ts new file mode 100644 index 000000000..ca118dc0d --- /dev/null +++ b/cli/tests/testdata/test/shuffle/foo_test.ts @@ -0,0 +1,3 @@ +for (let i = 0; i < 10; i++) { + Deno.test(`test ${i}`, () => {}); +} diff --git a/cli/tests/testdata/test/unhandled_rejection.out b/cli/tests/testdata/test/unhandled_rejection.out new file mode 100644 index 000000000..fae353a28 --- /dev/null +++ b/cli/tests/testdata/test/unhandled_rejection.out @@ -0,0 +1,10 @@ +Check [WILDCARD]/test/unhandled_rejection.ts + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + +error: Uncaught (in promise) Error: rejection + reject(new Error("rejection")); + ^ + at [WILDCARD]/test/unhandled_rejection.ts:2:10 + at new Promise (<anonymous>) + at [WILDCARD]/test/unhandled_rejection.ts:1:1 diff --git a/cli/tests/testdata/test/unhandled_rejection.ts b/cli/tests/testdata/test/unhandled_rejection.ts new file mode 100644 index 000000000..32f3111ea --- /dev/null +++ b/cli/tests/testdata/test/unhandled_rejection.ts @@ -0,0 +1,3 @@ +new Promise((_resolve, reject) => { + reject(new Error("rejection")); +}); diff --git a/cli/tests/testdata/test/unresolved_promise.out b/cli/tests/testdata/test/unresolved_promise.out new file mode 100644 index 000000000..cd505bcbf --- /dev/null +++ b/cli/tests/testdata/test/unresolved_promise.out @@ -0,0 +1,6 @@ +Check [WILDCARD]/test/unresolved_promise.ts +running 2 tests from [WILDCARD]/test/unresolved_promise.ts +test unresolved promise ... +test result: FAILED. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + +error: Module evaluation is still pending but there are no pending ops or dynamic imports. This situation is often caused by unresolved promise. diff --git a/cli/tests/testdata/test/unresolved_promise.ts b/cli/tests/testdata/test/unresolved_promise.ts new file mode 100644 index 000000000..8f50e907a --- /dev/null +++ b/cli/tests/testdata/test/unresolved_promise.ts @@ -0,0 +1,11 @@ +Deno.test({ + name: "unresolved promise", + fn() { + return new Promise((_resolve, _reject) => {}); + }, +}); + +Deno.test({ + name: "ok", + fn() {}, +}); diff --git a/cli/tests/testdata/text_decoder_perf.js b/cli/tests/testdata/text_decoder_perf.js new file mode 100644 index 000000000..2e52b1f8b --- /dev/null +++ b/cli/tests/testdata/text_decoder_perf.js @@ -0,0 +1,38 @@ +const mixed = new TextEncoder().encode("@Ä€à¹ðŸ˜€"); + +function generateRandom(bytes) { + const result = new Uint8Array(bytes); + let i = 0; + while (i < bytes) { + const toAdd = Math.floor(Math.random() * Math.min(4, bytes - i)); + switch (toAdd) { + case 0: + result[i] = mixed[0]; + i++; + break; + case 1: + result[i] = mixed[1]; + result[i + 1] = mixed[2]; + i += 2; + break; + case 2: + result[i] = mixed[3]; + result[i + 1] = mixed[4]; + result[i + 2] = mixed[5]; + i += 3; + break; + case 3: + result[i] = mixed[6]; + result[i + 1] = mixed[7]; + result[i + 2] = mixed[8]; + result[i + 3] = mixed[9]; + i += 4; + break; + } + } + return result; +} + +const randomData = generateRandom(1024); +const decoder = new TextDecoder(); +for (let i = 0; i < 10_000; i++) decoder.decode(randomData); diff --git a/cli/tests/testdata/text_encoder_into_perf.js b/cli/tests/testdata/text_encoder_into_perf.js new file mode 100644 index 000000000..8d60e9f00 --- /dev/null +++ b/cli/tests/testdata/text_encoder_into_perf.js @@ -0,0 +1,34 @@ +const mixed = "@Ä€à¹ðŸ˜€"; + +function generateRandom(bytes) { + let result = ""; + let i = 0; + while (i < bytes) { + const toAdd = Math.floor(Math.random() * Math.min(4, bytes - i)); + switch (toAdd) { + case 0: + result += mixed[0]; + i++; + break; + case 1: + result += mixed[1]; + i++; + break; + case 2: + result += mixed[2]; + i++; + break; + case 3: + result += mixed[3]; + result += mixed[4]; + i += 2; + break; + } + } + return result; +} + +const randomData = generateRandom(1024); +const encoder = new TextEncoder(); +const targetBuffer = new Uint8Array(randomData.length * 4); +for (let i = 0; i < 10_000; i++) encoder.encodeInto(randomData, targetBuffer); diff --git a/cli/tests/testdata/text_encoder_perf.js b/cli/tests/testdata/text_encoder_perf.js new file mode 100644 index 000000000..6f61f019e --- /dev/null +++ b/cli/tests/testdata/text_encoder_perf.js @@ -0,0 +1,33 @@ +const mixed = "@Ä€à¹ðŸ˜€"; + +function generateRandom(bytes) { + let result = ""; + let i = 0; + while (i < bytes) { + const toAdd = Math.floor(Math.random() * Math.min(4, bytes - i)); + switch (toAdd) { + case 0: + result += mixed[0]; + i++; + break; + case 1: + result += mixed[1]; + i++; + break; + case 2: + result += mixed[2]; + i++; + break; + case 3: + result += mixed[3]; + result += mixed[4]; + i += 2; + break; + } + } + return result; +} + +const randomData = generateRandom(1024); +const encoder = new TextEncoder(); +for (let i = 0; i < 10_000; i++) encoder.encode(randomData); diff --git a/cli/tests/testdata/tla/a.js b/cli/tests/testdata/tla/a.js new file mode 100644 index 000000000..c3ef3f7db --- /dev/null +++ b/cli/tests/testdata/tla/a.js @@ -0,0 +1,3 @@ +import order from "./order.js"; + +order.push("b"); diff --git a/cli/tests/testdata/tla/b.js b/cli/tests/testdata/tla/b.js new file mode 100644 index 000000000..3271c92d8 --- /dev/null +++ b/cli/tests/testdata/tla/b.js @@ -0,0 +1,7 @@ +import order from "./order.js"; + +await new Promise((resolve) => { + setTimeout(resolve, 200); +}); + +order.push("a"); diff --git a/cli/tests/testdata/tla/c.js b/cli/tests/testdata/tla/c.js new file mode 100644 index 000000000..806eb0a8b --- /dev/null +++ b/cli/tests/testdata/tla/c.js @@ -0,0 +1,3 @@ +import order from "./order.js"; + +order.push("c"); diff --git a/cli/tests/testdata/tla/d.js b/cli/tests/testdata/tla/d.js new file mode 100644 index 000000000..283ebf817 --- /dev/null +++ b/cli/tests/testdata/tla/d.js @@ -0,0 +1,8 @@ +import order from "./order.js"; + +const end = Date.now() + 500; +while (end < Date.now()) { + // pass +} + +order.push("d"); diff --git a/cli/tests/testdata/tla/order.js b/cli/tests/testdata/tla/order.js new file mode 100644 index 000000000..f213a562c --- /dev/null +++ b/cli/tests/testdata/tla/order.js @@ -0,0 +1 @@ +export default ["order"]; diff --git a/cli/tests/testdata/tla/parent.js b/cli/tests/testdata/tla/parent.js new file mode 100644 index 000000000..1ecc15463 --- /dev/null +++ b/cli/tests/testdata/tla/parent.js @@ -0,0 +1,9 @@ +import order from "./order.js"; +import "./a.js"; +import "./b.js"; +import "./c.js"; +import "./d.js"; + +order.push("parent"); + +export default order; diff --git a/cli/tests/testdata/tla2/a.js b/cli/tests/testdata/tla2/a.js new file mode 100644 index 000000000..d07bcb94d --- /dev/null +++ b/cli/tests/testdata/tla2/a.js @@ -0,0 +1,5 @@ +export default class Foo { + constructor(message) { + this.message = message; + } +} diff --git a/cli/tests/testdata/tla2/b.js b/cli/tests/testdata/tla2/b.js new file mode 100644 index 000000000..68e357c1e --- /dev/null +++ b/cli/tests/testdata/tla2/b.js @@ -0,0 +1,5 @@ +export default class Bar { + constructor(message) { + this.message = message; + } +} diff --git a/cli/tests/testdata/tla3/b.js b/cli/tests/testdata/tla3/b.js new file mode 100644 index 000000000..b74c659e4 --- /dev/null +++ b/cli/tests/testdata/tla3/b.js @@ -0,0 +1,7 @@ +import { foo } from "./timeout_loop.js"; +import { collection } from "../top_level_await_circular.js"; + +console.log("collection in b", collection); +console.log("foo in b", foo); + +export const a = "a"; diff --git a/cli/tests/testdata/tla3/timeout_loop.js b/cli/tests/testdata/tla3/timeout_loop.js new file mode 100644 index 000000000..860e6cd2a --- /dev/null +++ b/cli/tests/testdata/tla3/timeout_loop.js @@ -0,0 +1,23 @@ +export const foo = "foo"; + +export function delay(ms) { + return new Promise((res) => + setTimeout(() => { + res(); + }, ms) + ); +} + +let i = 0; + +async function timeoutLoop() { + await delay(1000); + console.log("timeout loop", i); + i++; + if (i > 5) { + return; + } + timeoutLoop(); +} + +timeoutLoop(); diff --git a/cli/tests/testdata/tls.out b/cli/tests/testdata/tls.out new file mode 100644 index 000000000..c8e8a135c --- /dev/null +++ b/cli/tests/testdata/tls.out @@ -0,0 +1 @@ +DONE diff --git a/cli/tests/testdata/tls/README.md b/cli/tests/testdata/tls/README.md new file mode 100644 index 000000000..19bbaec35 --- /dev/null +++ b/cli/tests/testdata/tls/README.md @@ -0,0 +1,47 @@ +The certificates in this dir expire on Sept, 27th, 2118 + +Certificates generated using original instructions from this gist: +https://gist.github.com/cecilemuller/9492b848eb8fe46d462abeb26656c4f8 + +## Certificate authority (CA) + +Generate RootCA.pem, RootCA.key, RootCA.crt: + +```shell +openssl req -x509 -nodes -new -sha256 -days 36135 -newkey rsa:2048 -keyout RootCA.key -out RootCA.pem -subj "/C=US/CN=Example-Root-CA" +openssl x509 -outform pem -in RootCA.pem -out RootCA.crt +``` + +Note that Example-Root-CA is an example, you can customize the name. + +## Domain name certificate + +First, create a file domains.txt that lists all your local domains (here we only +list localhost): + +```shell +authorityKeyIdentifier=keyid,issuer +basicConstraints=CA:FALSE +keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment +subjectAltName = @alt_names +[alt_names] +DNS.1 = localhost +``` + +Generate localhost.key, localhost.csr, and localhost.crt: + +```shell +openssl req -new -nodes -newkey rsa:2048 -keyout localhost.key -out localhost.csr -subj "/C=US/ST=YourState/L=YourCity/O=Example-Certificates/CN=localhost.local" +openssl x509 -req -sha256 -days 36135 -in localhost.csr -CA RootCA.pem -CAkey RootCA.key -CAcreateserial -extfile domains.txt -out localhost.crt +``` + +Note that the country / state / city / name in the first command can be +customized. + +For testing purposes we need following files: + +- `RootCA.crt` +- `RootCA.key` +- `RootCA.pem` +- `localhost.crt` +- `localhost.key` diff --git a/cli/tests/testdata/tls/RootCA.crt b/cli/tests/testdata/tls/RootCA.crt new file mode 100644 index 000000000..c2f84ceeb --- /dev/null +++ b/cli/tests/testdata/tls/RootCA.crt @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIDIzCCAgugAwIBAgIJAMKPPW4tsOymMA0GCSqGSIb3DQEBCwUAMCcxCzAJBgNV +BAYTAlVTMRgwFgYDVQQDDA9FeGFtcGxlLVJvb3QtQ0EwIBcNMTkxMDIxMTYyODIy +WhgPMjExODA5MjcxNjI4MjJaMCcxCzAJBgNVBAYTAlVTMRgwFgYDVQQDDA9FeGFt +cGxlLVJvb3QtQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDMH/IO +2qtHfyBKwANNPB4K0q5JVSg8XxZdRpTTlz0CwU0oRO3uHrI52raCCfVeiQutyZop +eFZTDWeXGudGAFA2B5m3orWt0s+touPi8MzjsG2TQ+WSI66QgbXTNDitDDBtTVcV +5G3Ic+3SppQAYiHSekLISnYWgXLl+k5CnEfTowg6cjqjVr0KjL03cTN3H7b+6+0S +ws4rYbW1j4ExR7K6BFNH6572yq5qR20E6GqlY+EcOZpw4CbCk9lS8/CWuXze/vMs +OfDcc6K+B625d27wyEGZHedBomT2vAD7sBjvO8hn/DP1Qb46a8uCHR6NSfnJ7bXO +G1igaIbgY1zXirNdAgMBAAGjUDBOMB0GA1UdDgQWBBTzut+pwwDfqmMYcI9KNWRD +hxcIpTAfBgNVHSMEGDAWgBTzut+pwwDfqmMYcI9KNWRDhxcIpTAMBgNVHRMEBTAD +AQH/MA0GCSqGSIb3DQEBCwUAA4IBAQB9AqSbZ+hEglAgSHxAMCqRFdhVu7MvaQM0 +P090mhGlOCt3yB7kdGfsIrUW6nQcTz7PPQFRaJMrFHPvFvPootkBUpTYR4hTkdce +H6RCRu2Jxl4Y9bY/uezd9YhGCYfUtfjA6/TH9FcuZfttmOOlxOt01XfNvVMIR6RM +z/AYhd+DeOXjr35F/VHeVpnk+55L0PYJsm1CdEbOs5Hy1ecR7ACuDkXnbM4fpz9I +kyIWJwk2zJReKcJMgi1aIinDM9ao/dca1G99PHOw8dnr4oyoTiv8ao6PWiSRHHMi +MNf4EgWfK+tZMnuqfpfO9740KzfcVoMNo4QJD4yn5YxroUOO/Azi +-----END CERTIFICATE----- diff --git a/cli/tests/testdata/tls/RootCA.key b/cli/tests/testdata/tls/RootCA.key new file mode 100644 index 000000000..98ce53b0b --- /dev/null +++ b/cli/tests/testdata/tls/RootCA.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDMH/IO2qtHfyBK +wANNPB4K0q5JVSg8XxZdRpTTlz0CwU0oRO3uHrI52raCCfVeiQutyZopeFZTDWeX +GudGAFA2B5m3orWt0s+touPi8MzjsG2TQ+WSI66QgbXTNDitDDBtTVcV5G3Ic+3S +ppQAYiHSekLISnYWgXLl+k5CnEfTowg6cjqjVr0KjL03cTN3H7b+6+0Sws4rYbW1 +j4ExR7K6BFNH6572yq5qR20E6GqlY+EcOZpw4CbCk9lS8/CWuXze/vMsOfDcc6K+ +B625d27wyEGZHedBomT2vAD7sBjvO8hn/DP1Qb46a8uCHR6NSfnJ7bXOG1igaIbg +Y1zXirNdAgMBAAECggEASvdsicILZ42ryWgtjj8G9Yick7gft9RgPU9/txnzQUDG +2oQ+Mda6M/88ShPoNpj0XhYNdS+J3KSup9MsnwvcaYtvC/9I5BbpSObq9NzlErYn ++A7WkE5kfRP2OCQUsJEqc+oUkqi7HQRekp+0+VMRAuD+B9s49VkDXq0H8vS8eF/e +J9nj6c/RTK+Er5ccG5jSLrSy3kiIjAN1a6OIU/YPjPx7qv8ZZ6TLeRtvc8PV++cH +wB1qapZg5cuKge9UEcg+WINCkD2n9iK1jKC1ULYsiuwUR6LX9YHLUwr6S5/Dwwqc +Vb9nmftqJtCz+McrqRCdfeqSNGi0tjVEX7i+DtfZrQKBgQD7firgBE7nb53VDirG +W8Leo6EhCS/hCZFo0QhSBUCeOpmSaMsCzUIlqqPIBIQXir0AtBno/qXYiIJ4HgUB +lScrK+7KUirEO8o4x6xC2hbPk/A7fTgf0G5Mvj2TRidiLGGIupuRHeyjigiGa0mG +yWLoil6MJX44usnE49qDVy77/wKBgQDPyHThAugFSsVedxy29NQx7Zp8s/htpGHZ +wYksbunz+NlO/xzRvSu2OAps/WD6F+3KhCB5fV2tESVs7u2oQPLcjmIpurDtATWE +DJAAvcBl1L+cpQGN4D8zUrrZO8rw01sUZSv+kAnfsC01exzZe64+VDl3a1cYZkDT +A9RmbF/AowKBgDTYVxQJc7cH6idZub1CjNkRkwsJDimARDC9M71gYyqcb6anJHlr +PgoCKDYgVM1Jlttt/L/Lunecf6XT0QN7HubgbWXQDDJ9yclSk6zcfMyTbnhhoIh2 +2KaBlxi6Ng5X+wqrA4NjwVS/7XipVKLg8EqiwKk8O6CaB0m7AzB0AmhrAoGAcGsi +YYNzCTn1IzEKxiocjI7jYMj2hkvD7U766qFvzuI6oLUCYLAa8FHNwj4ss+Mycrmd +4F1ly3dVamSzDK9nNtGKZs1tYC2hSLqLRvtjFzVOHnBgMOS9DQWbtmDVYgrYYmaC +sQ45aV8mdqMPbtOt6GclWGkpDDh2pjSSPIAyJkUCgYAHw7dKqYO/YQPKmswVZm5t +TelfdJJG6GCXnFryyqo4pmEMy/i5kzF1t9Cnchhx/WeU+wGxrWd3RMP/sqP7MW9q +6Ie9Jj2vk4lUBoeFKk+kLeBUr+TkLSdcVEI0DSOdX681AUmxkVzVjGKYeiNa+V6u +XmgzS8JEYoMbNEAKXYX2qg== +-----END PRIVATE KEY----- diff --git a/cli/tests/testdata/tls/RootCA.pem b/cli/tests/testdata/tls/RootCA.pem new file mode 100644 index 000000000..c2f84ceeb --- /dev/null +++ b/cli/tests/testdata/tls/RootCA.pem @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIDIzCCAgugAwIBAgIJAMKPPW4tsOymMA0GCSqGSIb3DQEBCwUAMCcxCzAJBgNV +BAYTAlVTMRgwFgYDVQQDDA9FeGFtcGxlLVJvb3QtQ0EwIBcNMTkxMDIxMTYyODIy +WhgPMjExODA5MjcxNjI4MjJaMCcxCzAJBgNVBAYTAlVTMRgwFgYDVQQDDA9FeGFt +cGxlLVJvb3QtQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDMH/IO +2qtHfyBKwANNPB4K0q5JVSg8XxZdRpTTlz0CwU0oRO3uHrI52raCCfVeiQutyZop +eFZTDWeXGudGAFA2B5m3orWt0s+touPi8MzjsG2TQ+WSI66QgbXTNDitDDBtTVcV +5G3Ic+3SppQAYiHSekLISnYWgXLl+k5CnEfTowg6cjqjVr0KjL03cTN3H7b+6+0S +ws4rYbW1j4ExR7K6BFNH6572yq5qR20E6GqlY+EcOZpw4CbCk9lS8/CWuXze/vMs +OfDcc6K+B625d27wyEGZHedBomT2vAD7sBjvO8hn/DP1Qb46a8uCHR6NSfnJ7bXO +G1igaIbgY1zXirNdAgMBAAGjUDBOMB0GA1UdDgQWBBTzut+pwwDfqmMYcI9KNWRD +hxcIpTAfBgNVHSMEGDAWgBTzut+pwwDfqmMYcI9KNWRDhxcIpTAMBgNVHRMEBTAD +AQH/MA0GCSqGSIb3DQEBCwUAA4IBAQB9AqSbZ+hEglAgSHxAMCqRFdhVu7MvaQM0 +P090mhGlOCt3yB7kdGfsIrUW6nQcTz7PPQFRaJMrFHPvFvPootkBUpTYR4hTkdce +H6RCRu2Jxl4Y9bY/uezd9YhGCYfUtfjA6/TH9FcuZfttmOOlxOt01XfNvVMIR6RM +z/AYhd+DeOXjr35F/VHeVpnk+55L0PYJsm1CdEbOs5Hy1ecR7ACuDkXnbM4fpz9I +kyIWJwk2zJReKcJMgi1aIinDM9ao/dca1G99PHOw8dnr4oyoTiv8ao6PWiSRHHMi +MNf4EgWfK+tZMnuqfpfO9740KzfcVoMNo4QJD4yn5YxroUOO/Azi +-----END CERTIFICATE----- diff --git a/cli/tests/testdata/tls/domains.txt b/cli/tests/testdata/tls/domains.txt new file mode 100644 index 000000000..0bba95d33 --- /dev/null +++ b/cli/tests/testdata/tls/domains.txt @@ -0,0 +1,6 @@ +authorityKeyIdentifier=keyid,issuer +basicConstraints=CA:FALSE +keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment +subjectAltName = @alt_names +[alt_names] +DNS.1 = localhost diff --git a/cli/tests/testdata/tls/localhost.crt b/cli/tests/testdata/tls/localhost.crt new file mode 100644 index 000000000..a71ae9050 --- /dev/null +++ b/cli/tests/testdata/tls/localhost.crt @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDajCCAlKgAwIBAgIJAOPyQVdy/UpPMA0GCSqGSIb3DQEBCwUAMCcxCzAJBgNV +BAYTAlVTMRgwFgYDVQQDDA9FeGFtcGxlLVJvb3QtQ0EwIBcNMTkxMDIxMTYyODU4 +WhgPMjExODA5MjcxNjI4NThaMG0xCzAJBgNVBAYTAlVTMRIwEAYDVQQIDAlZb3Vy +U3RhdGUxETAPBgNVBAcMCFlvdXJDaXR5MR0wGwYDVQQKDBRFeGFtcGxlLUNlcnRp +ZmljYXRlczEYMBYGA1UEAwwPbG9jYWxob3N0LmxvY2FsMIIBIjANBgkqhkiG9w0B +AQEFAAOCAQ8AMIIBCgKCAQEAz9svjVdf5jihUBtofd84XKdb8dEHQRJfDNKaJ4Ar +baqMHAdnqi/fWtlqEEMn8gweZ7+4hshECY5mnx4Hhy7IAbePDsTTbSm01dChhlxF +uvd9QuvzvrqSjSq+v4Jlau+pQIhUzzV12dF5bFvrIrGWxCZp+W7lLDZI6Pd6Su+y +ZIeiwrUaPMzdUePNf2hZI/IvWCUMCIyoqrrKHdHoPuvQCW17IyxsnFQJNbmN+Rtp +BQilhtwvBbggCBWhHxEdiqBaZHDw6Zl+bU7ejx1mu9A95wpQ9SCL2cRkAlz2LDOy +wznrTAwGcvqvFKxlV+3HsaD7rba4kCA1Ihp5mm/dS2k94QIDAQABo1EwTzAfBgNV +HSMEGDAWgBTzut+pwwDfqmMYcI9KNWRDhxcIpTAJBgNVHRMEAjAAMAsGA1UdDwQE +AwIE8DAUBgNVHREEDTALgglsb2NhbGhvc3QwDQYJKoZIhvcNAQELBQADggEBAKVu +vVpu5nPGAGn1SX4FQUcbn9Z5wgBkjnZxfJHJQX4sYIRlcirZviPHCZGPWex4VHC+ +lFMm+70YEN2uoe5jGrdgcugzx2Amc7/mLrsvvpMsaS0PlxNMcqhdM1WHbGjjdNln +XICVITSKnB1fSGH6uo9CMCWw5kgPS9o4QWrLLkxnds3hoz7gVEUyi/6V65mcfFNA +lof9iKcK9JsSHdBs35vpv7UKLX+96RM7Nm2Mu0yue5JiS79/zuMA/Kryxot4jv5z +ecdWFl0eIyQBZmBzMw2zPUqkxEnXLiKjV8jutEg/4qovTOB6YiA41qbARXdzNA2V +FYuchcTcWmnmVVRFyyU= +-----END CERTIFICATE----- diff --git a/cli/tests/testdata/tls/localhost.key b/cli/tests/testdata/tls/localhost.key new file mode 100644 index 000000000..42774c977 --- /dev/null +++ b/cli/tests/testdata/tls/localhost.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDP2y+NV1/mOKFQ +G2h93zhcp1vx0QdBEl8M0pongCttqowcB2eqL99a2WoQQyfyDB5nv7iGyEQJjmaf +HgeHLsgBt48OxNNtKbTV0KGGXEW6931C6/O+upKNKr6/gmVq76lAiFTPNXXZ0Xls +W+sisZbEJmn5buUsNkjo93pK77Jkh6LCtRo8zN1R481/aFkj8i9YJQwIjKiqusod +0eg+69AJbXsjLGycVAk1uY35G2kFCKWG3C8FuCAIFaEfER2KoFpkcPDpmX5tTt6P +HWa70D3nClD1IIvZxGQCXPYsM7LDOetMDAZy+q8UrGVX7cexoPuttriQIDUiGnma +b91LaT3hAgMBAAECggEBAJABfn+BQorBP1m9s3ZJmcXvmW7+7/SwYrQCkRS+4te2 +6h1dMAAj7K4HpUkhDeLPbJ1aoeCXjTPFuemRp4uL6Lvvzahgy059L7FXOyFYemMf +pmQgDx5cKr6tF7yc/eDJrExuZ7urgTvouiRNxqmhuh+psZBDuXkZHwhwtQSH7uNg +KBDKu0qWO73vFLcLckdGEU3+H9oIWs5xcvvOkWzyvHbRGFJSihgcRpPPHodF5xB9 +T/gZIoJHMmCbUMlWaSasUyNXTuvCnkvBDol8vXrMJCVzKZj9GpPDcIFdc08GSn4I +pTdSNwzUcHbdERzdVU28Xt+t6W5rvp/4FWrssi4IzkUCgYEA//ZcEcBguRD4OFrx +6wbSjzCcUW1NWhzA8uTOORZi4SvndcH1cU4S2wznuHNubU1XlrGwJX6PUGebmY/l +53B5PJvStbVtZCVIxllR+ZVzRuL8wLodRHzlYH8GOzHwoa4ivSupkzl72ij1u/tI +NMLGfYEKVdNd8zXIESUY88NszvsCgYEAz+MDp3xOhFaCe+CPv80A592cJcfzc8Al ++rahEOu+VdN2QBZf86PIf2Bfv/t0QvnRvs1z648TuH6h83YSggOAbmfHyd789jkq +UWlktIaXbVn+VaHmPTcBWTg3ZTlvG+fiFCbZXiYhm+UUf1MDqZHdiifAoyVIjV/Z +YhCNJo3q39MCgYEAknrpK5t9fstwUcfyA/9OhnVaL9suVjB4V0iLn+3ovlXCywgp +ryLv9X3IKi2c9144jtu3I23vFCOGz3WjKzSZnQ7LogNmy9XudNxu5jcZ1mpWHPEl +iKk1F2j6Juwoek5OQRX4oHFYKHwiTOa75r3Em9Q6Fu20KVgQ24bwZafj3/sCgYAy +k0AoVw2jFIjaKl/Ogclen4OFjYek+XJD9Hpq62964d866Dafx5DXrFKfGkXGpZBp +owI4pK5fjC9KU8dc6g0szwLEEgPowy+QbtuZL8VXTTWbD7A75E3nrs2LStXFLDzM +OkdXqF801h6Oe1vAvUPwgItVJZTpEBCK0wwD/TLPEQKBgQDRkhlTtAoHW7W6STd0 +A/OWc0dxhzMurpxg0bLgCqUjw1ESGrSCGhffFn0IWa8sv19VWsZuBhTgjNatZsYB +AhDs/6OosT/3nJoh2/t0hYDj1FBI0lPXWYD4pesuZ5yIMrmSaAOtIzp4BGY7ui8N +wOqcq/jdiHj/MKEdqOXy3YAJrA== +-----END PRIVATE KEY----- diff --git a/cli/tests/testdata/tls_connecttls.js b/cli/tests/testdata/tls_connecttls.js new file mode 100644 index 000000000..1e8cf320c --- /dev/null +++ b/cli/tests/testdata/tls_connecttls.js @@ -0,0 +1,70 @@ +import { deferred } from "../../../test_util/std/async/deferred.ts"; +import { + assert, + assertEquals, +} from "../../../test_util/std/testing/asserts.ts"; +import { BufReader, BufWriter } from "../../../test_util/std/io/bufio.ts"; +import { TextProtoReader } from "../../../test_util/std/textproto/mod.ts"; + +const encoder = new TextEncoder(); +const decoder = new TextDecoder(); + +const resolvable = deferred(); +const hostname = "localhost"; +const port = 3505; + +const listener = Deno.listenTls({ + hostname, + port, + certFile: "./tls/localhost.crt", + keyFile: "./tls/localhost.key", +}); + +const response = encoder.encode( + "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n", +); + +listener.accept().then( + async (conn) => { + assert(conn.remoteAddr != null); + assert(conn.localAddr != null); + await conn.write(response); + // TODO(bartlomieju): this might be a bug + setTimeout(() => { + conn.close(); + resolvable.resolve(); + }, 0); + }, +); + +const conn = await Deno.connectTls({ + hostname, + port, +}); +assert(conn.rid > 0); +const w = new BufWriter(conn); +const r = new BufReader(conn); +const body = `GET / HTTP/1.1\r\nHost: ${hostname}:${port}\r\n\r\n`; +const writeResult = await w.write(encoder.encode(body)); +assertEquals(body.length, writeResult); +await w.flush(); +const tpr = new TextProtoReader(r); +const statusLine = await tpr.readLine(); +assert(statusLine !== null, `line must be read: ${String(statusLine)}`); +const m = statusLine.match(/^(.+?) (.+?) (.+?)$/); +assert(m !== null, "must be matched"); +const [_, proto, status, ok] = m; +assertEquals(proto, "HTTP/1.1"); +assertEquals(status, "200"); +assertEquals(ok, "OK"); +const headers = await tpr.readMIMEHeader(); +assert(headers !== null); +const contentLength = parseInt(headers.get("content-length")); +const bodyBuf = new Uint8Array(contentLength); +await r.readFull(bodyBuf); +assertEquals(decoder.decode(bodyBuf), "Hello World\n"); +conn.close(); +listener.close(); +await resolvable; + +console.log("DONE"); diff --git a/cli/tests/testdata/tls_starttls.js b/cli/tests/testdata/tls_starttls.js new file mode 100644 index 000000000..9b8767eaa --- /dev/null +++ b/cli/tests/testdata/tls_starttls.js @@ -0,0 +1,68 @@ +import { deferred } from "../../../test_util/std/async/deferred.ts"; +import { + assert, + assertEquals, +} from "../../../test_util/std/testing/asserts.ts"; +import { BufReader, BufWriter } from "../../../test_util/std/io/bufio.ts"; +import { TextProtoReader } from "../../../test_util/std/textproto/mod.ts"; + +const encoder = new TextEncoder(); +const decoder = new TextDecoder(); + +const resolvable = deferred(); +const hostname = "localhost"; +const port = 3504; + +const listener = Deno.listenTls({ + hostname, + port, + certFile: "./tls/localhost.crt", + keyFile: "./tls/localhost.key", +}); + +const response = encoder.encode( + "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n", +); + +listener.accept().then( + async (conn) => { + assert(conn.remoteAddr != null); + assert(conn.localAddr != null); + await conn.write(response); + // TODO(bartlomieju): this might be a bug + setTimeout(() => { + conn.close(); + resolvable.resolve(); + }, 0); + }, +); + +let conn = await Deno.connect({ hostname, port }); +conn = await Deno.startTls(conn, { hostname }); +assert(conn.rid > 0); +const w = new BufWriter(conn); +const r = new BufReader(conn); +const body = `GET / HTTP/1.1\r\nHost: ${hostname}:${port}\r\n\r\n`; +const writeResult = await w.write(encoder.encode(body)); +assertEquals(body.length, writeResult); +await w.flush(); +const tpr = new TextProtoReader(r); +const statusLine = await tpr.readLine(); +assert(statusLine !== null, `line must be read: ${String(statusLine)}`); +const m = statusLine.match(/^(.+?) (.+?) (.+?)$/); +assert(m !== null, "must be matched"); +const [_, proto, status, ok] = m; +assertEquals(proto, "HTTP/1.1"); +assertEquals(status, "200"); +assertEquals(ok, "OK"); +const headers = await tpr.readMIMEHeader(); +assert(headers !== null); +const contentLength = parseInt(headers.get("content-length")); +const bodyBuf = new Uint8Array(contentLength); +await r.readFull(bodyBuf); +assertEquals(decoder.decode(bodyBuf), "Hello World\n"); +conn.close(); +listener.close(); +await resolvable; + +console.log("DONE"); diff --git a/cli/tests/testdata/top_level_await.js b/cli/tests/testdata/top_level_await.js new file mode 100644 index 000000000..af6fbd662 --- /dev/null +++ b/cli/tests/testdata/top_level_await.js @@ -0,0 +1,3 @@ +const buf = await Deno.readFile("hello.txt"); +const n = await Deno.stdout.write(buf); +console.log(`\n\nwrite ${n}`); diff --git a/cli/tests/testdata/top_level_await.out b/cli/tests/testdata/top_level_await.out new file mode 100644 index 000000000..4b65d15fe --- /dev/null +++ b/cli/tests/testdata/top_level_await.out @@ -0,0 +1,3 @@ +Hello world! + +write 12 diff --git a/cli/tests/testdata/top_level_await.ts b/cli/tests/testdata/top_level_await.ts new file mode 100644 index 000000000..65de253ea --- /dev/null +++ b/cli/tests/testdata/top_level_await.ts @@ -0,0 +1,3 @@ +const buf: Uint8Array = await Deno.readFile("hello.txt"); +const n: number = await Deno.stdout.write(buf); +console.log(`\n\nwrite ${n}`); diff --git a/cli/tests/testdata/top_level_await_circular.js b/cli/tests/testdata/top_level_await_circular.js new file mode 100644 index 000000000..ff2964b6a --- /dev/null +++ b/cli/tests/testdata/top_level_await_circular.js @@ -0,0 +1,8 @@ +import { foo } from "./tla3/timeout_loop.js"; + +export const collection = []; + +const mod = await import("./tla3/b.js"); + +console.log("foo in main", foo); +console.log("mod", mod); diff --git a/cli/tests/testdata/top_level_await_circular.out b/cli/tests/testdata/top_level_await_circular.out new file mode 100644 index 000000000..fcbc001c3 --- /dev/null +++ b/cli/tests/testdata/top_level_await_circular.out @@ -0,0 +1,9 @@ +timeout loop 0 +timeout loop 1 +timeout loop 2 +timeout loop 3 +timeout loop 4 +timeout loop 5 +error: Dynamically imported module evaluation is still pending but there are no pending ops. This situation is often caused by unresolved promise. +Pending dynamic modules: +- [WILDCARD]/tla3/b.js diff --git a/cli/tests/testdata/top_level_await_loop.js b/cli/tests/testdata/top_level_await_loop.js new file mode 100644 index 000000000..384f8d0ed --- /dev/null +++ b/cli/tests/testdata/top_level_await_loop.js @@ -0,0 +1,18 @@ +const importsDir = Deno.readDirSync(Deno.realPathSync("./tla2")); + +const resolvedPaths = []; + +for (const { name } of importsDir) { + const filePath = Deno.realPathSync(`./tla2/${name}`); + resolvedPaths.push(filePath); +} + +resolvedPaths.sort(); + +for (const filePath of resolvedPaths) { + console.log("loading", filePath); + const mod = await import(`file://${filePath}`); + console.log("loaded", mod); +} + +console.log("all loaded"); diff --git a/cli/tests/testdata/top_level_await_loop.out b/cli/tests/testdata/top_level_await_loop.out new file mode 100644 index 000000000..70e621e45 --- /dev/null +++ b/cli/tests/testdata/top_level_await_loop.out @@ -0,0 +1,5 @@ +loading [WILDCARD]a.js +loaded Module { default: [Function: Foo] } +loading [WILDCARD]b.js +loaded Module { default: [Function: Bar] } +all loaded diff --git a/cli/tests/testdata/top_level_await_nested.out b/cli/tests/testdata/top_level_await_nested.out new file mode 100644 index 000000000..8a1218a10 --- /dev/null +++ b/cli/tests/testdata/top_level_await_nested.out @@ -0,0 +1,5 @@ +1 +2 +3 +4 +5 diff --git a/cli/tests/testdata/top_level_await_nested/a.js b/cli/tests/testdata/top_level_await_nested/a.js new file mode 100644 index 000000000..74837d4ba --- /dev/null +++ b/cli/tests/testdata/top_level_await_nested/a.js @@ -0,0 +1,3 @@ +console.log(2); +await import("./b.js"); +console.log(4); diff --git a/cli/tests/testdata/top_level_await_nested/b.js b/cli/tests/testdata/top_level_await_nested/b.js new file mode 100644 index 000000000..3bd241b50 --- /dev/null +++ b/cli/tests/testdata/top_level_await_nested/b.js @@ -0,0 +1 @@ +console.log(3); diff --git a/cli/tests/testdata/top_level_await_nested/main.js b/cli/tests/testdata/top_level_await_nested/main.js new file mode 100644 index 000000000..ed46a4717 --- /dev/null +++ b/cli/tests/testdata/top_level_await_nested/main.js @@ -0,0 +1,3 @@ +console.log(1); +await import("./a.js"); +console.log(5); diff --git a/cli/tests/testdata/top_level_await_order.js b/cli/tests/testdata/top_level_await_order.js new file mode 100644 index 000000000..30659cdfb --- /dev/null +++ b/cli/tests/testdata/top_level_await_order.js @@ -0,0 +1,21 @@ +// Ported from Node +// https://github.com/nodejs/node/blob/54746bb763ebea0dc7e99d88ff4b379bcd680964/test/es-module/test-esm-tla.mjs + +const { default: order } = await import("./tla/parent.js"); + +console.log("order", JSON.stringify(order)); + +if ( + !( + order[0] === "order" && + order[1] === "b" && + order[2] === "c" && + order[3] === "d" && + order[4] === "a" && + order[5] === "parent" + ) +) { + throw new Error("TLA wrong order"); +} + +console.log("TLA order correct"); diff --git a/cli/tests/testdata/top_level_await_order.out b/cli/tests/testdata/top_level_await_order.out new file mode 100644 index 000000000..4cc27858c --- /dev/null +++ b/cli/tests/testdata/top_level_await_order.out @@ -0,0 +1,2 @@ +order ["order","b","c","d","a","parent"] +TLA order correct diff --git a/cli/tests/testdata/top_level_await_unresolved.js b/cli/tests/testdata/top_level_await_unresolved.js new file mode 100644 index 000000000..231a8cd63 --- /dev/null +++ b/cli/tests/testdata/top_level_await_unresolved.js @@ -0,0 +1 @@ +await new Promise(() => {}); diff --git a/cli/tests/testdata/top_level_await_unresolved.out b/cli/tests/testdata/top_level_await_unresolved.out new file mode 100644 index 000000000..77395f5d0 --- /dev/null +++ b/cli/tests/testdata/top_level_await_unresolved.out @@ -0,0 +1 @@ +error: Module evaluation is still pending but there are no pending ops or dynamic imports. This situation is often caused by unresolved promise. diff --git a/cli/tests/testdata/top_level_for_await.js b/cli/tests/testdata/top_level_for_await.js new file mode 100644 index 000000000..a330f6c71 --- /dev/null +++ b/cli/tests/testdata/top_level_for_await.js @@ -0,0 +1,10 @@ +function* asyncGenerator() { + let i = 0; + while (i < 3) { + yield i++; + } +} + +for await (const num of asyncGenerator()) { + console.log(num); +} diff --git a/cli/tests/testdata/top_level_for_await.out b/cli/tests/testdata/top_level_for_await.out new file mode 100644 index 000000000..4539bbf2d --- /dev/null +++ b/cli/tests/testdata/top_level_for_await.out @@ -0,0 +1,3 @@ +0 +1 +2 diff --git a/cli/tests/testdata/top_level_for_await.ts b/cli/tests/testdata/top_level_for_await.ts new file mode 100644 index 000000000..9179322d7 --- /dev/null +++ b/cli/tests/testdata/top_level_for_await.ts @@ -0,0 +1,10 @@ +async function* asyncGenerator(): AsyncIterableIterator<number> { + let i = 0; + while (i < 3) { + yield i++; + } +} + +for await (const num of asyncGenerator()) { + console.log(num); +} diff --git a/cli/tests/testdata/ts_decorators.ts b/cli/tests/testdata/ts_decorators.ts new file mode 100644 index 000000000..95fba6cd4 --- /dev/null +++ b/cli/tests/testdata/ts_decorators.ts @@ -0,0 +1,14 @@ +// deno-lint-ignore-file + +function Decorate() { + return function (constructor: any): any { + return class extends constructor { + protected someField: string = "asdf"; + }; + }; +} + +@Decorate() +class SomeClass {} + +console.log(new SomeClass()); diff --git a/cli/tests/testdata/ts_decorators.ts.out b/cli/tests/testdata/ts_decorators.ts.out new file mode 100644 index 000000000..381c7a809 --- /dev/null +++ b/cli/tests/testdata/ts_decorators.ts.out @@ -0,0 +1,2 @@ +Check [WILDCARD] +{ someField: "asdf" } diff --git a/cli/tests/testdata/ts_decorators_bundle.out b/cli/tests/testdata/ts_decorators_bundle.out new file mode 100644 index 000000000..a5b77b7bf --- /dev/null +++ b/cli/tests/testdata/ts_decorators_bundle.out @@ -0,0 +1,5 @@ +[WILDCARD] +function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { +[WILDCARD] +new SomeClass().test(); +[WILDCARD]
\ No newline at end of file diff --git a/cli/tests/testdata/ts_decorators_bundle.ts b/cli/tests/testdata/ts_decorators_bundle.ts new file mode 100644 index 000000000..72120b2ec --- /dev/null +++ b/cli/tests/testdata/ts_decorators_bundle.ts @@ -0,0 +1,25 @@ +// deno-lint-ignore-file + +import { B } from "./subdir/more_decorators.ts"; + +function Decorator() { + return function ( + target: Record<string, any>, + propertyKey: string, + descriptor: TypedPropertyDescriptor<any>, + ) { + const originalFn: Function = descriptor.value as Function; + descriptor.value = async function (...args: any[]) { + return await originalFn.apply(this, args); + }; + return descriptor; + }; +} + +class SomeClass { + @Decorator() + async test() {} +} + +new SomeClass().test(); +new B().method(); diff --git a/cli/tests/testdata/ts_import_from_js.deps.js b/cli/tests/testdata/ts_import_from_js.deps.js new file mode 100644 index 000000000..ef326c444 --- /dev/null +++ b/cli/tests/testdata/ts_import_from_js.deps.js @@ -0,0 +1,2 @@ +import "./005_more_imports.ts"; +export { printHello } from "http://localhost:4545/subdir/mod2.ts"; diff --git a/cli/tests/testdata/ts_import_from_js.js b/cli/tests/testdata/ts_import_from_js.js new file mode 100644 index 000000000..f912c2723 --- /dev/null +++ b/cli/tests/testdata/ts_import_from_js.js @@ -0,0 +1,3 @@ +import { printHello } from "./ts_import_from_js.deps.js"; +printHello(); +console.log("success"); diff --git a/cli/tests/testdata/ts_import_from_js.js.out b/cli/tests/testdata/ts_import_from_js.js.out new file mode 100644 index 000000000..e1d7a869f --- /dev/null +++ b/cli/tests/testdata/ts_import_from_js.js.out @@ -0,0 +1,3 @@ +Hello +Hello +success diff --git a/cli/tests/testdata/ts_type_imports.ts b/cli/tests/testdata/ts_type_imports.ts new file mode 100644 index 000000000..73c779156 --- /dev/null +++ b/cli/tests/testdata/ts_type_imports.ts @@ -0,0 +1,5 @@ +// deno-lint-ignore-file + +type Foo = import("./ts_type_imports_foo.ts").Foo; + +const foo: Foo = new Map<string, string>(); diff --git a/cli/tests/testdata/ts_type_imports.ts.out b/cli/tests/testdata/ts_type_imports.ts.out new file mode 100644 index 000000000..3972d6a97 --- /dev/null +++ b/cli/tests/testdata/ts_type_imports.ts.out @@ -0,0 +1,6 @@ +Check [WILDCARD]ts_type_imports.ts +error: TS2322 [ERROR]: Type 'Map<string, string>' is not assignable to type 'Foo'. + Type 'string' is not assignable to type 'number'. +const foo: Foo = new Map<string, string>(); + ~~~ + at [WILDCARD]ts_type_imports.ts:5:7 diff --git a/cli/tests/testdata/ts_type_imports_foo.ts b/cli/tests/testdata/ts_type_imports_foo.ts new file mode 100644 index 000000000..db20773f6 --- /dev/null +++ b/cli/tests/testdata/ts_type_imports_foo.ts @@ -0,0 +1 @@ +export type Foo = Map<string, number>; diff --git a/cli/tests/testdata/ts_type_only_import.d.ts b/cli/tests/testdata/ts_type_only_import.d.ts new file mode 100644 index 000000000..d48e4b48a --- /dev/null +++ b/cli/tests/testdata/ts_type_only_import.d.ts @@ -0,0 +1,3 @@ +export interface HelloWorld { + a: string; +} diff --git a/cli/tests/testdata/ts_type_only_import.ts b/cli/tests/testdata/ts_type_only_import.ts new file mode 100644 index 000000000..53e114373 --- /dev/null +++ b/cli/tests/testdata/ts_type_only_import.ts @@ -0,0 +1 @@ +export * from "./ts_type_only_import.d.ts"; diff --git a/cli/tests/testdata/ts_type_only_import.ts.out b/cli/tests/testdata/ts_type_only_import.ts.out new file mode 100644 index 000000000..f808ed21a --- /dev/null +++ b/cli/tests/testdata/ts_type_only_import.ts.out @@ -0,0 +1,4 @@ +Check [WILDCARD]ts_type_only_import.ts +warning: Compiled module not found "[WILDCARD]ts_type_only_import.d.ts" + From: [WILDCARD]ts_type_only_import.ts + If the source module contains only types, use `import type` and `export type` to import it instead. diff --git a/cli/tests/testdata/ts_with_generic.ts b/cli/tests/testdata/ts_with_generic.ts new file mode 100644 index 000000000..1e3591f40 --- /dev/null +++ b/cli/tests/testdata/ts_with_generic.ts @@ -0,0 +1,3 @@ +// deno-lint-ignore-file + +const foo = { delete<S>() {} }; diff --git a/cli/tests/testdata/tsc/a.js b/cli/tests/testdata/tsc/a.js new file mode 100644 index 000000000..5a7b3ff93 --- /dev/null +++ b/cli/tests/testdata/tsc/a.js @@ -0,0 +1,2 @@ +import { v4 } from "./d.ts"; +export function a() {} diff --git a/cli/tests/testdata/tsc/d.ts b/cli/tests/testdata/tsc/d.ts new file mode 100644 index 000000000..3c74b8c83 --- /dev/null +++ b/cli/tests/testdata/tsc/d.ts @@ -0,0 +1,3 @@ +export function v4() { + return "hello"; +} diff --git a/cli/tests/testdata/tsc/node_modules/b.js b/cli/tests/testdata/tsc/node_modules/b.js new file mode 100644 index 000000000..191660935 --- /dev/null +++ b/cli/tests/testdata/tsc/node_modules/b.js @@ -0,0 +1,2 @@ +import c from "./c.js"; +export { c }; diff --git a/cli/tests/testdata/tsc/node_modules/c.js b/cli/tests/testdata/tsc/node_modules/c.js new file mode 100644 index 000000000..cff71c44a --- /dev/null +++ b/cli/tests/testdata/tsc/node_modules/c.js @@ -0,0 +1 @@ +export default function c() {} diff --git a/cli/tests/testdata/tsc/test.js b/cli/tests/testdata/tsc/test.js new file mode 100644 index 000000000..b7f46b351 --- /dev/null +++ b/cli/tests/testdata/tsc/test.js @@ -0,0 +1,4 @@ +import { a } from "./a.js"; +import { c } from "./node_modules/b.js"; + +console.log("hello"); diff --git a/cli/tests/testdata/tsc2/file_exportc.ts b/cli/tests/testdata/tsc2/file_exportc.ts new file mode 100644 index 000000000..efcc5bb46 --- /dev/null +++ b/cli/tests/testdata/tsc2/file_exportc.ts @@ -0,0 +1 @@ +export * as c from "https://deno.land/x/c.js"; diff --git a/cli/tests/testdata/tsc2/file_libref.ts b/cli/tests/testdata/tsc2/file_libref.ts new file mode 100644 index 000000000..6f37da139 --- /dev/null +++ b/cli/tests/testdata/tsc2/file_libref.ts @@ -0,0 +1,8 @@ +// deno-lint-ignore-file +/// <reference no-default-lib="true"/> +/// <reference lib="dom" /> +/// <reference lib="deno.ns" /> + +export const div = document.createElement("div"); +div.innerHTML = `<span>Hello World!</span>`; +console.log(Deno.args); diff --git a/cli/tests/testdata/tsc2/file_main.ts b/cli/tests/testdata/tsc2/file_main.ts new file mode 100644 index 000000000..a45477fde --- /dev/null +++ b/cli/tests/testdata/tsc2/file_main.ts @@ -0,0 +1 @@ +console.log("hello deno"); diff --git a/cli/tests/testdata/tsc2/file_reexports.ts b/cli/tests/testdata/tsc2/file_reexports.ts new file mode 100644 index 000000000..b26297423 --- /dev/null +++ b/cli/tests/testdata/tsc2/file_reexports.ts @@ -0,0 +1,3 @@ +import * as c from "./exportc.ts"; + +console.log(c.c); diff --git a/cli/tests/testdata/tsc2/https_deno.land-x-a.ts b/cli/tests/testdata/tsc2/https_deno.land-x-a.ts new file mode 100644 index 000000000..72b3a67bc --- /dev/null +++ b/cli/tests/testdata/tsc2/https_deno.land-x-a.ts @@ -0,0 +1,3 @@ +import * as b from "./b.ts"; + +console.log(b); diff --git a/cli/tests/testdata/tsc2/https_deno.land-x-b.ts b/cli/tests/testdata/tsc2/https_deno.land-x-b.ts new file mode 100644 index 000000000..59d168993 --- /dev/null +++ b/cli/tests/testdata/tsc2/https_deno.land-x-b.ts @@ -0,0 +1 @@ +export const b = "b"; diff --git a/cli/tests/testdata/tsc2/https_deno.land-x-c.d.ts b/cli/tests/testdata/tsc2/https_deno.land-x-c.d.ts new file mode 100644 index 000000000..bf3a09240 --- /dev/null +++ b/cli/tests/testdata/tsc2/https_deno.land-x-c.d.ts @@ -0,0 +1 @@ +export const c: string; diff --git a/cli/tests/testdata/tsc2/https_deno.land-x-c.js b/cli/tests/testdata/tsc2/https_deno.land-x-c.js new file mode 100644 index 000000000..7f2cfac77 --- /dev/null +++ b/cli/tests/testdata/tsc2/https_deno.land-x-c.js @@ -0,0 +1 @@ +export const c = "c"; diff --git a/cli/tests/testdata/tsc2/https_deno.land-x-mod.ts b/cli/tests/testdata/tsc2/https_deno.land-x-mod.ts new file mode 100644 index 000000000..a45477fde --- /dev/null +++ b/cli/tests/testdata/tsc2/https_deno.land-x-mod.ts @@ -0,0 +1 @@ +console.log("hello deno"); diff --git a/cli/tests/testdata/tsconfig.decorators.json b/cli/tests/testdata/tsconfig.decorators.json new file mode 100644 index 000000000..504cd646e --- /dev/null +++ b/cli/tests/testdata/tsconfig.decorators.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "experimentalDecorators": true + } +} diff --git a/cli/tests/testdata/tsx_imports.ts b/cli/tests/testdata/tsx_imports.ts new file mode 100644 index 000000000..44ba10b7a --- /dev/null +++ b/cli/tests/testdata/tsx_imports.ts @@ -0,0 +1 @@ +import "./Component.tsx"; diff --git a/cli/tests/testdata/tsx_imports.ts.out b/cli/tests/testdata/tsx_imports.ts.out new file mode 100644 index 000000000..1f8b10d32 --- /dev/null +++ b/cli/tests/testdata/tsx_imports.ts.out @@ -0,0 +1,2 @@ +Check [WILDCARD]tsx_imports.ts +{ factory: [Function: View], props: null, children: [] } diff --git a/cli/tests/testdata/type_definitions.ts b/cli/tests/testdata/type_definitions.ts new file mode 100644 index 000000000..a1bb37a65 --- /dev/null +++ b/cli/tests/testdata/type_definitions.ts @@ -0,0 +1,12 @@ +// deno-lint-ignore-file + +// @deno-types="./type_definitions/foo.d.ts" +import { foo } from "./type_definitions/foo.js"; +// @deno-types="./type_definitions/fizz.d.ts" +import "./type_definitions/fizz.js"; + +import * as qat from "./type_definitions/qat.ts"; + +console.log(foo); +console.log(fizz); +console.log(qat.qat); diff --git a/cli/tests/testdata/type_definitions.ts.out b/cli/tests/testdata/type_definitions.ts.out new file mode 100644 index 000000000..b4fa88c50 --- /dev/null +++ b/cli/tests/testdata/type_definitions.ts.out @@ -0,0 +1,3 @@ +[WILDCARD]foo +fizz +qat diff --git a/cli/tests/testdata/type_definitions/bar.d.ts b/cli/tests/testdata/type_definitions/bar.d.ts new file mode 100644 index 000000000..d43335dbb --- /dev/null +++ b/cli/tests/testdata/type_definitions/bar.d.ts @@ -0,0 +1,7 @@ +/// <reference types="baz" /> + +declare namespace bar { + export class Bar { + baz: string; + } +} diff --git a/cli/tests/testdata/type_definitions/bar.js b/cli/tests/testdata/type_definitions/bar.js new file mode 100644 index 000000000..e9c2e5193 --- /dev/null +++ b/cli/tests/testdata/type_definitions/bar.js @@ -0,0 +1,5 @@ +export class Bar { + constructor() { + this.baz = "baz"; + } +} diff --git a/cli/tests/testdata/type_definitions/fizz.d.ts b/cli/tests/testdata/type_definitions/fizz.d.ts new file mode 100644 index 000000000..34eb41b96 --- /dev/null +++ b/cli/tests/testdata/type_definitions/fizz.d.ts @@ -0,0 +1,2 @@ +/** A global value. */ +declare const fizz: string; diff --git a/cli/tests/testdata/type_definitions/fizz.js b/cli/tests/testdata/type_definitions/fizz.js new file mode 100644 index 000000000..852162c94 --- /dev/null +++ b/cli/tests/testdata/type_definitions/fizz.js @@ -0,0 +1 @@ +globalThis.fizz = "fizz"; diff --git a/cli/tests/testdata/type_definitions/foo.d.ts b/cli/tests/testdata/type_definitions/foo.d.ts new file mode 100644 index 000000000..ce39201e1 --- /dev/null +++ b/cli/tests/testdata/type_definitions/foo.d.ts @@ -0,0 +1,2 @@ +/** An exported value. */ +export const foo: string; diff --git a/cli/tests/testdata/type_definitions/foo.js b/cli/tests/testdata/type_definitions/foo.js new file mode 100644 index 000000000..61d366eb2 --- /dev/null +++ b/cli/tests/testdata/type_definitions/foo.js @@ -0,0 +1 @@ +export const foo = "foo"; diff --git a/cli/tests/testdata/type_definitions/qat.ts b/cli/tests/testdata/type_definitions/qat.ts new file mode 100644 index 000000000..6196c9d38 --- /dev/null +++ b/cli/tests/testdata/type_definitions/qat.ts @@ -0,0 +1 @@ +export const qat = "qat"; diff --git a/cli/tests/testdata/type_definitions_for_export.ts b/cli/tests/testdata/type_definitions_for_export.ts new file mode 100644 index 000000000..1f17b4962 --- /dev/null +++ b/cli/tests/testdata/type_definitions_for_export.ts @@ -0,0 +1,7 @@ +import { foo } from "./export_type_def.ts"; + +function bar(a: number) { + console.log(a); +} + +bar(foo); diff --git a/cli/tests/testdata/type_definitions_for_export.ts.out b/cli/tests/testdata/type_definitions_for_export.ts.out new file mode 100644 index 000000000..8f1240bc7 --- /dev/null +++ b/cli/tests/testdata/type_definitions_for_export.ts.out @@ -0,0 +1,5 @@ +Check [WILDCARD]type_definitions_for_export.ts +error: TS2345 [ERROR]: Argument of type 'string' is not assignable to parameter of type 'number'. +bar(foo); + ~~~ + at [WILDCARD]type_definitions_for_export.ts:7:5 diff --git a/cli/tests/testdata/type_directives_01.ts b/cli/tests/testdata/type_directives_01.ts new file mode 100644 index 000000000..71305824c --- /dev/null +++ b/cli/tests/testdata/type_directives_01.ts @@ -0,0 +1,3 @@ +import * as foo from "http://127.0.0.1:4545/xTypeScriptTypes.js"; + +console.log(foo.foo); diff --git a/cli/tests/testdata/type_directives_01.ts.out b/cli/tests/testdata/type_directives_01.ts.out new file mode 100644 index 000000000..77ed3ae26 --- /dev/null +++ b/cli/tests/testdata/type_directives_01.ts.out @@ -0,0 +1,3 @@ +[WILDCARD] +DEBUG TS - host.getSourceFile("http://127.0.0.1:4545/xTypeScriptTypes.d.ts", Latest) +[WILDCARD]
\ No newline at end of file diff --git a/cli/tests/testdata/type_directives_02.ts b/cli/tests/testdata/type_directives_02.ts new file mode 100644 index 000000000..f7274bf26 --- /dev/null +++ b/cli/tests/testdata/type_directives_02.ts @@ -0,0 +1,3 @@ +import * as foo from "./subdir/type_reference.js"; + +console.log(foo.foo); diff --git a/cli/tests/testdata/type_directives_02.ts.out b/cli/tests/testdata/type_directives_02.ts.out new file mode 100644 index 000000000..b064483b4 --- /dev/null +++ b/cli/tests/testdata/type_directives_02.ts.out @@ -0,0 +1,3 @@ +[WILDCARD] +DEBUG TS - host.getSourceFile("file:///[WILDCARD]/subdir/type_reference.d.ts", Latest) +[WILDCARD]
\ No newline at end of file diff --git a/cli/tests/testdata/type_directives_js_main.js b/cli/tests/testdata/type_directives_js_main.js new file mode 100644 index 000000000..f7274bf26 --- /dev/null +++ b/cli/tests/testdata/type_directives_js_main.js @@ -0,0 +1,3 @@ +import * as foo from "./subdir/type_reference.js"; + +console.log(foo.foo); diff --git a/cli/tests/testdata/type_directives_js_main.js.out b/cli/tests/testdata/type_directives_js_main.js.out new file mode 100644 index 000000000..7bca837f0 --- /dev/null +++ b/cli/tests/testdata/type_directives_js_main.js.out @@ -0,0 +1,3 @@ +[WILDCARD] +DEBUG RS - [WILDCARD] - FileFetcher::fetch() - specifier: file:///[WILDCARD]/subdir/type_reference.d.ts +[WILDCARD] diff --git a/cli/tests/testdata/type_directives_redirect.ts b/cli/tests/testdata/type_directives_redirect.ts new file mode 100644 index 000000000..1756d5af9 --- /dev/null +++ b/cli/tests/testdata/type_directives_redirect.ts @@ -0,0 +1 @@ +import "http://localhost:4545/type_directives_redirect.js"; diff --git a/cli/tests/testdata/type_directives_redirect.ts.out b/cli/tests/testdata/type_directives_redirect.ts.out new file mode 100644 index 000000000..471d9c0b4 --- /dev/null +++ b/cli/tests/testdata/type_directives_redirect.ts.out @@ -0,0 +1,5 @@ +Download [WILDCARD]type_directives_redirect.js +Download [WILDCARD]xTypeScriptTypesRedirect.d.ts +Download [WILDCARD]xTypeScriptTypesRedirect.d.ts +Download [WILDCARD]xTypeScriptTypesRedirected.d.ts +Check [WILDCARD]type_directives_redirect.ts diff --git a/cli/tests/testdata/type_headers_deno_types.ts b/cli/tests/testdata/type_headers_deno_types.ts new file mode 100644 index 000000000..92391c666 --- /dev/null +++ b/cli/tests/testdata/type_headers_deno_types.ts @@ -0,0 +1,18 @@ +/** + * Following import uses two distinct ways to provide types: + * - X-TypeScript-Types headers + * - @deno-types directive + * + * Because "@deno-types" directive must be placed by user explicitly it + * should have higher precedence than type header. + * + * This is verified by providing conflicting type declaration + * depending on a way. There should be no TS error, otherwise + * it means that wrong type declarations are used (from X-TypeScript-Types) + * header. + */ + +// @deno-types="http://127.0.0.1:4545/type_headers_deno_types.foo.d.ts" +import { foo } from "http://127.0.0.1:4545/type_headers_deno_types.foo.js"; + +foo("hello"); diff --git a/cli/tests/testdata/type_headers_deno_types.ts.out b/cli/tests/testdata/type_headers_deno_types.ts.out new file mode 100644 index 000000000..f1e4ca1f8 --- /dev/null +++ b/cli/tests/testdata/type_headers_deno_types.ts.out @@ -0,0 +1,5 @@ +Download http://[WILDCARD]:4545/type_headers_deno_types.foo.js +Download http://[WILDCARD]:4545/type_headers_deno_types.foo.d.ts +Download http://[WILDCARD]:4545/type_headers_deno_types.d.ts +Check [WILDCARD]/type_headers_deno_types.ts +hello diff --git a/cli/tests/testdata/types.out b/cli/tests/testdata/types.out new file mode 100644 index 000000000..9cda650eb --- /dev/null +++ b/cli/tests/testdata/types.out @@ -0,0 +1,4 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +[WILDCARD] +declare namespace Deno [WILDCARD] +declare var window: Window [WILDCARD] diff --git a/cli/tests/testdata/unbuffered_stderr.ts b/cli/tests/testdata/unbuffered_stderr.ts new file mode 100644 index 000000000..0f1d2a999 --- /dev/null +++ b/cli/tests/testdata/unbuffered_stderr.ts @@ -0,0 +1 @@ +Deno.stderr.write(new TextEncoder().encode("x")); diff --git a/cli/tests/testdata/unbuffered_stderr.ts.out b/cli/tests/testdata/unbuffered_stderr.ts.out new file mode 100644 index 000000000..500019738 --- /dev/null +++ b/cli/tests/testdata/unbuffered_stderr.ts.out @@ -0,0 +1,2 @@ +[WILDCARD] +x
\ No newline at end of file diff --git a/cli/tests/testdata/unbuffered_stdout.ts b/cli/tests/testdata/unbuffered_stdout.ts new file mode 100644 index 000000000..9f1e07a97 --- /dev/null +++ b/cli/tests/testdata/unbuffered_stdout.ts @@ -0,0 +1 @@ +Deno.stdout.write(new TextEncoder().encode("a")); diff --git a/cli/tests/testdata/unbuffered_stdout.ts.out b/cli/tests/testdata/unbuffered_stdout.ts.out new file mode 100644 index 000000000..2e65efe2a --- /dev/null +++ b/cli/tests/testdata/unbuffered_stdout.ts.out @@ -0,0 +1 @@ +a
\ No newline at end of file diff --git a/cli/tests/testdata/unstable.js b/cli/tests/testdata/unstable.js new file mode 100644 index 000000000..a9894be3e --- /dev/null +++ b/cli/tests/testdata/unstable.js @@ -0,0 +1 @@ +console.log(Deno.loadavg); diff --git a/cli/tests/testdata/unstable.ts b/cli/tests/testdata/unstable.ts new file mode 100644 index 000000000..a9894be3e --- /dev/null +++ b/cli/tests/testdata/unstable.ts @@ -0,0 +1 @@ +console.log(Deno.loadavg); diff --git a/cli/tests/testdata/unstable_disabled.out b/cli/tests/testdata/unstable_disabled.out new file mode 100644 index 000000000..28659645d --- /dev/null +++ b/cli/tests/testdata/unstable_disabled.out @@ -0,0 +1,5 @@ +[WILDCARD] +error: TS2339 [ERROR]: Property 'loadavg' does not exist on type 'typeof Deno'. 'Deno.loadavg' is an unstable API. Did you forget to run with the '--unstable' flag? +console.log(Deno.loadavg); + ~~~~~~~ + at [WILDCARD]/unstable.ts:1:18 diff --git a/cli/tests/testdata/unstable_disabled_js.out b/cli/tests/testdata/unstable_disabled_js.out new file mode 100644 index 000000000..417b7b537 --- /dev/null +++ b/cli/tests/testdata/unstable_disabled_js.out @@ -0,0 +1 @@ +undefined diff --git a/cli/tests/testdata/unstable_enabled.out b/cli/tests/testdata/unstable_enabled.out new file mode 100644 index 000000000..b4cedce14 --- /dev/null +++ b/cli/tests/testdata/unstable_enabled.out @@ -0,0 +1 @@ +[Function: loadavg] diff --git a/cli/tests/testdata/unstable_enabled_js.out b/cli/tests/testdata/unstable_enabled_js.out new file mode 100644 index 000000000..b4cedce14 --- /dev/null +++ b/cli/tests/testdata/unstable_enabled_js.out @@ -0,0 +1 @@ +[Function: loadavg] diff --git a/cli/tests/testdata/unstable_worker.ts b/cli/tests/testdata/unstable_worker.ts new file mode 100644 index 000000000..429754dfe --- /dev/null +++ b/cli/tests/testdata/unstable_worker.ts @@ -0,0 +1,12 @@ +const w = new Worker( + new URL("workers/worker_unstable.ts", import.meta.url).href, + { + type: "module", + deno: { + namespace: true, + }, + name: "Unstable Worker", + }, +); + +w.postMessage({}); diff --git a/cli/tests/testdata/unstable_worker.ts.out b/cli/tests/testdata/unstable_worker.ts.out new file mode 100644 index 000000000..ece47de97 --- /dev/null +++ b/cli/tests/testdata/unstable_worker.ts.out @@ -0,0 +1,2 @@ +[Function: query] +[Function: emit] diff --git a/cli/tests/testdata/unsupported_dynamic_import_scheme.out b/cli/tests/testdata/unsupported_dynamic_import_scheme.out new file mode 100644 index 000000000..c708fced4 --- /dev/null +++ b/cli/tests/testdata/unsupported_dynamic_import_scheme.out @@ -0,0 +1,7 @@ +error: Uncaught (in promise) TypeError: Unsupported scheme "xxx" for module "xxx:". Supported schemes: [ + "data", + "blob", + "file", + "http", + "https", +] diff --git a/cli/tests/testdata/v8_flags.js b/cli/tests/testdata/v8_flags.js new file mode 100644 index 000000000..f7999c4af --- /dev/null +++ b/cli/tests/testdata/v8_flags.js @@ -0,0 +1 @@ +console.log(typeof gc); diff --git a/cli/tests/testdata/v8_flags.js.out b/cli/tests/testdata/v8_flags.js.out new file mode 100644 index 000000000..e2dbde096 --- /dev/null +++ b/cli/tests/testdata/v8_flags.js.out @@ -0,0 +1 @@ +function diff --git a/cli/tests/testdata/v8_flags_unrecognized.out b/cli/tests/testdata/v8_flags_unrecognized.out new file mode 100644 index 000000000..56e70f830 --- /dev/null +++ b/cli/tests/testdata/v8_flags_unrecognized.out @@ -0,0 +1,5 @@ +error: V8 did not recognize flag '--foo' +error: V8 did not recognize flag 'bar' +error: V8 did not recognize flag '-baz' + +For a list of V8 flags, use '--v8-flags=--help' diff --git a/cli/tests/testdata/v8_help.out b/cli/tests/testdata/v8_help.out new file mode 100644 index 000000000..006d73557 --- /dev/null +++ b/cli/tests/testdata/v8_help.out @@ -0,0 +1,4 @@ +[WILDCARD] +Options: +[WILDCARD] + --trace-gc [WILDCARD] diff --git a/cli/tests/testdata/wasm.ts b/cli/tests/testdata/wasm.ts new file mode 100644 index 000000000..96b5fdffc --- /dev/null +++ b/cli/tests/testdata/wasm.ts @@ -0,0 +1,16 @@ +// deno-fmt-ignore +const wasmCode = new Uint8Array([ + 0, 97, 115, 109, 1, 0, 0, 0, 1, 133, 128, 128, 128, 0, 1, 96, 0, 1, 127, + 3, 130, 128, 128, 128, 0, 1, 0, 4, 132, 128, 128, 128, 0, 1, 112, 0, 0, + 5, 131, 128, 128, 128, 0, 1, 0, 1, 6, 129, 128, 128, 128, 0, 0, 7, 145, + 128, 128, 128, 0, 2, 6, 109, 101, 109, 111, 114, 121, 2, 0, 4, 109, 97, + 105, 110, 0, 0, 10, 138, 128, 128, 128, 0, 1, 132, 128, 128, 128, 0, 0, + 65, 42, 11 + ]); + +const wasmModule = new WebAssembly.Module(wasmCode); + +const wasmInstance = new WebAssembly.Instance(wasmModule); + +const main = wasmInstance.exports.main as CallableFunction; +console.log(main().toString()); diff --git a/cli/tests/testdata/wasm.ts.out b/cli/tests/testdata/wasm.ts.out new file mode 100644 index 000000000..d81cc0710 --- /dev/null +++ b/cli/tests/testdata/wasm.ts.out @@ -0,0 +1 @@ +42 diff --git a/cli/tests/testdata/wasm_async.js b/cli/tests/testdata/wasm_async.js new file mode 100644 index 000000000..837460ae9 --- /dev/null +++ b/cli/tests/testdata/wasm_async.js @@ -0,0 +1,27 @@ +// The following blob can be created by taking the following s-expr and pass +// it through wat2wasm. +// (module +// (func $add (param $a i32) (param $b i32) (result i32) +// local.get $a +// local.get $b +// i32.add) +// (export "add" (func $add)) +// ) +// deno-fmt-ignore +const bytes = new Uint8Array([ + 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x07, 0x01, 0x60, + 0x02, 0x7f, 0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x07, 0x01, + 0x03, 0x61, 0x64, 0x64, 0x00, 0x00, 0x0a, 0x09, 0x01, 0x07, 0x00, 0x20, + 0x00, 0x20, 0x01, 0x6a, 0x0b +]); + +async function main() { + const wasm = await WebAssembly.instantiate(bytes); + const result = wasm.instance.exports.add(1, 3); + console.log("1 + 3 =", result); + if (result != 4) { + throw Error("bad"); + } +} + +main(); diff --git a/cli/tests/testdata/wasm_async.out b/cli/tests/testdata/wasm_async.out new file mode 100644 index 000000000..5cdf17de7 --- /dev/null +++ b/cli/tests/testdata/wasm_async.out @@ -0,0 +1 @@ +1 + 3 = 4 diff --git a/cli/tests/testdata/wasm_shared.out b/cli/tests/testdata/wasm_shared.out new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/cli/tests/testdata/wasm_shared.out diff --git a/cli/tests/testdata/wasm_shared.ts b/cli/tests/testdata/wasm_shared.ts new file mode 100644 index 000000000..b713385d5 --- /dev/null +++ b/cli/tests/testdata/wasm_shared.ts @@ -0,0 +1,6 @@ +const memory = new WebAssembly.Memory({ + initial: 1, + maximum: 10, + shared: true, +}); +console.assert(memory.buffer instanceof SharedArrayBuffer); diff --git a/cli/tests/testdata/wasm_unreachable.js b/cli/tests/testdata/wasm_unreachable.js new file mode 100644 index 000000000..991ebcec8 --- /dev/null +++ b/cli/tests/testdata/wasm_unreachable.js @@ -0,0 +1,50 @@ +// WebAssembly module containing a single function with an unreachable instruction +const binary = Uint8Array.from([ + 0x00, + 0x61, + 0x73, + 0x6d, + 0x01, + 0x00, + 0x00, + 0x00, + 0x01, + 0x04, + 0x01, + 0x60, + 0x00, + 0x00, + 0x03, + 0x02, + 0x01, + 0x00, + 0x07, + 0x0f, + 0x01, + 0x0b, + 0x75, + 0x6e, + 0x72, + 0x65, + 0x61, + 0x63, + 0x68, + 0x61, + 0x62, + 0x6c, + 0x65, + 0x00, + 0x00, + 0x0a, + 0x05, + 0x01, + 0x03, + 0x00, + 0x00, + 0x0b, +]); + +const module = new WebAssembly.Module(binary); +const instance = new WebAssembly.Instance(module); + +instance.exports.unreachable(); diff --git a/cli/tests/testdata/wasm_unreachable.out b/cli/tests/testdata/wasm_unreachable.out new file mode 100644 index 000000000..28fe00de6 --- /dev/null +++ b/cli/tests/testdata/wasm_unreachable.out @@ -0,0 +1,3 @@ +error: Uncaught RuntimeError: unreachable + at <anonymous> (wasm://wasm/[WILDCARD]) + at [WILDCARD]/wasm_unreachable.js:[WILDCARD] diff --git a/cli/tests/testdata/weakref.ts b/cli/tests/testdata/weakref.ts new file mode 100644 index 000000000..47c3985fe --- /dev/null +++ b/cli/tests/testdata/weakref.ts @@ -0,0 +1 @@ +console.log(WeakRef, FinalizationRegistry); diff --git a/cli/tests/testdata/weakref.ts.out b/cli/tests/testdata/weakref.ts.out new file mode 100644 index 000000000..32bafcf2d --- /dev/null +++ b/cli/tests/testdata/weakref.ts.out @@ -0,0 +1 @@ +[Function: WeakRef] [Function: FinalizationRegistry] diff --git a/cli/tests/testdata/webgpu_computepass_shader.wgsl b/cli/tests/testdata/webgpu_computepass_shader.wgsl new file mode 100644 index 000000000..7d4748e2a --- /dev/null +++ b/cli/tests/testdata/webgpu_computepass_shader.wgsl @@ -0,0 +1,37 @@ +[[block]] +struct PrimeIndices { + data: [[stride(4)]] array<u32>; +}; // this is used as both input and output for convenience +[[group(0), binding(0)]] +var<storage> v_indices: [[access(read_write)]] PrimeIndices; +// The Collatz Conjecture states that for any integer n: +// If n is even, n = n/2 +// If n is odd, n = 3n+1 +// And repeat this process for each new n, you will always eventually reach 1. +// Though the conjecture has not been proven, no counterexample has ever been found. +// This function returns how many times this recurrence needs to be applied to reach 1. +fn collatz_iterations(n_base: u32) -> u32{ + var n: u32 = n_base; + var i: u32 = 0u; + loop { + if (n <= 1u) { + break; + } + if (n % 2u == 0u) { + n = n / 2u; + } + else { + // Overflow? (i.e. 3*n + 1 > 0xffffffffu?) + if (n >= 1431655765u) { // 0x55555555u + return 4294967295u; // 0xffffffffu + } + n = 3u * n + 1u; + } + i = i + 1u; + } + return i; +} +[[stage(compute), workgroup_size(1)]] +fn main([[builtin(global_invocation_id)]] global_id: vec3<u32>) { + v_indices.data[global_id.x] = collatz_iterations(v_indices.data[global_id.x]); +} diff --git a/cli/tests/testdata/webgpu_hellotriangle.out b/cli/tests/testdata/webgpu_hellotriangle.out Binary files differnew file mode 100644 index 000000000..91454dbfc --- /dev/null +++ b/cli/tests/testdata/webgpu_hellotriangle.out diff --git a/cli/tests/testdata/webgpu_hellotriangle_shader.wgsl b/cli/tests/testdata/webgpu_hellotriangle_shader.wgsl new file mode 100644 index 000000000..b8b2b69fc --- /dev/null +++ b/cli/tests/testdata/webgpu_hellotriangle_shader.wgsl @@ -0,0 +1,10 @@ +[[stage(vertex)]] +fn vs_main([[builtin(vertex_index)]] in_vertex_index: u32) -> [[builtin(position)]] vec4<f32> { + let x = f32(i32(in_vertex_index) - 1); + let y = f32(i32(in_vertex_index & 1u) * 2 - 1); + return vec4<f32>(x, y, 0.0, 1.0); +} +[[stage(fragment)]] +fn fs_main() -> [[location(0)]] vec4<f32> { + return vec4<f32>(1.0, 0.0, 0.0, 1.0); +} diff --git a/cli/tests/testdata/websocket_test.ts b/cli/tests/testdata/websocket_test.ts new file mode 100644 index 000000000..5229ad875 --- /dev/null +++ b/cli/tests/testdata/websocket_test.ts @@ -0,0 +1,308 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +import { + assert, + assertEquals, + assertThrows, + fail, +} from "../../../test_util/std/testing/asserts.ts"; +import { deferred } from "../../../test_util/std/async/deferred.ts"; + +Deno.test("invalid scheme", () => { + assertThrows(() => new WebSocket("foo://localhost:4242")); +}); + +Deno.test("fragment", () => { + assertThrows(() => new WebSocket("ws://localhost:4242/#")); + assertThrows(() => new WebSocket("ws://localhost:4242/#foo")); +}); + +Deno.test("duplicate protocols", () => { + assertThrows(() => new WebSocket("ws://localhost:4242", ["foo", "foo"])); +}); + +Deno.test("invalid server", async () => { + const promise = deferred(); + const ws = new WebSocket("ws://localhost:2121"); + let err = false; + ws.onerror = () => { + err = true; + }; + ws.onclose = () => { + if (err) { + promise.resolve(); + } else { + fail(); + } + }; + ws.onopen = () => fail(); + await promise; +}); + +Deno.test("connect & close", async () => { + const promise = deferred(); + const ws = new WebSocket("ws://localhost:4242"); + ws.onerror = () => fail(); + ws.onopen = () => { + ws.close(); + }; + ws.onclose = () => { + promise.resolve(); + }; + await promise; +}); + +Deno.test("connect & abort", async () => { + const promise = deferred(); + const ws = new WebSocket("ws://localhost:4242"); + ws.close(); + let err = false; + ws.onerror = () => { + err = true; + }; + ws.onclose = () => { + if (err) { + promise.resolve(); + } else { + fail(); + } + }; + ws.onopen = () => fail(); + await promise; +}); + +Deno.test("connect & close custom valid code", async () => { + const promise = deferred(); + const ws = new WebSocket("ws://localhost:4242"); + ws.onerror = () => fail(); + ws.onopen = () => ws.close(1000); + ws.onclose = () => { + promise.resolve(); + }; + await promise; +}); + +Deno.test("connect & close custom invalid code", async () => { + const promise = deferred(); + const ws = new WebSocket("ws://localhost:4242"); + ws.onerror = () => fail(); + ws.onopen = () => { + assertThrows(() => ws.close(1001)); + ws.close(); + }; + ws.onclose = () => { + promise.resolve(); + }; + await promise; +}); + +Deno.test("connect & close custom valid reason", async () => { + const promise = deferred(); + const ws = new WebSocket("ws://localhost:4242"); + ws.onerror = () => fail(); + ws.onopen = () => ws.close(1000, "foo"); + ws.onclose = () => { + promise.resolve(); + }; + await promise; +}); + +Deno.test("connect & close custom invalid reason", async () => { + const promise = deferred(); + const ws = new WebSocket("ws://localhost:4242"); + ws.onerror = () => fail(); + ws.onopen = () => { + assertThrows(() => ws.close(1000, "".padEnd(124, "o"))); + ws.close(); + }; + ws.onclose = () => { + promise.resolve(); + }; + await promise; +}); + +Deno.test("echo string", async () => { + const promise = deferred(); + const ws = new WebSocket("ws://localhost:4242"); + ws.onerror = () => fail(); + ws.onopen = () => ws.send("foo"); + ws.onmessage = (e) => { + assertEquals(e.data, "foo"); + ws.close(); + }; + ws.onclose = () => { + promise.resolve(); + }; + await promise; +}); + +Deno.test("echo string tls", async () => { + const promise1 = deferred(); + const promise2 = deferred(); + const ws = new WebSocket("wss://localhost:4243"); + ws.onerror = () => fail(); + ws.onopen = () => ws.send("foo"); + ws.onmessage = (e) => { + assertEquals(e.data, "foo"); + ws.close(); + promise1.resolve(); + }; + ws.onclose = () => { + promise2.resolve(); + }; + await promise1; + await promise2; +}); + +Deno.test("websocket error", async () => { + const promise1 = deferred(); + const ws = new WebSocket("wss://localhost:4242"); + ws.onopen = () => fail(); + ws.onerror = (err) => { + assert(err instanceof ErrorEvent); + + // Error message got changed because we don't use warp in test_util + assertEquals(err.message, "UnexpectedEof: tls handshake eof"); + promise1.resolve(); + }; + await promise1; +}); + +Deno.test("echo blob with binaryType blob", async () => { + const promise = deferred(); + const ws = new WebSocket("ws://localhost:4242"); + const blob = new Blob(["foo"]); + ws.onerror = () => fail(); + ws.onopen = () => ws.send(blob); + ws.onmessage = (e) => { + e.data.text().then((actual: string) => { + blob.text().then((expected) => { + assertEquals(actual, expected); + }); + }); + ws.close(); + }; + ws.onclose = () => { + promise.resolve(); + }; + await promise; +}); + +Deno.test("echo blob with binaryType arraybuffer", async () => { + const promise = deferred(); + const ws = new WebSocket("ws://localhost:4242"); + ws.binaryType = "arraybuffer"; + const blob = new Blob(["foo"]); + ws.onerror = () => fail(); + ws.onopen = () => ws.send(blob); + ws.onmessage = (e) => { + blob.arrayBuffer().then((expected) => { + assertEquals(e.data, expected); + }); + ws.close(); + }; + ws.onclose = () => { + promise.resolve(); + }; + await promise; +}); + +Deno.test("echo uint8array with binaryType blob", async () => { + const promise = deferred(); + const ws = new WebSocket("ws://localhost:4242"); + const uint = new Uint8Array([102, 111, 111]); + ws.onerror = () => fail(); + ws.onopen = () => ws.send(uint); + ws.onmessage = (e) => { + e.data.arrayBuffer().then((actual: ArrayBuffer) => { + assertEquals(actual, uint.buffer); + }); + ws.close(); + }; + ws.onclose = () => { + promise.resolve(); + }; + await promise; +}); + +Deno.test("echo uint8array with binaryType arraybuffer", async () => { + const promise = deferred(); + const ws = new WebSocket("ws://localhost:4242"); + ws.binaryType = "arraybuffer"; + const uint = new Uint8Array([102, 111, 111]); + ws.onerror = () => fail(); + ws.onopen = () => ws.send(uint); + ws.onmessage = (e) => { + assertEquals(e.data, uint.buffer); + ws.close(); + }; + ws.onclose = () => { + promise.resolve(); + }; + await promise; +}); + +Deno.test("echo arraybuffer with binaryType blob", async () => { + const promise = deferred(); + const ws = new WebSocket("ws://localhost:4242"); + const buffer = new ArrayBuffer(3); + ws.onerror = () => fail(); + ws.onopen = () => ws.send(buffer); + ws.onmessage = (e) => { + e.data.arrayBuffer().then((actual: ArrayBuffer) => { + assertEquals(actual, buffer); + }); + ws.close(); + }; + ws.onclose = () => { + promise.resolve(); + }; + await promise; +}); + +Deno.test("echo arraybuffer with binaryType arraybuffer", async () => { + const promise = deferred(); + const ws = new WebSocket("ws://localhost:4242"); + ws.binaryType = "arraybuffer"; + const buffer = new ArrayBuffer(3); + ws.onerror = () => fail(); + ws.onopen = () => ws.send(buffer); + ws.onmessage = (e) => { + assertEquals(e.data, buffer); + ws.close(); + }; + ws.onclose = () => { + promise.resolve(); + }; + await promise; +}); + +Deno.test("Event Handlers order", async () => { + const promise = deferred(); + const ws = new WebSocket("ws://localhost:4242"); + const arr: number[] = []; + ws.onerror = () => fail(); + ws.addEventListener("message", () => arr.push(1)); + ws.onmessage = () => fail(); + ws.addEventListener("message", () => { + arr.push(3); + ws.close(); + assertEquals(arr, [1, 2, 3]); + }); + ws.onmessage = () => arr.push(2); + ws.onopen = () => ws.send("Echo"); + ws.onclose = () => { + promise.resolve(); + }; + await promise; +}); + +Deno.test("Close without frame", async () => { + const promise = deferred(); + const ws = new WebSocket("ws://localhost:4244"); + ws.onerror = () => fail(); + ws.onclose = (e) => { + assertEquals(e.code, 1005); + promise.resolve(); + }; + await promise; +}); diff --git a/cli/tests/testdata/websocketstream_test.ts b/cli/tests/testdata/websocketstream_test.ts new file mode 100644 index 000000000..aa809ba16 --- /dev/null +++ b/cli/tests/testdata/websocketstream_test.ts @@ -0,0 +1,82 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. + +import { + assertEquals, + assertThrows, + assertThrowsAsync, +} from "../../../test_util/std/testing/asserts.ts"; + +Deno.test("fragment", () => { + assertThrows(() => new WebSocketStream("ws://localhost:4242/#")); + assertThrows(() => new WebSocketStream("ws://localhost:4242/#foo")); +}); + +Deno.test("duplicate protocols", () => { + assertThrows(() => + new WebSocketStream("ws://localhost:4242", { + protocols: ["foo", "foo"], + }) + ); +}); + +Deno.test("connect & close custom valid code", async () => { + const ws = new WebSocketStream("ws://localhost:4242"); + await ws.connection; + ws.close({ code: 1000 }); + await ws.closed; +}); + +Deno.test("connect & close custom invalid reason", async () => { + const ws = new WebSocketStream("ws://localhost:4242"); + await ws.connection; + assertThrows(() => ws.close({ code: 1000, reason: "".padEnd(124, "o") })); + ws.close(); + await ws.closed; +}); + +Deno.test("echo string", async () => { + const ws = new WebSocketStream("ws://localhost:4242"); + const { readable, writable } = await ws.connection; + await writable.getWriter().write("foo"); + const res = await readable.getReader().read(); + assertEquals(res.value, "foo"); + ws.close(); + await ws.closed; +}); + +Deno.test("echo string tls", async () => { + const ws = new WebSocketStream("wss://localhost:4243"); + const { readable, writable } = await ws.connection; + await writable.getWriter().write("foo"); + const res = await readable.getReader().read(); + assertEquals(res.value, "foo"); + ws.close(); + await ws.closed; +}); + +Deno.test("websocket error", async () => { + const ws = new WebSocketStream("wss://localhost:4242"); + await Promise.all([ + assertThrowsAsync( + () => ws.connection, + Deno.errors.UnexpectedEof, + "tls handshake eof", + ), + assertThrowsAsync( + () => ws.closed, + Deno.errors.UnexpectedEof, + "tls handshake eof", + ), + ]); +}); + +Deno.test("echo uint8array", async () => { + const ws = new WebSocketStream("ws://localhost:4242"); + const { readable, writable } = await ws.connection; + const uint = new Uint8Array([102, 111, 111]); + await writable.getWriter().write(uint); + const res = await readable.getReader().read(); + assertEquals(res.value, uint); + ws.close(); + await ws.closed; +}); diff --git a/cli/tests/testdata/worker_close_race.js b/cli/tests/testdata/worker_close_race.js new file mode 100644 index 000000000..6d5bbe2c3 --- /dev/null +++ b/cli/tests/testdata/worker_close_race.js @@ -0,0 +1,14 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. + +// https://github.com/denoland/deno/issues/11416 +// Test for a race condition between a worker's `close()` and the main thread's +// `Worker.prototype.terminate()`. + +const worker = new Worker( + new URL("./workers/close_race_worker.js", import.meta.url), + { type: "module" }, +); + +worker.onmessage = () => { + worker.terminate(); +}; diff --git a/cli/tests/testdata/worker_close_race.js.out b/cli/tests/testdata/worker_close_race.js.out new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/cli/tests/testdata/worker_close_race.js.out diff --git a/cli/tests/testdata/worker_event_handler_test.js b/cli/tests/testdata/worker_event_handler_test.js new file mode 100644 index 000000000..e0ce3d9f8 --- /dev/null +++ b/cli/tests/testdata/worker_event_handler_test.js @@ -0,0 +1,5 @@ +const w = new Worker( + new URL("./workers/worker_event_handlers.js", import.meta.url).href, + { type: "module" }, +); +w.postMessage({}); diff --git a/cli/tests/testdata/worker_event_handler_test.js.out b/cli/tests/testdata/worker_event_handler_test.js.out new file mode 100644 index 000000000..5556633b1 --- /dev/null +++ b/cli/tests/testdata/worker_event_handler_test.js.out @@ -0,0 +1,11 @@ +Target from self.onmessage: [object DedicatedWorkerGlobalScope] +Target from message event listener: [object DedicatedWorkerGlobalScope] +Arguments from self.onerror: [ + "Some error message", + "", + 0, + 0, + Error: Some error message + at [WILDCARD] +] +Is event canceled?: true diff --git a/cli/tests/testdata/workers/bench_large_message.ts b/cli/tests/testdata/workers/bench_large_message.ts new file mode 100644 index 000000000..a89ea9a78 --- /dev/null +++ b/cli/tests/testdata/workers/bench_large_message.ts @@ -0,0 +1,31 @@ +// Copyright 2020 the Deno authors. All rights reserved. MIT license. + +function oneWorker(i: number) { + return new Promise<void>((resolve) => { + let countDown = 10; + const worker = new Worker( + new URL("worker_large_message.js", import.meta.url).href, + { type: "module" }, + ); + worker.onmessage = (_e) => { + if (countDown > 0) { + countDown--; + return; + } + worker.terminate(); + resolve(); + }; + worker.postMessage("hi " + i); + }); +} + +function bench() { + const promises = []; + for (let i = 0; i < 50; i++) { + promises.push(oneWorker(i)); + } + + return Promise.all(promises); +} + +bench(); diff --git a/cli/tests/testdata/workers/bench_round_robin.ts b/cli/tests/testdata/workers/bench_round_robin.ts new file mode 100644 index 000000000..13afe286b --- /dev/null +++ b/cli/tests/testdata/workers/bench_round_robin.ts @@ -0,0 +1,68 @@ +// Benchmark measures time it takes to send a message to a group of workers one +// at a time and wait for a response from all of them. Just a general +// throughput and consistency benchmark. +const data = "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n"; +const workerCount = 4; +const cmdsPerWorker = 400; + +import { + Deferred, + deferred, +} from "../../../../test_util/std/async/deferred.ts"; + +function handleAsyncMsgFromWorker( + promiseTable: Map<number, Deferred<string>>, + msg: { cmdId: number; data: string }, +) { + const promise = promiseTable.get(msg.cmdId); + if (promise === null) { + throw new Error(`Failed to find promise: cmdId: ${msg.cmdId}, msg: ${msg}`); + } + promise?.resolve(data); +} + +async function main() { + const workers: Array<[Map<number, Deferred<string>>, Worker]> = []; + for (let i = 1; i <= workerCount; ++i) { + const worker = new Worker( + new URL("bench_worker.ts", import.meta.url).href, + { type: "module" }, + ); + const promise = deferred(); + worker.onmessage = (e) => { + if (e.data.cmdId === 0) promise.resolve(); + }; + worker.postMessage({ cmdId: 0, action: 2 }); + await promise; + workers.push([new Map(), worker]); + } + // assign callback function + for (const [promiseTable, worker] of workers) { + worker.onmessage = (e) => { + handleAsyncMsgFromWorker(promiseTable, e.data); + }; + } + for (const cmdId of Array(cmdsPerWorker).keys()) { + const promises: Array<Promise<string>> = []; + for (const [promiseTable, worker] of workers) { + const promise = deferred<string>(); + promiseTable.set(cmdId, promise); + worker.postMessage({ cmdId: cmdId, action: 1, data }); + promises.push(promise); + } + for (const promise of promises) { + await promise; + } + } + for (const [, worker] of workers) { + const promise = deferred(); + worker.onmessage = (e) => { + if (e.data.cmdId === 3) promise.resolve(); + }; + worker.postMessage({ action: 3 }); + await promise; + } + console.log("Finished!"); +} + +main(); diff --git a/cli/tests/testdata/workers/bench_startup.ts b/cli/tests/testdata/workers/bench_startup.ts new file mode 100644 index 000000000..bcf21ef44 --- /dev/null +++ b/cli/tests/testdata/workers/bench_startup.ts @@ -0,0 +1,33 @@ +// Benchmark measures time it takes to start and stop a number of workers. +const workerCount = 50; + +async function bench() { + const workers: Worker[] = []; + for (let i = 1; i <= workerCount; ++i) { + const worker = new Worker( + new URL("bench_worker.ts", import.meta.url).href, + { type: "module" }, + ); + const promise = new Promise<void>((resolve) => { + worker.onmessage = (e) => { + if (e.data.cmdId === 0) resolve(); + }; + }); + worker.postMessage({ cmdId: 0, action: 2 }); + await promise; + workers.push(worker); + } + console.log("Done creating workers closing workers!"); + for (const worker of workers) { + const promise = new Promise<void>((resolve) => { + worker.onmessage = (e) => { + if (e.data.cmdId === 3) resolve(); + }; + }); + worker.postMessage({ action: 3 }); + await promise; + } + console.log("Finished!"); +} + +bench(); diff --git a/cli/tests/testdata/workers/bench_worker.ts b/cli/tests/testdata/workers/bench_worker.ts new file mode 100644 index 000000000..1edd2750f --- /dev/null +++ b/cli/tests/testdata/workers/bench_worker.ts @@ -0,0 +1,21 @@ +onmessage = function (e) { + const { cmdId, action, data } = e.data; + switch (action) { + case 0: // Static response + postMessage({ + cmdId, + data: "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n", + }); + break; + case 1: // Respond with request data + postMessage({ cmdId, data }); + break; + case 2: // Ping + postMessage({ cmdId }); + break; + case 3: // Close + postMessage({ cmdId: 3 }); + close(); + break; + } +}; diff --git a/cli/tests/testdata/workers/broadcast_channel.ts b/cli/tests/testdata/workers/broadcast_channel.ts new file mode 100644 index 000000000..5076e9eb7 --- /dev/null +++ b/cli/tests/testdata/workers/broadcast_channel.ts @@ -0,0 +1,5 @@ +new BroadcastChannel("intercom").onmessage = function (e) { + this.postMessage(e.data); +}; + +self.postMessage("go"); diff --git a/cli/tests/testdata/workers/busy_worker.js b/cli/tests/testdata/workers/busy_worker.js new file mode 100644 index 000000000..7deba0321 --- /dev/null +++ b/cli/tests/testdata/workers/busy_worker.js @@ -0,0 +1,8 @@ +self.onmessage = function (_evt) { + // infinite loop + for (let i = 0; true; i++) { + if (i % 1000 == 0) { + postMessage(i); + } + } +}; diff --git a/cli/tests/testdata/workers/close_race_worker.js b/cli/tests/testdata/workers/close_race_worker.js new file mode 100644 index 000000000..f582a0d99 --- /dev/null +++ b/cli/tests/testdata/workers/close_race_worker.js @@ -0,0 +1,6 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. + +setTimeout(() => { + self.postMessage(""); + self.close(); +}, 500); diff --git a/cli/tests/testdata/workers/deno_worker.ts b/cli/tests/testdata/workers/deno_worker.ts new file mode 100644 index 000000000..2a29c8c4d --- /dev/null +++ b/cli/tests/testdata/workers/deno_worker.ts @@ -0,0 +1,7 @@ +onmessage = function (e) { + if (typeof self.Deno === "undefined") { + throw new Error("Deno namespace not available in worker"); + } + + postMessage(e.data); +}; diff --git a/cli/tests/testdata/workers/dynamic_remote.ts b/cli/tests/testdata/workers/dynamic_remote.ts new file mode 100644 index 000000000..381c7f374 --- /dev/null +++ b/cli/tests/testdata/workers/dynamic_remote.ts @@ -0,0 +1,2 @@ +// This file doesn't really exist, but it doesn't matter, a "PermissionsDenied" error should be thrown. +await import("https://example.com/some/file.ts"); diff --git a/cli/tests/testdata/workers/error.ts b/cli/tests/testdata/workers/error.ts new file mode 100644 index 000000000..495971090 --- /dev/null +++ b/cli/tests/testdata/workers/error.ts @@ -0,0 +1,5 @@ +function foo() { + throw new Error("foo"); +} + +foo(); diff --git a/cli/tests/testdata/workers/event_worker.js b/cli/tests/testdata/workers/event_worker.js new file mode 100644 index 000000000..849b6026c --- /dev/null +++ b/cli/tests/testdata/workers/event_worker.js @@ -0,0 +1,7 @@ +onmessage = function (e) { + if (e.data === "boom") { + throw new Error("boom error!"); + } + + postMessage(e.data); +}; diff --git a/cli/tests/testdata/workers/event_worker_scope.js b/cli/tests/testdata/workers/event_worker_scope.js new file mode 100644 index 000000000..0381801a8 --- /dev/null +++ b/cli/tests/testdata/workers/event_worker_scope.js @@ -0,0 +1,43 @@ +let messageHandlersCalled = 0; +let errorHandlersCalled = 0; + +onmessage = function (e) { + if (e.data === "boom") { + throw new Error("boom error!"); + } + messageHandlersCalled++; +}; + +self.addEventListener("message", (_e) => { + messageHandlersCalled++; +}); + +self.addEventListener("message", (_e) => { + messageHandlersCalled++; +}); + +self.addEventListener("message", (_e) => { + messageHandlersCalled++; + + postMessage({ + messageHandlersCalled, + errorHandlersCalled, + }); +}); + +onerror = function (_e) { + errorHandlersCalled++; +}; + +self.addEventListener("error", (_e) => { + errorHandlersCalled++; +}); + +self.addEventListener("error", (_e) => { + errorHandlersCalled++; +}); + +self.addEventListener("error", (e) => { + errorHandlersCalled++; + e.preventDefault(); +}); diff --git a/cli/tests/testdata/workers/fetching_worker.js b/cli/tests/testdata/workers/fetching_worker.js new file mode 100644 index 000000000..77ff471d7 --- /dev/null +++ b/cli/tests/testdata/workers/fetching_worker.js @@ -0,0 +1,6 @@ +const r = await fetch( + "http://localhost:4545/workers/fetching_worker.js", +); +await r.text(); +postMessage("Done!"); +close(); diff --git a/cli/tests/testdata/workers/http_worker.js b/cli/tests/testdata/workers/http_worker.js new file mode 100644 index 000000000..34603ed56 --- /dev/null +++ b/cli/tests/testdata/workers/http_worker.js @@ -0,0 +1,11 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +const listener = Deno.listen({ hostname: "127.0.0.1", port: 4506 }); +postMessage("ready"); +for await (const conn of listener) { + (async () => { + const requests = Deno.serveHttp(conn); + for await (const { respondWith } of requests) { + respondWith(new Response("Hello world")); + } + })(); +} diff --git a/cli/tests/testdata/workers/immediately_close_worker.js b/cli/tests/testdata/workers/immediately_close_worker.js new file mode 100644 index 000000000..8fd27343a --- /dev/null +++ b/cli/tests/testdata/workers/immediately_close_worker.js @@ -0,0 +1 @@ +self.close(); diff --git a/cli/tests/testdata/workers/message_port.ts b/cli/tests/testdata/workers/message_port.ts new file mode 100644 index 000000000..d78304a39 --- /dev/null +++ b/cli/tests/testdata/workers/message_port.ts @@ -0,0 +1,14 @@ +const channel = new MessageChannel(); + +channel.port2.onmessage = (e) => { + channel.port2.postMessage(e.data === "2"); + channel.port2.close(); +}; + +self.postMessage("1", [channel.port1]); + +self.onmessage = (e) => { + const port1 = e.ports[0]; + port1.postMessage(e.data === "3"); + port1.close(); +}; diff --git a/cli/tests/testdata/workers/nested_worker.js b/cli/tests/testdata/workers/nested_worker.js new file mode 100644 index 000000000..4b51b8763 --- /dev/null +++ b/cli/tests/testdata/workers/nested_worker.js @@ -0,0 +1,18 @@ +// Specifier should be resolved relative to current file +const jsWorker = new Worker( + new URL("sibling_worker.js", import.meta.url).href, + { type: "module", name: "sibling" }, +); + +jsWorker.onerror = (_e) => { + postMessage({ type: "error" }); +}; + +jsWorker.onmessage = (e) => { + postMessage({ type: "msg", text: e }); + close(); +}; + +onmessage = function (e) { + jsWorker.postMessage(e.data); +}; diff --git a/cli/tests/testdata/workers/no_permissions_worker.js b/cli/tests/testdata/workers/no_permissions_worker.js new file mode 100644 index 000000000..db0d911ac --- /dev/null +++ b/cli/tests/testdata/workers/no_permissions_worker.js @@ -0,0 +1,17 @@ +self.onmessage = async () => { + const hrtime = await Deno.permissions.query({ name: "hrtime" }); + const net = await Deno.permissions.query({ name: "net" }); + const ffi = await Deno.permissions.query({ name: "ffi" }); + const read = await Deno.permissions.query({ name: "read" }); + const run = await Deno.permissions.query({ name: "run" }); + const write = await Deno.permissions.query({ name: "write" }); + self.postMessage( + hrtime.state === "denied" && + net.state === "denied" && + ffi.state === "denied" && + read.state === "denied" && + run.state === "denied" && + write.state === "denied", + ); + self.close(); +}; diff --git a/cli/tests/testdata/workers/non_deno_worker.js b/cli/tests/testdata/workers/non_deno_worker.js new file mode 100644 index 000000000..773721560 --- /dev/null +++ b/cli/tests/testdata/workers/non_deno_worker.js @@ -0,0 +1,7 @@ +onmessage = function (e) { + if (typeof self.Deno !== "undefined") { + throw new Error("Deno namespace unexpectedly available in worker"); + } + + postMessage(e.data); +}; diff --git a/cli/tests/testdata/workers/nonexistent_worker.out b/cli/tests/testdata/workers/nonexistent_worker.out new file mode 100644 index 000000000..1651321bc --- /dev/null +++ b/cli/tests/testdata/workers/nonexistent_worker.out @@ -0,0 +1,3 @@ +[WILDCARD]error: Uncaught (in worker "") Cannot resolve module "file:///[WILDCARD]/workers/doesnt_exist.js". +error: Uncaught (in promise) Error: Unhandled error event reached main worker. + at Worker.#pollControl ([WILDCARD]) diff --git a/cli/tests/testdata/workers/nonexistent_worker.ts b/cli/tests/testdata/workers/nonexistent_worker.ts new file mode 100644 index 000000000..8ebe29114 --- /dev/null +++ b/cli/tests/testdata/workers/nonexistent_worker.ts @@ -0,0 +1,5 @@ +const w = new Worker(new URL("doesnt_exist.js", import.meta.url).href, { + type: "module", +}); + +w.postMessage("hello"); diff --git a/cli/tests/testdata/workers/parent_read_check_granular_worker.js b/cli/tests/testdata/workers/parent_read_check_granular_worker.js new file mode 100644 index 000000000..1391190cd --- /dev/null +++ b/cli/tests/testdata/workers/parent_read_check_granular_worker.js @@ -0,0 +1,41 @@ +const worker = new Worker( + new URL("./read_check_granular_worker.js", import.meta.url).href, + { + type: "module", + deno: { + namespace: true, + permissions: { + read: [], + }, + }, + }, +); + +let received = 0; +const messages = []; + +worker.onmessage = ({ data: childResponse }) => { + received++; + postMessage({ + childHasPermission: childResponse.hasPermission, + index: childResponse.index, + parentHasPermission: messages[childResponse.index], + }); + if (received === messages.length) { + worker.terminate(); + } +}; + +onmessage = async ({ data }) => { + const { state } = await Deno.permissions.query({ + name: "read", + path: data.path, + }); + + messages[data.index] = state === "granted"; + + worker.postMessage({ + index: data.index, + route: data.route, + }); +}; diff --git a/cli/tests/testdata/workers/parent_read_check_worker.js b/cli/tests/testdata/workers/parent_read_check_worker.js new file mode 100644 index 000000000..ec92cca3f --- /dev/null +++ b/cli/tests/testdata/workers/parent_read_check_worker.js @@ -0,0 +1,27 @@ +onmessage = async () => { + const { state } = await Deno.permissions.query({ + name: "read", + }); + + const worker = new Worker( + new URL("./read_check_worker.js", import.meta.url).href, + { + type: "module", + deno: { + namespace: true, + permissions: { + read: false, + }, + }, + }, + ); + + worker.onmessage = ({ data: childHasPermission }) => { + postMessage({ + parentHasPermission: state === "granted", + childHasPermission, + }); + close(); + }; + worker.postMessage(null); +}; diff --git a/cli/tests/testdata/workers/permissions_blob_local.ts b/cli/tests/testdata/workers/permissions_blob_local.ts new file mode 100644 index 000000000..52f630bd8 --- /dev/null +++ b/cli/tests/testdata/workers/permissions_blob_local.ts @@ -0,0 +1,6 @@ +// This file doesn't really exist, but it doesn't matter, a "PermissionsDenied" error should be thrown. +const code = `import "file:///${ + Deno.build.os == "windows" ? "C:/" : "" +}local_file.ts";`; +const blob = new Blob([code]); +new Worker(URL.createObjectURL(blob), { type: "module" }); diff --git a/cli/tests/testdata/workers/permissions_blob_local.ts.out b/cli/tests/testdata/workers/permissions_blob_local.ts.out new file mode 100644 index 000000000..0835777ec --- /dev/null +++ b/cli/tests/testdata/workers/permissions_blob_local.ts.out @@ -0,0 +1,4 @@ +error: Uncaught (in worker "") Requires read access to "[WILDCARD]local_file.ts", run again with the --allow-read flag + at blob:null/[WILDCARD]:1:0 +error: Uncaught (in promise) Error: Unhandled error event reached main worker. + at Worker.#pollControl ([WILDCARD]) diff --git a/cli/tests/testdata/workers/permissions_blob_remote.ts b/cli/tests/testdata/workers/permissions_blob_remote.ts new file mode 100644 index 000000000..4808bc57b --- /dev/null +++ b/cli/tests/testdata/workers/permissions_blob_remote.ts @@ -0,0 +1,4 @@ +// This file doesn't really exist, but it doesn't matter, a "PermissionsDenied" error should be thrown. +const code = `import "https://example.com/some/file.ts";`; +const blob = new Blob([code]); +new Worker(URL.createObjectURL(blob), { type: "module" }); diff --git a/cli/tests/testdata/workers/permissions_blob_remote.ts.out b/cli/tests/testdata/workers/permissions_blob_remote.ts.out new file mode 100644 index 000000000..2d01458ca --- /dev/null +++ b/cli/tests/testdata/workers/permissions_blob_remote.ts.out @@ -0,0 +1,4 @@ +error: Uncaught (in worker "") Requires net access to "example.com", run again with the --allow-net flag + at blob:null/[WILDCARD]:1:0 +error: Uncaught (in promise) Error: Unhandled error event reached main worker. + at Worker.#pollControl ([WILDCARD]) diff --git a/cli/tests/testdata/workers/permissions_data_local.ts b/cli/tests/testdata/workers/permissions_data_local.ts new file mode 100644 index 000000000..cda80bed6 --- /dev/null +++ b/cli/tests/testdata/workers/permissions_data_local.ts @@ -0,0 +1,7 @@ +// This file doesn't really exist, but it doesn't matter, a "PermissionsDenied" error should be thrown. +const code = `import "file:///${ + Deno.build.os == "windows" ? "C:/" : "" +}local_file.ts";`; +new Worker(`data:application/javascript;base64,${btoa(code)}`, { + type: "module", +}); diff --git a/cli/tests/testdata/workers/permissions_data_local.ts.out b/cli/tests/testdata/workers/permissions_data_local.ts.out new file mode 100644 index 000000000..2a6be2b57 --- /dev/null +++ b/cli/tests/testdata/workers/permissions_data_local.ts.out @@ -0,0 +1,4 @@ +error: Uncaught (in worker "") Requires read access to "[WILDCARD]local_file.ts", run again with the --allow-read flag + at data:application/javascript;base64,[WILDCARD]:1:0 +error: Uncaught (in promise) Error: Unhandled error event reached main worker. + at Worker.#pollControl ([WILDCARD]) diff --git a/cli/tests/testdata/workers/permissions_data_remote.ts b/cli/tests/testdata/workers/permissions_data_remote.ts new file mode 100644 index 000000000..b37bd661d --- /dev/null +++ b/cli/tests/testdata/workers/permissions_data_remote.ts @@ -0,0 +1,5 @@ +// This file doesn't really exist, but it doesn't matter, a "PermissionsDenied" error should be thrown. +const code = `import "https://example.com/some/file.ts";`; +new Worker(`data:application/javascript;base64,${btoa(code)}`, { + type: "module", +}); diff --git a/cli/tests/testdata/workers/permissions_data_remote.ts.out b/cli/tests/testdata/workers/permissions_data_remote.ts.out new file mode 100644 index 000000000..90677892a --- /dev/null +++ b/cli/tests/testdata/workers/permissions_data_remote.ts.out @@ -0,0 +1,4 @@ +error: Uncaught (in worker "") Requires net access to "example.com", run again with the --allow-net flag + at data:application/javascript;base64,aW1wb3J0ICJodHRwczovL2V4YW1wbGUuY29tL3NvbWUvZmlsZS50cyI7:1:0 +error: Uncaught (in promise) Error: Unhandled error event reached main worker. + at Worker.#pollControl ([WILDCARD]) diff --git a/cli/tests/testdata/workers/permissions_dynamic_remote.ts b/cli/tests/testdata/workers/permissions_dynamic_remote.ts new file mode 100644 index 000000000..54a361bc0 --- /dev/null +++ b/cli/tests/testdata/workers/permissions_dynamic_remote.ts @@ -0,0 +1,11 @@ +new Worker( + "http://localhost:4545/workers/dynamic_remote.ts", + { + type: "module", + deno: { + permissions: { + net: false, + }, + }, + }, +); diff --git a/cli/tests/testdata/workers/permissions_dynamic_remote.ts.out b/cli/tests/testdata/workers/permissions_dynamic_remote.ts.out new file mode 100644 index 000000000..3c4523ce0 --- /dev/null +++ b/cli/tests/testdata/workers/permissions_dynamic_remote.ts.out @@ -0,0 +1,6 @@ +error: Uncaught (in worker "") (in promise) TypeError: Requires net access to "example.com", run again with the --allow-net flag +await import("https://example.com/some/file.ts"); +^ + at async http://localhost:4545/workers/dynamic_remote.ts:2:1 +[WILDCARD]error: Uncaught (in promise) Error: Unhandled error event reached main worker. + at Worker.#pollControl ([WILDCARD]) diff --git a/cli/tests/testdata/workers/permissions_remote_remote.ts b/cli/tests/testdata/workers/permissions_remote_remote.ts new file mode 100644 index 000000000..4df2a8a5d --- /dev/null +++ b/cli/tests/testdata/workers/permissions_remote_remote.ts @@ -0,0 +1,3 @@ +new Worker("http://localhost:4545/workers/static_remote.ts", { + type: "module", +}); diff --git a/cli/tests/testdata/workers/permissions_remote_remote.ts.out b/cli/tests/testdata/workers/permissions_remote_remote.ts.out new file mode 100644 index 000000000..94a92c72d --- /dev/null +++ b/cli/tests/testdata/workers/permissions_remote_remote.ts.out @@ -0,0 +1,4 @@ +error: Uncaught (in worker "") Requires net access to "example.com", run again with the --allow-net flag + at http://localhost:4545/workers/static_remote.ts:2:0 +error: Uncaught (in promise) Error: Unhandled error event reached main worker. + at Worker.#pollControl ([WILDCARD]) diff --git a/cli/tests/testdata/workers/post_undefined.ts b/cli/tests/testdata/workers/post_undefined.ts new file mode 100644 index 000000000..1b9b8d6ca --- /dev/null +++ b/cli/tests/testdata/workers/post_undefined.ts @@ -0,0 +1,5 @@ +self.onmessage = (ev: MessageEvent) => { + console.log("received in worker", ev.data); + self.postMessage(undefined); + console.log("posted from worker"); +}; diff --git a/cli/tests/testdata/workers/racy_worker.js b/cli/tests/testdata/workers/racy_worker.js new file mode 100644 index 000000000..0f66c6278 --- /dev/null +++ b/cli/tests/testdata/workers/racy_worker.js @@ -0,0 +1,25 @@ +// See issue for details +// https://github.com/denoland/deno/issues/4080 +// +// After first received message, this worker schedules +// [assert(), close(), assert()] ops on the same turn of microtask queue +// All tasks after close should not make it + +onmessage = async function () { + let stage = 0; + await new Promise((_) => { + setTimeout(() => { + if (stage !== 0) throw "Unexpected stage"; + stage = 1; + }, 50); + setTimeout(() => { + if (stage !== 1) throw "Unexpected stage"; + stage = 2; + postMessage("DONE"); + close(); + }, 50); + setTimeout(() => { + throw "This should not be run"; + }, 50); + }); +}; diff --git a/cli/tests/testdata/workers/read_check_granular_worker.js b/cli/tests/testdata/workers/read_check_granular_worker.js new file mode 100644 index 000000000..25f2058b3 --- /dev/null +++ b/cli/tests/testdata/workers/read_check_granular_worker.js @@ -0,0 +1,11 @@ +onmessage = async ({ data }) => { + const { state } = await Deno.permissions.query({ + name: "read", + path: data.path, + }); + + postMessage({ + hasPermission: state === "granted", + index: data.index, + }); +}; diff --git a/cli/tests/testdata/workers/read_check_worker.js b/cli/tests/testdata/workers/read_check_worker.js new file mode 100644 index 000000000..2ad01bf5b --- /dev/null +++ b/cli/tests/testdata/workers/read_check_worker.js @@ -0,0 +1,7 @@ +onmessage = async () => { + const { state } = await Deno.permissions.query({ + name: "read", + }); + postMessage(state === "granted"); + close(); +}; diff --git a/cli/tests/testdata/workers/shared_array_buffer.ts b/cli/tests/testdata/workers/shared_array_buffer.ts new file mode 100644 index 000000000..4af95863a --- /dev/null +++ b/cli/tests/testdata/workers/shared_array_buffer.ts @@ -0,0 +1,9 @@ +self.postMessage("ready"); + +globalThis.addEventListener("message", (e) => { + const bytes1 = new Uint8Array(e.data[0]); + const bytes2 = new Uint8Array(e.data[1]); + bytes1[0] = 1; + bytes2[0] = 2; + self.postMessage("done"); +}); diff --git a/cli/tests/testdata/workers/sibling_worker.js b/cli/tests/testdata/workers/sibling_worker.js new file mode 100644 index 000000000..99707e5d6 --- /dev/null +++ b/cli/tests/testdata/workers/sibling_worker.js @@ -0,0 +1,4 @@ +onmessage = (e) => { + postMessage(e.data); + close(); +}; diff --git a/cli/tests/testdata/workers/static_remote.ts b/cli/tests/testdata/workers/static_remote.ts new file mode 100644 index 000000000..2d6e820fd --- /dev/null +++ b/cli/tests/testdata/workers/static_remote.ts @@ -0,0 +1,2 @@ +// This file doesn't really exist, but it doesn't matter, a "PermissionsDenied" error should be thrown. +import "https://example.com/some/file.ts"; diff --git a/cli/tests/testdata/workers/test.ts b/cli/tests/testdata/workers/test.ts new file mode 100644 index 000000000..9d3855fe1 --- /dev/null +++ b/cli/tests/testdata/workers/test.ts @@ -0,0 +1,852 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. + +// Requires to be run with `--allow-net` flag + +import { + assert, + assertEquals, + assertThrows, +} from "../../../../test_util/std/testing/asserts.ts"; +import { deferred } from "../../../../test_util/std/async/deferred.ts"; +import { fromFileUrl } from "../../../../test_util/std/path/mod.ts"; + +Deno.test({ + name: "worker terminate", + fn: async function () { + const promise = deferred(); + + const jsWorker = new Worker( + new URL("test_worker.js", import.meta.url).href, + { type: "module" }, + ); + const tsWorker = new Worker( + new URL("test_worker.ts", import.meta.url).href, + { type: "module", name: "tsWorker" }, + ); + + tsWorker.onmessage = (e) => { + assertEquals(e.data, "Hello World"); + promise.resolve(); + }; + + jsWorker.onmessage = (e) => { + assertEquals(e.data, "Hello World"); + tsWorker.postMessage("Hello World"); + }; + + jsWorker.onerror = (e: Event) => { + e.preventDefault(); + jsWorker.postMessage("Hello World"); + }; + + jsWorker.postMessage("Hello World"); + await promise; + tsWorker.terminate(); + jsWorker.terminate(); + }, +}); + +Deno.test({ + name: "worker from data url", + async fn() { + const promise = deferred(); + const tsWorker = new Worker( + "data:application/typescript;base64,aWYgKHNlbGYubmFtZSAhPT0gInRzV29ya2VyIikgewogIHRocm93IEVycm9yKGBJbnZhbGlkIHdvcmtlciBuYW1lOiAke3NlbGYubmFtZX0sIGV4cGVjdGVkIHRzV29ya2VyYCk7Cn0KCm9ubWVzc2FnZSA9IGZ1bmN0aW9uIChlKTogdm9pZCB7CiAgcG9zdE1lc3NhZ2UoZS5kYXRhKTsKICBjbG9zZSgpOwp9Owo=", + { type: "module", name: "tsWorker" }, + ); + + tsWorker.onmessage = (e) => { + assertEquals(e.data, "Hello World"); + promise.resolve(); + }; + + tsWorker.postMessage("Hello World"); + + await promise; + tsWorker.terminate(); + }, +}); + +Deno.test({ + name: "worker nested", + fn: async function () { + const promise = deferred(); + + const nestedWorker = new Worker( + new URL("nested_worker.js", import.meta.url).href, + { type: "module", name: "nested" }, + ); + + nestedWorker.onmessage = (e) => { + assert(e.data.type !== "error"); + promise.resolve(); + }; + + nestedWorker.postMessage("Hello World"); + await promise; + nestedWorker.terminate(); + }, +}); + +Deno.test({ + name: "worker throws when executing", + fn: async function () { + const promise = deferred(); + const throwingWorker = new Worker( + new URL("throwing_worker.js", import.meta.url).href, + { type: "module" }, + ); + + // deno-lint-ignore no-explicit-any + throwingWorker.onerror = (e: any) => { + e.preventDefault(); + assert(/Uncaught Error: Thrown error/.test(e.message)); + promise.resolve(); + }; + + await promise; + throwingWorker.terminate(); + }, +}); + +Deno.test({ + name: "worker globals", + fn: async function () { + const promise = deferred(); + const workerOptions: WorkerOptions = { type: "module" }; + const w = new Worker( + new URL("worker_globals.ts", import.meta.url).href, + workerOptions, + ); + w.onmessage = (e) => { + assertEquals(e.data, "true, true, true, true"); + promise.resolve(); + }; + w.postMessage("Hello, world!"); + await promise; + w.terminate(); + }, +}); + +Deno.test({ + name: "worker fetch API", + fn: async function () { + const promise = deferred(); + + const fetchingWorker = new Worker( + new URL("fetching_worker.js", import.meta.url).href, + { type: "module" }, + ); + + // deno-lint-ignore no-explicit-any + fetchingWorker.onerror = (e: any) => { + e.preventDefault(); + promise.reject(e.message); + }; + + // Defer promise.resolve() to allow worker to shut down + fetchingWorker.onmessage = (e) => { + assert(e.data === "Done!"); + promise.resolve(); + }; + + await promise; + fetchingWorker.terminate(); + }, +}); + +Deno.test({ + name: "worker terminate busy loop", + fn: async function () { + const promise = deferred(); + + const busyWorker = new Worker( + new URL("busy_worker.js", import.meta.url), + { type: "module" }, + ); + + let testResult = 0; + + busyWorker.onmessage = (e) => { + testResult = e.data; + if (testResult >= 10000) { + busyWorker.terminate(); + busyWorker.onmessage = (_e) => { + throw new Error("unreachable"); + }; + setTimeout(() => { + assertEquals(testResult, 10000); + promise.resolve(); + }, 100); + } + }; + + busyWorker.postMessage("ping"); + await promise; + }, +}); + +Deno.test({ + name: "worker race condition", + fn: async function () { + // See issue for details + // https://github.com/denoland/deno/issues/4080 + const promise = deferred(); + + const racyWorker = new Worker( + new URL("racy_worker.js", import.meta.url), + { type: "module" }, + ); + + racyWorker.onmessage = (_e) => { + setTimeout(() => { + promise.resolve(); + }, 100); + }; + + racyWorker.postMessage("START"); + await promise; + }, +}); + +Deno.test({ + name: "worker is event listener", + fn: async function () { + let messageHandlersCalled = 0; + let errorHandlersCalled = 0; + + const promise1 = deferred(); + const promise2 = deferred(); + + const worker = new Worker( + new URL("event_worker.js", import.meta.url), + { type: "module" }, + ); + + worker.onmessage = (_e: Event) => { + messageHandlersCalled++; + }; + worker.addEventListener("message", (_e: Event) => { + messageHandlersCalled++; + }); + worker.addEventListener("message", (_e: Event) => { + messageHandlersCalled++; + promise1.resolve(); + }); + + worker.onerror = (e) => { + errorHandlersCalled++; + e.preventDefault(); + }; + worker.addEventListener("error", (_e: Event) => { + errorHandlersCalled++; + }); + worker.addEventListener("error", (_e: Event) => { + errorHandlersCalled++; + promise2.resolve(); + }); + + worker.postMessage("ping"); + await promise1; + assertEquals(messageHandlersCalled, 3); + + worker.postMessage("boom"); + await promise2; + assertEquals(errorHandlersCalled, 3); + worker.terminate(); + }, +}); + +Deno.test({ + name: "worker scope is event listener", + fn: async function () { + const promise1 = deferred(); + + const worker = new Worker( + new URL("event_worker_scope.js", import.meta.url), + { type: "module" }, + ); + + worker.onmessage = (e: MessageEvent) => { + const { messageHandlersCalled, errorHandlersCalled } = e.data; + assertEquals(messageHandlersCalled, 4); + assertEquals(errorHandlersCalled, 4); + promise1.resolve(); + }; + + worker.onerror = (_e) => { + throw new Error("unreachable"); + }; + + worker.postMessage("boom"); + worker.postMessage("ping"); + await promise1; + worker.terminate(); + }, +}); + +Deno.test({ + name: "worker with Deno namespace", + fn: async function () { + const promise = deferred(); + const promise2 = deferred(); + + const regularWorker = new Worker( + new URL("non_deno_worker.js", import.meta.url), + { type: "module" }, + ); + const denoWorker = new Worker( + new URL("deno_worker.ts", import.meta.url), + { + type: "module", + deno: { + namespace: true, + permissions: "inherit", + }, + }, + ); + + regularWorker.onmessage = (e) => { + assertEquals(e.data, "Hello World"); + regularWorker.terminate(); + promise.resolve(); + }; + + denoWorker.onmessage = (e) => { + assertEquals(e.data, "Hello World"); + denoWorker.terminate(); + promise2.resolve(); + }; + + regularWorker.postMessage("Hello World"); + await promise; + denoWorker.postMessage("Hello World"); + await promise2; + }, +}); + +Deno.test({ + name: "worker with crypto in scope", + fn: async function () { + const promise = deferred(); + const w = new Worker( + new URL("worker_crypto.js", import.meta.url).href, + { type: "module" }, + ); + w.onmessage = (e) => { + assertEquals(e.data, true); + promise.resolve(); + }; + w.postMessage(null); + await promise; + w.terminate(); + }, +}); + +Deno.test({ + name: "Worker event handler order", + fn: async function () { + const promise = deferred(); + const w = new Worker( + new URL("test_worker.ts", import.meta.url).href, + { type: "module", name: "tsWorker" }, + ); + const arr: number[] = []; + w.addEventListener("message", () => arr.push(1)); + w.onmessage = (_e) => { + arr.push(2); + }; + w.addEventListener("message", () => arr.push(3)); + w.addEventListener("message", () => { + assertEquals(arr, [1, 2, 3]); + promise.resolve(); + }); + w.postMessage("Hello World"); + await promise; + w.terminate(); + }, +}); + +Deno.test({ + name: "Worker immediate close", + fn: async function () { + const promise = deferred(); + const w = new Worker( + new URL("./immediately_close_worker.js", import.meta.url).href, + { type: "module" }, + ); + setTimeout(() => { + promise.resolve(); + }, 1000); + await promise; + w.terminate(); + }, +}); + +Deno.test({ + name: "Worker post undefined", + fn: async function () { + const promise = deferred(); + const worker = new Worker( + new URL("./post_undefined.ts", import.meta.url).href, + { type: "module" }, + ); + + const handleWorkerMessage = (e: MessageEvent) => { + console.log("main <- worker:", e.data); + worker.terminate(); + promise.resolve(); + }; + + worker.addEventListener("messageerror", () => console.log("message error")); + worker.addEventListener("error", () => console.log("error")); + worker.addEventListener("message", handleWorkerMessage); + + console.log("\npost from parent"); + worker.postMessage(undefined); + await promise; + }, +}); + +Deno.test("Worker inherits permissions", async function () { + const promise = deferred(); + const worker = new Worker( + new URL("./read_check_worker.js", import.meta.url).href, + { + type: "module", + deno: { + namespace: true, + permissions: "inherit", + }, + }, + ); + + worker.onmessage = ({ data: hasPermission }) => { + assert(hasPermission); + promise.resolve(); + }; + + worker.postMessage(null); + + await promise; + worker.terminate(); +}); + +Deno.test("Worker limit children permissions", async function () { + const promise = deferred(); + const worker = new Worker( + new URL("./read_check_worker.js", import.meta.url).href, + { + type: "module", + deno: { + namespace: true, + permissions: { + read: false, + }, + }, + }, + ); + + worker.onmessage = ({ data: hasPermission }) => { + assert(!hasPermission); + promise.resolve(); + }; + + worker.postMessage(null); + + await promise; + worker.terminate(); +}); + +Deno.test("Worker limit children permissions granularly", async function () { + const promise = deferred(); + const worker = new Worker( + new URL("./read_check_granular_worker.js", import.meta.url).href, + { + type: "module", + deno: { + namespace: true, + permissions: { + read: [ + new URL("./read_check_worker.js", import.meta.url), + ], + }, + }, + }, + ); + + //Routes are relative to the spawned worker location + const routes = [ + { + permission: false, + path: fromFileUrl( + new URL("read_check_granular_worker.js", import.meta.url), + ), + }, + { + permission: true, + path: fromFileUrl(new URL("read_check_worker.js", import.meta.url)), + }, + ]; + + let checked = 0; + worker.onmessage = ({ data }) => { + checked++; + assertEquals(data.hasPermission, routes[data.index].permission); + routes.shift(); + if (checked === routes.length) { + promise.resolve(); + } + }; + + routes.forEach(({ path }, index) => + worker.postMessage({ + index, + path, + }) + ); + + await promise; + worker.terminate(); +}); + +Deno.test("Nested worker limit children permissions", async function () { + const promise = deferred(); + + /** This worker has read permissions but doesn't grant them to its children */ + const worker = new Worker( + new URL("./parent_read_check_worker.js", import.meta.url).href, + { + type: "module", + deno: { + namespace: true, + permissions: "inherit", + }, + }, + ); + + worker.onmessage = ({ data }) => { + assert(data.parentHasPermission); + assert(!data.childHasPermission); + promise.resolve(); + }; + + worker.postMessage(null); + + await promise; + worker.terminate(); +}); + +Deno.test("Nested worker limit children permissions granularly", async function () { + const promise = deferred(); + + /** This worker has read permissions but doesn't grant them to its children */ + const worker = new Worker( + new URL("./parent_read_check_granular_worker.js", import.meta.url) + .href, + { + type: "module", + deno: { + namespace: true, + permissions: { + read: [ + new URL("./read_check_granular_worker.js", import.meta.url), + ], + }, + }, + }, + ); + + //Routes are relative to the spawned worker location + const routes = [ + { + childHasPermission: false, + parentHasPermission: true, + path: fromFileUrl( + new URL("read_check_granular_worker.js", import.meta.url), + ), + }, + { + childHasPermission: false, + parentHasPermission: false, + path: fromFileUrl(new URL("read_check_worker.js", import.meta.url)), + }, + ]; + + let checked = 0; + worker.onmessage = ({ data }) => { + checked++; + assertEquals( + data.childHasPermission, + routes[data.index].childHasPermission, + ); + assertEquals( + data.parentHasPermission, + routes[data.index].parentHasPermission, + ); + if (checked === routes.length) { + promise.resolve(); + } + }; + + // Index needed cause requests will be handled asynchronously + routes.forEach(({ path }, index) => + worker.postMessage({ + index, + path, + }) + ); + + await promise; + worker.terminate(); +}); + +// This test relies on env permissions not being granted on main thread +Deno.test("Worker initialization throws on worker permissions greater than parent thread permissions", function () { + assertThrows( + () => { + const worker = new Worker( + new URL("./deno_worker.ts", import.meta.url).href, + { + type: "module", + deno: { + namespace: true, + permissions: { + env: true, + }, + }, + }, + ); + worker.terminate(); + }, + Deno.errors.PermissionDenied, + "Can't escalate parent thread permissions", + ); +}); + +Deno.test("Worker with disabled permissions", async function () { + const promise = deferred(); + + const worker = new Worker( + new URL("./no_permissions_worker.js", import.meta.url).href, + { + type: "module", + deno: { + namespace: true, + permissions: "none", + }, + }, + ); + + worker.onmessage = ({ data: sandboxed }) => { + assert(sandboxed); + promise.resolve(); + }; + + worker.postMessage(null); + await promise; + worker.terminate(); +}); + +Deno.test({ + name: "worker location", + fn: async function () { + const promise = deferred(); + const workerModuleHref = + new URL("worker_location.ts", import.meta.url).href; + const w = new Worker(workerModuleHref, { type: "module" }); + w.onmessage = (e) => { + assertEquals(e.data, `${workerModuleHref}, true`); + promise.resolve(); + }; + w.postMessage("Hello, world!"); + await promise; + w.terminate(); + }, +}); + +Deno.test({ + name: "worker with relative specifier", + fn: async function () { + assertEquals(location.href, "http://127.0.0.1:4545/"); + const promise = deferred(); + const w = new Worker( + "./workers/test_worker.ts", + { type: "module", name: "tsWorker" }, + ); + w.onmessage = (e) => { + assertEquals(e.data, "Hello, world!"); + promise.resolve(); + }; + w.postMessage("Hello, world!"); + await promise; + w.terminate(); + }, +}); + +Deno.test({ + name: "Worker with top-level-await", + fn: async function () { + const result = deferred(); + const worker = new Worker( + new URL("worker_with_top_level_await.ts", import.meta.url).href, + { type: "module" }, + ); + worker.onmessage = (e) => { + if (e.data == "ready") { + worker.postMessage("trigger worker handler"); + } else if (e.data == "triggered worker handler") { + result.resolve(); + } else { + result.reject(new Error("Handler didn't run during top-level delay.")); + } + }; + await result; + worker.terminate(); + }, +}); + +Deno.test({ + name: "Worker with native HTTP", + fn: async function () { + const result = deferred(); + const worker = new Worker( + new URL( + "./http_worker.js", + import.meta.url, + ).href, + { + type: "module", + deno: { + namespace: true, + permissions: "inherit", + }, + }, + ); + worker.onmessage = () => { + result.resolve(); + }; + await result; + + assert(worker); + const response = await fetch("http://localhost:4506"); + assert(await response.arrayBuffer()); + worker.terminate(); + }, +}); + +Deno.test({ + name: "structured cloning postMessage", + fn: async function () { + const result = deferred(); + const worker = new Worker( + new URL("worker_structured_cloning.ts", import.meta.url).href, + { type: "module" }, + ); + + worker.onmessage = (e) => { + // self field should reference itself (circular ref) + const value = e.data.self.self.self; + + // fields a and b refer to the same array + assertEquals(value.a, ["a", true, 432]); + assertEquals(value.a, ["a", true, 432]); + value.b[0] = "b"; + value.a[2] += 5; + assertEquals(value.a, ["b", true, 437]); + assertEquals(value.b, ["b", true, 437]); + + const len = value.c.size; + value.c.add(1); // This value is already in the set. + value.c.add(2); + assertEquals(len + 1, value.c.size); + + result.resolve(); + }; + + worker.postMessage("START"); + await result; + worker.terminate(); + }, +}); + +Deno.test({ + name: "worker with relative specifier", + fn: async function () { + assertEquals(location.href, "http://127.0.0.1:4545/"); + const promise = deferred(); + const w = new Worker( + "./workers/test_worker.ts", + { type: "module", name: "tsWorker" }, + ); + w.onmessage = (e) => { + assertEquals(e.data, "Hello, world!"); + promise.resolve(); + }; + w.postMessage("Hello, world!"); + await promise; + w.terminate(); + }, +}); + +Deno.test({ + name: "worker SharedArrayBuffer", + fn: async function () { + const promise = deferred(); + const workerOptions: WorkerOptions = { type: "module" }; + const w = new Worker( + new URL("shared_array_buffer.ts", import.meta.url).href, + workerOptions, + ); + const sab1 = new SharedArrayBuffer(1); + const sab2 = new SharedArrayBuffer(1); + const bytes1 = new Uint8Array(sab1); + const bytes2 = new Uint8Array(sab2); + assertEquals(bytes1[0], 0); + assertEquals(bytes2[0], 0); + w.onmessage = () => { + w.postMessage([sab1, sab2]); + w.onmessage = () => { + assertEquals(bytes1[0], 1); + assertEquals(bytes2[0], 2); + promise.resolve(); + }; + }; + await promise; + w.terminate(); + }, +}); + +Deno.test({ + name: "Send MessagePorts from / to workers", + fn: async function () { + const result = deferred(); + const worker = new Worker( + new URL("message_port.ts", import.meta.url).href, + { type: "module" }, + ); + + const channel = new MessageChannel(); + + worker.onmessage = (e) => { + assertEquals(e.data, "1"); + assertEquals(e.ports.length, 1); + const port1 = e.ports[0]; + port1.onmessage = (e) => { + assertEquals(e.data, true); + port1.close(); + worker.postMessage("3", [channel.port1]); + }; + port1.postMessage("2"); + }; + + channel.port2.onmessage = (e) => { + assertEquals(e.data, true); + channel.port2.close(); + result.resolve(); + }; + + await result; + worker.terminate(); + }, +}); diff --git a/cli/tests/testdata/workers/test.ts.out b/cli/tests/testdata/workers/test.ts.out new file mode 100644 index 000000000..1b4238a9b --- /dev/null +++ b/cli/tests/testdata/workers/test.ts.out @@ -0,0 +1,3 @@ +[WILDCARD] +test result: ok. [WILDCARD] passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]ms) + diff --git a/cli/tests/testdata/workers/test_worker.js b/cli/tests/testdata/workers/test_worker.js new file mode 100644 index 000000000..4260975a6 --- /dev/null +++ b/cli/tests/testdata/workers/test_worker.js @@ -0,0 +1,19 @@ +let thrown = false; + +if (self.name !== "") { + throw Error(`Bad worker name: ${self.name}, expected empty string.`); +} + +onmessage = function (e) { + if (thrown === false) { + thrown = true; + throw new SyntaxError("[test error]"); + } + + postMessage(e.data); + close(); +}; + +onerror = function () { + return false; +}; diff --git a/cli/tests/testdata/workers/test_worker.ts b/cli/tests/testdata/workers/test_worker.ts new file mode 100644 index 000000000..996476058 --- /dev/null +++ b/cli/tests/testdata/workers/test_worker.ts @@ -0,0 +1,8 @@ +if (self.name !== "tsWorker") { + throw Error(`Invalid worker name: ${self.name}, expected tsWorker`); +} + +onmessage = function (e) { + postMessage(e.data); + close(); +}; diff --git a/cli/tests/testdata/workers/throwing_worker.js b/cli/tests/testdata/workers/throwing_worker.js new file mode 100644 index 000000000..56ee4ff88 --- /dev/null +++ b/cli/tests/testdata/workers/throwing_worker.js @@ -0,0 +1,2 @@ +// This worker just throws error when it's being executed +throw Error("Thrown error"); diff --git a/cli/tests/testdata/workers/worker_crypto.js b/cli/tests/testdata/workers/worker_crypto.js new file mode 100644 index 000000000..4398ad068 --- /dev/null +++ b/cli/tests/testdata/workers/worker_crypto.js @@ -0,0 +1,5 @@ +self.crypto.getRandomValues(new Uint8Array(16)); + +onmessage = function () { + postMessage(!!self.crypto); +}; diff --git a/cli/tests/testdata/workers/worker_error.ts b/cli/tests/testdata/workers/worker_error.ts new file mode 100644 index 000000000..696680de8 --- /dev/null +++ b/cli/tests/testdata/workers/worker_error.ts @@ -0,0 +1,5 @@ +const worker = new Worker( + new URL("error.ts", import.meta.url).href, + { type: "module", name: "bar" }, +); +setTimeout(() => worker.terminate(), 30000); diff --git a/cli/tests/testdata/workers/worker_error.ts.out b/cli/tests/testdata/workers/worker_error.ts.out new file mode 100644 index 000000000..4a8e92f00 --- /dev/null +++ b/cli/tests/testdata/workers/worker_error.ts.out @@ -0,0 +1,5 @@ +[WILDCARD]error: Uncaught (in worker "bar") Error: foo[WILDCARD] + at foo ([WILDCARD]) + at [WILDCARD] +error: Uncaught (in promise) Error: Unhandled error event reached main worker. + at Worker.#pollControl ([WILDCARD]) diff --git a/cli/tests/testdata/workers/worker_event_handlers.js b/cli/tests/testdata/workers/worker_event_handlers.js new file mode 100644 index 000000000..c8976f79e --- /dev/null +++ b/cli/tests/testdata/workers/worker_event_handlers.js @@ -0,0 +1,23 @@ +self.onmessage = (evt) => { + console.log("Target from self.onmessage:", String(evt.target)); +}; + +self.addEventListener("message", (evt) => { + console.log("Target from message event listener:", String(evt.target)); + + // Throw an error here so the global's error event will fire. + throw new Error("Some error message"); +}); + +self.onerror = (...args) => { + console.log("Arguments from self.onerror:", args); + return true; +}; + +self.addEventListener("error", (evt) => { + // Returning true from self.onerror means that subsequent event listeners + // should see the event as canceled. + console.log("Is event canceled?:", evt.defaultPrevented); + + self.close(); +}); diff --git a/cli/tests/testdata/workers/worker_globals.ts b/cli/tests/testdata/workers/worker_globals.ts new file mode 100644 index 000000000..90e369e41 --- /dev/null +++ b/cli/tests/testdata/workers/worker_globals.ts @@ -0,0 +1,13 @@ +onmessage = function () { + postMessage( + [ + self instanceof DedicatedWorkerGlobalScope, + self instanceof WorkerGlobalScope, + self instanceof EventTarget, + // TODO(nayeemrmn): Add `WorkerNavigator` to deno_lint globals. + // deno-lint-ignore no-undef + navigator instanceof WorkerNavigator, + ].join(", "), + ); + close(); +}; diff --git a/cli/tests/testdata/workers/worker_large_message.js b/cli/tests/testdata/workers/worker_large_message.js new file mode 100644 index 000000000..a1ddae4f9 --- /dev/null +++ b/cli/tests/testdata/workers/worker_large_message.js @@ -0,0 +1,14 @@ +// Copyright 2020 the Deno authors. All rights reserved. MIT license. + +const dataSmall = ""; +const dataLarge = "x".repeat(10 * 1024); + +onmessage = function (_e) { + for (let i = 0; i <= 10; i++) { + if (i % 2 == 0) { + postMessage(dataLarge); + } else { + postMessage(dataSmall); + } + } +}; diff --git a/cli/tests/testdata/workers/worker_location.ts b/cli/tests/testdata/workers/worker_location.ts new file mode 100644 index 000000000..c3c1bb26f --- /dev/null +++ b/cli/tests/testdata/workers/worker_location.ts @@ -0,0 +1,6 @@ +onmessage = function () { + postMessage( + `${location.href}, ${location instanceof WorkerLocation}`, + ); + close(); +}; diff --git a/cli/tests/testdata/workers/worker_nested_error.ts b/cli/tests/testdata/workers/worker_nested_error.ts new file mode 100644 index 000000000..aba2011be --- /dev/null +++ b/cli/tests/testdata/workers/worker_nested_error.ts @@ -0,0 +1,5 @@ +const worker = new Worker( + new URL("worker_error.ts", import.meta.url).href, + { type: "module", name: "baz" }, +); +setTimeout(() => worker.terminate(), 30000); diff --git a/cli/tests/testdata/workers/worker_nested_error.ts.out b/cli/tests/testdata/workers/worker_nested_error.ts.out new file mode 100644 index 000000000..4a8e92f00 --- /dev/null +++ b/cli/tests/testdata/workers/worker_nested_error.ts.out @@ -0,0 +1,5 @@ +[WILDCARD]error: Uncaught (in worker "bar") Error: foo[WILDCARD] + at foo ([WILDCARD]) + at [WILDCARD] +error: Uncaught (in promise) Error: Unhandled error event reached main worker. + at Worker.#pollControl ([WILDCARD]) diff --git a/cli/tests/testdata/workers/worker_structured_cloning.ts b/cli/tests/testdata/workers/worker_structured_cloning.ts new file mode 100644 index 000000000..eb1719a9a --- /dev/null +++ b/cli/tests/testdata/workers/worker_structured_cloning.ts @@ -0,0 +1,15 @@ +// More info on structured cloning can be found here: +// https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm + +self.onmessage = () => { + const arr = ["a", true, 432]; + const set = new Set([1, 3, 5, 7, 9]); + const selfReference = { + a: arr, + b: arr, + c: set, + }; + // deno-lint-ignore no-explicit-any + (selfReference as any).self = selfReference; + self.postMessage(selfReference); +}; diff --git a/cli/tests/testdata/workers/worker_types.ts b/cli/tests/testdata/workers/worker_types.ts new file mode 100644 index 000000000..b67a3b782 --- /dev/null +++ b/cli/tests/testdata/workers/worker_types.ts @@ -0,0 +1,4 @@ +// deno-lint-ignore require-await +self.onmessage = async (_msg: MessageEvent) => { + self.postMessage("hello"); +}; diff --git a/cli/tests/testdata/workers/worker_unstable.ts b/cli/tests/testdata/workers/worker_unstable.ts new file mode 100644 index 000000000..a5b5f7ba2 --- /dev/null +++ b/cli/tests/testdata/workers/worker_unstable.ts @@ -0,0 +1,5 @@ +console.log(Deno.permissions.query); +console.log(Deno.emit); +self.onmessage = () => { + self.close(); +}; diff --git a/cli/tests/testdata/workers/worker_with_top_level_await.ts b/cli/tests/testdata/workers/worker_with_top_level_await.ts new file mode 100644 index 000000000..1d20bb736 --- /dev/null +++ b/cli/tests/testdata/workers/worker_with_top_level_await.ts @@ -0,0 +1,15 @@ +function delay(ms: number) { + return new Promise<void>((resolve) => { + setTimeout(() => { + resolve(); + }, ms); + }); +} + +onmessage = (_e: MessageEvent) => { + postMessage("triggered worker handler"); + close(); +}; +postMessage("ready"); +await delay(1000); +postMessage("never"); diff --git a/cli/tests/testdata/x_deno_warning.js b/cli/tests/testdata/x_deno_warning.js new file mode 100644 index 000000000..34b950566 --- /dev/null +++ b/cli/tests/testdata/x_deno_warning.js @@ -0,0 +1 @@ +console.log("testing x-deno-warning header"); |
