diff options
| author | David Sherret <dsherret@users.noreply.github.com> | 2023-12-01 15:12:10 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-01 20:12:10 +0000 |
| commit | a1d823e27d1b605b5658fddc1c9273667f0e9e84 (patch) | |
| tree | 213f35fb40b5c70832b1d9473947b3de48d4ec9e /cli/tests/integration | |
| parent | d8e8497eb3049f58632e4d7507090ef9915b3af6 (diff) | |
feat(compile): support discovering modules for more dynamic arguments (#21381)
This PR causes Deno to include more files in the graph based on how a
template literal looks that's provided to a dynamic import:
```ts
const file = await import(`./dir/${expr}`);
```
In this case, it will search the `dir` directory and descendant
directories for any .js/jsx/etc modules and include them in the graph.
To opt out of this behaviour, move the template literal to a separate
line:
```ts
const specifier = `./dir/${expr}`
const file = await import(specifier);
```
Diffstat (limited to 'cli/tests/integration')
| -rw-r--r-- | cli/tests/integration/compile_tests.rs | 24 | ||||
| -rw-r--r-- | cli/tests/integration/doc_tests.rs | 10 | ||||
| -rw-r--r-- | cli/tests/integration/info_tests.rs | 6 |
3 files changed, 36 insertions, 4 deletions
diff --git a/cli/tests/integration/compile_tests.rs b/cli/tests/integration/compile_tests.rs index df339c369..653b2bc8d 100644 --- a/cli/tests/integration/compile_tests.rs +++ b/cli/tests/integration/compile_tests.rs @@ -1061,3 +1061,27 @@ fn compile_node_modules_symlink_outside() { let output = context.new_command().name(binary_path).run(); output.assert_matches_file("compile/node_modules_symlink_outside/main.out"); } + +#[test] +fn dynamic_imports_tmp_lit() { + let context = TestContextBuilder::new().build(); + let dir = context.temp_dir(); + let exe = if cfg!(windows) { + dir.path().join("app.exe") + } else { + dir.path().join("app") + }; + let output = context + .new_command() + .args_vec([ + "compile", + "--output", + &exe.to_string_lossy(), + "./compile/dynamic_imports_tmp_lit/main.js", + ]) + .run(); + output.assert_exit_code(0); + output.skip_output_check(); + let output = context.new_command().name(&exe).run(); + output.assert_matches_text("a\nb\n{ data: 5 }\n{ data: 1 }\n"); +} diff --git a/cli/tests/integration/doc_tests.rs b/cli/tests/integration/doc_tests.rs index 7a3f08f48..9accd8304 100644 --- a/cli/tests/integration/doc_tests.rs +++ b/cli/tests/integration/doc_tests.rs @@ -138,13 +138,15 @@ fn deno_doc_html() { .run(); output.assert_exit_code(0); - assert_contains!(output.stderr(), "Written 8 files to"); + assert_contains!(output.stderr(), "Written 10 files to"); + assert!(temp_dir.path().join("all_symbols.html").exists()); assert!(temp_dir.path().join("index.html").exists()); - assert!(temp_dir.path().join("compound_index.html").exists()); assert!(temp_dir.path().join("fuse.js").exists()); + assert!(temp_dir.path().join("page.css").exists()); assert!(temp_dir.path().join("search.js").exists()); assert!(temp_dir.path().join("search_index.js").exists()); assert!(temp_dir.path().join("styles.css").exists()); - assert!(temp_dir.path().join("MyInterface.html").exists()); - assert!(temp_dir.path().join("MyClass.html").exists()); + assert!(temp_dir.path().join("~/MyInterface.html").exists()); + assert!(temp_dir.path().join("~/MyClass.html").exists()); + assert!(temp_dir.path().join("~/index.html").exists()); } diff --git a/cli/tests/integration/info_tests.rs b/cli/tests/integration/info_tests.rs index 47c5cc1d0..f7889f3c3 100644 --- a/cli/tests/integration/info_tests.rs +++ b/cli/tests/integration/info_tests.rs @@ -154,3 +154,9 @@ itest!(info_import_map { cwd: Some("info/with_import_map"), exit_code: 0, }); + +itest!(info_dynamic_imports_tmpl_lit { + args: "info compile/dynamic_imports_tmp_lit/main.js", + output: "compile/dynamic_imports_tmp_lit/main.info.out", + exit_code: 0, +}); |
