Skip to content

Commit

Permalink
Merge branch 'main' into mischnic/js-lint-lower-severity
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic authored Jul 26, 2024
2 parents 3f5383e + 2422858 commit 69dde72
Show file tree
Hide file tree
Showing 44 changed files with 572 additions and 325 deletions.
4 changes: 2 additions & 2 deletions .github/turbo-orchestrator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ labeler:
isPRAuthorMatch: "^(arlyon|bgw|ForsakenHarmony|kdy1|LichuAcu|mischnic|padmaia|sokra|wbinnssmith)$"
- label: "created-by: turborepo"
when:
isPRAuthorMatch: "^(anthonyshew|dimitropoulos|tknickman|mehulkar|chris-olszewski|NicholasLYang|Zertsov|paulogdm|codybrouwers)$"
isPRAuthorMatch: "^(anthonyshew|dimitropoulos|tknickman|chris-olszewski|NicholasLYang|Zertsov|paulogdm|codybrouwers)$"

# needs: triage when not any of the turbopack or turborepo team
- label: "needs: triage"
when:
isNotPRAuthorMatch: "^(arlyon|bgw|ForsakenHarmony|kdy1|LichuAcu|mischnic|padmaia|sokra|wbinnssmith|anthonyshew|dimitropoulos|tknickman|mehulkar|chris-olszewski|NicholasLYang|Zertsov|paulogdm|codybrouwers)$"
isNotPRAuthorMatch: "^(arlyon|bgw|ForsakenHarmony|kdy1|LichuAcu|mischnic|padmaia|sokra|wbinnssmith|anthonyshew|dimitropoulos|tknickman|chris-olszewski|NicholasLYang|Zertsov|paulogdm|codybrouwers)$"

# areas
- label: "area: ci"
Expand Down
7 changes: 1 addition & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions crates/turbo-tasks-fetch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ workspace = true

[dependencies]
anyhow = { workspace = true }
lazy_static = { workspace = true }
reqwest = { workspace = true }
serde = { workspace = true }
tokio = { workspace = true }
Expand All @@ -31,7 +30,6 @@ turbopack-core = { workspace = true }
[dev-dependencies]
httpmock = { workspace = true }
tokio = { workspace = true, features = ["full"] }
turbo-tasks-memory = { workspace = true }
turbo-tasks-testing = { workspace = true }

[build-dependencies]
Expand Down
142 changes: 79 additions & 63 deletions crates/turbo-tasks-fetch/tests/fetch.rs
Original file line number Diff line number Diff line change
@@ -1,143 +1,159 @@
#![cfg(test)]

use turbo_tasks::Vc;
use turbo_tasks_fetch::{fetch, register, FetchErrorKind};
use turbo_tasks_fetch::{fetch, FetchErrorKind};
use turbo_tasks_fs::{DiskFileSystem, FileSystem, FileSystemPath};
use turbo_tasks_testing::{register, run};
use turbo_tasks_testing::{register, run, Registration};
use turbopack_core::issue::{Issue, IssueSeverity, StyledString};

register!();
static REGISTRATION: Registration = register!(turbo_tasks_fetch::register);

#[tokio::test]
async fn basic_get() {
run! {
register();

run(&REGISTRATION, async {
let server = httpmock::MockServer::start();
let resource_mock = server.mock(|when, then| {
when.path("/foo.woff");
then.status(200)
.body("responsebody");
then.status(200).body("responsebody");
});


let result = &*fetch(Vc::cell(server.url("/foo.woff").into()), Vc::cell(None), Vc::cell(None)).await?;
let result = &*fetch(
Vc::cell(server.url("/foo.woff").into()),
Vc::cell(None),
Vc::cell(None),
)
.await
.unwrap();
resource_mock.assert();

match result {
Err(_) => panic!(),
Ok(response) => {
let response = response.await?;
let response = response.await.unwrap();
assert_eq!(response.status, 200);
assert_eq!(*response.body.to_string().await?, "responsebody");
assert_eq!(*response.body.to_string().await.unwrap(), "responsebody");
}
}
}
})
.await
}

