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/dynamic_import | |
| 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/dynamic_import')
17 files changed, 67 insertions, 0 deletions
diff --git a/tests/testdata/dynamic_import/b.js b/tests/testdata/dynamic_import/b.js new file mode 100644 index 000000000..6ea50d360 --- /dev/null +++ b/tests/testdata/dynamic_import/b.js @@ -0,0 +1,2 @@ +import "./bad.mjs"; +export default () => "error"; diff --git a/tests/testdata/dynamic_import/c.js b/tests/testdata/dynamic_import/c.js new file mode 100644 index 000000000..20546455e --- /dev/null +++ b/tests/testdata/dynamic_import/c.js @@ -0,0 +1,2 @@ +await import("./bad2.mjs"); +export default () => "error"; diff --git a/tests/testdata/dynamic_import/empty_1.ts b/tests/testdata/dynamic_import/empty_1.ts new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/testdata/dynamic_import/empty_1.ts diff --git a/tests/testdata/dynamic_import/empty_2.ts b/tests/testdata/dynamic_import/empty_2.ts new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/testdata/dynamic_import/empty_2.ts diff --git a/tests/testdata/dynamic_import/permissions_blob_local.ts b/tests/testdata/dynamic_import/permissions_blob_local.ts new file mode 100644 index 000000000..9ef4158ce --- /dev/null +++ b/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/tests/testdata/dynamic_import/permissions_blob_local.ts.out b/tests/testdata/dynamic_import/permissions_blob_local.ts.out new file mode 100644 index 000000000..b7b246ba2 --- /dev/null +++ b/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:8 +await import(URL.createObjectURL(blob)); +^ + at async file://[WILDCARD]/permissions_blob_local.ts:6:1 diff --git a/tests/testdata/dynamic_import/permissions_blob_remote.ts b/tests/testdata/dynamic_import/permissions_blob_remote.ts new file mode 100644 index 000000000..1e2c8c21a --- /dev/null +++ b/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/tests/testdata/dynamic_import/permissions_blob_remote.ts.out b/tests/testdata/dynamic_import/permissions_blob_remote.ts.out new file mode 100644 index 000000000..a00c02d72 --- /dev/null +++ b/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:8 +await import(URL.createObjectURL(blob)); +^ + at async file:///[WILDCARD]/dynamic_import/permissions_blob_remote.ts:4:1 diff --git a/tests/testdata/dynamic_import/permissions_data_local.ts b/tests/testdata/dynamic_import/permissions_data_local.ts new file mode 100644 index 000000000..be4fc1c34 --- /dev/null +++ b/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/tests/testdata/dynamic_import/permissions_data_local.ts.out b/tests/testdata/dynamic_import/permissions_data_local.ts.out new file mode 100644 index 000000000..98c8a7310 --- /dev/null +++ b/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:8 +await import(`data:application/javascript;base64,${btoa(code)}`); +^ + at async file:///[WILDCARD]/dynamic_import/permissions_data_local.ts:5:1 diff --git a/tests/testdata/dynamic_import/permissions_data_remote.ts b/tests/testdata/dynamic_import/permissions_data_remote.ts new file mode 100644 index 000000000..b0a9540c3 --- /dev/null +++ b/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/tests/testdata/dynamic_import/permissions_data_remote.ts.out b/tests/testdata/dynamic_import/permissions_data_remote.ts.out new file mode 100644 index 000000000..cb2a7ccf7 --- /dev/null +++ b/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:8 +await import(`data:application/javascript;base64,${btoa(code)}`); +^ + at async file:///[WILDCARD]/dynamic_import/permissions_data_remote.ts:3:1 diff --git a/tests/testdata/dynamic_import/permissions_remote_remote.ts b/tests/testdata/dynamic_import/permissions_remote_remote.ts new file mode 100644 index 000000000..65a254191 --- /dev/null +++ b/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/tests/testdata/dynamic_import/permissions_remote_remote.ts.out b/tests/testdata/dynamic_import/permissions_remote_remote.ts.out new file mode 100644 index 000000000..bd88dd4d9 --- /dev/null +++ b/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:8 +await import( +^ + at async file:///[WILDCARD]/dynamic_import/permissions_remote_remote.ts:1:1 diff --git a/tests/testdata/dynamic_import/static_analysis_no_permissions.ts b/tests/testdata/dynamic_import/static_analysis_no_permissions.ts new file mode 100644 index 000000000..de75ba87b --- /dev/null +++ b/tests/testdata/dynamic_import/static_analysis_no_permissions.ts @@ -0,0 +1,13 @@ +try { + await import("./empty_1.ts"); + console.log("✅ Succeeded importing statically analyzable specifier"); +} catch { + console.log("❌ Failed importing statically analyzable specifier"); +} + +try { + await import("" + "./empty_2.ts"); + console.log("❌ Succeeded importing non-statically analyzable specifier"); +} catch { + console.log("✅ Failed importing non-statically analyzable specifier"); +} diff --git a/tests/testdata/dynamic_import/static_analysis_no_permissions.ts.out b/tests/testdata/dynamic_import/static_analysis_no_permissions.ts.out new file mode 100644 index 000000000..ba9249ab0 --- /dev/null +++ b/tests/testdata/dynamic_import/static_analysis_no_permissions.ts.out @@ -0,0 +1,2 @@ +✅ Succeeded importing statically analyzable specifier +✅ Failed importing non-statically analyzable specifier diff --git a/tests/testdata/dynamic_import/static_remote.ts b/tests/testdata/dynamic_import/static_remote.ts new file mode 100644 index 000000000..2d6e820fd --- /dev/null +++ b/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"; |
