From 6f278e5c40d101f0fb8e7b69e28d34b1c766a8fe Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 15 Apr 2024 17:50:52 -0400 Subject: fix(lsp): improved cjs tracking (#23374) Our cjs tracking was a bit broken. It was marking stuff as esm that was actually cjs leading to type checking errors. --- tests/specs/mod.rs | 31 +++++++++++++--------- .../__test__.jsonc | 15 +++++++++++ .../npm/cjs_internal_types_default_export/main.out | 5 ++++ .../npm/cjs_internal_types_default_export/main.ts | 3 +++ .../cjs_internal_types_default_export/package.json | 5 ++++ 5 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 tests/specs/npm/cjs_internal_types_default_export/__test__.jsonc create mode 100644 tests/specs/npm/cjs_internal_types_default_export/main.out create mode 100644 tests/specs/npm/cjs_internal_types_default_export/main.ts create mode 100644 tests/specs/npm/cjs_internal_types_default_export/package.json (limited to 'tests/specs') diff --git a/tests/specs/mod.rs b/tests/specs/mod.rs index 1028519cf..2040eea62 100644 --- a/tests/specs/mod.rs +++ b/tests/specs/mod.rs @@ -9,6 +9,10 @@ use std::sync::Arc; use deno_core::anyhow::Context; use deno_core::serde_json; +use file_test_runner::collection::collect_tests_or_exit; +use file_test_runner::collection::strategies::TestPerDirectoryCollectionStrategy; +use file_test_runner::collection::CollectOptions; +use file_test_runner::collection::CollectedTest; use serde::Deserialize; use test_util::tests_path; use test_util::PathRef; @@ -69,6 +73,7 @@ struct StepMetaData { pub clean_deno_dir: bool, pub args: VecOrString, pub cwd: Option, + pub command_name: Option, #[serde(default)] pub envs: HashMap, pub output: String, @@ -77,15 +82,13 @@ struct StepMetaData { } pub fn main() { - let root_category = - file_test_runner::collect_tests_or_exit(file_test_runner::CollectOptions { - base: tests_path().join("specs").to_path_buf(), - strategy: file_test_runner::FileCollectionStrategy::TestPerDirectory { - file_name: MANIFEST_FILE_NAME.to_string(), - }, - root_category_name: "specs".to_string(), - filter_override: None, - }); + let root_category = collect_tests_or_exit(CollectOptions { + base: tests_path().join("specs").to_path_buf(), + strategy: Box::new(TestPerDirectoryCollectionStrategy { + file_name: MANIFEST_FILE_NAME.to_string(), + }), + filter_override: None, + }); if root_category.is_empty() { return; // all tests filtered out @@ -111,15 +114,13 @@ pub fn main() { output.extend(panic_output); file_test_runner::TestResult::Failed { output } } + file_test_runner::TestResult::Steps(_) => unreachable!(), } }), ); } -fn run_test( - test: &file_test_runner::CollectedTest, - diagnostic_logger: Rc>>, -) { +fn run_test(test: &CollectedTest, diagnostic_logger: Rc>>) { let metadata_path = PathRef::new(&test.path); let metadata_value = metadata_path.read_jsonc_value(); // checking for "steps" leads to a more targeted error message @@ -182,6 +183,10 @@ fn run_test( Some(cwd) => command.current_dir(cwd), None => command, }; + let command = match &step.command_name { + Some(command_name) => command.name(command_name), + None => command, + }; let output = command.run(); if step.output.ends_with(".out") { let test_output_path = cwd.join(&step.output); diff --git a/tests/specs/npm/cjs_internal_types_default_export/__test__.jsonc b/tests/specs/npm/cjs_internal_types_default_export/__test__.jsonc new file mode 100644 index 000000000..dc8aabedb --- /dev/null +++ b/tests/specs/npm/cjs_internal_types_default_export/__test__.jsonc @@ -0,0 +1,15 @@ +{ + "tempDir": true, + "envs": { + "DENO_FUTURE": "1" + }, + "steps": [{ + "commandName": "npm", + "args": "install", + "output": "[WILDCARD]" + }, { + "args": "check main.ts", + "exitCode": 1, + "output": "main.out" + }] +} diff --git a/tests/specs/npm/cjs_internal_types_default_export/main.out b/tests/specs/npm/cjs_internal_types_default_export/main.out new file mode 100644 index 000000000..66ec3f37b --- /dev/null +++ b/tests/specs/npm/cjs_internal_types_default_export/main.out @@ -0,0 +1,5 @@ +Check file:///[WILDLINE]/main.ts +error: TS2345 [ERROR]: Argument of type 'string' is not assignable to parameter of type 'number'. +add(1, "test"); // should error + ~~~~~~ + at file:///[WILDLINE]/main.ts:3:8 diff --git a/tests/specs/npm/cjs_internal_types_default_export/main.ts b/tests/specs/npm/cjs_internal_types_default_export/main.ts new file mode 100644 index 000000000..339efcc59 --- /dev/null +++ b/tests/specs/npm/cjs_internal_types_default_export/main.ts @@ -0,0 +1,3 @@ +import { add } from "@denotest/cjs-internal-types-default-export"; + +add(1, "test"); // should error diff --git a/tests/specs/npm/cjs_internal_types_default_export/package.json b/tests/specs/npm/cjs_internal_types_default_export/package.json new file mode 100644 index 000000000..f97b7b565 --- /dev/null +++ b/tests/specs/npm/cjs_internal_types_default_export/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "@denotest/cjs-internal-types-default-export": "*" + } +} -- cgit v1.2.3