#[tokio::test]
async fn sends_user_agent() {
run! {
register();

run(&REGISTRATION, async {
let server = httpmock::MockServer::start();
let resource_mock = server.mock(|when, then| {
when.path("/foo.woff").header("User-Agent", "foo");
then.status(200)
.body("responsebody");
then.status(200).body("responsebody");
});

let result = &*fetch(Vc::cell(server.url("/foo.woff").into()), Vc::cell(Some("foo".into())), Vc::cell(None)).await?;
let result = &*fetch(
Vc::cell(server.url("/foo.woff").into()),
Vc::cell(Some("foo".into())),
Vc::cell(None),
)
.await
.unwrap();
resource_mock.assert();

let Ok(response) = result else {
panic!()
};
let Ok(response) = result else { panic!() };

let response = response.await?;
let response = response.await.unwrap();
assert_eq!(response.status, 200);
assert_eq!(*response.body.to_string().await?, "responsebody");
}
assert_eq!(*response.body.to_string().await.unwrap(), "responsebody");
})
.await
}

// This is temporary behavior.
// TODO: Implement invalidation that respects Cache-Control headers.
#[tokio::test]
async fn invalidation_does_not_invalidate() {
run! {
register();

run(&REGISTRATION, async {
let server = httpmock::MockServer::start();
let resource_mock = server.mock(|when, then| {
when.path("/foo.woff").header("User-Agent", "foo");
then.status(200)
.body("responsebody");
then.status(200).body("responsebody");
});

let url = Vc::cell(server.url("/foo.woff").into());
let user_agent = Vc::cell(Some("foo".into()));
let proxy = Vc::cell(None);
let result = &*fetch(url, user_agent, proxy).await?;
let result = &*fetch(url, user_agent, proxy).await.unwrap();
resource_mock.assert();

let Ok(response_vc) = result else {
panic!()
};
let response = response_vc.await?;
let Ok(response_vc) = result else { panic!() };
let response = response_vc.await.unwrap();
assert_eq!(response.status, 200);
assert_eq!(*response.body.to_string().await?, "responsebody");
assert_eq!(*response.body.to_string().await.unwrap(), "responsebody");

let second_result = &*fetch(url, user_agent, proxy).await?;
let second_result = &*fetch(url, user_agent, proxy).await.unwrap();
let Ok(second_response_vc) = second_result else {
panic!()
};
let second_response = second_response_vc.await?;
let second_response = second_response_vc.await.unwrap();

// Assert that a second request is never sent -- the result is cached via turbo tasks
// Assert that a second request is never sent -- the result is cached via turbo
// tasks
resource_mock.assert_hits(1);
assert_eq!(response, second_response);
}
})
.await
}

#[tokio::test]
async fn errors_on_failed_connection() {
run! {
register();

run(&REGISTRATION, async {
let url = "https://doesnotexist/foo.woff";
let result = &*fetch(Vc::cell(url.into()), Vc::cell(None), Vc::cell(None)).await?;
let result = &*fetch(Vc::cell(url.into()), Vc::cell(None), Vc::cell(None)).await.unwrap();
let Err(err_vc) = result else {
panic!()
};
let err = &*err_vc.await?;
assert_eq!(*err.kind.await?, FetchErrorKind::Connect);
assert_eq!(*err.url.await?, url);
let err = &*err_vc.await.unwrap();
assert_eq!(*err.kind.await.unwrap(), FetchErrorKind::Connect);
assert_eq!(*err.url.await.unwrap(), url);

let issue = err_vc.to_issue(IssueSeverity::Error.into(), get_issue_context());
assert_eq!(*issue.severity().await?, IssueSeverity::Error);
assert_eq!(*issue.description().await?.unwrap().await?, StyledString::Text("There was an issue establishing a connection while requesting https://doesnotexist/foo.woff.".into()));
}
assert_eq!(*issue.severity().await.unwrap(), IssueSeverity::Error);
assert_eq!(*issue.description().await.unwrap().unwrap().await.unwrap(), StyledString::Text("There was an issue establishing a connection while requesting https://doesnotexist/foo.woff.".into()));
})
.await
}

