Skip to content

Commit

Permalink
re-enable next-dev-tests (#47087)
Browse files Browse the repository at this point in the history
### What?

enables the next-dev-tests crate integration tests from trubopack

### Why?

to unblock the move PR we temporarily disabled the tests

### How?

Fix the new location and fix the expect dependency

Fixes WEB-708

---------

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
  • Loading branch information
sokra and jridgewell committed Mar 14, 2023
1 parent e6bca73 commit c27b546
Show file tree
Hide file tree
Showing 28 changed files with 363 additions and 96 deletions.
6 changes: 5 additions & 1 deletion .devcontainer/Dockerfile
Expand Up @@ -12,7 +12,11 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 \
libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 \
libxdamage1 libxss1 libxtst6 libappindicator1 libnss3 libasound2 \
libatk1.0-0 libc6 libdrm-dev libgbm-dev ca-certificates fonts-liberation lsb-release xdg-utils wget
libatk1.0-0 libc6 libdrm-dev libgbm-dev ca-certificates fonts-liberation lsb-release xdg-utils wget \
# Chromium for running Turbopack benchmarks
chromium \
# Used for plotters graph visualizations in turbopack benchmarks
libfontconfig1-dev

# [Optional] Uncomment if you want to install an additional version of node using nvm
# ARG EXTRA_NODE_VERSION=10
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/build_test_deploy.yml
Expand Up @@ -816,6 +816,7 @@ jobs:
lint,
check-examples,
test-native,
test-native-integration,
checkPrecompiled,
testIntegration,
testUnit,
Expand Down Expand Up @@ -1130,6 +1131,47 @@ jobs:
- run: cd packages/next-swc && cargo test --workspace --exclude next-dev-tests
if: ${{ steps.swc-change.outputs.SWC_CHANGE == 'yup' }}

test-native-integration:
name: Integration Test Native Code
runs-on: ubuntu-latest-16-core-oss
needs: build

env:
CARGO_PROFILE_RELEASE_LTO: false

steps:
- uses: actions/cache@v3
timeout-minutes: 5
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}

- run: echo "SWC_CHANGE<<EOF" >> $GITHUB_OUTPUT; echo "$(node scripts/run-for-change.js --type next-swc --exec echo 'yup')" >> $GITHUB_OUTPUT; echo 'EOF' >> $GITHUB_OUTPUT
id: swc-change

- run: echo "${{ steps.swc-change.outputs.SWC_CHANGE }}"

- name: Install
if: ${{ steps.swc-change.outputs.SWC_CHANGE == 'yup' }}
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
profile: minimal

- name: Install nextest
uses: taiki-e/install-action@nextest

- name: Build tests
timeout-minutes: 60
run: cd packages/next-swc && cargo nextest run -p next-dev-tests --release --no-run
if: ${{ steps.swc-change.outputs.SWC_CHANGE == 'yup' }}

- name: Run tests
timeout-minutes: 20
run: cd packages/next-swc && cargo nextest run -p next-dev-tests --release --no-fail-fast
if: ${{ steps.swc-change.outputs.SWC_CHANGE == 'yup' }}

test-wasm:
name: Test the wasm build
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions packages/next-swc/.cargo/config.toml
@@ -1,5 +1,6 @@
[env]
CARGO_WORKSPACE_DIR = { value = "", relative = true }
PNPM_WORKSPACE_DIR = { value = "../../", relative = true }

[build]

Expand Down
9 changes: 9 additions & 0 deletions packages/next-swc/.config/nextest.toml
@@ -0,0 +1,9 @@
[[profile.default.overrides]]
filter = "package(next-dev-tests)"
# Default is 100ms. Extending this addresses false positives in the
# next-dev integration tests.
leak-timeout = "500ms"
retries = 2
slow-timeout = "60s"
threads-required = 2
failure-output = "immediate-final"
1 change: 1 addition & 0 deletions packages/next-swc/Cargo.lock

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

1 change: 1 addition & 0 deletions packages/next-swc/crates/next-dev-tests/Cargo.toml
Expand Up @@ -24,6 +24,7 @@ anyhow = { workspace = true }
chromiumoxide = { workspace = true, features = [
"tokio-runtime",
], default-features = false }
dunce = { workspace = true }
futures = { workspace = true }
httpmock = { workspace = true, features = ["standalone"] }
lazy_static = { workspace = true }
Expand Down
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.1",
"main": "./harness.ts",
"dependencies": {
"expect": "27.5.1",
"expect": "24.5.0",
"jest-circus": "27.5.1",
"jest-circus-browser": "^1.0.7"
}
Expand Down
101 changes: 88 additions & 13 deletions packages/next-swc/crates/next-dev-tests/tests/integration.rs
Expand Up @@ -2,6 +2,8 @@
#![cfg(test)]
extern crate test_generator;

