test_action-clear-snapshots_04.js (1774B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test clearSnapshots deletes several snapshots 7 8 const { 9 takeSnapshotAndCensus, 10 clearSnapshots, 11 } = require("resource://devtools/client/memory/actions/snapshot.js"); 12 const { 13 snapshotState: states, 14 actions, 15 treeMapState, 16 } = require("resource://devtools/client/memory/constants.js"); 17 18 add_task(async function () { 19 const front = new StubbedMemoryFront(); 20 const heapWorker = new HeapAnalysesClient(); 21 await front.attach(); 22 const store = Store(); 23 const { getState, dispatch } = store; 24 25 ok(true, "create 3 snapshots with a saved census"); 26 dispatch(takeSnapshotAndCensus(front, heapWorker)); 27 dispatch(takeSnapshotAndCensus(front, heapWorker)); 28 dispatch(takeSnapshotAndCensus(front, heapWorker)); 29 await waitUntilCensusState(store, snapshot => snapshot.treeMap, [ 30 treeMapState.SAVED, 31 treeMapState.SAVED, 32 treeMapState.SAVED, 33 ]); 34 ok(true, "snapshots created with a saved census"); 35 36 ok(true, "set first snapshot state to error"); 37 const id = getState().snapshots[0].id; 38 dispatch({ type: actions.SNAPSHOT_ERROR, id, error: new Error("_") }); 39 await waitUntilSnapshotState(store, [states.ERROR, states.READ, states.READ]); 40 ok(true, "first snapshot set to error state"); 41 42 ok(true, "dispatch clearSnapshots action"); 43 const deleteEvents = Promise.all([ 44 waitForDispatch(store, actions.DELETE_SNAPSHOTS_START), 45 waitForDispatch(store, actions.DELETE_SNAPSHOTS_END), 46 ]); 47 dispatch(clearSnapshots(heapWorker)); 48 await deleteEvents; 49 ok(true, "received delete snapshots events"); 50 51 equal(getState().snapshots.length, 0, "no snapshot remaining"); 52 53 heapWorker.destroy(); 54 await front.detach(); 55 });