Path: blob/main/crates/bevy_dev_tools/src/ci_testing/config.rs
9300 views
use bevy_ecs::prelude::*;1use bevy_math::{Quat, Vec3};2use serde::Deserialize;34/// A configuration struct for automated CI testing.5///6/// It gets used when the `bevy_ci_testing` feature is enabled to automatically7/// exit a Bevy app when run through the CI. This is needed because otherwise8/// Bevy apps would be stuck in the game loop and wouldn't allow the CI to progress.9#[derive(Deserialize, Resource, PartialEq, Debug, Default, Clone)]10pub struct CiTestingConfig {11/// The setup for this test.12#[serde(default)]13pub setup: CiTestingSetup,14/// Events to send, with their associated frame.15#[serde(default)]16pub events: Vec<CiTestingEventOnFrame>,17}1819/// Setup for a test.20#[derive(Deserialize, Default, PartialEq, Debug, Clone)]21pub struct CiTestingSetup {22/// The amount of time in seconds between frame updates.23///24/// This is set through the [`TimeUpdateStrategy::ManualDuration`] resource.25///26/// [`TimeUpdateStrategy::ManualDuration`]: bevy_time::TimeUpdateStrategy::ManualDuration27pub fixed_frame_time: Option<f32>,28}2930/// An event to send at a given frame, used for CI testing.31#[derive(Deserialize, PartialEq, Debug, Clone)]32pub struct CiTestingEventOnFrame(pub u32, pub CiTestingEvent);3334/// An event to send, used for CI testing.35#[derive(Deserialize, PartialEq, Debug, Clone)]36pub enum CiTestingEvent {37/// Takes a screenshot of the entire screen, and saves the results to38/// `screenshot-{current_frame}.png`.39Screenshot,40/// Takes a screenshot of the entire screen, saves the results to41/// `screenshot-{current_frame}.png`, and exits once the screenshot is taken.42ScreenshotAndExit,43/// Takes a screenshot of the entire screen, and saves the results to44/// `screenshot-{name}.png`.45NamedScreenshot(String),46/// Stops the program by sending [`AppExit::Success`].47///48/// [`AppExit::Success`]: bevy_app::AppExit::Success49AppExit,50/// Starts recording the screen.51StartScreenRecording,52/// Stops recording the screen.53StopScreenRecording,54/// Smoothly moves the camera to the given position.55MoveCamera {56/// Position to move the camera to.57translation: Vec3,58/// Rotation to move the camera to.59rotation: Quat,60},61/// Sends a [`CiTestingCustomEvent`] using the given [`String`].62Custom(String),63}6465/// A custom event that can be configured from a configuration file for CI testing.66#[derive(Message)]67pub struct CiTestingCustomEvent(pub String);6869#[cfg(test)]70mod tests {71use super::*;7273#[test]74fn deserialize() {75const INPUT: &str = r#"76(77setup: (78fixed_frame_time: Some(0.03),79),80events: [81(100, Custom("Hello, world!")),82(200, Screenshot),83(300, AppExit),84],85)"#;8687let expected = CiTestingConfig {88setup: CiTestingSetup {89fixed_frame_time: Some(0.03),90},91events: vec![92CiTestingEventOnFrame(100, CiTestingEvent::Custom("Hello, world!".into())),93CiTestingEventOnFrame(200, CiTestingEvent::Screenshot),94CiTestingEventOnFrame(300, CiTestingEvent::AppExit),95],96};9798let config: CiTestingConfig = ron::from_str(INPUT).unwrap();99100assert_eq!(config, expected);101}102}103104105