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

Add SWC test cases #49189

Merged
merged 2 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 35 additions & 3 deletions packages/next-swc/crates/core/tests/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ fn next_font_loaders_errors(input: PathBuf) {
);
}

#[fixture("tests/errors/server-actions/**/input.js")]
fn react_server_actions_errors(input: PathBuf) {
#[fixture("tests/errors/server-actions/server-graph/**/input.js")]
fn react_server_actions_server_errors(input: PathBuf) {
let output = input.parent().unwrap().join("output.js");
test_fixture(
syntax(),
Expand All @@ -161,7 +161,7 @@ fn react_server_actions_errors(input: PathBuf) {
server_components(
FileName::Real(PathBuf::from("/app/item.js")),
next_swc::react_server_components::Config::WithOptions(
next_swc::react_server_components::Options { is_server: false },
next_swc::react_server_components::Options { is_server: true },
),
tr.comments.as_ref().clone(),
None,
Expand All @@ -181,3 +181,35 @@ fn react_server_actions_errors(input: PathBuf) {
},
);
}

#[fixture("tests/errors/server-actions/client-graph/**/input.js")]
fn react_server_actions_client_errors(input: PathBuf) {
let output = input.parent().unwrap().join("output.js");
test_fixture(
syntax(),
&|tr| {
chain!(
resolver(Mark::new(), Mark::new(), false),
server_components(
FileName::Real(PathBuf::from("/app/item.js")),
next_swc::react_server_components::Config::WithOptions(
next_swc::react_server_components::Options { is_server: false },
),
tr.comments.as_ref().clone(),
None,
),
server_actions(
&FileName::Real("/app/item.js".into()),
server_actions::Config { is_server: false },
tr.comments.as_ref().clone(),
)
)
},
&input,
&output,
FixtureTestConfig {
allow_error: true,
..Default::default()
},
);
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use client'

export default function App() {
async function fn() {
'use server'
}
return <div>App</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* __next_internal_client_entry_do_not_use__ default auto */ /* __next_internal_action_entry_do_not_use__ $$ACTION_0 */ export default function App() {
async function fn() {
return $$ACTION_0(fn.$$bound);
}
fn.$$typeof = Symbol.for("react.server.reference");
fn.$$id = "6d53ce510b2e36499b8f56038817b9bad86cabb4";
fn.$$bound = null;
return <div>App</div>;
}
export async function $$ACTION_0(closure) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

x "use server" functions are not allowed in client components. You can import them from a "use server" file instead.
,-[input.js:3:1]
3 | export default function App() {
4 | ,-> async function fn() {
5 | | 'use server'
6 | `-> }
7 | return <div>App</div>
`----
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* __next_internal_client_entry_do_not_use__ foo auto */ const { createProxy } = require("private-next-rsc-mod-ref-proxy");
module.exports = createProxy("/app/item.js");
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* __next_internal_client_entry_do_not_use__ foo auto */ const { createProxy } = require("private-next-rsc-mod-ref-proxy");
module.exports = createProxy("/app/item.js");