summaryrefslogtreecommitdiff
path: root/tests/specs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-04-27 17:11:57 -0400
committerGitHub <noreply@github.com>2024-04-27 21:11:57 +0000
commit651e3e9e6daf3243dd21b7f66ce9738abdc39a37 (patch)
tree0417415c1a5fa79d0ae5d8f0f75561138275e34e /tests/specs
parente0f849289fdb2c2d86f7fb04182c37012ce2bb69 (diff)
fix(compile): certain jsr specifiers sometimes can't load (#23567)
When returning a jsr specifier for resolve it seems like deno core does not work properly and hangs. Closes https://github.com/denoland/deno/issues/23551 Closes https://github.com/denoland/deno/issues/23139
Diffstat (limited to 'tests/specs')
-rw-r--r--tests/specs/README.md1
-rw-r--r--tests/specs/compile/jsr_with_deps/__test__.jsonc22
-rw-r--r--tests/specs/compile/jsr_with_deps/main.out2
-rw-r--r--tests/specs/compile/jsr_with_deps/main.ts8
-rw-r--r--tests/specs/mod.rs25
-rw-r--r--tests/specs/schema.json9
6 files changed, 64 insertions, 3 deletions
diff --git a/tests/specs/README.md b/tests/specs/README.md
index d9c620aa7..55880fe23 100644
--- a/tests/specs/README.md
+++ b/tests/specs/README.md
@@ -78,6 +78,7 @@ a "steps" array.
- `output` - Path to use to assert the output.
- `cleanDenoDir` (boolean) - Whether to empty the deno_dir before running the
step.
+- `if` (`"windows"`, `"linux"`, `"mac"`, `"unix"`) - Whether to run this step.
- `exitCode` (number) - Expected exit code.
### Auto-complete
diff --git a/tests/specs/compile/jsr_with_deps/__test__.jsonc b/tests/specs/compile/jsr_with_deps/__test__.jsonc
new file mode 100644
index 000000000..be2bbd1e4
--- /dev/null
+++ b/tests/specs/compile/jsr_with_deps/__test__.jsonc
@@ -0,0 +1,22 @@
+{
+ "tempDir": true,
+ "steps": [{
+ "if": "unix",
+ "args": "compile --output main main.ts",
+ "output": "[WILDCARD]"
+ }, {
+ "if": "unix",
+ "commandName": "./main",
+ "args": [],
+ "output": "main.out"
+ }, {
+ "if": "windows",
+ "args": "compile --output main.exe main.ts",
+ "output": "[WILDCARD]"
+ }, {
+ "if": "windows",
+ "commandName": "./main.exe",
+ "args": [],
+ "output": "main.out"
+ }]
+}
diff --git a/tests/specs/compile/jsr_with_deps/main.out b/tests/specs/compile/jsr_with_deps/main.out
new file mode 100644
index 000000000..6340327e0
--- /dev/null
+++ b/tests/specs/compile/jsr_with_deps/main.out
@@ -0,0 +1,2 @@
+[Function: join]
+http://[WILDLINE]/@std/url/0.220.1/join.ts
diff --git a/tests/specs/compile/jsr_with_deps/main.ts b/tests/specs/compile/jsr_with_deps/main.ts
new file mode 100644
index 000000000..44a7dc08c
--- /dev/null
+++ b/tests/specs/compile/jsr_with_deps/main.ts
@@ -0,0 +1,8 @@
+// this was previously hanging in deno compile and wouldn't work
+import { join } from "jsr:@std/url@0.220/join";
+import "jsr:@std/url@0.220/normalize";
+
+console.log(join);
+
+// ensure import.meta.resolve works in compile for jsr specifiers
+console.log(import.meta.resolve("jsr:@std/url@0.220/join"));
diff --git a/tests/specs/mod.rs b/tests/specs/mod.rs
index 2040eea62..16a9e6f05 100644
--- a/tests/specs/mod.rs
+++ b/tests/specs/mod.rs
@@ -73,6 +73,8 @@ struct StepMetaData {
pub clean_deno_dir: bool,
pub args: VecOrString,
pub cwd: Option<String>,
+ #[serde(rename = "if")]
+ pub if_cond: Option<String>,
pub command_name: Option<String>,
#[serde(default)]
pub envs: HashMap<String, String>,
@@ -152,8 +154,11 @@ fn run_test(test: &CollectedTest, diagnostic_logger: Rc<RefCell<Vec<u8>>>) {
// todo(dsherret): add bases in the future as needed
Some(base) => panic!("Unknown test base: {}", base),
None => {
- // by default add npm and jsr env vars
- builder = builder.add_jsr_env_vars().add_npm_env_vars();
+ // by default add all these
+ builder = builder
+ .add_jsr_env_vars()
+ .add_npm_env_vars()
+ .add_compile_env_vars();
}
}
@@ -167,7 +172,7 @@ fn run_test(test: &CollectedTest, diagnostic_logger: Rc<RefCell<Vec<u8>>>) {
cwd.copy_to_recursive_with_exclusions(temp_dir, &assertion_paths);
}
- for step in &metadata.steps {
+ for step in metadata.steps.iter().filter(|s| should_run_step(s)) {
if step.clean_deno_dir {
context.deno_dir().path().remove_dir_all();
}
@@ -198,6 +203,20 @@ fn run_test(test: &CollectedTest, diagnostic_logger: Rc<RefCell<Vec<u8>>>) {
}
}
+fn should_run_step(step: &StepMetaData) -> bool {
+ if let Some(cond) = &step.if_cond {
+ match cond.as_str() {
+ "windows" => cfg!(windows),
+ "unix" => cfg!(unix),
+ "mac" => cfg!(target_os = "macos"),
+ "linux" => cfg!(target_os = "linux"),
+ value => panic!("Unknown if condition: {}", value),
+ }
+ } else {
+ true
+ }
+}
+
fn resolve_test_and_assertion_files(
dir: &PathRef,
metadata: &MultiTestMetaData,
diff --git a/tests/specs/schema.json b/tests/specs/schema.json
index 8b21ab32c..b3a30f936 100644
--- a/tests/specs/schema.json
+++ b/tests/specs/schema.json
@@ -36,6 +36,15 @@
"type": "string"
}
},
+ "if": {
+ "type": "string",
+ "examples": [
+ "mac",
+ "linux",
+ "windows",
+ "unix"
+ ]
+ },
"output": {
"type": "string"
},