Skip to content

Commit 6cd3641

Browse files
authored
Merge branch 'dev' into phantom-e2e-tests
2 parents ccfa5e5 + 736f870 commit 6cd3641

File tree

24 files changed

+404
-96
lines changed

24 files changed

+404
-96
lines changed

examples/ethereum-wallet-mock/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# example-ethereum-wallet-mock
22

3+
## 0.0.9
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
- @synthetixio/synpress@4.0.8
9+
10+
## 0.0.8
11+
12+
### Patch Changes
13+
14+
- Updated dependencies
15+
- @synthetixio/synpress@4.0.7
16+
317
## 0.0.7
418

519
### Patch Changes

examples/ethereum-wallet-mock/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@examples/ethereum-wallet-mock",
3-
"version": "0.0.7",
3+
"version": "0.0.9",
44
"private": true,
55
"homepage": "https://synpress.io",
66
"repository": {
@@ -22,7 +22,7 @@
2222
},
2323
"devDependencies": {
2424
"@metamask/test-dapp": "8.1.0",
25-
"@synthetixio/synpress-tsconfig": "0.0.7",
25+
"@synthetixio/synpress-tsconfig": "0.0.9",
2626
"@types/node": "20.11.17",
2727
"cypress": "13.15.1",
2828
"serve": "14.2.1",

examples/metamask/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# example-metamask
22

3+
## 0.0.9
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
- @synthetixio/synpress@4.0.8
9+
10+
## 0.0.8
11+
12+
### Patch Changes
13+
14+
- Updated dependencies
15+
- @synthetixio/synpress@4.0.7
16+
317
## 0.0.7
418

519
### Patch Changes

examples/metamask/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@examples/metamask",
3-
"version": "0.0.7",
3+
"version": "0.0.9",
44
"private": true,
55
"homepage": "https://synpress.io",
66
"repository": {
@@ -26,7 +26,7 @@
2626
},
2727
"devDependencies": {
2828
"@metamask/test-dapp": "8.1.0",
29-
"@synthetixio/synpress-tsconfig": "0.0.7",
29+
"@synthetixio/synpress-tsconfig": "0.0.9",
3030
"@types/node": "20.11.17",
3131
"cypress": "13.15.1",
3232
"serve": "14.2.1",

packages/cache/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# @synthetixio/synpress-cache
22

3+
## 0.0.9
4+
5+
### Patch Changes
6+
7+
- Release
8+
9+
## 0.0.8
10+
11+
### Patch Changes
12+
13+
- Release
14+
315
## 0.0.7
416

517
### Patch Changes

packages/cache/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@synthetixio/synpress-cache",
3-
"version": "0.0.7",
3+
"version": "0.0.9",
44
"homepage": "https://synpress.io",
55
"repository": {
66
"type": "git",
@@ -49,7 +49,7 @@
4949
"zod": "3.22.4"
5050
},
5151
"devDependencies": {
52-
"@synthetixio/synpress-tsconfig": "0.0.7",
52+
"@synthetixio/synpress-tsconfig": "0.0.9",
5353
"@types/archiver": "6.0.2",
5454
"@types/fs-extra": "11.0.4",
5555
"@types/gradient-string": "1.1.5",

packages/cache/src/cli/cliEntrypoint.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from 'node:fs'
12
import os from 'node:os'
23
import path from 'node:path'
34
import chalk from 'chalk'
@@ -17,6 +18,16 @@ interface CliFlags {
1718
phantom: boolean
1819
}
1920

21+
// Helper function to check if running in WSL
22+
const isRunningInWsl = (): boolean => {
23+
try {
24+
const releaseContent = fs.readFileSync('/proc/version', 'utf8').toLowerCase()
25+
return releaseContent.includes('microsoft') || releaseContent.includes('wsl')
26+
} catch (error) {
27+
return false
28+
}
29+
}
30+
2031
// TODO: Add unit tests for the CLI!
2132
export const cliEntrypoint = async () => {
2233
console.log(`⚠️ ${chalk.yellowBright`The CLI is in alpha so expect breaking changes!`} ⚠️\n`)
@@ -61,7 +72,7 @@ export const cliEntrypoint = async () => {
6172
)
6273
}
6374

64-
if (os.platform() === 'win32') {
75+
if (os.platform() === 'win32' && !isRunningInWsl()) {
6576
console.log(
6677
[
6778
chalk.redBright('🚨 Sorry, Windows is currently not supported. Please use WSL instead! 🚨'),
Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,36 @@
11
import { type BrowserContext, errors as playwrightErrors } from 'playwright-core'
22

3+
const EXTENSION_LOAD_TIMEOUT = 10000
4+
const MAX_RETRIES = 2
5+
6+
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
7+
38
export async function waitForExtensionOnLoadPage(context: BrowserContext) {
4-
try {
5-
return await context.waitForEvent('page', { timeout: 5000 }) // TODO: Extract & Make this timeout configurable.
6-
} catch (e) {
7-
if (e instanceof playwrightErrors.TimeoutError) {
8-
throw new Error('[WaitForExtensionOnLoadPage] Extension did not load in time!')
9-
}
9+
let retries = 0
10+
11+
while (retries <= MAX_RETRIES) {
12+
try {
13+
// Attempt to wait for the extension to load
14+
return await context.waitForEvent('page', { timeout: EXTENSION_LOAD_TIMEOUT })
15+
} catch (e) {
16+
if (e instanceof playwrightErrors.TimeoutError) {
17+
retries++
1018

11-
throw e
19+
if (retries <= MAX_RETRIES) {
20+
console.warn(
21+
`[WaitForExtensionOnLoadPage] Extension did not load in time, retrying (attempt ${retries}/${MAX_RETRIES})...`
22+
)
23+
24+
await sleep(1000 * retries)
25+
continue
26+
}
27+
28+
throw new Error('[WaitForExtensionOnLoadPage] Extension failed to load after multiple attempts!')
29+
}
30+
throw e
31+
}
1232
}
33+
34+
// This should never be reached
35+
throw new Error('[WaitForExtensionOnLoadPage] Unexpected end of function reached')
1336
}

packages/cache/test/utils/waitForExtensionOnLoadPage.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ describe('waitForExtensionOnLoadPage', () => {
3434
await waitForExtensionOnLoadPage(context)
3535

3636
expect(waitForEventSpy).toHaveBeenCalledOnce()
37-
expect(waitForEventSpy).toHaveBeenCalledWith('page', { timeout: 5000 })
37+
expect(waitForEventSpy).toHaveBeenCalledWith('page', { timeout: 10000 })
3838
})
3939

4040
it('throws with custom error if waitForEvent throws due to timeout', async () => {
4141
const context = createTimeoutContext()
4242

4343
await expect(waitForExtensionOnLoadPage(context)).rejects.toThrowError(
44-
'[WaitForExtensionOnLoadPage] Extension did not load in time!'
44+
'[WaitForExtensionOnLoadPage] Extension failed to load after multiple attempts!'
4545
)
4646
})
4747

packages/core/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# @synthetixio/synpress-core
22

3+
## 0.0.9
4+
5+
### Patch Changes
6+
7+
- Release
8+
9+
## 0.0.8
10+
11+
### Patch Changes
12+
13+
- Release
14+
315
## 0.0.7
416

517
### Patch Changes

0 commit comments

Comments
 (0)