diff options
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/integration/npm_tests.rs | 44 | ||||
-rw-r--r-- | cli/tests/integration/run_tests.rs | 164 | ||||
-rw-r--r-- | cli/tests/testdata/npm/lock_file/main.out | 3 | ||||
-rw-r--r-- | cli/tests/testdata/run/lock_check_ok2.json | 19 |
4 files changed, 200 insertions, 30 deletions
diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs index cfb1861b7..9840f2771 100644 --- a/cli/tests/integration/npm_tests.rs +++ b/cli/tests/integration/npm_tests.rs @@ -256,7 +256,7 @@ itest!(import_map { http_server: true, }); -itest!(lock_file { +itest!(lock_file_integrity_failure { args: "run --allow-read --allow-env --lock npm/lock_file/lock.json npm/lock_file/main.js", output: "npm/lock_file/main.out", envs: env_vars_for_npm_tests(), @@ -1517,10 +1517,9 @@ fn lock_file_lock_write() { #[test] fn auto_discover_lock_file() { - let _server = http_server(); + let context = TestContextBuilder::for_npm().use_temp_cwd().build(); - let deno_dir = util::new_deno_dir(); - let temp_dir = util::TempDir::new(); + let temp_dir = context.temp_dir(); // write empty config file temp_dir.write("deno.json", "{}"); @@ -1541,25 +1540,26 @@ fn auto_discover_lock_file() { }"#; temp_dir.write("deno.lock", lock_file_content); - let deno = util::deno_cmd_with_deno_dir(&deno_dir) - .current_dir(temp_dir.path()) - .arg("run") - .arg("--unstable") - .arg("-A") - .arg("npm:@denotest/bin/cli-esm") - .arg("test") - .envs(env_vars_for_npm_tests()) - .piped_output() - .spawn() - .unwrap(); - let output = deno.wait_with_output().unwrap(); - assert!(!output.status.success()); - assert_eq!(output.status.code(), Some(10)); + let output = context + .new_command() + .args("run --unstable -A npm:@denotest/bin/cli-esm test") + .run(); + output + .assert_matches_text( +r#"Download http://localhost:4545/npm/registry/@denotest/bin +error: Integrity check failed for npm package: "@denotest/bin@1.0.0". Unable to verify that the package +is the same as when the lockfile was generated. - let stderr = String::from_utf8(output.stderr).unwrap(); - assert!(stderr.contains( - "Integrity check failed for npm package: \"@denotest/bin@1.0.0\"" - )); +Actual: sha512-[WILDCARD] +Expected: sha512-foobar + +This could be caused by: + * the lock file may be corrupt + * the source itself may be corrupt + +Use "--lock-write" flag to regenerate the lockfile at "[WILDCARD]deno.lock". +"#) + .assert_exit_code(10); } #[test] diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index d7d65726e..466972c92 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -1017,6 +1017,170 @@ fn lock_redirects() { ); } +#[test] +fn lock_deno_json_package_json_deps() { + let context = TestContextBuilder::new() + .use_temp_cwd() + .use_http_server() + .add_npm_env_vars() + .add_jsr_env_vars() + .build(); + let temp_dir = context.temp_dir().path(); + let deno_json = temp_dir.join("deno.json"); + let package_json = temp_dir.join("package.json"); + + // add a jsr and npm dependency + deno_json.write_json(&json!({ + "imports": { + "esm-basic": "npm:@denotest/esm-basic", + "module_graph": "jsr:@denotest/module_graph@1.4", + } + })); + let main_ts = temp_dir.join("main.ts"); + main_ts.write("import 'esm-basic'; import 'module_graph';"); + context + .new_command() + .args("cache main.ts") + .run() + .skip_output_check(); + let lockfile = temp_dir.join("deno.lock"); + // todo(dsherret): it would be nice if the test server didn't produce + // different hashes depending on what operating system it's running on + let esm_basic_integrity = lockfile + .read_json_value() + .get("packages") + .unwrap() + .get("npm") + .unwrap() + .get("@denotest/esm-basic@1.0.0") + .unwrap() + .get("integrity") + .unwrap() + .as_str() + .unwrap() + .to_string(); + lockfile.assert_matches_json(json!({ + "version": "3", + "packages": { + "specifiers": { + "jsr:@denotest/module_graph@1.4": "jsr:@denotest/module_graph@1.4.0", + "npm:@denotest/esm-basic": "npm:@denotest/esm-basic@1.0.0" + }, + "npm": { + "@denotest/esm-basic@1.0.0": { + "integrity": esm_basic_integrity, + "dependencies": {} + } + } + }, + "remote": { + "http://localhost:4545/jsr/registry/@denotest/module_graph/1.4.0/mod.ts": "5b0ce36e08d759118200d8b4627627b5a89b6261fbb0598e6961a6b287abb699", + "http://localhost:4545/jsr/registry/@denotest/module_graph/1.4.0/other.ts": "9ce27ca439cb0e218b6e1ec26c043dbc0b54c9babc4cb432df478dd1721faade" + }, + "workspace": { + "dependencies": [ + "jsr:@denotest/module_graph@1.4", + "npm:@denotest/esm-basic" + ] + } + })); + + // now remove the npm dependency from the deno.json and move + // it to a package.json that uses an alias + deno_json.write_json(&json!({ + "imports": { + "module_graph": "jsr:@denotest/module_graph@1.4", + } + })); + package_json.write_json(&json!({ + "dependencies": { + "esm-basic": "npm:@denotest/esm-basic" + } + })); + context + .new_command() + .args("cache main.ts") + .run() + .skip_output_check(); + main_ts.write("import 'module_graph';"); + context + .new_command() + // ensure this doesn't clear out packageJson below + .args("cache --no-npm main.ts") + .run() + .skip_output_check(); + lockfile.assert_matches_json(json!({ + "version": "3", + "packages": { + "specifiers": { + "jsr:@denotest/module_graph@1.4": "jsr:@denotest/module_graph@1.4.0", + "npm:@denotest/esm-basic": "npm:@denotest/esm-basic@1.0.0" + }, + "npm": { + "@denotest/esm-basic@1.0.0": { + "integrity": esm_basic_integrity, + "dependencies": {} + } + } + }, + "remote": { + "http://localhost:4545/jsr/registry/@denotest/module_graph/1.4.0/mod.ts": "5b0ce36e08d759118200d8b4627627b5a89b6261fbb0598e6961a6b287abb699", + "http://localhost:4545/jsr/registry/@denotest/module_graph/1.4.0/other.ts": "9ce27ca439cb0e218b6e1ec26c043dbc0b54c9babc4cb432df478dd1721faade" + }, + "workspace": { + "dependencies": [ + "jsr:@denotest/module_graph@1.4" + ], + "packageJson": { + "dependencies": [ + "npm:@denotest/esm-basic" + ] + } + } + })); + + // now remove the package.json + package_json.remove_file(); + + // cache and it will remove the package.json + context + .new_command() + .args("cache main.ts") + .run() + .skip_output_check(); + lockfile.assert_matches_json(json!({ + "version": "3", + "packages": { + "specifiers": { + "jsr:@denotest/module_graph@1.4": "jsr:@denotest/module_graph@1.4.0", + } + }, + "remote": { + "http://localhost:4545/jsr/registry/@denotest/module_graph/1.4.0/mod.ts": "5b0ce36e08d759118200d8b4627627b5a89b6261fbb0598e6961a6b287abb699", + "http://localhost:4545/jsr/registry/@denotest/module_graph/1.4.0/other.ts": "9ce27ca439cb0e218b6e1ec26c043dbc0b54c9babc4cb432df478dd1721faade" + }, + "workspace": { + "dependencies": [ + "jsr:@denotest/module_graph@1.4" + ] + } + })); + + // now remove the deps from the deno.json + deno_json.write("{}"); + main_ts.write(""); + context + .new_command() + .args("cache main.ts") + .run() + .skip_output_check(); + + lockfile.assert_matches_json(json!({ + "version": "3", + "remote": {} + })); +} + itest!(mts_dmts_mjs { args: "run subdir/import.mts", output: "run/mts_dmts_mjs.out", diff --git a/cli/tests/testdata/npm/lock_file/main.out b/cli/tests/testdata/npm/lock_file/main.out index b8447bee6..65e881be6 100644 --- a/cli/tests/testdata/npm/lock_file/main.out +++ b/cli/tests/testdata/npm/lock_file/main.out @@ -2,6 +2,9 @@ Download [WILDCARD] error: Integrity check failed for npm package: "@babel/parser@7.19.0". Unable to verify that the package is the same as when the lockfile was generated. +Actual: sha512-74bEXKX2h+8rrfQUfsBfuZZHzsEs6Eql4pqy/T4Nn6Y9wNPggQOqD6z6pn5Bl8ZfysKouFZT/UXEH94ummEeQw== +Expected: sha512-foobar! + This could be caused by: * the lock file may be corrupt * the source itself may be corrupt diff --git a/cli/tests/testdata/run/lock_check_ok2.json b/cli/tests/testdata/run/lock_check_ok2.json index 162c755e2..14d8b7117 100644 --- a/cli/tests/testdata/run/lock_check_ok2.json +++ b/cli/tests/testdata/run/lock_check_ok2.json @@ -1,10 +1,13 @@ { - "http://localhost:4545/subdir/mt_application_ecmascript.j2.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", - "http://localhost:4545/subdir/mt_application_x_javascript.j4.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", - "http://localhost:4545/subdir/mt_application_x_typescript.t4.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", - "http://localhost:4545/subdir/mt_text_ecmascript.j3.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", - "http://localhost:4545/subdir/mt_text_javascript.j1.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", - "http://localhost:4545/subdir/mt_text_typescript.t1.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", - "http://localhost:4545/subdir/mt_video_mp2t.t3.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", - "http://localhost:4545/subdir/mt_video_vdn.t2.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18" + "version": "3", + "remote": { + "http://localhost:4545/subdir/mt_application_ecmascript.j2.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_application_x_javascript.j4.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_application_x_typescript.t4.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_text_ecmascript.j3.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_text_javascript.j1.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_text_typescript.t1.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_video_mp2t.t3.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_video_vdn.t2.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18" + } } |