Skip to content

Commit

Permalink
Allow exporting state during e2e tests (#7860)
Browse files Browse the repository at this point in the history
As of #7663, an in-memory store was used in place of local storage
during e2e tests, to facilitate the use of state fixtures. However,
this made it difficult to export state during a test run. The
instructions for exporting state to create fixtures assumed that local
storage was being used.

A new global function has been added to the background context to allow
exporting state. This method is available during testing and
development, and it works with either local storage or the in-memory
store. The fixture instructions have been updated to reference this new
function.
  • Loading branch information
Gudahtt authored Jan 17, 2020
1 parent 3a2c81d commit 7b35ea6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
4 changes: 4 additions & 0 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ const localStore = inTest
: new LocalStore()
let versionedData

if (inTest || process.env.METAMASK_DEBUG) {
global.metamaskGetState = localStore.get.bind(localStore)
}

// initialization flow
initialize().catch(log.error)

Expand Down
27 changes: 7 additions & 20 deletions test/e2e/fixtures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,17 @@ one thing:

## Generating fixture data

Fixture data can be generated by loading the unpacked extension, inspecting the background context,
dumping `chrome.storage.local`, and using [`copy`][1] to copy it to the clipboard, and manually pasting the contents into
a file on disk.
Fixture data can be generated by following these steps:

```js
// Step 1:
chrome.storage.local.get(null, (x) => console.log(x))
// Should print something like:
// > temp1
// > {data: {…}, meta: {…}}
1. Load the unpacked extension in development or test mode
2. Inspecting the background context of the extension
3. Call `metamaskGetState`, then call [`copy`][1] on the results

// Step 2:
// Store the value as a global via the 'Store as global variable' option in context menu (shown below)
You can then paste the contents directly in your fixture file.

// Step 3:
copy(temp1)
```js
copy(await metamaskGetState())
```

Store the value as a global variable:

<img
width="840"
alt="Store as global variable"
src="https://user-images.githubusercontent.com/1623628/60987884-1a2c4a00-a31d-11e9-932e-b7fab452e6bd.png"
/>

[1]:https://developers.google.com/web/tools/chrome-devtools/console/utilities

0 comments on commit 7b35ea6

Please sign in to comment.