Skip to content

Commit

Permalink
chore: move more tests away from itest (#22909)
Browse files Browse the repository at this point in the history
Part of #22907
  • Loading branch information
dsherret authored Mar 15, 2024
1 parent 392579b commit e40f9a5
Show file tree
Hide file tree
Showing 45 changed files with 112 additions and 178 deletions.
7 changes: 0 additions & 7 deletions tests/integration/coverage_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use deno_core::serde_json;
use std::fs;
use test_util as util;
use test_util::itest;
use test_util::TempDir;
use util::assert_starts_with;
use util::env_vars_for_npm_tests;
Expand Down Expand Up @@ -631,9 +630,3 @@ File | Branch % | Line % |
",
);
}

itest!(no_files_found {
args: "coverage doesnt_exist.js",
exit_code: 1,
output: "coverage/doesnt_exist.out",
});
42 changes: 0 additions & 42 deletions tests/integration/flags_tests.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

use test_util as util;
use test_util::itest;
use util::assert_contains;

#[test]
fn help_flag() {
let status = util::deno_cmd()
.current_dir(util::testdata_path())
.arg("--help")
.spawn()
.unwrap()
.wait()
.unwrap();
assert!(status.success());
}

#[test]
fn help_output() {
let output = util::deno_cmd()
Expand Down Expand Up @@ -56,32 +43,3 @@ fn help_output() {
assert_contains!(stdout, description);
}
}

#[test]
fn version_short_flag() {
let status = util::deno_cmd()
.current_dir(util::testdata_path())
.arg("-V")
.spawn()
.unwrap()
.wait()
.unwrap();
assert!(status.success());
}

#[test]
fn version_long_flag() {
let status = util::deno_cmd()
.current_dir(util::testdata_path())
.arg("--version")
.spawn()
.unwrap()
.wait()
.unwrap();
assert!(status.success());
}

itest!(types {
args: "types",
output: "types/types.out",
});
100 changes: 0 additions & 100 deletions tests/integration/jsr_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,87 +4,11 @@ use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_lockfile::Lockfile;
use test_util as util;
use test_util::itest;
use url::Url;
use util::assert_contains;
use util::assert_not_contains;
use util::env_vars_for_jsr_npm_tests;
use util::env_vars_for_jsr_tests;
use util::TestContextBuilder;

itest!(no_module_graph_run {
args: "run jsr/no_module_graph/main.ts",
output: "jsr/no_module_graph/main.out",
envs: env_vars_for_jsr_tests(),
http_server: true,
});

itest!(no_module_graph_info {
args: "info jsr/no_module_graph/main.ts",
output: "jsr/no_module_graph/main_info.out",
envs: env_vars_for_jsr_tests(),
http_server: true,
});

itest!(same_package_multiple_versions {
args: "run --quiet jsr/no_module_graph/multiple.ts",
output: "jsr/no_module_graph/multiple.out",
envs: env_vars_for_jsr_tests(),
http_server: true,
});

itest!(module_graph_run {
args: "run jsr/module_graph/main.ts",
output: "jsr/module_graph/main.out",
envs: env_vars_for_jsr_tests(),
http_server: true,
});

itest!(module_graph_info {
args: "info jsr/module_graph/main.ts",
output: "jsr/module_graph/main_info.out",
envs: env_vars_for_jsr_tests(),
http_server: true,
});

itest!(deps_run {
args: "run jsr/deps/main.ts",
output: "jsr/deps/main.out",
envs: env_vars_for_jsr_tests(),
http_server: true,
});

itest!(deps_info {
args: "info jsr/deps/main.ts",
output: "jsr/deps/main_info.out",
envs: env_vars_for_jsr_tests(),
http_server: true,
});

itest!(import_https_url_analyzable {
args: "run -A jsr/import_https_url/analyzable.ts",
output: "jsr/import_https_url/analyzable.out",
envs: env_vars_for_jsr_tests(),
http_server: true,
exit_code: 1,
});

itest!(import_https_url_unanalyzable {
args: "run -A jsr/import_https_url/unanalyzable.ts",
output: "jsr/import_https_url/unanalyzable.out",
envs: env_vars_for_jsr_tests(),
http_server: true,
exit_code: 1,
});

itest!(subset_type_graph {
args: "check --all jsr/subset_type_graph/main.ts",
output: "jsr/subset_type_graph/main.check.out",
envs: env_vars_for_jsr_tests(),
http_server: true,
exit_code: 1,
});

#[test]
fn fast_check_cache() {
let test_context = TestContextBuilder::for_jsr().use_temp_cwd().build();
Expand Down Expand Up @@ -197,14 +121,6 @@ export function asdf(a: number) { let err: number = ''; return Math.random(); }
);
}

itest!(version_not_found {
args: "run jsr/version_not_found/main.ts",
output: "jsr/version_not_found/main.out",
envs: env_vars_for_jsr_tests(),
http_server: true,
exit_code: 1,
});

