Skip to content

Commit

Permalink
Add SWC test cases (#49189)
Browse files Browse the repository at this point in the history
Reorganize the test cases a bit by separating server/client graphs. And
make sure that using `'use server'` inside a Client Component will
result in a compilation error.
  • Loading branch information
shuding authored May 4, 2023
1 parent 83e7d6b commit 17597c2
Show file tree
Hide file tree
Showing 45 changed files with 66 additions and 22 deletions.
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");

0 comments on commit 17597c2

Please sign in to comment.