summaryrefslogtreecommitdiff
path: root/tests/integration/pm_tests.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-02-29 19:12:04 +0000
committerGitHub <noreply@github.com>2024-02-29 19:12:04 +0000
commitfb31ae73e40896c1d1dfdb26c265222f49907d32 (patch)
treef113a07ecf0dd54f7df38b5b3c1f7f481b581498 /tests/integration/pm_tests.rs
parenta9aef0d017bd053d7f4014c363dbc5898ced1a2e (diff)
feat(unstable): `deno add` subcommand (#22520)
This commit adds "deno add" subcommand that has a basic support for adding "jsr:" packages to "deno.json" file. This currently doesn't support "npm:" specifiers and specifying version constraints.
Diffstat (limited to 'tests/integration/pm_tests.rs')
-rw-r--r--tests/integration/pm_tests.rs108
1 files changed, 108 insertions, 0 deletions
diff --git a/tests/integration/pm_tests.rs b/tests/integration/pm_tests.rs
new file mode 100644
index 000000000..4e0345331
--- /dev/null
+++ b/tests/integration/pm_tests.rs
@@ -0,0 +1,108 @@
+// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+
+use deno_core::serde_json::json;
+use test_util::assert_contains;
+use test_util::env_vars_for_jsr_tests;
+// use test_util::env_vars_for_npm_tests;
+// use test_util::itest;
+use test_util::TestContextBuilder;
+
+#[test]
+fn add_basic() {
+ let starting_deno_json = json!({
+ "name": "@foo/bar",
+ "version": "1.0.0",
+ "exports": "./mod.ts",
+ });
+ let context = pm_context_builder().build();
+ let temp_dir = context.temp_dir().path();
+ temp_dir.join("deno.json").write_json(&starting_deno_json);
+
+ let output = context.new_command().args("add @denotest/add").run();
+ output.assert_exit_code(0);
+ let output = output.combined_output();
+ assert_contains!(output, "Add @denotest/add");
+ temp_dir.join("deno.json").assert_matches_json(json!({
+ "name": "@foo/bar",
+ "version": "1.0.0",
+ "exports": "./mod.ts",
+ "imports": {
+ "@denotest/add": "jsr:@denotest/add@^1.0.0"
+ }
+ }));
+}
+
+#[test]
+fn add_basic_no_deno_json() {
+ let context = pm_context_builder().build();
+ let temp_dir = context.temp_dir().path();
+
+ let output = context.new_command().args("add @denotest/add").run();
+ output.assert_exit_code(0);
+ let output = output.combined_output();
+ assert_contains!(output, "Add @denotest/add");
+ temp_dir.join("deno.json").assert_matches_json(json!({
+ "imports": {
+ "@denotest/add": "jsr:@denotest/add@^1.0.0"
+ }
+ }));
+}
+
+#[test]
+fn add_multiple() {
+ let starting_deno_json = json!({
+ "name": "@foo/bar",
+ "version": "1.0.0",
+ "exports": "./mod.ts",
+ });
+ let context = pm_context_builder().build();
+ let temp_dir = context.temp_dir().path();
+ temp_dir.join("deno.json").write_json(&starting_deno_json);
+
+ let output = context
+ .new_command()
+ .args("add @denotest/add @denotest/subset-type-graph")
+ .run();
+ output.assert_exit_code(0);
+ let output = output.combined_output();
+ assert_contains!(output, "Add @denotest/add");
+ temp_dir.join("deno.json").assert_matches_json(json!({
+ "name": "@foo/bar",
+ "version": "1.0.0",
+ "exports": "./mod.ts",
+ "imports": {
+ "@denotest/add": "jsr:@denotest/add@^1.0.0",
+ "@denotest/subset-type-graph": "jsr:@denotest/subset-type-graph@^0.1.0"
+ }
+ }));
+}
+
+#[test]
+fn add_not_supported_npm() {
+ let context = pm_context_builder().build();
+
+ let output = context
+ .new_command()
+ .args("add @denotest/add npm:express")
+ .run();
+ output.assert_exit_code(1);
+ let output = output.combined_output();
+ assert_contains!(output, "error: Adding npm: packages is currently not supported. Package: npm:express");
+}
+
+#[test]
+fn add_not_supported_version_constraint() {
+ let context = pm_context_builder().build();
+
+ let output = context.new_command().args("add @denotest/add@1").run();
+ output.assert_exit_code(1);
+ let output = output.combined_output();
+ assert_contains!(output, "error: Specifying version constraints is currently not supported. Package: jsr:@denotest/add@1");
+}
+
+fn pm_context_builder() -> TestContextBuilder {
+ TestContextBuilder::new()
+ .use_http_server()
+ .envs(env_vars_for_jsr_tests())
+ .use_temp_cwd()
+}