Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow exporting state during e2e tests #7860

Merged
merged 1 commit into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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