diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/mod.rs | 2 | ||||
-rw-r--r-- | tests/integration/pm_tests.rs | 108 | ||||
-rw-r--r-- | tests/testdata/jsr/registry/@denotest/subset-type-graph-invalid/0.1.0/mod.ts (renamed from tests/testdata/jsr/registry/@denotest/subset_type_graph_invalid/0.1.0/mod.ts) | 0 | ||||
-rw-r--r-- | tests/testdata/jsr/registry/@denotest/subset-type-graph-invalid/0.1.0_meta.json (renamed from tests/testdata/jsr/registry/@denotest/subset_type_graph/0.1.0_meta.json) | 0 | ||||
-rw-r--r-- | tests/testdata/jsr/registry/@denotest/subset-type-graph-invalid/meta.json (renamed from tests/testdata/jsr/registry/@denotest/subset_type_graph/meta.json) | 0 | ||||
-rw-r--r-- | tests/testdata/jsr/registry/@denotest/subset-type-graph/0.1.0/mod.ts (renamed from tests/testdata/jsr/registry/@denotest/subset_type_graph/0.1.0/mod.ts) | 0 | ||||
-rw-r--r-- | tests/testdata/jsr/registry/@denotest/subset-type-graph/0.1.0_meta.json (renamed from tests/testdata/jsr/registry/@denotest/subset_type_graph_invalid/0.1.0_meta.json) | 0 | ||||
-rw-r--r-- | tests/testdata/jsr/registry/@denotest/subset-type-graph/meta.json (renamed from tests/testdata/jsr/registry/@denotest/subset_type_graph_invalid/meta.json) | 0 | ||||
-rw-r--r-- | tests/testdata/jsr/subset_type_graph/main.check.out | 18 | ||||
-rw-r--r-- | tests/testdata/jsr/subset_type_graph/main.ts | 4 | ||||
-rw-r--r-- | tests/util/server/src/servers/registry.rs | 7 |
11 files changed, 127 insertions, 12 deletions
diff --git a/tests/integration/mod.rs b/tests/integration/mod.rs index 89a66385e..9253cae32 100644 --- a/tests/integration/mod.rs +++ b/tests/integration/mod.rs @@ -50,6 +50,8 @@ mod node_compat_tests; mod node_unit_tests; #[path = "npm_tests.rs"] mod npm; +#[path = "pm_tests.rs"] +mod pm; #[path = "publish_tests.rs"] mod publish; 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() +} diff --git a/tests/testdata/jsr/registry/@denotest/subset_type_graph_invalid/0.1.0/mod.ts b/tests/testdata/jsr/registry/@denotest/subset-type-graph-invalid/0.1.0/mod.ts index 6a5036bf5..6a5036bf5 100644 --- a/tests/testdata/jsr/registry/@denotest/subset_type_graph_invalid/0.1.0/mod.ts +++ b/tests/testdata/jsr/registry/@denotest/subset-type-graph-invalid/0.1.0/mod.ts diff --git a/tests/testdata/jsr/registry/@denotest/subset_type_graph/0.1.0_meta.json b/tests/testdata/jsr/registry/@denotest/subset-type-graph-invalid/0.1.0_meta.json index 631a18d0e..631a18d0e 100644 --- a/tests/testdata/jsr/registry/@denotest/subset_type_graph/0.1.0_meta.json +++ b/tests/testdata/jsr/registry/@denotest/subset-type-graph-invalid/0.1.0_meta.json diff --git a/tests/testdata/jsr/registry/@denotest/subset_type_graph/meta.json b/tests/testdata/jsr/registry/@denotest/subset-type-graph-invalid/meta.json index d10aa5c3a..d10aa5c3a 100644 --- a/tests/testdata/jsr/registry/@denotest/subset_type_graph/meta.json +++ b/tests/testdata/jsr/registry/@denotest/subset-type-graph-invalid/meta.json diff --git a/tests/testdata/jsr/registry/@denotest/subset_type_graph/0.1.0/mod.ts b/tests/testdata/jsr/registry/@denotest/subset-type-graph/0.1.0/mod.ts index e81b2309a..e81b2309a 100644 --- a/tests/testdata/jsr/registry/@denotest/subset_type_graph/0.1.0/mod.ts +++ b/tests/testdata/jsr/registry/@denotest/subset-type-graph/0.1.0/mod.ts diff --git a/tests/testdata/jsr/registry/@denotest/subset_type_graph_invalid/0.1.0_meta.json b/tests/testdata/jsr/registry/@denotest/subset-type-graph/0.1.0_meta.json index 631a18d0e..631a18d0e 100644 --- a/tests/testdata/jsr/registry/@denotest/subset_type_graph_invalid/0.1.0_meta.json +++ b/tests/testdata/jsr/registry/@denotest/subset-type-graph/0.1.0_meta.json diff --git a/tests/testdata/jsr/registry/@denotest/subset_type_graph_invalid/meta.json b/tests/testdata/jsr/registry/@denotest/subset-type-graph/meta.json index d10aa5c3a..d10aa5c3a 100644 --- a/tests/testdata/jsr/registry/@denotest/subset_type_graph_invalid/meta.json +++ b/tests/testdata/jsr/registry/@denotest/subset-type-graph/meta.json diff --git a/tests/testdata/jsr/subset_type_graph/main.check.out b/tests/testdata/jsr/subset_type_graph/main.check.out index 278884579..f46610c0a 100644 --- a/tests/testdata/jsr/subset_type_graph/main.check.out +++ b/tests/testdata/jsr/subset_type_graph/main.check.out @@ -1,16 +1,16 @@ -Download http://127.0.0.1:4250/@denotest/subset_type_graph/meta.json -Download http://127.0.0.1:4250/@denotest/subset_type_graph_invalid/meta.json -Download http://127.0.0.1:4250/@denotest/subset_type_graph/0.1.0_meta.json -Download http://127.0.0.1:4250/@denotest/subset_type_graph_invalid/0.1.0_meta.json +Download http://127.0.0.1:4250/@denotest/subset-type-graph/meta.json +Download http://127.0.0.1:4250/@denotest/subset-type-graph-invalid/meta.json +Download http://127.0.0.1:4250/@denotest/subset-type-graph/0.1.0_meta.json +Download http://127.0.0.1:4250/@denotest/subset-type-graph-invalid/0.1.0_meta.json [UNORDERED_START] -Download http://127.0.0.1:4250/@denotest/subset_type_graph/0.1.0/mod.ts -Download http://127.0.0.1:4250/@denotest/subset_type_graph_invalid/0.1.0/mod.ts +Download http://127.0.0.1:4250/@denotest/subset-type-graph/0.1.0/mod.ts +Download http://127.0.0.1:4250/@denotest/subset-type-graph-invalid/0.1.0/mod.ts [UNORDERED_END] Check file:///[WILDCARD]/subset_type_graph/main.ts error: TS2322 [ERROR]: Type 'string' is not assignable to type 'number'. const invalidTypeCheck: number = ""; ~~~~~~~~~~~~~~~~ - at http://127.0.0.1:4250/@denotest/subset_type_graph_invalid/0.1.0/mod.ts:11:7 + at http://127.0.0.1:4250/@denotest/subset-type-graph-invalid/0.1.0/mod.ts:11:7 TS2322 [ERROR]: Type 'number' is not assignable to type 'string'. const error1: string = new Foo1().method(); @@ -30,7 +30,7 @@ new Foo1().method2(); 'method' is declared here. method(): number { ~~~~~~ - at http://127.0.0.1:4250/@denotest/subset_type_graph/0.1.0/mod.ts:8:3 + at http://127.0.0.1:4250/@denotest/subset-type-graph/0.1.0/mod.ts:8:3 TS2551 [ERROR]: Property 'method2' does not exist on type 'Foo'. Did you mean 'method'? new Foo2().method2(); @@ -40,6 +40,6 @@ new Foo2().method2(); 'method' is declared here. method() { ~~~~~~ - at http://127.0.0.1:4250/@denotest/subset_type_graph_invalid/0.1.0/mod.ts:2:3 + at http://127.0.0.1:4250/@denotest/subset-type-graph-invalid/0.1.0/mod.ts:2:3 Found 5 errors. diff --git a/tests/testdata/jsr/subset_type_graph/main.ts b/tests/testdata/jsr/subset_type_graph/main.ts index 2e1614be9..2fff966a7 100644 --- a/tests/testdata/jsr/subset_type_graph/main.ts +++ b/tests/testdata/jsr/subset_type_graph/main.ts @@ -1,5 +1,5 @@ -import { Foo as Foo1 } from "jsr:@denotest/subset_type_graph@0.1.0"; -import { Foo as Foo2 } from "jsr:@denotest/subset_type_graph_invalid@0.1.0"; +import { Foo as Foo1 } from "jsr:@denotest/subset-type-graph@0.1.0"; +import { Foo as Foo2 } from "jsr:@denotest/subset-type-graph-invalid@0.1.0"; // these will both raise type checking errors const error1: string = new Foo1().method(); diff --git a/tests/util/server/src/servers/registry.rs b/tests/util/server/src/servers/registry.rs index 1a0caff1f..09b80c8d5 100644 --- a/tests/util/server/src/servers/registry.rs +++ b/tests/util/server/src/servers/registry.rs @@ -142,7 +142,12 @@ async fn registry_server_handler( // serve the registry package files let mut file_path = testdata_path().to_path_buf().join("jsr").join("registry"); - file_path.push(&req.uri().path()[1..].replace("%2f", "/")); + file_path.push( + &req.uri().path()[1..] + .replace("%2f", "/") + .replace("%2F", "/"), + ); + if let Ok(body) = tokio::fs::read(&file_path).await { let body = if let Some(version) = file_path .file_name() |