Path: blob/main/crates/bevy_dev_tools/src/ci_testing/mod.rs
6598 views
//! Utilities for testing in CI environments.12mod config;3mod systems;45pub use self::config::*;67use bevy_app::prelude::*;8use bevy_ecs::prelude::*;9use bevy_render::view::screenshot::trigger_screenshots;10use bevy_time::TimeUpdateStrategy;11use core::time::Duration;1213/// A plugin that instruments continuous integration testing by automatically executing user-defined actions.14///15/// This plugin reads a [`ron`] file specified with the `CI_TESTING_CONFIG` environmental variable16/// (`ci_testing_config.ron` by default) and executes its specified actions. For a reference of the17/// allowed configuration, see [`CiTestingConfig`].18///19/// This plugin is included within `DefaultPlugins` and `MinimalPlugins`20/// when the `bevy_ci_testing` feature is enabled.21/// It is recommended to only used this plugin during testing (manual or22/// automatic), and disable it during regular development and for production builds.23#[derive(Default)]24pub struct CiTestingPlugin;2526impl Plugin for CiTestingPlugin {27fn build(&self, app: &mut App) {28#[cfg(not(target_arch = "wasm32"))]29let config: CiTestingConfig = {30let filename = std::env::var("CI_TESTING_CONFIG")31.unwrap_or_else(|_| "ci_testing_config.ron".to_string());32std::fs::read_to_string(filename)33.map(|content| {34ron::from_str(&content)35.expect("error deserializing CI testing configuration file")36})37.unwrap_or_default()38};3940#[cfg(target_arch = "wasm32")]41let config: CiTestingConfig = {42let config = include_str!("../../../../ci_testing_config.ron");43ron::from_str(config).expect("error deserializing CI testing configuration file")44};4546// Configure a fixed frame time if specified.47if let Some(fixed_frame_time) = config.setup.fixed_frame_time {48app.insert_resource(TimeUpdateStrategy::ManualDuration(Duration::from_secs_f32(49fixed_frame_time,50)));51}52app.add_event::<CiTestingCustomEvent>()53.insert_resource(config)54.add_systems(55Update,56systems::send_events57.before(trigger_screenshots)58.before(bevy_window::close_when_requested)59.in_set(EventSenderSystems)60.ambiguous_with_all(),61);6263// The offending system does not exist in the wasm32 target.64// As a result, we must conditionally order the two systems using a system set.65#[cfg(any(unix, windows))]66app.configure_sets(67Update,68EventSenderSystems.before(bevy_app::TerminalCtrlCHandlerPlugin::exit_on_flag),69);70}71}7273#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]74struct EventSenderSystems;757677