Synthetixio / synpress

Synpress is e2e testing framework based on Cypress.io and playwright with support for metamask.
https://synpress.io
611 stars 195 forks source link

Typescript migration #180

Open anthanh opened 3 years ago

anthanh commented 3 years ago

Would be nice to have typescript support

DaRabus commented 1 year ago

Is there a type library already?

I checked but couldn't find any typings, so there is no proper way right now to use it with playwright in typescript?

Edit: Ok found this:https://github.com/CryptKeeperZK/crypt-keeper-extension/blob/master/packages/e2e/%40types/synpress.d.ts

joelamouche commented 1 year ago

Is there a more complete type document?

joelamouche commented 1 year ago

I wrote this thanks to chatGPT, but I can't figure out how to get ts to use it:

import type { BrowserType } from "@playwright/test";

declare module "@synthetixio/synpress/helpers" {
  export function prepareMetamask(version: string): Promise<string>;
}
declare module "@synthetixio/synpress/commands/playwright" {
  export function setExpectInstance(expect: Expect): Promise<void>;
}

type AcceptAccessOptions = {
  allAccounts?: boolean;
  signInSignature?: boolean;
  confirmSignatureRequest?: boolean;
  confirmDataSignatureRequest?: boolean;
};
type Network = {
  name: string;
  rpcUrl: string;
  chainId: number;
  symbol: string;
  isTestnet?: boolean;
  blockExplorer?: string;
};

declare module "@synthetixio/synpress/commands/metamask" {
  export function acceptAccess(options?: AcceptAccessOptions): Promise<boolean>;

  export function initialSetup(
    browser: BrowserType,
    options: {
      secretWordsOrPrivateKey: string;
      network: Network;
      password: string;
      enableAdvancedSettings: boolean;
    },
  ): Promise<void>;
  export function addNetwork(network: string | Network): Promise<boolean>;
  export function changeNetwork(network: string | Network): Promise<boolean>;
  export function confirmSignatureRequest(): Promise<boolean>;
}