test_action-export-snapshot.js (1323B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test exporting a snapshot to a user specified location on disk. 7 8 const { 9 exportSnapshot, 10 } = require("resource://devtools/client/memory/actions/io.js"); 11 const { 12 takeSnapshotAndCensus, 13 } = require("resource://devtools/client/memory/actions/snapshot.js"); 14 const { 15 actions, 16 treeMapState, 17 } = require("resource://devtools/client/memory/constants.js"); 18 19 add_task(async function () { 20 const front = new StubbedMemoryFront(); 21 const heapWorker = new HeapAnalysesClient(); 22 await front.attach(); 23 const store = Store(); 24 const { getState, dispatch } = store; 25 26 const destPath = await createTempFile(); 27 dispatch(takeSnapshotAndCensus(front, heapWorker)); 28 await waitUntilCensusState(store, snapshot => snapshot.treeMap, [ 29 treeMapState.SAVED, 30 ]); 31 32 const exportEvents = Promise.all([ 33 waitForDispatch(store, actions.EXPORT_SNAPSHOT_START), 34 waitForDispatch(store, actions.EXPORT_SNAPSHOT_END), 35 ]); 36 dispatch(exportSnapshot(getState().snapshots[0], destPath)); 37 await exportEvents; 38 39 const stat = await IOUtils.stat(destPath); 40 info(stat.size); 41 Assert.greater(stat.size, 0, "destination file is more than 0 bytes"); 42 43 heapWorker.destroy(); 44 await front.detach(); 45 });