 e57f73207e
			
		
	
	
		e57f73207e
		
			
		
	
	
	
	
		
			
			# Objective - Improve CI when testing rendering by having smarter testbeds ## Solution - CI testing no longer need a config file and will run with a default config if not found - It is now possible to give a name to a screenshot instead of just a frame number - 2d and 3d testbeds are now driven from code - a new system in testbed will watch for state changed - on state changed, trigger a screenshot 100 frames after (so that the scene has time to render) with the name of the scene - when the screenshot is taken (`Captured` component has been removed), switch scene - this means less setup to run a testbed (no need for a config file), screenshots have better names, and it's faster as we don't wait 100 frames for the screenshot to be taken ## Testing - `cargo run --example testbed_2d --features bevy_ci_testing`
		
			
				
	
	
		
			46 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| #[cfg(feature = "bevy_ci_testing")]
 | |
| use bevy::{
 | |
|     dev_tools::ci_testing::{CiTestingConfig, CiTestingEvent, CiTestingEventOnFrame},
 | |
|     diagnostic::FrameCount,
 | |
|     platform_support::collections::HashSet,
 | |
|     prelude::*,
 | |
|     render::view::screenshot::Captured,
 | |
|     state::state::FreelyMutableState,
 | |
| };
 | |
| 
 | |
| #[cfg(feature = "bevy_ci_testing")]
 | |
| pub fn switch_scene_in_ci<Scene: States + FreelyMutableState + Next>(
 | |
|     mut ci_config: ResMut<CiTestingConfig>,
 | |
|     scene: Res<State<Scene>>,
 | |
|     mut next_scene: ResMut<NextState<Scene>>,
 | |
|     mut scenes_visited: Local<HashSet<Scene>>,
 | |
|     frame_count: Res<FrameCount>,
 | |
|     captured: RemovedComponents<Captured>,
 | |
| ) {
 | |
|     if scene.is_changed() {
 | |
|         // Changed scene! trigger a screenshot in 100 frames
 | |
|         ci_config.events.push(CiTestingEventOnFrame(
 | |
|             frame_count.0 + 100,
 | |
|             CiTestingEvent::NamedScreenshot(format!("{:?}", scene.get())),
 | |
|         ));
 | |
|         if scenes_visited.contains(scene.get()) {
 | |
|             // Exit once all scenes have been screenshotted
 | |
|             ci_config.events.push(CiTestingEventOnFrame(
 | |
|                 frame_count.0 + 1,
 | |
|                 CiTestingEvent::AppExit,
 | |
|             ));
 | |
|         }
 | |
|         return;
 | |
|     }
 | |
| 
 | |
|     if !captured.is_empty() {
 | |
|         // Screenshot taken! Switch to the next scene
 | |
|         scenes_visited.insert(scene.get().clone());
 | |
|         next_scene.set(scene.get().next());
 | |
|     }
 | |
| }
 | |
| 
 | |
| pub trait Next {
 | |
|     fn next(&self) -> Self;
 | |
| }
 |