summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-03-25 18:20:15 -0400
committerGitHub <noreply@github.com>2024-03-25 18:20:15 -0400
commit0346e597bf2d95f5bfce20d3aadf697e9ee45fe4 (patch)
tree68acec662839ebc5f61cd9f5377b0277dac9ee42 /tests
parentfb1aa4e6d2339f0a62aa33e19ea403c059b38d43 (diff)
feat(lint): automatically opt-in packages to `jsr` lint tag (#23072)
This automatically opts packages (deno.json's with a name, version, and exports field) into the "jsr" lint tag.
Diffstat (limited to 'tests')
-rw-r--r--tests/specs/lint/jsr_tag/__test__.jsonc14
-rw-r--r--tests/specs/lint/jsr_tag/non_package.out1
-rw-r--r--tests/specs/lint/jsr_tag/non_package/mod.ts3
-rw-r--r--tests/specs/lint/jsr_tag/non_package/type.ts1
-rw-r--r--tests/specs/lint/jsr_tag/package.out12
-rw-r--r--tests/specs/lint/jsr_tag/package/deno.json5
-rw-r--r--tests/specs/lint/jsr_tag/package/mod.ts3
-rw-r--r--tests/specs/lint/jsr_tag/package/type.ts1
-rw-r--r--tests/specs/mod.rs39
9 files changed, 67 insertions, 12 deletions
diff --git a/tests/specs/lint/jsr_tag/__test__.jsonc b/tests/specs/lint/jsr_tag/__test__.jsonc
new file mode 100644
index 000000000..100dcbd13
--- /dev/null
+++ b/tests/specs/lint/jsr_tag/__test__.jsonc
@@ -0,0 +1,14 @@
+{
+ // packages will be automatically entered into the "jsr" tag
+ "steps": [{
+ "args": "lint",
+ "cwd": "./package",
+ "output": "package.out",
+ "exitCode": 1
+ }, {
+ "args": "lint",
+ "cwd": "./non_package",
+ "output": "non_package.out",
+ "exitCode": 0
+ }]
+}
diff --git a/tests/specs/lint/jsr_tag/non_package.out b/tests/specs/lint/jsr_tag/non_package.out
new file mode 100644
index 000000000..158c556c2
--- /dev/null
+++ b/tests/specs/lint/jsr_tag/non_package.out
@@ -0,0 +1 @@
+Checked 2 files
diff --git a/tests/specs/lint/jsr_tag/non_package/mod.ts b/tests/specs/lint/jsr_tag/non_package/mod.ts
new file mode 100644
index 000000000..efb884a2c
--- /dev/null
+++ b/tests/specs/lint/jsr_tag/non_package/mod.ts
@@ -0,0 +1,3 @@
+import { MyType } from "./type.ts";
+
+export const myVar: MyType = "hello";
diff --git a/tests/specs/lint/jsr_tag/non_package/type.ts b/tests/specs/lint/jsr_tag/non_package/type.ts
new file mode 100644
index 000000000..ed7545c16
--- /dev/null
+++ b/tests/specs/lint/jsr_tag/non_package/type.ts
@@ -0,0 +1 @@
+export type MyType = string;
diff --git a/tests/specs/lint/jsr_tag/package.out b/tests/specs/lint/jsr_tag/package.out
new file mode 100644
index 000000000..5169d9815
--- /dev/null
+++ b/tests/specs/lint/jsr_tag/package.out
@@ -0,0 +1,12 @@
+error[verbatim-module-syntax]: All import identifiers are used in types
+ --> [WILDCARD]mod.ts:1:1
+ |
+1 | import { MyType } from "./type.ts";
+ | ^^^^^^
+ = hint: Change `import` to `import type` and optionally add an explicit side effect import
+
+ docs: https://lint.deno.land/rules/verbatim-module-syntax
+
+
+Found 1 problem (1 fixable via --fix)
+Checked 2 files
diff --git a/tests/specs/lint/jsr_tag/package/deno.json b/tests/specs/lint/jsr_tag/package/deno.json
new file mode 100644
index 000000000..8c1c8f8a4
--- /dev/null
+++ b/tests/specs/lint/jsr_tag/package/deno.json
@@ -0,0 +1,5 @@
+{
+ "name": "@scope/package",
+ "version": "1.0.0",
+ "exports": "./mod.ts"
+}
diff --git a/tests/specs/lint/jsr_tag/package/mod.ts b/tests/specs/lint/jsr_tag/package/mod.ts
new file mode 100644
index 000000000..efb884a2c
--- /dev/null
+++ b/tests/specs/lint/jsr_tag/package/mod.ts
@@ -0,0 +1,3 @@
+import { MyType } from "./type.ts";
+
+export const myVar: MyType = "hello";
diff --git a/tests/specs/lint/jsr_tag/package/type.ts b/tests/specs/lint/jsr_tag/package/type.ts
new file mode 100644
index 000000000..ed7545c16
--- /dev/null
+++ b/tests/specs/lint/jsr_tag/package/type.ts
@@ -0,0 +1 @@
+export type MyType = string;
diff --git a/tests/specs/mod.rs b/tests/specs/mod.rs
index feed09871..3eb8bb386 100644
--- a/tests/specs/mod.rs
+++ b/tests/specs/mod.rs
@@ -128,19 +128,22 @@ fn run_test(test: &Test, diagnostic_logger: Rc<RefCell<Vec<u8>>>) {
context.deno_dir().path().remove_dir_all();
}
- let expected_output = if step.output.ends_with(".out") {
- let test_output_path = cwd.join(&step.output);
- test_output_path.read_to_string()
- } else {
- step.output.clone()
- };
let command = context.new_command().envs(&step.envs);
let command = match &step.args {
VecOrString::Vec(args) => command.args_vec(args),
VecOrString::String(text) => command.args(text),
};
+ let command = match &step.cwd {
+ Some(cwd) => command.current_dir(cwd),
+ None => command,
+ };
let output = command.run();
- output.assert_matches_text(expected_output);
+ if step.output.ends_with(".out") {
+ let test_output_path = cwd.join(&step.output);
+ output.assert_matches_file(test_output_path);
+ } else {
+ output.assert_matches_text(&step.output);
+ }
output.assert_exit_code(step.exit_code);
}
}
@@ -194,6 +197,7 @@ struct StepMetaData {
#[serde(default)]
pub clean_deno_dir: bool,
pub args: VecOrString,
+ pub cwd: Option<String>,
#[serde(default)]
pub envs: HashMap<String, String>,
pub output: String,
@@ -299,12 +303,23 @@ fn collect_tests() -> Vec<TestCategory> {
}
.with_context(|| format!("Failed to parse {}", metadata_path))
.unwrap();
+
+ let test_name =
+ format!("{}::{}", category.name, entry.file_name().to_string_lossy());
+
+ // only support characters that work with filtering with `cargo test`
+ if !test_name
+ .chars()
+ .all(|c| c.is_alphanumeric() || matches!(c, '_' | ':'))
+ {
+ panic!(
+ "Invalid test name (only supports alphanumeric and underscore): {}",
+ test_name
+ );
+ }
+
category.tests.push(Test {
- name: format!(
- "{}::{}",
- category.name,
- entry.file_name().to_string_lossy()
- ),
+ name: test_name,
cwd: test_dir,
metadata,
});