#[tokio::test]
async fn errors_on_404() {
run! {
register();

run(&REGISTRATION, async {
let server = httpmock::MockServer::start();
let resource_url = server.url("/");
let result = &*fetch(Vc::cell(resource_url.clone().into()), Vc::cell(None), Vc::cell(None)).await?;
let Err(err_vc) = result else {
panic!()
};
let err = &*err_vc.await?;
assert!(matches!(*err.kind.await?, FetchErrorKind::Status(404)));
assert_eq!(*err.url.await?, resource_url);
let result = &*fetch(
Vc::cell(resource_url.clone().into()),
Vc::cell(None),
Vc::cell(None),
)
.await
.unwrap();
let Err(err_vc) = result else { panic!() };
let err = &*err_vc.await.unwrap();
assert!(matches!(
*err.kind.await.unwrap(),
FetchErrorKind::Status(404)
));
assert_eq!(*err.url.await.unwrap(), resource_url);

let issue = err_vc.to_issue(IssueSeverity::Error.into(), get_issue_context());
assert_eq!(*issue.severity().await?, IssueSeverity::Error);
assert_eq!(*issue.description().await?.unwrap().await?, StyledString::Text(format!("Received response with status 404 when requesting {}", &resource_url).into()));
}
assert_eq!(*issue.severity().await.unwrap(), IssueSeverity::Error);
assert_eq!(
*issue.description().await.unwrap().unwrap().await.unwrap(),
StyledString::Text(
format!(
"Received response with status 404 when requesting {}",
&resource_url
)
.into()
)
);
})
.await
}

fn get_issue_context() -> Vc<FileSystemPath> {
Expand Down
5 changes: 1 addition & 4 deletions crates/turbo-tasks-macros-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ edition = "2021"
anyhow = { workspace = true }
serde = { workspace = true }
tokio = { workspace = true }
trybuild = { version = "1.0.97" }
turbo-tasks = { workspace = true }
turbo-tasks-memory = { workspace = true }
turbo-tasks-testing = { workspace = true }
# TODO: turbo-tasks-testing uses a macro that requires us to depend on lazy-static.
lazy_static = { workspace = true }
trybuild = { version = "1.0.97" }

[build-dependencies]
turbo-tasks-build = { workspace = true }
16 changes: 10 additions & 6 deletions crates/turbo-tasks-macros-tests/tests/task_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
//! macro and the `#[turbo_tasks::function]` macro.

use serde::{Deserialize, Serialize};
use turbo_tasks::{Completion, TaskInput, Vc};
use turbo_tasks_testing::{register, run};
use turbo_tasks::{Completion, ReadRef, TaskInput, Vc};
use turbo_tasks_testing::{register, run, Registration};

register!();
static REGISTRATION: Registration = register!();

#[derive(Clone, TaskInput, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
struct OneUnnamedField(u32);
Expand All @@ -19,7 +19,11 @@ async fn one_unnamed_field(input: OneUnnamedField) -> Vc<Completion> {

#[tokio::test]
async fn tests() {
run! {
one_unnamed_field(OneUnnamedField(42)).await?;
}
run(&REGISTRATION, async {
assert!(ReadRef::ptr_eq(
&one_unnamed_field(OneUnnamedField(42)).await.unwrap(),
&Completion::immutable().await.unwrap(),
))
})
.await
}
15 changes: 10 additions & 5 deletions crates/turbo-tasks-macros-tests/tests/value_debug.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use turbo_tasks::debug::ValueDebugFormat;
use turbo_tasks_testing::{register, run};
use turbo_tasks_testing::{register, run, Registration};

register!();
static REGISTRATION: Registration = register!();

#[tokio::test]
async fn ignored_indexes() {
Expand All @@ -17,11 +17,16 @@ async fn ignored_indexes() {
i32,
);

run! {
run(&REGISTRATION, async {
let input = IgnoredIndexes(-1, 2, -3);
let debug = input.value_debug_format(usize::MAX).try_to_string().await?;
let debug = input
.value_debug_format(usize::MAX)
.try_to_string()
.await
.unwrap();
assert!(!debug.contains("-1"));
assert!(debug.contains('2'));
assert!(!debug.contains("-3"));
}
})
.await;
}
1 change: 0 additions & 1 deletion crates/turbo-tasks-memory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ turbo-tasks-malloc = { workspace = true, default-features = false }

[dev-dependencies]
criterion = { workspace = true, features = ["async_tokio"] }
lazy_static = { workspace = true }
loom = "0.7.2"
rand = { workspace = true, features = ["small_rng"] }
regex = { workspace = true }
Expand Down
Loading

0 comments on commit 69dde72

Please sign in to comment.