diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-02-20 16:29:57 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-20 21:29:57 +0000 |
commit | f90889e5ee19e0ddcd9c1dbcce98720e417dd83e (patch) | |
tree | e44392e9506ba8cddc4c142d304f43879a418152 /tests | |
parent | dbc4a4d6327062918b3bc41dc3f60c84ae3c620b (diff) |
perf(jsr): fast check cache and lazy fast check graph (#22485)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/info_tests.rs | 1 | ||||
-rw-r--r-- | tests/integration/jsr_tests.rs | 114 | ||||
-rw-r--r-- | tests/util/server/src/fs.rs | 7 |
3 files changed, 122 insertions, 0 deletions
diff --git a/tests/integration/info_tests.rs b/tests/integration/info_tests.rs index 8fae81a61..62e169c9e 100644 --- a/tests/integration/info_tests.rs +++ b/tests/integration/info_tests.rs @@ -175,6 +175,7 @@ itest!(info_import_map { args: "info preact/debug", output: "info/with_import_map/with_import_map.out", cwd: Some("info/with_import_map"), + copy_temp_dir: Some("info/with_import_map"), exit_code: 0, }); diff --git a/tests/integration/jsr_tests.rs b/tests/integration/jsr_tests.rs index b6e4d8a4f..fa8a9d8b9 100644 --- a/tests/integration/jsr_tests.rs +++ b/tests/integration/jsr_tests.rs @@ -6,6 +6,8 @@ use deno_lockfile::Lockfile; use test_util as util; use test_util::itest; use url::Url; +use util::assert_contains; +use util::assert_not_contains; use util::env_vars_for_jsr_tests; use util::TestContextBuilder; @@ -66,6 +68,118 @@ itest!(subset_type_graph { exit_code: 1, }); +#[test] +fn fast_check_cache() { + let test_context = TestContextBuilder::for_jsr().use_temp_cwd().build(); + let deno_dir = test_context.deno_dir(); + let temp_dir = test_context.temp_dir(); + let type_check_cache_path = deno_dir.path().join("check_cache_v1"); + + temp_dir.write( + "main.ts", + r#"import { add } from "jsr:@denotest/add@1"; + const value: number = add(1, 2); + console.log(value);"#, + ); + temp_dir.path().join("deno.json").write_json(&json!({ + "vendor": true + })); + + test_context + .new_command() + .args("check main.ts") + .run() + .skip_output_check(); + + type_check_cache_path.remove_file(); + let check_debug_cmd = test_context + .new_command() + .args("check --log-level=debug main.ts"); + let output = check_debug_cmd.run(); + assert_contains!( + output.combined_output(), + "Using FastCheck cache for: @denotest/add@1.0.0" + ); + + // modify the file in the vendor folder + let vendor_dir = temp_dir.path().join("vendor"); + let pkg_dir = vendor_dir.join("http_127.0.0.1_4250/@denotest/add/1.0.0/"); + pkg_dir + .join("mod.ts") + .append("\nexport * from './other.ts';"); + let nested_pkg_file = pkg_dir.join("other.ts"); + nested_pkg_file.write("export function other(): string { return ''; }"); + + // invalidated + let output = check_debug_cmd.run(); + assert_not_contains!( + output.combined_output(), + "Using FastCheck cache for: @denotest/add@1.0.0" + ); + + // ensure cache works + let output = check_debug_cmd.run(); + assert_contains!(output.combined_output(), "Already type checked."); + let building_fast_check_msg = "Building fast check graph"; + assert_not_contains!(output.combined_output(), building_fast_check_msg); + + // now validated + type_check_cache_path.remove_file(); + let output = check_debug_cmd.run(); + assert_contains!(output.combined_output(), building_fast_check_msg); + assert_contains!( + output.combined_output(), + "Using FastCheck cache for: @denotest/add@1.0.0" + ); + + // cause a fast check error in the nested package + nested_pkg_file + .append("\nexport function asdf(a: number) { let err: number = ''; return Math.random(); }"); + check_debug_cmd.run().skip_output_check(); + + // ensure the cache still picks it up for this file + type_check_cache_path.remove_file(); + let output = check_debug_cmd.run(); + assert_contains!(output.combined_output(), building_fast_check_msg); + assert_contains!( + output.combined_output(), + "Using FastCheck cache for: @denotest/add@1.0.0" + ); + + // see that the type checking error in the internal function gets surfaced with --all + test_context + .new_command() + .args("check --all main.ts") + .run() + .assert_matches_text( + "Check file:///[WILDCARD]main.ts +error: TS2322 [ERROR]: Type 'string' is not assignable to type 'number'. +export function asdf(a: number) { let err: number = ''; return Math.random(); } + ~~~ + at http://127.0.0.1:4250/@denotest/add/1.0.0/other.ts:2:39 +", + ) + .assert_exit_code(1); + + // now fix the package + nested_pkg_file.write("export function test() {}"); + let output = check_debug_cmd.run(); + assert_contains!(output.combined_output(), building_fast_check_msg); + assert_not_contains!( + output.combined_output(), + "Using FastCheck cache for: @denotest/add@1.0.0" + ); + + // finally ensure it uses the cache + type_check_cache_path.remove_file(); + let output = check_debug_cmd.run(); + assert_contains!(output.combined_output(), building_fast_check_msg); + assert_contains!( + output.combined_output(), + "Using FastCheck cache for: @denotest/add@1.0.0" + ); +} + itest!(version_not_found { args: "run jsr/version_not_found/main.ts", output: "jsr/version_not_found/main.out", diff --git a/tests/util/server/src/fs.rs b/tests/util/server/src/fs.rs index 0e47a7503..d99572b06 100644 --- a/tests/util/server/src/fs.rs +++ b/tests/util/server/src/fs.rs @@ -4,6 +4,8 @@ use pretty_assertions::assert_eq; use std::borrow::Cow; use std::ffi::OsStr; use std::fs; +use std::fs::OpenOptions; +use std::io::Write; use std::path::Path; use std::path::PathBuf; use std::process::Command; @@ -134,6 +136,11 @@ impl PathRef { fs::rename(self, self.join(to)).unwrap(); } + pub fn append(&self, text: impl AsRef<str>) { + let mut file = OpenOptions::new().append(true).open(self).unwrap(); + file.write_all(text.as_ref().as_bytes()).unwrap(); + } + pub fn write(&self, text: impl AsRef<str>) { fs::write(self, text.as_ref()).unwrap(); } |