synpress icon indicating copy to clipboard operation
synpress copied to clipboard

cypress thinks that `cy.task('setupMetamask')` is not finished

Open fandrupaw opened this issue 3 years ago • 2 comments

I cannot run my tests cuz cypress thinks that cy.task('setupMetamask') is not finished Metamask setup goes smooth, then first test cannot start because cypress hangs on before all hook. Extending defaultCommandTimeout does not help

On the first run (just after install synpress) i got Cannot read property 'waitForTimeout' of undefined then error disappeared but above problem happen

image image image

1) Connect-view
       Connecting
         "before all" hook for "should login to app":
     CypressError: `cy.task('setupMetamask')` failed with the following error:

> waiting for function failed: timeout 30000ms exceeded

tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "baseUrl": "../../node_modules",
    "types": [
      "cypress",
      "@types/puppeteer-core",
      "@synthetixio/synpress/support",
      "cypress-wait-until",
      "@testing-library/cypress"
    ],
    "outDir": "./output",
    "lib": ["ESNext", "dom"]
  },
  "include": ["**/*.*"]
}

.env

PRIVATE_KEY=...

NETWORK_NAME=BSC-Testnet
RPC_URL=https://data-seed-prebsc-1-s1.binance.org:8545/
CHAIN_ID=97
SYMBOL=BNB
BLOCK_EXPLORER=https://testnet.bscscan.com/
IS_TESTNET=true

spec

import * as connectViewAction from '../../actions/connect-view-actions';

describe('Connect-view', () => {
  context('Connecting', () => {
    it('should login to app', () => {
      connectViewAction.connectViaMetamask();
    });
  });
});

...

export const connectViaMetamask = () => {
  navigationActions.goToConnectView();

  connectViewPage.getConnectViaMetamaskButton().click();

  cy.acceptMetamaskAccess().then(connected => {
    expect(connected).to.be.true;
  });
};

fandrupaw avatar Feb 01 '22 23:02 fandrupaw

looks like cypress has a problem with resolving promise from setupMetamask task

setupMetamask: async ({
  secretWordsOrPrivateKey,
  network = 'kovan',
  password,
}) => {
  if (process.env.NETWORK_NAME) {
    network = process.env.NETWORK_NAME;
  }
  if (process.env.PRIVATE_KEY) {
    secretWordsOrPrivateKey = process.env.PRIVATE_KEY;
  }
  if (process.env.SECRET_WORDS) {
    secretWordsOrPrivateKey = process.env.SECRET_WORDS;
  }
  await metamask.initialSetup({
    secretWordsOrPrivateKey,
    network,
    password,
  });
  return true;
},

fandrupaw avatar Feb 02 '22 10:02 fandrupaw

ok, after tons of debugging I found that setupMetamask is invoked twice, dunno why :/ I modified cypress/commands/metamask.js

let isInitialSetupDone = false;
...
initialSetup: async ({ secretWordsOrPrivateKey, network, password }) => {
    if (isInitialSetupDone) {
      console.log('Initial setup already done, skipping');
      return;
    }

    ...

fandrupaw avatar Feb 03 '22 11:02 fandrupaw

Hey, this is from old version of synpress.

Please, update to latest (@synthetixio/[email protected]) - this issue shouldn't exist.

Thanks!

drptbl avatar Oct 31 '22 12:10 drptbl