Skip to content

Commit

Permalink
feat(ui-tests): cover ethers (#1646)
Browse files Browse the repository at this point in the history
  • Loading branch information
arein committed Dec 21, 2023
1 parent 1a95822 commit 08f3909
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
27 changes: 19 additions & 8 deletions apps/laboratory/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { defineConfig, devices } from '@playwright/test'
import { LOCAL_LABS_URL } from './tests/shared/constants'
import { BASE_URL } from './tests/shared/constants'

import { config } from 'dotenv'
import type { ModalFixture } from './tests/shared/fixtures/w3m-fixture'
config({ path: './.env.local' })

export default defineConfig({
export default defineConfig<ModalFixture>({
testDir: './tests',

fullyParallel: true,
Expand All @@ -19,7 +20,7 @@ export default defineConfig({

use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: LOCAL_LABS_URL,
baseURL: BASE_URL,

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
Expand All @@ -30,20 +31,30 @@ export default defineConfig({
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] }
name: 'chromium/wagmi',
use: { ...devices['Desktop Chrome'], library: 'wagmi' }
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] }
name: 'firefox/wagmi',
use: { ...devices['Desktop Firefox'], library: 'wagmi' }
},

{
name: 'chromium/ethers',
use: { ...devices['Desktop Chrome'], library: 'ethers' }
},

{
name: 'firefox/ethers',
use: { ...devices['Desktop Firefox'], library: 'ethers' }
}
],

/* Run your local dev server before starting the tests */
webServer: {
command: 'npm run playwright:start',
url: LOCAL_LABS_URL,
url: BASE_URL,
reuseExistingServer: !process.env['CI']
}
})
2 changes: 1 addition & 1 deletion apps/laboratory/tests/shared/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { SessionParams } from '../types'

// Allow localhost
export const LOCAL_LABS_URL = 'http://localhost:3000/library/wagmi/'
export const BASE_URL = 'http://localhost:3000/'
export const WALLET_URL = 'https://react-wallet.walletconnect.com/'
export const DEFAULT_SESSION_PARAMS: SessionParams = {
reqAccounts: ['1', '2'],
Expand Down
8 changes: 5 additions & 3 deletions apps/laboratory/tests/shared/fixtures/w3m-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import { ModalPage } from '../pages/ModalPage'
import { ModalValidator } from '../validators/ModalValidator'

// Declare the types of fixtures to use
interface ModalFixture {
export interface ModalFixture {
modalPage: ModalPage
modalValidator: ModalValidator
library: string
}

// M -> test Modal
export const testM = base.extend<ModalFixture>({
modalPage: async ({ page }, use) => {
const modalPage = new ModalPage(page)
library: ['wagmi', { option: true }],
modalPage: async ({ page, library }, use) => {
const modalPage = new ModalPage(page, library)
await modalPage.load()
await use(modalPage)
},
Expand Down
13 changes: 8 additions & 5 deletions apps/laboratory/tests/shared/pages/ModalPage.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import type { Locator, Page } from '@playwright/test'
import { LOCAL_LABS_URL } from '../constants'
import { BASE_URL } from '../constants'

export class ModalPage {
private readonly baseURL = LOCAL_LABS_URL
private readonly baseURL = BASE_URL

private readonly connectButton: Locator

constructor(public readonly page: Page) {
constructor(
public readonly page: Page,
public readonly library: string
) {
this.connectButton = this.page.getByText('Connect Wallet')
}

async load() {
await this.page.goto(this.baseURL)
await this.page.goto(`${this.baseURL}library/${this.library}/`)
}

async copyConnectUriToClipboard() {
await this.page.goto(this.baseURL)
await this.page.goto(`${this.baseURL}library/${this.library}/`)
await this.connectButton.click()
await this.page.getByText('WalletConnect').click()
await this.page.waitForTimeout(2000)
Expand Down
3 changes: 2 additions & 1 deletion dangerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,9 @@ checkSdkVersion()
async function checkDevelopmentConstants() {
for (const f of updated_files) {
const diff = await diffForFile(f)
const fileContent = await danger.github.utils.fileContents(f)

if (diff?.added.includes('localhost:') && !diff?.added.includes('// Allow localhost')) {
if (diff?.added.includes('localhost:') && !fileContent.includes('// Allow localhost')) {
fail(`${f} uses localhost: which is likely a mistake`)
}
}
Expand Down

3 comments on commit 08f3909

@vercel
Copy link

@vercel vercel bot commented on 08f3909 Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 08f3909 Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 08f3909 Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.