Assert empty maps when there are no roots
Dan Abramov committed
Apr 26, 2019 at 17:47 UTC
b6a55989f50d21bd916049888c81a311589c6168
2 files changed
+29
src/__tests__/storeSerializer.js
+4
@@ -70,5 +70,9 @@ export function printStore(store, includeWeight = false) {
70
);
71
}
72
73
+ if (store.roots.length === 0) {
74
+ store.assertEmptyMaps();
75
+ }
76
+
77
return snapshotLines.join('\n');
78
}
src/devtools/store.js
+25
@@ -179,6 +179,31 @@ export default class Store extends EventEmitter {
179
this._profilingCache = new ProfilingCache(bridge, this);
180
}
181
182
+ assertEmptyMaps() {
183
+ // This is only used in tests to avoid memory leaks.
184
+ if (this._idToElement.size !== 0) {
185
+ throw new Error('Expected _idToElement to be empty.');
186
+ }
187
+ if (this._ownersMap.size !== 0) {
188
+ throw new Error('Expected _ownersMap to be empty.');
189
+ }
190
+ if (this._profilingOperations.size !== 0) {
191
+ throw new Error('Expected _profilingOperations to be empty.');
192
+ }
193
+ if (this._profilingScreenshots.size !== 0) {
194
+ throw new Error('Expected _profilingScreenshots to be empty.');
195
+ }
196
+ if (this._profilingSnapshot.size !== 0) {
197
+ throw new Error('Expected _profilingSnapshot to be empty.');
198
+ }
199
+ if (this._rootIDToCapabilities.size !== 0) {
200
+ throw new Error('Expected _rootIDToCapabilities to be empty.');
201
+ }
202
+ if (this._rootIDToRendererID.size !== 0) {
203
+ throw new Error('Expected _rootIDToRendererID to be empty.');
204
+ }
205
+ }
206
+
207
get captureScreenshots(): boolean {
208
return this._captureScreenshots;
209
}