#![cfg(all(feature = "devtools", debug_assertions))]
use std::time::Duration;
mod common;
use common::Js;
const APP: &str = r#"
const ops = Deno.core.ops;
ops.op_flush(JSON.stringify([
{ op: "create", id: 1, kind: "node", props: { style: { width: "aa16" } } },
{ op: "append", parent: 0, child: 1 },
{ op: "update", id: 2, kind: "node", props: { style: { display: "flexx", padding: "1px bogus" } } },
{ op: "update", id: 3, kind: "node", props: { style: { backgroundImage: { src: "x.png", mode: "tile" } } } },
{ op: "update", id: 4, kind: "node", props: { src: "a.png" } },
{ op: "update", id: 5, kind: "image", props: { src: "a.png" } },
]), false);
ops.op_emit("decodeWarnings", ops.op_take_decode_warnings());
"#;
#[test]
fn decode_warnings_round_trip() {
let js = Js::spawn("decode_warnings", APP);
let batch = js
.ops
.recv_timeout(Duration::from_secs(15))
.expect("no op batch from the JS thread");
assert_eq!(batch.len(), 6, "fallback decoding must not drop ops");
let warnings = js.emitted("decodeWarnings", Duration::from_secs(15));
let brief: Vec<(Option<u64>, &str, &str)> = warnings
.as_array()
.expect("warnings must be an array")
.iter()
.map(|w| {
(
w["node"].as_u64(),
w["kind"].as_str().unwrap_or(""),
w["value"].as_str().unwrap_or(""),
)
})
.collect();
assert_eq!(
brief,
vec![
(Some(1), "length", "aa16"),
(Some(2), "display", "flexx"),
(Some(2), "rect", "bogus"),
(Some(3), "backgroundImage", "tile"),
(Some(4), "unknownProp", "src"),
],
"the op decode must attribute each warning to its op's node"
);
eprintln!("PASS decode warnings end-to-end: {brief:?}");
}