Skip to content

Commit

Permalink
allow to create stress test for client components (vercel/turborepo#4581
Browse files Browse the repository at this point in the history
)

### Description

adds `--leaf-client-components` to the test app generator to make all
leaf components client components and allow to stress test an app with
many client components
  • Loading branch information
sokra authored Apr 14, 2023
1 parent aabb121 commit 6b6f5dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/turbopack-create-test-app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ struct Args {
/// How to communicate changes to the consumer (none | hook | component)
#[clap(long, default_value = "none")]
effect_mode: EffectMode,

/// Make leaf modules client components for app dir
#[clap(long, default_value_t = false)]
leaf_client_components: bool,
}

fn main() -> Result<()> {
Expand All @@ -53,6 +57,7 @@ fn main() -> Result<()> {
None
},
effect_mode: args.effect_mode,
leaf_client_components: args.leaf_client_components,
}
.build()?
.path()
Expand Down
9 changes: 9 additions & 0 deletions crates/turbopack-create-test-app/src/test_app_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub struct TestAppBuilder {
pub flatness: usize,
pub package_json: Option<PackageJsonConfig>,
pub effect_mode: EffectMode,
pub leaf_client_components: bool,
}

impl Default for TestAppBuilder {
Expand All @@ -88,6 +89,7 @@ impl Default for TestAppBuilder {
flatness: 5,
package_json: Some(Default::default()),
effect_mode: EffectMode::Hook,
leaf_client_components: false,
}
}
}
Expand Down Expand Up @@ -172,10 +174,17 @@ impl TestAppBuilder {
|| (!queue.is_empty()
&& (queue.len() + remaining_modules) % (self.flatness + 1) == 0);
if leaf {
let maybe_use_client = if self.leaf_client_components {
r#""use client";"#
} else {
""
};
write_file(
&format!("leaf file {}", file.display()),
&file,
formatdoc! {r#"
{maybe_use_client}
{setup_imports}
{SETUP_EFFECT_PROPS}
Expand Down

0 comments on commit 6b6f5dd

Please sign in to comment.