diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-03-07 21:13:36 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-07 22:13:36 +0100 |
commit | 914b7495a854981a3671e24f527d792f2ad1b324 (patch) | |
tree | ffe7eac41c1fe904f57973a8afaeb02d7df3a6f6 /tests/integration/publish_tests.rs | |
parent | e0c9102b49ab333e0229247c446d12e27750785c (diff) |
fix(publish): reland error if there are uncommitted changes (#22613) (#22632)
Reverted in https://github.com/denoland/deno/pull/22625
Diffstat (limited to 'tests/integration/publish_tests.rs')
-rw-r--r-- | tests/integration/publish_tests.rs | 85 |
1 files changed, 83 insertions, 2 deletions
diff --git a/tests/integration/publish_tests.rs b/tests/integration/publish_tests.rs index cb1072bc0..2c3bf9ff6 100644 --- a/tests/integration/publish_tests.rs +++ b/tests/integration/publish_tests.rs @@ -1,11 +1,14 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::process::Command; + use deno_core::serde_json::json; use test_util::assert_contains; use test_util::assert_not_contains; use test_util::env_vars_for_jsr_npm_tests; use test_util::env_vars_for_jsr_provenance_tests; use test_util::env_vars_for_jsr_tests; +use test_util::env_vars_for_jsr_tests_with_git_check; use test_util::env_vars_for_npm_tests; use test_util::itest; use test_util::TestContextBuilder; @@ -14,6 +17,7 @@ itest!(no_token { args: "publish", cwd: Some("publish/missing_deno_json"), output: "publish/no_token.out", + envs: env_vars_for_jsr_tests(), exit_code: 1, }); @@ -21,6 +25,7 @@ itest!(missing_deno_json { args: "publish --token 'sadfasdf'", output: "publish/missing_deno_json.out", cwd: Some("publish/missing_deno_json"), + envs: env_vars_for_jsr_tests(), exit_code: 1, }); @@ -28,6 +33,7 @@ itest!(has_slow_types { args: "publish --token 'sadfasdf'", output: "publish/has_slow_types.out", cwd: Some("publish/has_slow_types"), + envs: env_vars_for_jsr_tests(), exit_code: 1, }); @@ -44,6 +50,7 @@ itest!(invalid_path { args: "publish --token 'sadfasdf'", output: "publish/invalid_path.out", cwd: Some("publish/invalid_path"), + envs: env_vars_for_jsr_tests(), exit_code: 1, }); @@ -51,6 +58,7 @@ itest!(symlink { args: "publish --token 'sadfasdf' --dry-run", output: "publish/symlink.out", cwd: Some("publish/symlink"), + envs: env_vars_for_jsr_tests(), exit_code: 0, }); @@ -58,7 +66,7 @@ itest!(invalid_import { args: "publish --token 'sadfasdf' --dry-run", output: "publish/invalid_import.out", cwd: Some("publish/invalid_import"), - envs: env_vars_for_npm_tests(), + envs: env_vars_for_jsr_npm_tests(), exit_code: 1, http_server: true, }); @@ -67,7 +75,7 @@ itest!(invalid_import_esm_sh_suggestion { args: "publish --token 'sadfasdf' --dry-run", output: "publish/invalid_import_esm_sh_suggestion.out", cwd: Some("publish/invalid_import_esm_sh_suggestion"), - envs: env_vars_for_npm_tests(), + envs: env_vars_for_jsr_npm_tests(), exit_code: 1, http_server: true, }); @@ -488,3 +496,76 @@ fn publish_context_builder() -> TestContextBuilder { .envs(env_vars_for_jsr_tests()) .use_temp_cwd() } + +fn publish_context_builder_with_git_checks() -> TestContextBuilder { + TestContextBuilder::new() + .use_http_server() + .envs(env_vars_for_jsr_tests_with_git_check()) + .use_temp_cwd() +} + +#[test] +fn allow_dirty() { + let context = publish_context_builder_with_git_checks().build(); + let temp_dir = context.temp_dir().path(); + temp_dir.join("deno.json").write_json(&json!({ + "name": "@foo/bar", + "version": "1.0.0", + "exports": "./main.ts", + })); + + temp_dir.join("main.ts").write(""); + + let cmd = Command::new("git") + .arg("init") + .arg(temp_dir.as_path()) + .output() + .unwrap(); + assert!(cmd.status.success()); + + let output = context + .new_command() + .arg("publish") + .arg("--token") + .arg("sadfasdf") + .run(); + output.assert_exit_code(1); + let output = output.combined_output(); + assert_contains!(output, "Aborting due to uncomitted changes"); + + let output = context + .new_command() + .arg("publish") + .arg("--allow-dirty") + .arg("--token") + .arg("sadfasdf") + .run(); + output.assert_exit_code(0); + let output = output.combined_output(); + assert_contains!(output, "Successfully published"); +} + +#[test] +fn allow_dirty_not_in_repo() { + let context = publish_context_builder_with_git_checks().build(); + let temp_dir = context.temp_dir().path(); + temp_dir.join("deno.json").write_json(&json!({ + "name": "@foo/bar", + "version": "1.0.0", + "exports": "./main.ts", + })); + + temp_dir.join("main.ts").write(""); + // At this point there are untracked files, but we're not in Git repo, + // so we should be able to publish successfully. + + let output = context + .new_command() + .arg("publish") + .arg("--token") + .arg("sadfasdf") + .run(); + output.assert_exit_code(0); + let output = output.combined_output(); + assert_contains!(output, "Successfully published"); +} |