Skip to content

Commit 5d9bb0b

Browse files
feat: add more tests (#34)
1 parent 601c8fe commit 5d9bb0b

33 files changed

Lines changed: 2002 additions & 147 deletions

Cargo.lock

Lines changed: 95 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dom/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ repository.workspace = true
1010
version.workspace = true
1111

1212
[dependencies]
13-
aria-query = "0.0.4"
13+
aria-query = "0.0.5"
1414
dom-accessibility-api = "0.0.3"
1515
log.workspace = true
16+
ordered_hash_map = "0.4.0"
1617
paste = "1.0.15"
1718
pretty-format = { path = "../pretty-format", version = "0.0.1" }
1819
regex.workspace = true
1920
thiserror.workspace = true
2021
wasm-bindgen.workspace = true
2122
web-sys = { workspace = true, features = [
23+
"AddEventListenerOptions",
2224
"AnimationEvent",
2325
"AnimationEventInit",
2426
"Attr",
@@ -48,6 +50,8 @@ web-sys = { workspace = true, features = [
4850
"InputEventInit",
4951
"KeyboardEvent",
5052
"KeyboardEventInit",
53+
"MessageEvent",
54+
"MessageEventInit",
5155
"MouseEvent",
5256
"MouseEventInit",
5357
"NamedNodeMap",
@@ -75,7 +79,9 @@ web-sys = { workspace = true, features = [
7579
[dev-dependencies]
7680
indoc = "2.0.5"
7781
mockall = "0.13.0"
82+
pretty_assertions = "1.4.1"
7883
send_wrapper = "0.6.0"
84+
testing_logger = "0.1.1"
7985
wasm-bindgen-test.workspace = true
8086

8187
[lints.rust]

packages/dom/src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use crate::{
88

99
static CONFIG: LazyLock<Arc<Mutex<Config>>> = LazyLock::new(|| {
1010
Arc::new(Mutex::new(Config {
11-
test_id_attribute: "data-testid".into(),
11+
test_id_attribute: "data-testid".to_owned(),
1212
event_wrapper: Arc::new(|cb| cb()),
1313
default_hidden: false,
14-
default_ignore: "script, style".into(),
14+
default_ignore: "script, style".to_owned(),
1515
show_original_stack_trace: false,
1616
throw_suggestions: false,
1717
get_element_error: Arc::new(|message, container| {

packages/dom/src/dom_element_filter.rs

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ use regex::Regex;
55
use wasm_bindgen::{JsCast, JsValue};
66
use web_sys::{Comment, Element, Node, Text};
77

8-
use crate::util::{named_node_map_to_hashmap, node_list_to_vec};
8+
use crate::util::{named_node_map_to_hashmap, named_node_map_to_vec, node_list_to_vec};
99

1010
fn escape_html(text: String) -> String {
1111
text.replace('<', "&lt;").replace('>', "&gt;")
1212
}
1313

1414
fn print_props(
15-
attributes: HashMap<String, String>,
15+
keys: Vec<String>,
16+
props: HashMap<String, String>,
1617
config: &Config,
1718
indentation: String,
1819
depth: usize,
@@ -21,25 +22,26 @@ fn print_props(
2122
) -> String {
2223
let indentation_next = format!("{}{}", indentation, config.indent);
2324

24-
attributes
25-
.into_iter()
26-
.map(|(key, value)| {
27-
let printed = printer(
28-
&JsValue::from_str(&value),
29-
config,
30-
indentation_next.clone(),
31-
depth,
32-
refs.clone(),
33-
None,
34-
);
25+
keys.into_iter()
26+
.filter_map(|key| {
27+
props.get(&key).map(|value| {
28+
let printed = printer(
29+
&JsValue::from_str(value),
30+
config,
31+
indentation_next.clone(),
32+
depth,
33+
refs.clone(),
34+
None,
35+
);
3536

36-
format!(
37-
"{}{}{}={}",
38-
config.spacing_inner,
39-
indentation,
40-
config.colors.prop.paint(&key),
41-
config.colors.value.paint(&printed)
42-
)
37+
format!(
38+
"{}{}{}={}",
39+
config.spacing_inner,
40+
indentation,
41+
config.colors.prop.paint(&key),
42+
config.colors.value.paint(&printed)
43+
)
44+
})
4345
})
4446
.collect::<Vec<_>>()
4547
.join("")
@@ -67,7 +69,7 @@ fn print_children(
6769

6870
if printed_child.is_empty() && child.node_type() != Node::TEXT_NODE {
6971
// A plugin serialized this Node to '' meaning we should ignore it.
70-
"".into()
72+
"".to_owned()
7173
} else {
7274
format!("{}{}{}", config.spacing_outer, indentation, printed_child)
7375
}
@@ -99,7 +101,7 @@ fn print_element(
99101
"<{}{}{}>",
100102
r#type,
101103
if printed_props.is_empty() {
102-
"".into()
104+
"".to_owned()
103105
} else {
104106
format!(
105107
"{}{}{}{}{}",
@@ -112,9 +114,9 @@ fn print_element(
112114
},
113115
if printed_children.is_empty() {
114116
if !printed_props.is_empty() && !config.min {
115-
"/".into()
117+
"/".to_owned()
116118
} else {
117-
" /".into()
119+
" /".to_owned()
118120
}
119121
} else {
120122
format!(
@@ -207,7 +209,7 @@ impl Plugin for DomElementFilter {
207209
}
208210

209211
let r#type = if node_is_fragment(node) {
210-
"DocumentFragment".into()
212+
"DocumentFragment".to_owned()
211213
} else {
212214
node.unchecked_ref::<Element>().tag_name().to_lowercase()
213215
};
@@ -220,6 +222,19 @@ impl Plugin for DomElementFilter {
220222
print_element(
221223
r#type,
222224
print_props(
225+
if node_is_fragment(node) {
226+
vec![]
227+
} else {
228+
let mut keys =
229+
named_node_map_to_vec(node.unchecked_ref::<Element>().attributes())
230+
.into_iter()
231+
.map(|attr| attr.name())
232+
.collect::<Vec<_>>();
233+
234+
keys.sort();
235+
236+
keys
237+
},
223238
if node_is_fragment(node) {
224239
HashMap::new()
225240
} else {

packages/dom/src/events.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ use wasm_bindgen::JsValue;
33
use web_sys::{
44
AnimationEvent, AnimationEventInit, ClipboardEvent, ClipboardEventInit, CompositionEvent,
55
CompositionEventInit, DragEvent, DragEventInit, Event, EventInit, EventTarget, FocusEvent,
6-
FocusEventInit, InputEvent, InputEventInit, KeyboardEvent, KeyboardEventInit, MouseEvent,
7-
MouseEventInit, PageTransitionEvent, PageTransitionEventInit, PointerEvent, PointerEventInit,
8-
PopStateEvent, PopStateEventInit, ProgressEvent, ProgressEventInit, TouchEvent, TouchEventInit,
9-
TransitionEvent, TransitionEventInit, UiEvent, UiEventInit, WheelEvent, WheelEventInit,
6+
FocusEventInit, InputEvent, InputEventInit, KeyboardEvent, KeyboardEventInit, MessageEvent,
7+
MessageEventInit, MouseEvent, MouseEventInit, PageTransitionEvent, PageTransitionEventInit,
8+
PointerEvent, PointerEventInit, PopStateEvent, PopStateEventInit, ProgressEvent,
9+
ProgressEventInit, TouchEvent, TouchEventInit, TransitionEvent, TransitionEventInit, UiEvent,
10+
UiEventInit, WheelEvent, WheelEventInit,
1011
};
1112

1213
use crate::{
@@ -282,6 +283,7 @@ generate_event_types!(
282283
(FocusEvent, new_with_focus_event_init_dict),
283284
(InputEvent, new_with_event_init_dict),
284285
(KeyboardEvent, new_with_keyboard_event_init_dict),
286+
(MessageEvent, new_with_event_init_dict),
285287
(MouseEvent, new_with_mouse_event_init_dict),
286288
(PageTransitionEvent, new_with_event_init_dict),
287289
(PointerEvent, new_with_event_init_dict),

0 commit comments

Comments
 (0)