Path: blob/main/crates/bevy_dev_tools/src/ci_testing/config.rs
6601 views
use bevy_ecs::prelude::*;1use serde::Deserialize;23/// A configuration struct for automated CI testing.4///5/// It gets used when the `bevy_ci_testing` feature is enabled to automatically6/// exit a Bevy app when run through the CI. This is needed because otherwise7/// Bevy apps would be stuck in the game loop and wouldn't allow the CI to progress.8#[derive(Deserialize, Resource, PartialEq, Debug, Default)]9pub struct CiTestingConfig {10/// The setup for this test.11#[serde(default)]12pub setup: CiTestingSetup,13/// Events to send, with their associated frame.14#[serde(default)]15pub events: Vec<CiTestingEventOnFrame>,16}1718/// Setup for a test.19#[derive(Deserialize, Default, PartialEq, Debug)]20pub struct CiTestingSetup {21/// The amount of time in seconds between frame updates.22///23/// This is set through the [`TimeUpdateStrategy::ManualDuration`] resource.24///25/// [`TimeUpdateStrategy::ManualDuration`]: bevy_time::TimeUpdateStrategy::ManualDuration26pub fixed_frame_time: Option<f32>,27}2829/// An event to send at a given frame, used for CI testing.30#[derive(Deserialize, PartialEq, Debug)]31pub struct CiTestingEventOnFrame(pub u32, pub CiTestingEvent);3233/// An event to send, used for CI testing.34#[derive(Deserialize, PartialEq, Debug)]35pub enum CiTestingEvent {36/// Takes a screenshot of the entire screen, and saves the results to37/// `screenshot-{current_frame}.png`.38Screenshot,39/// Takes a screenshot of the entire screen, saves the results to40/// `screenshot-{current_frame}.png`, and exits once the screenshot is taken.41ScreenshotAndExit,42/// Takes a screenshot of the entire screen, and saves the results to43/// `screenshot-{name}.png`.44NamedScreenshot(String),45/// Stops the program by sending [`AppExit::Success`].46///47/// [`AppExit::Success`]: bevy_app::AppExit::Success48AppExit,49/// Sends a [`CiTestingCustomEvent`] using the given [`String`].50Custom(String),51}5253/// A custom event that can be configured from a configuration file for CI testing.54#[derive(BufferedEvent)]55pub struct CiTestingCustomEvent(pub String);5657#[cfg(test)]58mod tests {59use super::*;6061#[test]62fn deserialize() {63const INPUT: &str = r#"64(65setup: (66fixed_frame_time: Some(0.03),67),68events: [69(100, Custom("Hello, world!")),70(200, Screenshot),71(300, AppExit),72],73)"#;7475let expected = CiTestingConfig {76setup: CiTestingSetup {77fixed_frame_time: Some(0.03),78},79events: vec![80CiTestingEventOnFrame(100, CiTestingEvent::Custom("Hello, world!".into())),81CiTestingEventOnFrame(200, CiTestingEvent::Screenshot),82CiTestingEventOnFrame(300, CiTestingEvent::AppExit),83],84};8586let config: CiTestingConfig = ron::from_str(INPUT).unwrap();8788assert_eq!(config, expected);89}90}919293