Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshot issues in next-dev-tests #3774

Merged
merged 36 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a24c455
Snapshot issues in next-dev-tests
wbinnssmith Feb 9, 2023
b193c59
fixup! Snapshot issues in next-dev-tests
wbinnssmith Feb 13, 2023
9d4be12
update tests
wbinnssmith Feb 13, 2023
9defde4
update snapshots
wbinnssmith Feb 13, 2023
f9ff34a
Feedback
wbinnssmith Feb 13, 2023
ded055d
fixup! Feedback
wbinnssmith Feb 13, 2023
bc8845e
Use PlainIssueReadRefs in CapturedIssues
wbinnssmith Feb 14, 2023
1ace275
Revert "Use PlainIssueReadRefs in CapturedIssues"
wbinnssmith Feb 14, 2023
dac3448
Feedback
wbinnssmith Feb 14, 2023
6f18d49
Merge remote-tracking branch 'origin/main' into wbinnssmith/snapshot-…
wbinnssmith Feb 14, 2023
5322d7b
router.ts: throw on unknown data.type
wbinnssmith Feb 14, 2023
837bb81
Merge remote-tracking branch 'origin/main' into wbinnssmith/snapshot-…
wbinnssmith Feb 17, 2023
ab15345
fixup! Snapshot issues in next-dev-tests
wbinnssmith Feb 17, 2023
59e4b3b
Merge remote-tracking branch 'origin/main' into wbinnssmith/snapshot-…
wbinnssmith Feb 21, 2023
1ffcded
fixup! Snapshot issues in next-dev-tests
wbinnssmith Feb 21, 2023
6464ce0
fixup! Snapshot issues in next-dev-tests
wbinnssmith Feb 21, 2023
d1b85ff
fixup! Snapshot issues in next-dev-tests
wbinnssmith Feb 21, 2023
c3832c8
fixup! Snapshot issues in next-dev-tests
wbinnssmith Feb 21, 2023
e8e4523
Merge remote-tracking branch 'origin/main' into wbinnssmith/snapshot-…
wbinnssmith Feb 22, 2023
936f1bc
fixup! Snapshot issues in next-dev-tests
wbinnssmith Feb 22, 2023
d9b348d
fixup! Snapshot issues in next-dev-tests
wbinnssmith Feb 22, 2023
6aae25e
fixup! Snapshot issues in next-dev-tests
wbinnssmith Feb 22, 2023
7a612f9
fixup! Snapshot issues in next-dev-tests
wbinnssmith Feb 22, 2023
0e279f3
fixup! Snapshot issues in next-dev-tests
wbinnssmith Feb 22, 2023
31a6222
Merge remote-tracking branch 'origin/main' into wbinnssmith/snapshot-…
wbinnssmith Feb 22, 2023
c61b73a
fixup! Snapshot issues in next-dev-tests
wbinnssmith Feb 22, 2023
47a1577
fixup! Snapshot issues in next-dev-tests
wbinnssmith Feb 22, 2023
e173b1a
fixup! Snapshot issues in next-dev-tests
wbinnssmith Feb 22, 2023
a7cd685
fixup! Snapshot issues in next-dev-tests
wbinnssmith Feb 22, 2023
84ad1bb
fixup! Snapshot issues in next-dev-tests
wbinnssmith Feb 22, 2023
6df5954
Revert "fixup! Snapshot issues in next-dev-tests"
wbinnssmith Feb 23, 2023
4f909bc
Revert "fixup! Snapshot issues in next-dev-tests"
wbinnssmith Feb 23, 2023
90e070c
Revert "fixup! Snapshot issues in next-dev-tests"
wbinnssmith Feb 23, 2023
8d4ce84
fixup! Snapshot issues in next-dev-tests
wbinnssmith Feb 24, 2023
c91b07c
Merge remote-tracking branch 'origin/main' into wbinnssmith/snapshot-…
wbinnssmith Feb 27, 2023
93e27d5
fixup! Snapshot issues in next-dev-tests
wbinnssmith Feb 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions Cargo.lock

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

10 changes: 9 additions & 1 deletion crates/next-core/src/next_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use turbo_tasks::{
Value,
};
use turbo_tasks_env::EnvMapVc;
use turbo_tasks_fs::json::parse_json_rope_with_source_context;
use turbo_tasks_fs::{json::parse_json_rope_with_source_context, FileSystemPathVc};
use turbopack::{
evaluate_context::node_evaluate_asset_context,
module_options::{WebpackLoadersOptions, WebpackLoadersOptionsVc},
Expand Down Expand Up @@ -600,3 +600,11 @@ pub async fn load_next_config(execution_context: ExecutionContextVc) -> Result<N
}
}
}

#[turbo_tasks::function]
pub async fn has_next_config(context: FileSystemPathVc) -> Result<BoolVc> {
Ok(BoolVc::cell(!matches!(
*find_context_file(context, next_configs()).await?,
FindContextFileResult::NotFound(_)
wbinnssmith marked this conversation as resolved.
Show resolved Hide resolved
)))
}
15 changes: 14 additions & 1 deletion crates/next-core/src/router_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use turbopack_dev_server::source::{
};
use turbopack_node::execution_context::ExecutionContextVc;

use crate::router::{route, RouterRequest, RouterResult};
use crate::{
next_config::has_next_config,
router::{route, RouterRequest, RouterResult},
};

#[turbo_tasks::value(shared)]
pub struct NextRouterContentSource {
Expand Down Expand Up @@ -60,6 +63,16 @@ impl ContentSource for NextRouterContentSource {
) -> Result<ContentSourceResultVc> {
let this = self_vc.await?;

// The next-dev server can currently run against projects as simple as
// `index.js`. If this isn't a Next.js project, don't try to use the Next.js
// router.
let project_root = this.execution_context.await?.project_root;
if !(*has_next_config(project_root).await?) {
return Ok(this
.inner
.get(path, Value::new(ContentSourceData::default())));
}

let ContentSourceData {
method: Some(method),
raw_headers: Some(raw_headers),
Expand Down
2 changes: 1 addition & 1 deletion crates/next-dev-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ lazy_static = "1.4.0"
mime = "0.3.16"
next-core = { path = "../next-core" }
next-dev = { path = "../next-dev" }
once_cell = "1.13.0"
owo-colors = "3"
parking_lot = "0.12.1"
rand = "0.8.5"
Expand All @@ -53,6 +52,7 @@ turbopack-cli-utils = { path = "../turbopack-cli-utils" }
turbopack-core = { path = "../turbopack-core" }
turbopack-dev-server = { path = "../turbopack-dev-server" }
turbopack-node = { path = "../turbopack-node" }
turbopack-test-utils = { path = "../turbopack-test-utils" }
url = "2.2.2"
webbrowser = "0.7.1"

Expand Down
3 changes: 2 additions & 1 deletion crates/next-dev-tests/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use turbo_tasks_build::rerun_if_glob;
use turbo_tasks_build::{generate_register, rerun_if_glob};

fn main() {
generate_register();
// The test/integration crate need to be rebuilt if any test input is changed.
// Unfortunately, we can't have the build.rs file operate differently on
// each file, so the entire next-dev crate needs to be rebuilt.
Expand Down
99 changes: 91 additions & 8 deletions crates/next-dev-tests/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(min_specialization)]
#![cfg(test)]
extern crate test_generator;

Expand Down Expand Up @@ -25,16 +26,29 @@ use chromiumoxide::{
};
use futures::StreamExt;
use lazy_static::lazy_static;
use next_dev::{register, EntryRequest, NextDevServerBuilder};
use next_dev::{EntryRequest, NextDevServerBuilder};
use owo_colors::OwoColorize;
use serde::Deserialize;
use test_generator::test_resources;
use tokio::{net::TcpSocket, task::JoinSet};
use tokio::{
net::TcpSocket,
sync::mpsc::{channel, Sender},
task::JoinSet,
};
use tungstenite::{error::ProtocolError::ResetWithoutClosingHandshake, Error::Protocol};
use turbo_tasks::TurboTasks;
use turbo_tasks_fs::util::sys_to_unix;
use turbo_tasks::{
NothingVc, RawVc, ReadRef, State, TransientInstance, TransientValue, TurboTasks,
};
use turbo_tasks_fs::{util::sys_to_unix, DiskFileSystemVc, FileSystem};
use turbo_tasks_memory::MemoryBackend;
use turbo_tasks_testing::retry::retry_async;
use turbopack_core::issue::{CapturedIssues, IssueReporter, IssueReporterVc, PlainIssueReadRef};
use turbopack_test_utils::snapshot::snapshot_issues;

fn register() {
next_dev::register();
include!(concat!(env!("OUT_DIR"), "/register_test_integration.rs"));
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -155,16 +169,25 @@ async fn run_test(resource: &str) -> JestRunResult {
);

let package_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let workspace_root = package_root.parent().unwrap().parent().unwrap();
let project_dir = workspace_root.join(resource).join("input");
let workspace_root = package_root
.parent()
.unwrap()
.parent()
.unwrap()
.to_path_buf();
let test_dir = workspace_root.join(resource);
let project_dir = test_dir.join("input");
let requested_addr = get_free_local_addr().unwrap();

let mock_dir = path.join("__httpmock__");
let mock_server_future = get_mock_server_future(&mock_dir);

let turbo_tasks = TurboTasks::new(MemoryBackend::default());
let (issue_tx, mut issue_rx) = channel(u16::MAX as usize);
let issue_tx = TransientInstance::new(issue_tx);

let tt = TurboTasks::new(MemoryBackend::default());
let server = NextDevServerBuilder::new(
turbo_tasks,
tt.clone(),
sys_to_unix(&project_dir.to_string_lossy()).to_string(),
sys_to_unix(&workspace_root.to_string_lossy()).to_string(),
)
Expand All @@ -178,6 +201,9 @@ async fn run_test(resource: &str) -> JestRunResult {
.port(requested_addr.port())
.log_level(turbopack_core::issue::IssueSeverity::Warning)
.log_detail(true)
.issue_reporter(Box::new(move || {
TestIssueReporterVc::new(issue_tx.clone()).into()
}))
.show_all(true)
.build()
.await
Expand All @@ -198,6 +224,29 @@ async fn run_test(resource: &str) -> JestRunResult {

env::remove_var("TURBOPACK_TEST_ONLY_MOCK_SERVER");

let task = tt.spawn_once_task(async move {
let issues_fs = DiskFileSystemVc::new(
"issues".to_string(),
test_dir.join("issues").to_string_lossy().to_string(),
)
.as_file_system();

let mut issues = vec![];
while let Ok(issue) = issue_rx.try_recv() {
issues.push(issue);
}

snapshot_issues(
issues.iter().cloned(),
issues_fs.root(),
&workspace_root.to_string_lossy(),
)
.await?;

Ok(NothingVc::new().into())
});
tt.wait_task_completion(task, true).await.unwrap();

result
}

Expand Down Expand Up @@ -414,3 +463,37 @@ async fn get_mock_server_future(mock_dir: &Path) -> Result<(), String> {
std::future::pending::<Result<(), String>>().await
}
}

#[turbo_tasks::value(shared)]
struct TestIssueReporter {
#[turbo_tasks(trace_ignore, debug_ignore)]
pub issue_tx: State<Sender<PlainIssueReadRef>>,
}

#[turbo_tasks::value_impl]
impl TestIssueReporterVc {
#[turbo_tasks::function]
fn new(issue_tx: TransientInstance<Sender<PlainIssueReadRef>>) -> Self {
TestIssueReporter {
issue_tx: State::new((*issue_tx).clone()),
}
.cell()
}
}

#[turbo_tasks::value_impl]
impl IssueReporter for TestIssueReporter {
#[turbo_tasks::function]
async fn report_issues(
&self,
captured_issues: TransientInstance<ReadRef<CapturedIssues>>,
_source: TransientValue<RawVc>,
) -> Result<()> {
let issue_tx = self.issue_tx.get_untracked().clone();
for issue in captured_issues.iter().cloned() {
issue_tx.send(issue).await?;
}

Ok(())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
PlainIssue {
severity: Warning,
context: "[project-with-next]/node_modules/.pnpm/postcss@8.4.20/node_modules/postcss/lib/previous-map.js",
category: "parse",
title: "lint TP1004 fs.existsSync(???*0*) is very dynamic",
description: "- *0* arguments[0]\n ⚠\u{fe0f} function calls are not analysed yet",
detail: "",
documentation_link: "",
source: Some(
PlainIssueSource {
asset: PlainAsset {
path: FileSystemPath {
fs: FileSystemVc {
node: TaskCell(
TaskId {
id: 1674,
},
CellId {
type_id: ValueTypeId {
id: 24,
name: "turbo-tasks-fs@TODO::::attach::AttachedFileSystem",
},
index: 0,
},
),
},
path: "node_modules/.pnpm/postcss@8.4.20/node_modules/postcss/lib/previous-map.js",
},
content: Content(
File {
meta: FileMeta {
permissions: Writable,
content_type: None,
},
content (hash): 14360826439174780891,
},
),
},
start: SourcePos {
line: 87,
column: 8,
},
end: SourcePos {
line: 87,
column: 8,
},
},
),
sub_issues: [],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
PlainIssue {
severity: Warning,
context: "[project-with-next]/node_modules/.pnpm/postcss@8.4.20/node_modules/postcss/lib/previous-map.js",
category: "parse",
title: "lint TP1004 fs.readFileSync(???*0*, \"utf-8\") is very dynamic",
description: "- *0* arguments[0]\n ⚠\u{fe0f} function calls are not analysed yet",
detail: "",
documentation_link: "",
source: Some(
PlainIssueSource {
asset: PlainAsset {
path: FileSystemPath {
fs: FileSystemVc {
node: TaskCell(
TaskId {
id: 1674,
},
CellId {
type_id: ValueTypeId {
id: 24,
wbinnssmith marked this conversation as resolved.
Show resolved Hide resolved
name: "turbo-tasks-fs@TODO::::attach::AttachedFileSystem",
},
index: 0,
},
),
},
path: "node_modules/.pnpm/postcss@8.4.20/node_modules/postcss/lib/previous-map.js",
},
content: Content(
File {
meta: FileMeta {
permissions: Writable,
content_type: None,
},
content (hash): 14360826439174780891,
},
),
},
start: SourcePos {
line: 89,
column: 13,
},
end: SourcePos {
line: 89,
column: 13,
},
},
),
sub_issues: [],
}
Loading