1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

Allow exporting state during e2e tests (#7860)

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.
This commit is contained in:
Mark Stacey 2020-01-17 18:59:25 -04:00 committed by GitHub
parent 3a2c81d8bc
commit 7b35ea6400
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 21 deletions

View File

@ -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)

View File

@ -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:
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
You can then paste the contents directly in your fixture file.
```js
// Step 1:
chrome.storage.local.get(null, (x) => console.log(x))
// Should print something like:
// > temp1
// > {data: {…}, meta: {…}}
// Step 2:
// Store the value as a global via the 'Store as global variable' option in context menu (shown below)
// Step 3:
copy(temp1)
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