Skip to content

Commit 83074ca

Browse files
mmastraclittledivy
authored andcommittedFeb 15, 2024
refactor: split integration tests from CLI (part 1) (#22308)
This PR separates integration tests from CLI tests into a new project named `cli_tests`. This is a prerequisite for an integration test runner that can work with either the CLI binary in the current project, or one that is built ahead of time. ## Background Rust does not have the concept of artifact dependencies yet (rust-lang/cargo#9096). Because of this, the only way we can ensure a binary is built before running associated tests is by hanging tests off the crate with the binary itself. Unfortunately this means that to run those tests, you _must_ build the binary and in the case of the deno executable that might be a 10 minute wait in release mode. ## Implementation To allow for tests to run with and without the requirement that the binary is up-to-date, we split the integration tests into a project of their own. As these tests would not require the binary to build itself before being run as-is, we add a stub integration `[[test]]` target in the `cli` project that invokes these tests using `cargo test`. The stub test runner we add has `harness = false` so that we can get access to a `main` function. This `main` function's sole job is to `execvp` the command `cargo test -p deno_cli`, effectively "calling" another cargo target. This ensures that the deno executable is always correctly rebuilt before running the stub test runner from `cli`, and gets us closer to be able to run the entire integration test suite on arbitrary deno executables (and therefore split the build into multiple phases). The new `cli_tests` project lives within `cli` to avoid a large PR. In later PRs, the test data will be split from the `cli` project. As there are a few thousand files, it'll be better to do this as a completely separate PR to avoid noise.
1 parent bb8114f commit 83074ca

19 files changed

+228
-31
lines changed
 

‎.github/workflows/ci.generate.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ const ci = {
794794
// Run unit then integration tests. Skip doc tests here
795795
// since they are sometimes very slow on Mac.
796796
"cargo test --locked --lib",
797-
"cargo test --locked --test '*'",
797+
"cargo test --locked --tests",
798798
].join("\n"),
799799
env: { CARGO_PROFILE_DEV_DEBUG: 0 },
800800
},

‎.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ jobs:
482482
(startsWith(github.ref, 'refs/tags/') || matrix.os != 'linux'))
483483
run: |-
484484
cargo test --locked --lib
485-
cargo test --locked --test '*'
485+
cargo test --locked --tests
486486
env:
487487
CARGO_PROFILE_DEV_DEBUG: 0
488488
- name: Test (release)

‎Cargo.lock

