Skip to content

Commit 48e2a8a

Browse files
authored
fix(dapp): avoid tests failing when connecting wallet (#1159)
* fix(dapp): avoid tests failing when connecting wallet * fix: add missing dotenv config
1 parent 06f3718 commit 48e2a8a

File tree

8 files changed

+31
-28
lines changed

8 files changed

+31
-28
lines changed

dapp/playwright.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
import path from 'path';
12
import { defineConfig, devices } from '@playwright/test';
3+
import dotenv from 'dotenv';
4+
5+
dotenv.config({ path: path.resolve(__dirname, '.env') });
6+
dotenv.config({ path: path.resolve(__dirname, '.env.local'), override: true });
27

38
/**
49
* See https://playwright.dev/docs/test-configuration.

dapp/scripts/downloadWallet.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import dotenv from 'dotenv';
99
const __filename = fileURLToPath(import.meta.url);
1010
const __dirname = dirname(__filename);
1111

12-
dotenv.config({ path: join(__dirname, '../.env') });
12+
dotenv.config({ path: join(__dirname, '.env') });
13+
dotenv.config({ path: join(__dirname, '.env.local'), override: true });
1314

1415
const token = process.env.GITHUB_TOKEN;
1516

dapp/tests/auctions/auctions.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) 2025 IOTA Stiftung
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import 'dotenv/config';
5-
64
import { normalizeIotaName } from '@iota/iota-names-sdk';
75
import { Ed25519Keypair } from '@iota/iota-sdk/keypairs/ed25519';
86
import { formatAddress } from '@iota/iota-sdk/utils';

dapp/tests/common/basic.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Copyright (c) 2025 IOTA Stiftung
22
// SPDX-License-Identifier: Apache-2.0
3-
import 'dotenv/config';
4-
53
import { CONFIG } from '@/config';
64

75
import { expect, test } from '../helpers/fixtures';

dapp/tests/setup/auctions.setup.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Copyright (c) 2025 IOTA Stiftung
22
// SPDX-License-Identifier: Apache-2.0
3-
import 'dotenv/config';
4-
53
import { test as setup } from '@playwright/test';
64

75
import { toggleSmartContractMode } from './toggleSmartContract';

dapp/tests/setup/purchase.setup.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) 2025 IOTA Stiftung
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import 'dotenv/config';
5-
64
import { test as setup } from '@playwright/test';
75

86
import { toggleSmartContractMode } from './toggleSmartContract';

dapp/tests/setup/utils.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) 2025 IOTA Stiftung
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import 'dotenv/config';
5-
64
import { IotaClientGraphQLTransport } from '@iota/graphql-transport';
75
import { IotaNamesClient } from '@iota/iota-names-sdk';
86
import { getNetwork, IotaClient } from '@iota/iota-sdk/client';

dapp/tests/utils.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
// Copyright (c) 2025 IOTA Stiftung
22
// SPDX-License-Identifier: Apache-2.0
3-
import { getNetwork } from '@iota/iota-sdk/client';
4-
import { requestIotaFromFaucetV0 } from '@iota/iota-sdk/faucet';
5-
import { Ed25519Keypair } from '@iota/iota-sdk/keypairs/ed25519';
6-
import type { BrowserContext, Page } from '@playwright/test';
7-
8-
import 'dotenv/config';
9-
103
import { execFileSync } from 'child_process';
114
import { IotaNamesTransaction, isSubname, NameRecord } from '@iota/iota-names-sdk';
5+
import { getNetwork } from '@iota/iota-sdk/client';
126
import type { Signer } from '@iota/iota-sdk/cryptography';
7+
import { requestIotaFromFaucetV0 } from '@iota/iota-sdk/faucet';
8+
import { Ed25519Keypair } from '@iota/iota-sdk/keypairs/ed25519';
139
import { Transaction } from '@iota/iota-sdk/transactions';
1410
import { NANOS_PER_IOTA } from '@iota/iota-sdk/utils';
11+
import type { BrowserContext, Page } from '@playwright/test';
1512

1613
import { buildCreateAuctionTransaction, buildPlaceBidTransaction } from '@/auctions';
1714
import { CONFIG } from '@/config';
@@ -23,17 +20,27 @@ export async function connectWallet(page: Page, context: BrowserContext, extensi
2320
await page.getByRole('button', { name: /Connect/i }).click();
2421

2522
const pagePromise = context.waitForEvent('page', { timeout: 20_000 });
26-
const walletButton = page.getByText(new RegExp(extensionName, 'i'));
27-
28-
await walletButton.click();
23+
await page.getByText(extensionName, { exact: true }).click();
2924
const walletApprovePage = await pagePromise;
30-
if (walletApprovePage) {
31-
await walletApprovePage.waitForLoadState('domcontentloaded');
32-
await walletApprovePage.bringToFront();
33-
await walletApprovePage.getByRole('button', { name: /Continue/i }).click();
34-
await walletApprovePage.getByRole('button', { name: /Connect/i }).click();
35-
await page.bringToFront();
36-
}
25+
26+
await walletApprovePage.waitForLoadState('load');
27+
await walletApprovePage.bringToFront();
28+
29+
await walletApprovePage.getByRole('button', { name: 'Continue' }).click();
30+
31+
await Promise.race([
32+
walletApprovePage
33+
.getByRole('button', { name: 'Connect' })
34+
.click()
35+
.catch(() => {}),
36+
walletApprovePage.waitForEvent('close'),
37+
]);
38+
39+
await page.bringToFront();
40+
41+
await expect(page.getByRole('button', { name: 'Connect' })).not.toBeVisible({
42+
timeout: 5_000,
43+
});
3744
}
3845

3946
export async function createWallet(page: Page) {

0 commit comments

Comments
 (0)