dappress 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/metamask.js +37 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dappress",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "MetaMask automation for Cypress: load the real extension, import a test wallet, answer dapp requests with cy.* commands. Tracks the latest MetaMask release.",
5
5
  "license": "MIT",
6
6
  "author": "Benjamin Lassaut",
package/src/metamask.js CHANGED
@@ -191,7 +191,9 @@ function approveNetworkChange(page, timeout) {
191
191
  * Press a footer button, then wait for the confirmation to go away: the
192
192
  * popup closes, the side panel goes back to the home screen. A click that
193
193
  * lands while the confirmation is still settling is lost, so the click is
194
- * repeated while the button stays.
194
+ * repeated while the button stays. If it stays anyway, the error says
195
+ * whether it is the same request or a new one the dapp sent meanwhile, and
196
+ * what MetaMask logged.
195
197
  */
196
198
  async function pressAndWaitForDismissal(page, button, timeout) {
197
199
  await waitFor(page, button, { timeout });
@@ -199,14 +201,41 @@ async function pressAndWaitForDismissal(page, button, timeout) {
199
201
  if (await isVisible(page, selectors.confirmation.scrollToBottom, 500)) {
200
202
  await click(page, selectors.confirmation.scrollToBottom);
201
203
  }
202
- await clickWhenEnabled(page, button);
203
- for (let attempt = 0; attempt < 3; attempt++) {
204
- if (await isVisible(page, selectors.alert.acknowledge, 500)) await click(page, selectors.alert.acknowledge);
205
- if (await isGone(page, button, 3000)) return;
206
- await dismissModal(page);
207
- await dispatchClick(page, button, { timeout: 3000 }).catch(() => {});
204
+ const logged = recordErrors(page);
205
+ const request = page.url();
206
+ try {
207
+ await clickWhenEnabled(page, button);
208
+ for (let attempt = 0; attempt < 3; attempt++) {
209
+ if (await isVisible(page, selectors.alert.acknowledge, 500)) await click(page, selectors.alert.acknowledge);
210
+ if (await isGone(page, button, 3000)) return;
211
+ await dismissModal(page);
212
+ await dispatchClick(page, button, { timeout: 3000 }).catch(() => {});
213
+ }
214
+ const what = page.url() === request ? 'MetaMask kept the same request open' : 'MetaMask shows a new request: the dapp asked again';
215
+ const distinct = [...new Set(logged.errors)].slice(-3);
216
+ const errors = distinct.length ? `MetaMask logged: ${distinct.join(' | ')}` : 'MetaMask logged no error';
217
+ throw await failure(page, `"${describe(button)}" is still showing after being clicked. ${what}. ${errors}`);
218
+ } finally {
219
+ logged.stop();
208
220
  }
209
- throw await failure(page, `"${describe(button)}" is still showing after being clicked`);
221
+ }
222
+
223
+ /** Collect the errors MetaMask's page logs to its console, until stop(). */
224
+ function recordErrors(page) {
225
+ const errors = [];
226
+ const onConsole = (message) => {
227
+ if (message.type() === 'error') errors.push(message.text().slice(0, 300));
228
+ };
229
+ const onPageError = (error) => errors.push(String(error.message || error).slice(0, 300));
230
+ page.on('console', onConsole);
231
+ page.on('pageerror', onPageError);
232
+ return {
233
+ errors,
234
+ stop() {
235
+ page.off('console', onConsole);
236
+ page.off('pageerror', onPageError);
237
+ },
238
+ };
210
239
  }
211
240
 
212
241
  /** Close a modal shown over the confirmation (Escape, or its last button: "Cancel"). */