work on fixing some core tests

This commit is contained in:
Evan Almloff committed 2024-01-10 19:21:15 -06:00
1 parent 4a1a00b0f0
commit 55f76fede6
35 files changed
+422 -460

No files matched your search

+1
View File
@@ -326,6 +326,7 @@ pub enum Mutation {
}
/// A static list of mutations that can be applied to the DOM. Note: this list does not contain any `Any` attribute values
#[derive(Debug, PartialEq, Default)]
pub struct MutationsVec {
/// The list of Scopes that were diffed, created, and removed during the Diff process.
pub dirty_scopes: FxHashSet<ScopeId>,
+1 -1
View File
@@ -10,7 +10,7 @@ use std::{cell::Ref, fmt::Debug, rc::Rc};
/// time for any logic that relies on these IDs to properly update.
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
pub struct ScopeId(pub(crate) usize);
pub struct ScopeId(pub usize);
impl ScopeId {
/// The root ScopeId.
+29 -2
View File
@@ -13,7 +13,7 @@ use crate::{
nodes::{Template, TemplateId},
runtime::{Runtime, RuntimeGuard},
scopes::{ScopeId, ScopeState},
AttributeValue, Element, Event,
AttributeValue, Element, Event, MutationsVec,
};
use futures_util::{pin_mut, StreamExt};
use rustc_hash::{FxHashMap, FxHashSet};
@@ -300,7 +300,7 @@ impl VirtualDom {
/// Get the single scope at the top of the VirtualDom tree that will always be around
///
/// This scope has a ScopeId of 0 and is the root of the tree
pub(crate) fn base_scope(&self) -> &ScopeState {
pub fn base_scope(&self) -> &ScopeState {
self.get_scope(ScopeId::ROOT).unwrap()
}
@@ -563,6 +563,14 @@ impl VirtualDom {
to.append_children(ElementId(0), m);
}
#[cfg(features = "internal-testing")]
/// [`VirtualDom::rebuild`] to a vector of mutations for testing purposes
pub fn rebuild_to_vec(&mut self) -> MutationsVec {
let mut mutations = MutationsVec::default();
self.rebuild(&mut mutations);
mutations
}
/// Render whatever the VirtualDom has ready as fast as possible without requiring an executor to progress
/// suspended subtrees.
pub fn render_immediate(&mut self, to: &mut impl WriteMutations) {
@@ -582,6 +590,14 @@ impl VirtualDom {
}
}
#[cfg(features = "internal-testing")]
/// [`Self::render_immediate`] to a vector of mutations for testing purposes
pub fn render_immediate_to_vec(&mut self) -> MutationsVec {
let mut mutations = MutationsVec::default();
self.render_immediate(&mut mutations);
mutations
}
/// Render the virtual dom, waiting for all suspense to be finished
///
/// The mutations will be thrown out, so it's best to use this method for things like SSR that have async content
@@ -646,6 +662,17 @@ impl VirtualDom {
}
}
#[cfg(features = "internal-testing")]
/// [`Self::render_with_deadline`] to a vector of mutations for testing purposes
pub async fn render_with_deadline_to_vec(
&mut self,
deadline: impl Future<Output = ()>,
) -> MutationsVec {
let mut mutations = MutationsVec::default();
self.render_with_deadline(deadline, &mut mutations).await;
mutations
}
/// Get the current runtime
pub fn runtime(&self) -> Rc<Runtime> {
self.runtime.clone()