Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 95 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion packages/dom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ repository.workspace = true
version.workspace = true

[dependencies]
aria-query = "0.0.4"
aria-query = "0.0.5"
dom-accessibility-api = "0.0.3"
log.workspace = true
ordered_hash_map = "0.4.0"
paste = "1.0.15"
pretty-format = { path = "../pretty-format", version = "0.0.1" }
regex.workspace = true
thiserror.workspace = true
wasm-bindgen.workspace = true
web-sys = { workspace = true, features = [
"AddEventListenerOptions",
"AnimationEvent",
"AnimationEventInit",
"Attr",
Expand Down Expand Up @@ -48,6 +50,8 @@ web-sys = { workspace = true, features = [
"InputEventInit",
"KeyboardEvent",
"KeyboardEventInit",
"MessageEvent",
"MessageEventInit",
"MouseEvent",
"MouseEventInit",
"NamedNodeMap",
Expand Down Expand Up @@ -75,7 +79,9 @@ web-sys = { workspace = true, features = [
[dev-dependencies]
indoc = "2.0.5"
mockall = "0.13.0"
pretty_assertions = "1.4.1"
send_wrapper = "0.6.0"
testing_logger = "0.1.1"
wasm-bindgen-test.workspace = true

[lints.rust]
Expand Down
4 changes: 2 additions & 2 deletions packages/dom/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use crate::{

static CONFIG: LazyLock<Arc<Mutex<Config>>> = LazyLock::new(|| {
Arc::new(Mutex::new(Config {
test_id_attribute: "data-testid".into(),
test_id_attribute: "data-testid".to_owned(),
event_wrapper: Arc::new(|cb| cb()),
default_hidden: false,
default_ignore: "script, style".into(),
default_ignore: "script, style".to_owned(),
show_original_stack_trace: false,
throw_suggestions: false,
get_element_error: Arc::new(|message, container| {
Expand Down
65 changes: 40 additions & 25 deletions packages/dom/src/dom_element_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ use regex::Regex;
use wasm_bindgen::{JsCast, JsValue};
use web_sys::{Comment, Element, Node, Text};

use crate::util::{named_node_map_to_hashmap, node_list_to_vec};
use crate::util::{named_node_map_to_hashmap, named_node_map_to_vec, node_list_to_vec};

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

fn print_props(
attributes: HashMap<String, String>,
keys: Vec<String>,
props: HashMap<String, String>,
config: &Config,
indentation: String,
depth: usize,
Expand All @@ -21,25 +22,26 @@ fn print_props(
) -> String {
let indentation_next = format!("{}{}", indentation, config.indent);

attributes
.into_iter()
.map(|(key, value)| {
let printed = printer(
&JsValue::from_str(&value),
config,
indentation_next.clone(),
depth,
refs.clone(),
None,
);
keys.into_iter()
.filter_map(|key| {
props.get(&key).map(|value| {
let printed = printer(
&JsValue::from_str(value),
config,
indentation_next.clone(),
depth,
refs.clone(),
None,
);

format!(
"{}{}{}={}",
config.spacing_inner,
indentation,
config.colors.prop.paint(&key),
config.colors.value.paint(&printed)
)
format!(
"{}{}{}={}",
config.spacing_inner,
indentation,
config.colors.prop.paint(&key),
config.colors.value.paint(&printed)
)
})
})
.collect::<Vec<_>>()
.join("")
Expand Down Expand Up @@ -67,7 +69,7 @@ fn print_children(

if printed_child.is_empty() && child.node_type() != Node::TEXT_NODE {
// A plugin serialized this Node to '' meaning we should ignore it.
"".into()
"".to_owned()
} else {
format!("{}{}{}", config.spacing_outer, indentation, printed_child)
}
Expand Down Expand Up @@ -99,7 +101,7 @@ fn print_element(
"<{}{}{}>",
r#type,
if printed_props.is_empty() {
"".into()
"".to_owned()
} else {
format!(
"{}{}{}{}{}",
Expand All @@ -112,9 +114,9 @@ fn print_element(
},
if printed_children.is_empty() {
if !printed_props.is_empty() && !config.min {
"/".into()
"/".to_owned()
} else {
" /".into()
" /".to_owned()
}
} else {
format!(
Expand Down Expand Up @@ -207,7 +209,7 @@ impl Plugin for DomElementFilter {
}

let r#type = if node_is_fragment(node) {
"DocumentFragment".into()
"DocumentFragment".to_owned()
} else {
node.unchecked_ref::<Element>().tag_name().to_lowercase()
};
Expand All @@ -220,6 +222,19 @@ impl Plugin for DomElementFilter {
print_element(
r#type,
print_props(
if node_is_fragment(node) {
vec![]
} else {
let mut keys =
named_node_map_to_vec(node.unchecked_ref::<Element>().attributes())
.into_iter()
.map(|attr| attr.name())
.collect::<Vec<_>>();

keys.sort();

keys
},
if node_is_fragment(node) {
HashMap::new()
} else {
Expand Down
10 changes: 6 additions & 4 deletions packages/dom/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ use wasm_bindgen::JsValue;
use web_sys::{
AnimationEvent, AnimationEventInit, ClipboardEvent, ClipboardEventInit, CompositionEvent,
CompositionEventInit, DragEvent, DragEventInit, Event, EventInit, EventTarget, FocusEvent,
FocusEventInit, InputEvent, InputEventInit, KeyboardEvent, KeyboardEventInit, MouseEvent,
MouseEventInit, PageTransitionEvent, PageTransitionEventInit, PointerEvent, PointerEventInit,
PopStateEvent, PopStateEventInit, ProgressEvent, ProgressEventInit, TouchEvent, TouchEventInit,
TransitionEvent, TransitionEventInit, UiEvent, UiEventInit, WheelEvent, WheelEventInit,
FocusEventInit, InputEvent, InputEventInit, KeyboardEvent, KeyboardEventInit, MessageEvent,
MessageEventInit, MouseEvent, MouseEventInit, PageTransitionEvent, PageTransitionEventInit,
PointerEvent, PointerEventInit, PopStateEvent, PopStateEventInit, ProgressEvent,
ProgressEventInit, TouchEvent, TouchEventInit, TransitionEvent, TransitionEventInit, UiEvent,
UiEventInit, WheelEvent, WheelEventInit,
};

use crate::{
Expand Down Expand Up @@ -282,6 +283,7 @@ generate_event_types!(
(FocusEvent, new_with_focus_event_init_dict),
(InputEvent, new_with_event_init_dict),
(KeyboardEvent, new_with_keyboard_event_init_dict),
(MessageEvent, new_with_event_init_dict),
(MouseEvent, new_with_mouse_event_init_dict),
(PageTransitionEvent, new_with_event_init_dict),
(PointerEvent, new_with_event_init_dict),
Expand Down
Loading