From f5eb177f50a0bf37bc6bd9d87b447c73a53b6ea5 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Tue, 9 Nov 2021 12:26:39 +1100 Subject: feat(cli): support React 17 JSX transforms (#12631) Closes #8440 --- test_util/src/lib.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'test_util/src/lib.rs') diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs index 52924ac90..e57f55f1e 100644 --- a/test_util/src/lib.rs +++ b/test_util/src/lib.rs @@ -566,7 +566,9 @@ async fn absolute_redirect( Ok(file_resp) } -async fn main_server(req: Request) -> hyper::Result> { +async fn main_server( + req: Request, +) -> Result, hyper::http::Error> { return match (req.method(), req.uri().path()) { (&hyper::Method::POST, "/echo_server") => { let (parts, body) = req.into_parts(); @@ -849,6 +851,27 @@ async fn main_server(req: Request) -> hyper::Result> { let version = format!("{:?}", req.version()); Ok(Response::new(version.into())) } + (_, "/jsx/jsx-runtime") | (_, "/jsx/jsx-dev-runtime") => { + let mut res = Response::new(Body::from( + r#"export function jsx( + _type, + _props, + _key, + _source, + _self, + ) {} + export const jsxs = jsx; + export const jsxDEV = jsx; + export const Fragment = Symbol("Fragment"); + console.log("imported", import.meta.url); + "#, + )); + res.headers_mut().insert( + "Content-type", + HeaderValue::from_static("application/javascript"), + ); + Ok(res) + } _ => { let mut file_path = testdata_path(); file_path.push(&req.uri().path()[1..]); @@ -857,7 +880,9 @@ async fn main_server(req: Request) -> hyper::Result> { return Ok(file_resp); } - return Ok(Response::new(Body::empty())); + Response::builder() + .status(StatusCode::NOT_FOUND) + .body(Body::empty()) } }; } -- cgit v1.2.3