+65-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ members = [
66
"bench_util",
77
"cli",
88
"cli/napi/sym",
9+
"cli/tests",
910
"ext/broadcast_channel",
1011
"ext/cache",
1112
"ext/canvas",

‎cli/Cargo.toml

+6-11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
name = "deno"
55
version = "1.40.4"
66
authors.workspace = true
7+
autotests = false
78
default-run = "deno"
89
edition.workspace = true
910
exclude = ["tests/testdata/npm/registry/*"]
@@ -16,6 +17,11 @@ name = "deno"
1617
path = "main.rs"
1718
doc = false
1819

20+
[[test]]
21+
name = "integration"
22+
path = "tests/integration_tests_runner.rs"
23+
harness = false
24+
1925
[[bench]]
2026
name = "deno_bench"
2127
harness = false
@@ -149,19 +155,8 @@ nix.workspace = true
149155

150156
[dev-dependencies]
151157
deno_bench_util.workspace = true
152-
deno_core = { workspace = true, features = ["include_js_files_for_snapshotting", "unsafe_use_unprotected_platform"] }
153-
fastwebsockets = { workspace = true, features = ["upgrade", "unstable-split"] }
154-
flaky_test = "=0.1.0"
155-
http.workspace = true
156-
http-body-util.workspace = true
157-
hyper.workspace = true
158-
hyper-util.workspace = true
159-
once_cell.workspace = true
160-
os_pipe.workspace = true
161158
pretty_assertions.workspace = true
162159
test_util.workspace = true
163-
trust-dns-client = "=0.22.0"
164-
trust-dns-server = "=0.22.1"
165160

166161
[package.metadata.winres]
167162
# This section defines the metadata that appears in the deno.exe PE header.

‎cli/tests/Cargo.toml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2+
3+
[package]
4+
name = "cli_tests"
5+
version = "0.0.0"
6+
authors.workspace = true
7+
autotests = false
8+
edition.workspace = true
9+
license.workspace = true
10+
repository.workspace = true
11+
12+
[lib]
13+
path = "lib.rs"
14+
15+
[features]
16+
run = []
17+
18+
[[test]]
19+
name = "integration_tests"
20+
path = "integration_tests.rs"
21+
required-features = ["run"]
22+
23+
[dev-dependencies]
24+
bytes.workspace = true
25+
deno_ast.workspace = true
26+
deno_bench_util.workspace = true
27+
deno_core = { workspace = true, features = ["include_js_files_for_snapshotting", "unsafe_use_unprotected_platform"] }
28+
deno_fetch.workspace = true
29+
deno_lockfile.workspace = true
30+
deno_tls.workspace = true
31+
fastwebsockets = { workspace = true, features = ["upgrade", "unstable-split"] }
32+
flaky_test = "=0.1.0"
33+
http.workspace = true
34+
http-body-util.workspace = true
35+
hyper.workspace = true
36+
hyper-util.workspace = true
37+
once_cell.workspace = true
38+
os_pipe.workspace = true
39+
pretty_assertions.workspace = true
40+
serde.workspace = true
41+
serde_repr.workspace = true
42+
test_util.workspace = true
43+
tokio.workspace = true
44+
tokio-util.workspace = true
45+
tower-lsp.workspace = true
46+
trust-dns-client = "=0.22.0"
47+
trust-dns-server = "=0.22.1"
48+
url.workspace = true
49+
50+
[target.'cfg(unix)'.dev-dependencies]
51+
nix.workspace = true

‎cli/tests/integration/cert_tests.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
22

3-
use deno_runtime::deno_net::ops_tls::TlsStream;
4-
use deno_runtime::deno_tls::rustls;
5-
use deno_runtime::deno_tls::rustls_pemfile;
6-
use lsp_types::Url;
3+
use deno_tls::rustls;
4+
use deno_tls::rustls_pemfile;
5+
use deno_tls::rustls_tokio_stream::TlsStream;
76
use std::io::BufReader;
87
use std::io::Cursor;
98
use std::io::Read;
109
use std::sync::Arc;
1110
use test_util as util;
11+
use url::Url;
1212
use util::testdata_path;
1313
use util::TestContext;
1414

‎cli/tests/integration/inspector_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use deno_core::error::AnyError;
66
use deno_core::serde_json;
77
use deno_core::serde_json::json;
88
use deno_core::url;
9-
use deno_runtime::deno_fetch::reqwest;
9+
use deno_fetch::reqwest;
1010
use fastwebsockets::FragmentCollector;
1111
use fastwebsockets::Frame;
1212
use fastwebsockets::WebSocket;

‎cli/tests/integration/js_unit_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use test_util as util;
77

88
util::unit_test_factory!(
99
js_unit_test,
10-
"tests/unit",
10+
"../tests/unit",
1111
"*.ts",
1212
[
1313
abort_controller_test,

‎cli/tests/integration/node_unit_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use util::env_vars_for_npm_tests;
88

99
util::unit_test_factory!(
1010
node_unit_test,
11-
"tests/unit_node",
11+
"../tests/unit_node",
1212
"**/*_test.ts",
1313
[
1414
_fs_access_test = _fs / _fs_access_test,

‎cli/tests/integration/run_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use bytes::Bytes;
44
use deno_core::serde_json::json;
55
use deno_core::url;
6-
use deno_runtime::deno_fetch::reqwest;
6+
use deno_fetch::reqwest;
77
use pretty_assertions::assert_eq;
88
use std::io::Read;
99
use std::io::Write;

‎cli/tests/integration_tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
// The tests exist in a sub folder instead of as separate files in
44
// this directory so that cargo doesn't compile each file as a new crate.
55

6+
#[cfg(test)]
67
mod integration;

‎cli/tests/integration_tests_runner.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2+
pub fn main() {
3+
let mut args = vec!["cargo", "test", "-p", "cli_tests", "--features", "run"];
4+
5+
if !cfg!(debug_assertions) {
6+
args.push("--release");
7+
}
8+
9+
args.push("--");
10+
11+
// If any args were passed to this process, pass them through to the child
12+
let orig_args = std::env::args().skip(1).collect::<Vec<_>>();
13+
let orig_args: Vec<&str> =
14+
orig_args.iter().map(|x| x.as_ref()).collect::<Vec<_>>();
15+
args.extend(orig_args);
16+
17+
test_util::spawn::exec_replace("cargo", &args).unwrap();
18+
}

‎cli/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

‎ext/tls/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ deno_native_certs = "0.2.0"
1919
once_cell.workspace = true
2020
rustls = { workspace = true, features = ["dangerous_configuration"] }
2121
rustls-pemfile.workspace = true
22+
rustls-tokio-stream.workspace = true
2223
rustls-webpki.workspace = true
2324
serde.workspace = true
2425
webpki-roots.workspace = true

‎ext/tls/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
pub use deno_native_certs;
44
pub use rustls;
55
pub use rustls_pemfile;
6+
pub use rustls_tokio_stream;
67
pub use webpki;
78
pub use webpki_roots;
89

‎test_util/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ tempfile.workspace = true
5353
termcolor.workspace = true
5454
tokio.workspace = true
5555
url.workspace = true
56+
win32job = "2"
5657

5758
[target.'cfg(windows)'.dependencies]
5859
winapi = { workspace = true, features = ["consoleapi", "synchapi", "handleapi", "namedpipeapi", "winbase", "winerror"] }

‎test_util/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub mod lsp;
3232
mod npm;
3333
pub mod pty;
3434
pub mod servers;
35+
pub mod spawn;
3536

3637
pub use builders::DenoChild;
3738
pub use builders::TestCommandBuilder;

0 commit comments

Comments
 (0)
Please sign in to comment.