#[test]
fn specifiers_in_lockfile() {
let test_context = TestContextBuilder::for_jsr().use_temp_cwd().build();
Expand Down Expand Up @@ -478,19 +394,3 @@ fn set_lockfile_pkg_integrity(
.unwrap()
.integrity = integrity.to_string();
}

itest!(jsx_with_no_pragmas {
args: "run jsr/jsx_with_no_pragmas/main.ts",
output: "jsr/jsx_with_no_pragmas/main.out",
envs: env_vars_for_jsr_npm_tests(),
http_server: true,
exit_code: 1,
});

itest!(jsx_with_pragmas {
args: "run jsr/jsx_with_pragmas/main.ts",
output: "jsr/jsx_with_pragmas/main.out",
envs: env_vars_for_jsr_npm_tests(),
http_server: true,
exit_code: 0,
});
10 changes: 0 additions & 10 deletions tests/integration/jupyter_tests.rs

This file was deleted.

2 changes: 0 additions & 2 deletions tests/integration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ mod install;
mod js_unit_tests;
#[path = "jsr_tests.rs"]
mod jsr;
#[path = "jupyter_tests.rs"]
mod jupyter;
#[path = "lint_tests.rs"]
mod lint;
#[path = "lsp_tests.rs"]
Expand Down
5 changes: 5 additions & 0 deletions tests/specs/coverage/no_files_found/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"args": "coverage does_not_exit.js",
"output": "does_not_exist.out",
"exitCode": 1
}
File renamed without changes.
4 changes: 4 additions & 0 deletions tests/specs/flags/help_flag/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"args": "--help",
"output": "[WILDCARD]"
}
4 changes: 4 additions & 0 deletions tests/specs/flags/types/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"args": "types",
"output": "types.out"
}
File renamed without changes.
9 changes: 9 additions & 0 deletions tests/specs/flags/version_flag/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"steps": [{
"args": "-V",
"output": "[WILDCARD]"
}, {
"args": "--version",
"output": "[WILDCARD]"
}]
}
11 changes: 11 additions & 0 deletions tests/specs/jsr/deps/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"base": "jsr",
"steps": [{
"args": "run main.ts",
"output": "main.out"
}, {
"cleanDenoDir": true,
"args": "info main.ts",
"output": "main_info.out"
}]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions tests/specs/jsr/import_https_url/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"base": "jsr",
"steps": [{
"args": "run -A analyzable.ts",
"output": "analyzable.out",
"exitCode": 1
}, {
"cleanDenoDir": true,
"args": "run -A nonanalyzable.ts",
"output": "nonanalyzable.out",
"exitCode": 1
}]
}
6 changes: 6 additions & 0 deletions tests/specs/jsr/jsx_with_no_pragmas/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"base": "jsr",
"args": "run main.ts",
"output": "main.out",
"exitCode": 1
}
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/specs/jsr/jsx_with_pragmas/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"base": "jsr",
"args": "run main.ts",
"output": "main.out"
}
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions tests/specs/jsr/module_graph/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"base": "jsr",
"steps": [{
"args": "run main.ts",
"output": "main.out"
}, {
"cleanDenoDir": true,
"args": "info main.ts",
"output": "main_info.out"
}]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions tests/specs/jsr/no_module_graph/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"base": "jsr",
"steps": [{
"args": "run main.ts",
"output": "main.out"
}, {
"cleanDenoDir": true,
"args": "info main.ts",
"output": "main_info.out"
}, {
"args": "run --quiet multiple.ts",
"output": "multiple.out"
}]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions tests/specs/jsr/subset_type_graph/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"base": "jsr",
"args": "check --all main.ts",
"output": "main.check.out",
"exitCode": 1
}
File renamed without changes.
6 changes: 6 additions & 0 deletions tests/specs/jsr/version_not_found/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"base": "jsr",
"args": "run -A main.ts",
"output": "main.out",
"exitCode": 1
}
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions tests/specs/jupyter/install_command_not_exists/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"args": "jupyter --install",
"output": "install_command_not_exists.out",
"envs": {
"PATH": ""
},
"exitCode": 1
}
27 changes: 10 additions & 17 deletions tests/specs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

use std::cell::RefCell;
use std::collections::HashMap;
use std::collections::HashSet;
use std::panic::AssertUnwindSafe;
use std::rc::Rc;
Expand Down Expand Up @@ -127,15 +128,13 @@ fn run_test(test: &Test, diagnostic_logger: Rc<RefCell<Vec<u8>>>) {
context.deno_dir().path().remove_dir_all();
}

let test_output_path = cwd.join(&step.output);
if !test_output_path.to_string_lossy().ends_with(".out") {
panic!(
"Use the .out extension for output files (invalid: {})",
test_output_path
);
}
let expected_output = test_output_path.read_to_string();
let command = context.new_command();
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),
Expand Down Expand Up @@ -195,6 +194,8 @@ struct StepMetaData {
#[serde(default)]
pub clean_deno_dir: bool,
pub args: VecOrString,
#[serde(default)]
pub envs: HashMap<String, String>,
pub output: String,
#[serde(default)]
pub exit_code: i32,
Expand Down Expand Up @@ -283,14 +284,6 @@ fn collect_tests() -> Vec<TestCategory> {

let test_dir = PathRef::new(entry.path());
let metadata_path = test_dir.join("__test__.jsonc");
if !metadata_path.is_file() {
let json_path = test_dir.join("__test__.json");
if json_path.is_file() {
// automatically rename to jsonc
json_path.rename(&metadata_path);
}
}

let metadata_value = metadata_path.read_jsonc_value();
// checking for "steps" leads to a more targeted error message
// instead of when deserializing an untagged enum
Expand Down

0 comments on commit e40f9a5

Please sign in to comment.