Unverified Commit 17597c24 authored by Shu Ding's avatar Shu Ding Committed by GitHub

Add SWC test cases (#49189)

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.
parent 83e7d6be
...@@ -150,8 +150,8 @@ fn next_font_loaders_errors(input: PathBuf) { ...@@ -150,8 +150,8 @@ fn next_font_loaders_errors(input: PathBuf) {
); );
} }
#[fixture("tests/errors/server-actions/**/input.js")] #[fixture("tests/errors/server-actions/server-graph/**/input.js")]
fn react_server_actions_errors(input: PathBuf) { fn react_server_actions_server_errors(input: PathBuf) {
let output = input.parent().unwrap().join("output.js"); let output = input.parent().unwrap().join("output.js");
test_fixture( test_fixture(
syntax(), syntax(),
...@@ -161,7 +161,7 @@ fn react_server_actions_errors(input: PathBuf) { ...@@ -161,7 +161,7 @@ fn react_server_actions_errors(input: PathBuf) {
server_components( server_components(
FileName::Real(PathBuf::from("/app/item.js")), FileName::Real(PathBuf::from("/app/item.js")),
next_swc::react_server_components::Config::WithOptions( 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(), tr.comments.as_ref().clone(),
None, None,
...@@ -181,3 +181,35 @@ fn react_server_actions_errors(input: PathBuf) { ...@@ -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()
},
);
}
/* __next_internal_client_entry_do_not_use__ foo auto */ /* __next_internal_action_entry_do_not_use__ foo */ export async function foo() {}
import ensureServerEntryExports from "private-next-rsc-action-proxy";
ensureServerEntryExports([
foo
]);
foo.$$typeof = Symbol.for("react.server.reference");
foo.$$id = "ab21efdafbe611287bc25c0462b1e0510d13e48b";
foo.$$bound = null;
foo.$$with_bound = false;
/* __next_internal_client_entry_do_not_use__ foo auto */ /* __next_internal_action_entry_do_not_use__ foo */ 'use strict';
export async function foo() {}
import ensureServerEntryExports from "private-next-rsc-action-proxy";
ensureServerEntryExports([
foo
]);
foo.$$typeof = Symbol.for("react.server.reference");
foo.$$id = "ab21efdafbe611287bc25c0462b1e0510d13e48b";
foo.$$bound = null;
foo.$$with_bound = false;
'use client'
export default function App() {
async function fn() {
'use server'
}
return <div>App</div>
}
/* __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) {}
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>
`----
/* __next_internal_client_entry_do_not_use__ foo auto */ const { createProxy } = require("private-next-rsc-mod-ref-proxy");
module.exports = createProxy("/app/item.js");
/* __next_internal_client_entry_do_not_use__ foo auto */ const { createProxy } = require("private-next-rsc-mod-ref-proxy");
module.exports = createProxy("/app/item.js");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment