summaryrefslogtreecommitdiff
path: root/cli/tests/integration/npm_tests.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-10-26 21:22:15 -0400
committerGitHub <noreply@github.com>2023-10-26 21:22:15 -0400
commit9026f20b2dc0ee97bde3cc6ea8438dafbec5fad3 (patch)
tree4b40a748fe956b8fa8fcba79d96ce57b5a86c1d1 /cli/tests/integration/npm_tests.rs
parentef2fadc6ae517cad487e16530fdcee50065ba05a (diff)
fix(unstable/byonm): improve error messages (#20987)
This improves the error messages when a specifier can't be resolved from a deno module into an npm package.
Diffstat (limited to 'cli/tests/integration/npm_tests.rs')
-rw-r--r--cli/tests/integration/npm_tests.rs51
1 files changed, 50 insertions, 1 deletions
diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs
index c3fe2949c..5104036e3 100644
--- a/cli/tests/integration/npm_tests.rs
+++ b/cli/tests/integration/npm_tests.rs
@@ -2314,6 +2314,55 @@ console.log(getKind());
}
#[test]
+pub fn byonm_package_specifier_not_installed_and_invalid_subpath() {
+ let test_context = TestContextBuilder::for_npm()
+ .env("DENO_UNSTABLE_BYONM", "1")
+ .use_temp_cwd()
+ .build();
+ let dir = test_context.temp_dir();
+ dir.path().join("package.json").write_json(&json!({
+ "dependencies": {
+ "chalk": "4",
+ "@denotest/conditional-exports-strict": "1"
+ }
+ }));
+ dir.write(
+ "main.ts",
+ "import chalk from 'chalk'; console.log(chalk.green('hi'));",
+ );
+
+ // no npm install has been run, so this should give an informative error
+ let output = test_context.new_command().args("run main.ts").run();
+ output.assert_matches_text(
+ r#"error: Could not resolve "chalk", but found it in a package.json. Deno expects the node_modules/ directory to be up to date. Did you forget to run `npm install`?
+ at file:///[WILDCARD]/main.ts:1:19
+"#,
+ );
+ output.assert_exit_code(1);
+
+ // now test for an invalid sub path after doing an npm install
+ dir.write(
+ "main.ts",
+ "import '@denotest/conditional-exports-strict/test';",
+ );
+
+ test_context
+ .new_command()
+ .name("npm")
+ .args("install")
+ .run()
+ .skip_output_check();
+
+ let output = test_context.new_command().args("run main.ts").run();
+ output.assert_matches_text(
+ r#"error: [ERR_PACKAGE_PATH_NOT_EXPORTED] Package subpath './test' is not defined by "exports" in '[WILDCARD]' imported from '[WILDCARD]main.ts'
+ at file:///[WILDCARD]/main.ts:1:8
+"#,
+ );
+ output.assert_exit_code(1);
+}
+
+#[test]
pub fn byonm_package_npm_specifier_not_installed_and_invalid_subpath() {
let test_context = TestContextBuilder::for_npm()
.env("DENO_UNSTABLE_BYONM", "1")
@@ -2334,7 +2383,7 @@ pub fn byonm_package_npm_specifier_not_installed_and_invalid_subpath() {
// no npm install has been run, so this should give an informative error
let output = test_context.new_command().args("run main.ts").run();
output.assert_matches_text(
- r#"error: Could not find '[WILDCARD]package.json'. Maybe run `npm install`?
+ r#"error: Could not find '[WILDCARD]package.json'. Deno expects the node_modules/ directory to be up to date. Did you forget to run `npm install`?
at file:///[WILDCARD]/main.ts:1:19
"#,
);