summaryrefslogtreecommitdiff
path: root/tests/specs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-04-15 17:50:52 -0400
committerGitHub <noreply@github.com>2024-04-15 17:50:52 -0400
commit6f278e5c40d101f0fb8e7b69e28d34b1c766a8fe (patch)
tree97d3edc0f0b527c3dc7f07ba71d5828cd2c77943 /tests/specs
parent7e4ee02e2e37db8adfaf4a05aba3819838904650 (diff)
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.
Diffstat (limited to 'tests/specs')
-rw-r--r--tests/specs/mod.rs31
-rw-r--r--tests/specs/npm/cjs_internal_types_default_export/__test__.jsonc15
-rw-r--r--tests/specs/npm/cjs_internal_types_default_export/main.out5
-rw-r--r--tests/specs/npm/cjs_internal_types_default_export/main.ts3
-rw-r--r--tests/specs/npm/cjs_internal_types_default_export/package.json5
5 files changed, 46 insertions, 13 deletions
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<String>,
+ pub command_name: Option<String>,
#[serde(default)]
pub envs: HashMap<String, String>,
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<RefCell<Vec<u8>>>,
-) {
+fn run_test(test: &CollectedTest, diagnostic_logger: Rc<RefCell<Vec<u8>>>) {
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": "*"
+ }
+}