Fix playwright tests (#2695)
This commit is contained in:
1 parent
9479d2376d
commit
bd484842bd
28 files changed
+477
-330
No files matched your search
@@ -117,6 +117,7 @@ impl BuildResult {
|
||||
&self,
|
||||
serve: &ServeArguments,
|
||||
fullstack_address: Option<SocketAddr>,
|
||||
workspace: &std::path::Path,
|
||||
) -> std::io::Result<Option<Child>> {
|
||||
if self.web {
|
||||
return Ok(None);
|
||||
@@ -124,12 +125,8 @@ impl BuildResult {
|
||||
|
||||
let arguments = RuntimeCLIArguments::new(serve.address.address(), fullstack_address);
|
||||
let executable = self.executable.canonicalize()?;
|
||||
// This is the /dist folder generally
|
||||
let output_folder = executable.parent().unwrap();
|
||||
// This is the workspace folder
|
||||
let workspace_folder = output_folder.parent().unwrap();
|
||||
Ok(Some(
|
||||
Command::new(&executable)
|
||||
Command::new(executable)
|
||||
// When building the fullstack server, we need to forward the serve arguments (like port) to the fullstack server through env vars
|
||||
.env(
|
||||
dioxus_cli_config::__private::SERVE_ENV,
|
||||
@@ -138,7 +135,7 @@ impl BuildResult {
|
||||
.stderr(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.kill_on_drop(true)
|
||||
.current_dir(workspace_folder)
|
||||
.current_dir(workspace)
|
||||
.spawn()?,
|
||||
))
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ pub async fn serve_all(serve: Serve, dioxus_crate: DioxusCrate) -> Result<()> {
|
||||
|
||||
// If we have a build result, open it
|
||||
for build_result in results.iter() {
|
||||
let child = build_result.open(&serve.server_arguments, server.fullstack_address());
|
||||
let child = build_result.open(&serve.server_arguments, server.fullstack_address(), &dioxus_crate.workspace_dir());
|
||||
match child {
|
||||
Ok(Some(child_proc)) => builder.children.push((build_result.platform,child_proc)),
|
||||
Err(_e) => break,
|
||||
|
||||
@@ -21,6 +21,7 @@ use axum_server::tls_rustls::RustlsConfig;
|
||||
use dioxus_cli_config::{Platform, WebHttpsConfig};
|
||||
use dioxus_hot_reload::{DevserverMsg, HotReloadMsg};
|
||||
use futures_channel::mpsc::{UnboundedReceiver, UnboundedSender};
|
||||
use futures_util::stream;
|
||||
use futures_util::{stream::FuturesUnordered, StreamExt};
|
||||
use hyper::header::ACCEPT;
|
||||
use hyper::HeaderMap;
|
||||
@@ -577,7 +578,9 @@ pub(crate) fn open_browser(base_path: Option<String>, address: SocketAddr, https
|
||||
}
|
||||
|
||||
fn get_available_port(address: IpAddr) -> Option<u16> {
|
||||
(8000..9000).find(|port| TcpListener::bind((address, *port)).is_ok())
|
||||
TcpListener::bind((address, 0))
|
||||
.map(|listener| listener.local_addr().unwrap().port())
|
||||
.ok()
|
||||
}
|
||||
|
||||
/// Middleware that intercepts html requests if the status is "Building" and returns a loading page instead
|
||||
@@ -598,7 +601,12 @@ async fn build_status_middleware(
|
||||
let html = include_str!("../../assets/loading.html");
|
||||
return axum::response::Response::builder()
|
||||
.status(StatusCode::OK)
|
||||
.body(Body::from(html))
|
||||
// Load the html loader then keep loading forever
|
||||
// We never close the stream so any headless testing framework (like playwright) will wait until the real build is done
|
||||
.body(Body::from_stream(
|
||||
stream::once(async move { Ok::<_, std::convert::Infallible>(html) })
|
||||
.chain(stream::pending()),
|
||||
))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user