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