Skip to content

Commit

Permalink
Add test fixtures demonstrating export statement validation bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Jan 24, 2025
1 parent 2c1f68e commit 5e1b67f
Show file tree
Hide file tree
Showing 20 changed files with 155 additions and 31 deletions.
38 changes: 7 additions & 31 deletions crates/next-custom-transforms/tests/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,45 +89,21 @@ fn next_ssg_errors(input: PathBuf) {
);
}

#[fixture("tests/errors/react-server-components/server-graph/**/input.js")]
fn react_server_components_server_graph_errors(input: PathBuf) {
use next_custom_transforms::transforms::react_server_components::{Config, Options};
let output = input.parent().unwrap().join("output.js");
test_fixture(
syntax(),
&|tr| {
server_components(
FileName::Real(PathBuf::from("/some-project/src/layout.js")).into(),
Config::WithOptions(Options {
is_react_server_layer: true,
dynamic_io_enabled: false,
}),
tr.comments.as_ref().clone(),
None,
)
},
&input,
&output,
FixtureTestConfig {
allow_error: true,
module: Some(true),
..Default::default()
},
);
}

#[fixture("tests/errors/react-server-components/client-graph/**/input.js")]
fn react_server_components_client_graph_errors(input: PathBuf) {
#[fixture("tests/errors/react-server-components/**/input.js")]
fn react_server_components_errors(input: PathBuf) {
use next_custom_transforms::transforms::react_server_components::{Config, Options};
let mut path_components = input.iter();
let is_react_server_layer = path_components.any(|s| s.to_str() == Some("server-graph"));
let dynamic_io_enabled = path_components.any(|s| s.to_str() == Some("dynamic-io"));
let output = input.parent().unwrap().join("output.js");
test_fixture(
syntax(),
&|tr| {
server_components(
FileName::Real(PathBuf::from("/some-project/src/page.js")).into(),
Config::WithOptions(Options {
is_react_server_layer: false,
dynamic_io_enabled: false,
is_react_server_layer,
dynamic_io_enabled,
}),
tr.comments.as_ref().clone(),
None,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function generateMetadata() {}

export default function () {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function generateMetadata() {}
export default function() {
return null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
x You are attempting to export "generateMetadata" from a component marked with "use client", which is disallowed. Either remove the export, or the "use client" directive. Read more: https://
| nextjs.org/docs/app/api-reference/directives/use-client
|
|
,-[input.js:1:1]
1 | export function generateMetadata() {}
: ^^^^^^^^^^^^^^^^
`----
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const metadata = {}

export default function () {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const metadata = {};
export default function() {
return null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
x You are attempting to export "metadata" from a component marked with "use client", which is disallowed. Either remove the export, or the "use client" directive. Read more: https://nextjs.org/
| docs/app/api-reference/directives/use-client
|
|
,-[input.js:1:1]
1 | export const metadata = {}
: ^^^^^^^^
`----
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const metadata = {}

export function generateMetadata() {}

export function getServerSideProps() {}

export default function () {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const metadata = {};
export function generateMetadata() {}
export function getServerSideProps() {}
export default function() {
return null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
x You are attempting to export "getServerSideProps" from a component marked with "use client", which is disallowed. Either remove the export, or the "use client" directive. Read more: https://
| nextjs.org/docs/app/api-reference/directives/use-client
|
|
,-[input.js:5:1]
4 |
5 | export function getServerSideProps() {}
: ^^^^^^^^^^^^^^^^^^
`----
x "getServerSideProps" is not supported in app/. Read more: https://nextjs.org/docs/app/building-your-application/data-fetching
|
|
,-[input.js:5:1]
4 |
5 | export function getServerSideProps() {}
: ^^^^^^^^^^^^^^^^^^
`----
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const runtime = 'edge'
export const dynamic = 'force-dynamic'
export const dynamicParams = false
export const fetchCache = 'force-no-store'
export const revalidate = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const runtime = 'edge';
export const dynamic = 'force-dynamic';
export const dynamicParams = false;
export const fetchCache = 'force-no-store';
export const revalidate = 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
x "fetchCache" is not compatible with `nextConfig.experimental.dynamicIO`. Please remove it.
,-[input.js:5:1]
4 | export const fetchCache = 'force-no-store'
5 | export const revalidate = 1
: ^^^^^^^^^^
`----
x "dynamic" is not compatible with `nextConfig.experimental.dynamicIO`. Please remove it.
,-[input.js:5:1]
4 | export const fetchCache = 'force-no-store'
5 | export const revalidate = 1
: ^^^^^^^^^^
`----
x "dynamicParams" is not compatible with `nextConfig.experimental.dynamicIO`. Please remove it.
,-[input.js:5:1]
4 | export const fetchCache = 'force-no-store'
5 | export const revalidate = 1
: ^^^^^^^^^^
`----
x "revalidate" is not compatible with `nextConfig.experimental.dynamicIO`. Please remove it.
,-[input.js:5:1]
4 | export const fetchCache = 'force-no-store'
5 | export const revalidate = 1
: ^^^^^^^^^^
`----
x "runtime" is not compatible with `nextConfig.experimental.dynamicIO`. Please remove it.
,-[input.js:5:1]
4 | export const fetchCache = 'force-no-store'
5 | export const revalidate = 1
: ^^^^^^^^^^
`----
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// generateMetadata without metadata is ok.
export function generateMetadata() {}

export default function () {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// generateMetadata without metadata is ok.
export function generateMetadata() {}
export default function() {
return null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const metadata = {}

export function generateMetadata() {}

export default function () {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const metadata = {};
export function generateMetadata() {}
export default function() {
return null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
x "metadata" and "generateMetadata" cannot be exported at the same time, please keep one of them. Read more: https://nextjs.org/docs/app/api-reference/file-conventions/metadata
|
|
,-[input.js:3:1]
2 |
3 | export function generateMetadata() {}
: ^^^^^^^^^^^^^^^^
`----
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// metadata without generateMetadata is ok.
export const metadata = {}

export default function () {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// metadata without generateMetadata is ok.
export const metadata = {};
export default function() {
return null;
}

0 comments on commit 5e1b67f

Please sign in to comment.