use dunce::canonicalize;
use regex::{Captures, Regex, Replacer};
use std::{
env,
fmt::Write,
Expand Down Expand Up @@ -32,19 +34,22 @@ use serde::Deserialize;
use test_generator::test_resources;
use tokio::{
net::TcpSocket,
sync::mpsc::{channel, Sender},
sync::mpsc::{unbounded_channel, UnboundedSender},
task::JoinSet,
};
use tungstenite::{error::ProtocolError::ResetWithoutClosingHandshake, Error::Protocol};
use turbo_tasks::{
debug::{ValueDebug, ValueDebugStringReadRef},
primitives::BoolVc,
primitives::{BoolVc, StringVc},
NothingVc, RawVc, ReadRef, State, TransientInstance, TransientValue, TurboTasks,
};
use turbo_tasks_fs::{DiskFileSystemVc, FileSystem};
use turbo_tasks_fs::{DiskFileSystemVc, FileSystem, FileSystemPathVc};
use turbo_tasks_memory::MemoryBackend;
use turbo_tasks_testing::retry::retry_async;
use turbopack_core::issue::{CapturedIssues, IssueReporter, IssueReporterVc, PlainIssueReadRef};
use turbopack_core::issue::{
CapturedIssues, Issue, IssueReporter, IssueReporterVc, IssueSeverityVc, IssueVc, IssuesVc,
OptionIssueSourceVc, PlainIssueReadRef,
};
use turbopack_test_utils::snapshot::snapshot_issues;

fn register() {
Expand Down Expand Up @@ -157,6 +162,7 @@ fn test_skipped_fails(resource: &str) {

async fn run_test(resource: &str) -> JestRunResult {
register();

let path = Path::new(resource)
// test_resources matches and returns relative paths from the workspace root,
// but pwd in cargo tests is the crate under test.
Expand All @@ -171,20 +177,21 @@ async fn run_test(resource: &str) -> JestRunResult {
);

let package_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let workspace_root = package_root
let cargo_workspace_root = package_root
.parent()
.unwrap()
.parent()
.unwrap()
.to_path_buf();
let test_dir = workspace_root.join(resource);
let test_dir = cargo_workspace_root.join(resource);
let workspace_root = canonicalize(PathBuf::from(env!("PNPM_WORKSPACE_DIR"))).unwrap();
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 (issue_tx, mut issue_rx) = channel(u16::MAX as usize);
let (issue_tx, mut issue_rx) = unbounded_channel();
let issue_tx = TransientInstance::new(issue_tx);

let tt = TurboTasks::new(MemoryBackend::default());
Expand Down Expand Up @@ -241,7 +248,7 @@ async fn run_test(resource: &str) -> JestRunResult {
snapshot_issues(
issues.iter().cloned(),
issues_fs.root(),
&workspace_root.to_string_lossy(),
&cargo_workspace_root.to_string_lossy(),
)
.await?;

Expand Down Expand Up @@ -469,14 +476,14 @@ async fn get_mock_server_future(mock_dir: &Path) -> Result<(), String> {
#[turbo_tasks::value(shared)]
struct TestIssueReporter {
#[turbo_tasks(trace_ignore, debug_ignore)]
pub issue_tx: State<Sender<(PlainIssueReadRef, ValueDebugStringReadRef)>>,
pub issue_tx: State<UnboundedSender<(PlainIssueReadRef, ValueDebugStringReadRef)>>,
}

#[turbo_tasks::value_impl]
impl TestIssueReporterVc {
#[turbo_tasks::function]
fn new(
issue_tx: TransientInstance<Sender<(PlainIssueReadRef, ValueDebugStringReadRef)>>,
issue_tx: TransientInstance<UnboundedSender<(PlainIssueReadRef, ValueDebugStringReadRef)>>,
) -> Self {
TestIssueReporter {
issue_tx: State::new((*issue_tx).clone()),
Expand All @@ -495,10 +502,78 @@ impl IssueReporter for TestIssueReporter {
) -> Result<BoolVc> {
let issue_tx = self.issue_tx.get_untracked().clone();
for (issue, path) in captured_issues.iter_with_shortest_path() {
let plain = issue.into_plain(path);
issue_tx.send((plain.await?, plain.dbg().await?)).await?;
let plain = NormalizedIssue(issue).cell().as_issue().into_plain(path);
issue_tx.send((plain.await?, plain.dbg().await?))?;
}

Ok(BoolVc::cell(false))
}
}

struct StackTraceReplacer;

impl Replacer for StackTraceReplacer {
fn replace_append(&mut self, caps: &Captures<'_>, dst: &mut String) {
let code = caps.get(2).map_or("", |m| m.as_str());
if code.starts_with("node:") {
return;
}
let mut name = caps.get(1).map_or("", |m| m.as_str());
name = name.strip_prefix("Object.").unwrap_or(name);
write!(dst, "\n at {} ({})", name, code).unwrap();
}
}

#[turbo_tasks::value(transparent)]
struct NormalizedIssue(IssueVc);

#[turbo_tasks::value_impl]
impl Issue for NormalizedIssue {
#[turbo_tasks::function]
fn severity(&self) -> IssueSeverityVc {
self.0.severity()
}

#[turbo_tasks::function]
fn context(&self) -> FileSystemPathVc {
self.0.context()
}

#[turbo_tasks::function]
fn category(&self) -> StringVc {
self.0.category()
}

#[turbo_tasks::function]
fn title(&self) -> StringVc {
self.0.title()
}

#[turbo_tasks::function]
async fn description(&self) -> Result<StringVc> {
let str = self.0.description().await?;
let regex = Regex::new(r"\n at (.+) \((.+)\)").unwrap();
Ok(StringVc::cell(
regex.replace_all(&str, StackTraceReplacer).to_string(),
))
}

#[turbo_tasks::function]
fn detail(&self) -> StringVc {
self.0.detail()
}

#[turbo_tasks::function]
fn documentation_link(&self) -> StringVc {
self.0.documentation_link()
}

#[turbo_tasks::function]
fn source(&self) -> OptionIssueSourceVc {
self.0.source()
}

#[turbo_tasks::function]
fn sub_issues(&self) -> IssuesVc {
self.0.sub_issues()
}
}
@@ -1,6 +1,6 @@
PlainIssue {
severity: Warning,
context: "[project]/node_modules/.pnpm/postcss@8.4.20/node_modules/postcss/lib/previous-map.js",
context: "[project]/node_modules/.pnpm/postcss@8.4.14/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",
Expand All @@ -9,7 +9,7 @@ PlainIssue {
source: Some(
PlainIssueSource {
asset: PlainAsset {
ident: "[project]/node_modules/.pnpm/postcss@8.4.20/node_modules/postcss/lib/previous-map.js",
ident: "[project]/node_modules/.pnpm/postcss@8.4.14/node_modules/postcss/lib/previous-map.js",
},
start: SourcePos {
line: 87,
Expand All @@ -26,13 +26,13 @@ PlainIssue {
[
PlainIssueProcessingPathItem {
context: Some(
"[project]/crates/next-dev-tests/tests/integration/next/tailwind/basic/input/pages/index.jsx",
"[project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/tailwind/basic/input/pages/index.jsx",
),
description: "Next.js pages directory",
},
PlainIssueProcessingPathItem {
context: Some(
"[project]/crates/next-dev-tests/tests/integration/next/tailwind/basic/input/styles/globals.css",
"[project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/tailwind/basic/input/styles/globals.css",
),
description: "PostCSS processing",
},
Expand Down
@@ -1,6 +1,6 @@
PlainIssue {
severity: Warning,
context: "[project]/node_modules/.pnpm/postcss@8.4.20/node_modules/postcss/lib/previous-map.js",
context: "[project]/node_modules/.pnpm/postcss@8.4.14/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",
Expand All @@ -9,7 +9,7 @@ PlainIssue {
source: Some(
PlainIssueSource {
asset: PlainAsset {
ident: "[project]/node_modules/.pnpm/postcss@8.4.20/node_modules/postcss/lib/previous-map.js",
ident: "[project]/node_modules/.pnpm/postcss@8.4.14/node_modules/postcss/lib/previous-map.js",
},
start: SourcePos {
line: 89,
Expand All @@ -26,13 +26,13 @@ PlainIssue {
[
PlainIssueProcessingPathItem {
context: Some(
"[project]/crates/next-dev-tests/tests/integration/next/tailwind/basic/input/pages/index.jsx",
"[project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/tailwind/basic/input/pages/index.jsx",
),
description: "Next.js pages directory",
},
PlainIssueProcessingPathItem {
context: Some(
"[project]/crates/next-dev-tests/tests/integration/next/tailwind/basic/input/styles/globals.css",
"[project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/tailwind/basic/input/styles/globals.css",
),
description: "PostCSS processing",
},
Expand Down
@@ -1,6 +1,6 @@
PlainIssue {
severity: Warning,
context: "[project]/node_modules/.pnpm/postcss@8.4.20/node_modules/postcss/lib/input.js",
context: "[project]/node_modules/.pnpm/postcss@8.4.14/node_modules/postcss/lib/input.js",
category: "parse",
title: "lint TP1006 path.resolve(???*0*) is very dynamic",
description: "- *0* ???*1*[\"from\"]\n ⚠\u{fe0f} unknown object\n- *1* opts\n ⚠\u{fe0f} pattern without value",
Expand All @@ -9,7 +9,7 @@ PlainIssue {
source: Some(
PlainIssueSource {
asset: PlainAsset {
ident: "[project]/node_modules/.pnpm/postcss@8.4.20/node_modules/postcss/lib/input.js",
ident: "[project]/node_modules/.pnpm/postcss@8.4.14/node_modules/postcss/lib/input.js",
},
start: SourcePos {
line: 43,
Expand All @@ -26,13 +26,13 @@ PlainIssue {
[
PlainIssueProcessingPathItem {
context: Some(
"[project]/crates/next-dev-tests/tests/integration/next/tailwind/basic/input/pages/index.jsx",
"[project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/tailwind/basic/input/pages/index.jsx",
),
description: "Next.js pages directory",
},
PlainIssueProcessingPathItem {
context: Some(
"[project]/crates/next-dev-tests/tests/integration/next/tailwind/basic/input/styles/globals.css",
"[project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/tailwind/basic/input/styles/globals.css",
),
description: "PostCSS processing",
},
Expand Down

0 comments on commit c27b546

Please sign in to comment.