From 1464b756a4ef091ef97d1bf7340188ab5fe5492a Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 19 Sep 2022 09:32:21 -0500 Subject: refactor: move out test files from root testdata directory into sub directories (#15949) --- cli/tests/testdata/run/import_meta/importmap.json | 11 ++++++++ cli/tests/testdata/run/import_meta/main.out | 9 ++++++ cli/tests/testdata/run/import_meta/main.ts | 34 +++++++++++++++++++++++ cli/tests/testdata/run/import_meta/other.ts | 1 + 4 files changed, 55 insertions(+) create mode 100644 cli/tests/testdata/run/import_meta/importmap.json create mode 100644 cli/tests/testdata/run/import_meta/main.out create mode 100644 cli/tests/testdata/run/import_meta/main.ts create mode 100644 cli/tests/testdata/run/import_meta/other.ts (limited to 'cli/tests/testdata/run/import_meta') diff --git a/cli/tests/testdata/run/import_meta/importmap.json b/cli/tests/testdata/run/import_meta/importmap.json new file mode 100644 index 000000000..f8c056afd --- /dev/null +++ b/cli/tests/testdata/run/import_meta/importmap.json @@ -0,0 +1,11 @@ +{ + "imports": { + "bare": "https://example.com/", + "https://example.com/rewrite": "https://example.com/rewritten", + + "1": "https://example.com/PASS-1", + "null": "https://example.com/PASS-null", + "undefined": "https://example.com/PASS-undefined", + "[object Object]": "https://example.com/PASS-object" + } +} diff --git a/cli/tests/testdata/run/import_meta/main.out b/cli/tests/testdata/run/import_meta/main.out new file mode 100644 index 000000000..89aeddaf3 --- /dev/null +++ b/cli/tests/testdata/run/import_meta/main.out @@ -0,0 +1,9 @@ +other [WILDCARD]other.ts false +main [WILDCARD]main.ts true +Resolving ./foo.js file:///[WILDCARD]/foo.js +Resolving bare from import map https://example.com/ +Resolving https://example.com/rewrite from import map https://example.com/rewritten +Resolving without a value from import map https://example.com/PASS-undefined +Resolving 1 from import map https://example.com/PASS-1 +Resolving null from import map https://example.com/PASS-null +Resolving object from import map https://example.com/PASS-object diff --git a/cli/tests/testdata/run/import_meta/main.ts b/cli/tests/testdata/run/import_meta/main.ts new file mode 100644 index 000000000..02f0a1c58 --- /dev/null +++ b/cli/tests/testdata/run/import_meta/main.ts @@ -0,0 +1,34 @@ +import { assertThrows } from "../../../../../test_util/std/testing/asserts.ts"; + +console.log("main", import.meta.url, import.meta.main); + +import "./other.ts"; + +console.log("Resolving ./foo.js", import.meta.resolve("./foo.js")); +console.log("Resolving bare from import map", import.meta.resolve("bare")); +console.log( + "Resolving https://example.com/rewrite from import map", + import.meta.resolve("https://example.com/rewrite"), +); +console.log( + "Resolving without a value from import map", + import.meta.resolve(), +); +console.log( + "Resolving 1 from import map", + import.meta.resolve(1), +); +console.log( + "Resolving null from import map", + import.meta.resolve(null), +); +console.log( + "Resolving object from import map", + import.meta.resolve({}), +); +assertThrows(() => { + import.meta.resolve("too", "many", "arguments"); +}, TypeError); +assertThrows(() => { + import.meta.resolve("://malformed/url?asdf"); +}, TypeError); diff --git a/cli/tests/testdata/run/import_meta/other.ts b/cli/tests/testdata/run/import_meta/other.ts new file mode 100644 index 000000000..47d7527cd --- /dev/null +++ b/cli/tests/testdata/run/import_meta/other.ts @@ -0,0 +1 @@ +console.log("other", import.meta.url, import.meta.main); -- cgit v1.2.3