refactor(fs)!: drop notify's serialization-compat-6, flatten WatchEvent (#3609)

`WatchEvent` now follows notify v8's format: the event kind is flattened
into the event, with `type` holding the top-level kind and `kind`/`mode`
refining it, e.g. `{ type: 'modify', kind: 'data', mode: 'content' }`
instead of `{ type: { modify: { kind: 'data', mode: 'content' } } }`.
`attrs` is now typed as `WatchEventAttributes` and its `flag` is
`rescan` instead of `Rescan`.
This commit is contained in:
Lucas Fernandes Nogueira
2026-09-22 06:05:51 -03:00
committed by GitHub
parent a315a07f36
commit 8083107a0a
4 changed files with 81 additions and 14 deletions
+31
View File
@@ -102,3 +102,34 @@ pub fn watch<R: Runtime>(
Ok(rid)
}
#[cfg(test)]
mod tests {
use notify::{
event::{DataChange, ModifyKind},
Event, EventKind,
};
// the `WatchEvent` type of the JavaScript API relies on this format
#[test]
fn event_kind_is_flattened_into_the_event() {
let event = Event::new(EventKind::Modify(ModifyKind::Data(DataChange::Content)))
.add_path("/tmp/file".into());
assert_eq!(
serde_json::to_value(event).unwrap(),
serde_json::json!({
"type": "modify",
"kind": "data",
"mode": "content",
"paths": ["/tmp/file"],
"attrs": {}
})
);
let event = Event::new(EventKind::Any);
assert_eq!(
serde_json::to_value(event).unwrap(),
serde_json::json!({ "type": "any", "paths": [], "attrs": {} })
);
}
}