mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-22 21:30:44 +02:00
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:
@@ -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": {} })
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user