diff options
| author | Matt Mastracci <matthew@mastracci.com> | 2024-02-10 13:22:13 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-10 20:22:13 +0000 |
| commit | f5e46c9bf2f50d66a953fa133161fc829cecff06 (patch) | |
| tree | 8faf2f5831c1c7b11d842cd9908d141082c869a5 /tests/testdata/import_attributes | |
| parent | d2477f780630a812bfd65e3987b70c0d309385bb (diff) | |
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.
This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.
While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).
And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.
For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
Diffstat (limited to 'tests/testdata/import_attributes')
17 files changed, 64 insertions, 0 deletions
diff --git a/tests/testdata/import_attributes/data.json b/tests/testdata/import_attributes/data.json new file mode 100644 index 000000000..37b3ee1e0 --- /dev/null +++ b/tests/testdata/import_attributes/data.json @@ -0,0 +1,6 @@ +{ + "a": "b", + "c": { + "d": 10 + } +} diff --git a/tests/testdata/import_attributes/dynamic_error.out b/tests/testdata/import_attributes/dynamic_error.out new file mode 100644 index 000000000..24f29de72 --- /dev/null +++ b/tests/testdata/import_attributes/dynamic_error.out @@ -0,0 +1,4 @@ +error: Uncaught (in promise) TypeError: Attempted to load JSON module without specifying "type": "json" attribute in the import statement. +const data = await import("./data.json"); + ^ + at async [WILDCARD]dynamic_error.ts:1:14 diff --git a/tests/testdata/import_attributes/dynamic_error.ts b/tests/testdata/import_attributes/dynamic_error.ts new file mode 100644 index 000000000..2d9c6757f --- /dev/null +++ b/tests/testdata/import_attributes/dynamic_error.ts @@ -0,0 +1,3 @@ +const data = await import("./data.json"); + +console.log(data); diff --git a/tests/testdata/import_attributes/dynamic_import.out b/tests/testdata/import_attributes/dynamic_import.out new file mode 100644 index 000000000..01bc76c8a --- /dev/null +++ b/tests/testdata/import_attributes/dynamic_import.out @@ -0,0 +1,3 @@ +[WILDCARD] +[Module: null prototype] { default: { a: "b", c: { d: 10 } } } +[Module: null prototype] { default: { a: "b", c: { d: 10 } } } diff --git a/tests/testdata/import_attributes/dynamic_import.ts b/tests/testdata/import_attributes/dynamic_import.ts new file mode 100644 index 000000000..73f348697 --- /dev/null +++ b/tests/testdata/import_attributes/dynamic_import.ts @@ -0,0 +1,5 @@ +const data1 = await import("./data.json", { with: { type: "json" } }); +const data2 = await import("./data.json", { assert: { type: "json" } }); + +console.log(data1); +console.log(data2); diff --git a/tests/testdata/import_attributes/json_with_shebang.json b/tests/testdata/import_attributes/json_with_shebang.json new file mode 100644 index 000000000..b695e4457 --- /dev/null +++ b/tests/testdata/import_attributes/json_with_shebang.json @@ -0,0 +1,4 @@ +#!/usr/env -S deno run +{ + "test": null +} diff --git a/tests/testdata/import_attributes/json_with_shebang.ts b/tests/testdata/import_attributes/json_with_shebang.ts new file mode 100644 index 000000000..523bf8772 --- /dev/null +++ b/tests/testdata/import_attributes/json_with_shebang.ts @@ -0,0 +1,3 @@ +import json from "./json_with_shebang.json" assert { type: "json" }; + +console.log(json); diff --git a/tests/testdata/import_attributes/json_with_shebang.ts.out b/tests/testdata/import_attributes/json_with_shebang.ts.out new file mode 100644 index 000000000..23eb03720 --- /dev/null +++ b/tests/testdata/import_attributes/json_with_shebang.ts.out @@ -0,0 +1 @@ +error: Uncaught SyntaxError: Unexpected token '#', "#!/usr/env"... is not valid JSON diff --git a/tests/testdata/import_attributes/static_error.out b/tests/testdata/import_attributes/static_error.out new file mode 100644 index 000000000..29b24b965 --- /dev/null +++ b/tests/testdata/import_attributes/static_error.out @@ -0,0 +1,3 @@ +error: Expected a JavaScript or TypeScript module, but identified a Json module. Consider importing Json modules with an import attribute with the type of "json". + Specifier: [WILDCARD]/data.json + at [WILDCARD]static_error.ts:1:18 diff --git a/tests/testdata/import_attributes/static_error.ts b/tests/testdata/import_attributes/static_error.ts new file mode 100644 index 000000000..0bc3a93f8 --- /dev/null +++ b/tests/testdata/import_attributes/static_error.ts @@ -0,0 +1,3 @@ +import data from "./data.json"; + +console.log(data); diff --git a/tests/testdata/import_attributes/static_export.out b/tests/testdata/import_attributes/static_export.out new file mode 100644 index 000000000..41af79d7c --- /dev/null +++ b/tests/testdata/import_attributes/static_export.out @@ -0,0 +1 @@ +{ a: "b", c: { d: 10 } } diff --git a/tests/testdata/import_attributes/static_export.ts b/tests/testdata/import_attributes/static_export.ts new file mode 100644 index 000000000..ac3ee694f --- /dev/null +++ b/tests/testdata/import_attributes/static_export.ts @@ -0,0 +1,3 @@ +import data from "./static_reexport.ts"; + +console.log(data); diff --git a/tests/testdata/import_attributes/static_import.out b/tests/testdata/import_attributes/static_import.out new file mode 100644 index 000000000..e57dffa99 --- /dev/null +++ b/tests/testdata/import_attributes/static_import.out @@ -0,0 +1,2 @@ +{ a: "b", c: { d: 10 } } +{ a: "b", c: { d: 10 } } diff --git a/tests/testdata/import_attributes/static_import.ts b/tests/testdata/import_attributes/static_import.ts new file mode 100644 index 000000000..d46d93b4a --- /dev/null +++ b/tests/testdata/import_attributes/static_import.ts @@ -0,0 +1,5 @@ +import data1 from "./data.json" with { type: "json" }; +import data2 from "./data.json" assert { type: "json" }; + +console.log(data1); +console.log(data2); diff --git a/tests/testdata/import_attributes/static_reexport.ts b/tests/testdata/import_attributes/static_reexport.ts new file mode 100644 index 000000000..81af428be --- /dev/null +++ b/tests/testdata/import_attributes/static_reexport.ts @@ -0,0 +1 @@ +export { default } from "./data.json" assert { type: "json" }; diff --git a/tests/testdata/import_attributes/type_check.out b/tests/testdata/import_attributes/type_check.out new file mode 100644 index 000000000..5ecdec82d --- /dev/null +++ b/tests/testdata/import_attributes/type_check.out @@ -0,0 +1,12 @@ +Check file:///[WILDCARD]/type_check.ts +error: TS2339 [ERROR]: Property 'foo' does not exist on type '{ a: string; c: { d: number; }; }'. +console.log(data1.foo); + ~~~ + at [WILDCARD]type_check.ts:4:19 + +TS2339 [ERROR]: Property 'foo' does not exist on type '{ a: string; c: { d: number; }; }'. +console.log(data2.foo); + ~~~ + at [WILDCARD]type_check.ts:5:19 + +Found 2 errors. diff --git a/tests/testdata/import_attributes/type_check.ts b/tests/testdata/import_attributes/type_check.ts new file mode 100644 index 000000000..ddf28e67a --- /dev/null +++ b/tests/testdata/import_attributes/type_check.ts @@ -0,0 +1,5 @@ +import data1 from "./data.json" with { type: "json" }; +import data2 from "./data.json" assert { type: "json" }; + +console.log(data1.foo); +console.log(data2.foo); |
