Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/optional cache #1177

Draft
wants to merge 35 commits into
base: new-dawn
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a2356f3
optional tagging setuo
Seroxdesign Jun 25, 2024
ffdee82
add cache check in fixture
Seroxdesign Jun 25, 2024
c8c0a26
do prep for cacheless download
Seroxdesign Jun 25, 2024
5417bdf
do prep for cacheless download
Seroxdesign Jun 25, 2024
d212b1b
cacheless fixture testing
Seroxdesign Jun 25, 2024
f591851
gitignore
Seroxdesign Jun 25, 2024
4e32ab5
load extension zip correctly
Seroxdesign Jun 26, 2024
bfac707
done
Seroxdesign Jun 26, 2024
172e2bd
cacheless import working
Seroxdesign Jun 26, 2024
ec6cff0
make compatible with windows
Seroxdesign Jun 26, 2024
a1d54b5
clean up, cache/cli message
Seroxdesign Jun 26, 2024
7600801
linting
Seroxdesign Jun 26, 2024
b06ef88
usecache setup
Seroxdesign Jun 27, 2024
018d040
cleaning up expanding fixture flow for cacheless setup
Seroxdesign Jun 27, 2024
f8f353b
fix an issue with async unzip
Seroxdesign Jun 27, 2024
f31b14a
clean up and solve most other text
Seroxdesign Jun 27, 2024
f790c24
skip broken tests
Seroxdesign Jun 28, 2024
4a2dc79
resolve sec issue, clean up
Seroxdesign Jun 28, 2024
69ace91
merge
Seroxdesign Jun 28, 2024
3ad020e
merge
Seroxdesign Jun 28, 2024
627f3b4
useCache
Seroxdesign Jun 28, 2024
31b6976
imports
Seroxdesign Jun 28, 2024
ef4d995
fix issues for review
Seroxdesign Jul 1, 2024
8700fbc
Merge branch 'new-dawn' into feat/optional-cache
Seroxdesign Jul 1, 2024
8d58391
Merge branch 'new-dawn' into feat/optional-cache
Seroxdesign Jul 1, 2024
694c270
review changes
Seroxdesign Jul 3, 2024
0a2e392
Merge branch 'new-dawn' into feat/optional-cache
Seroxdesign Jul 5, 2024
30fadc9
lint
Seroxdesign Jul 5, 2024
05506de
lint
Seroxdesign Jul 5, 2024
1834f10
irg
Seroxdesign Jul 5, 2024
8f83ea3
console r
Seroxdesign Jul 5, 2024
8c57cd9
Merge branch 'new-dawn' into feat/optional-cache
Seroxdesign Jul 5, 2024
0044dd0
docs
Seroxdesign Jul 9, 2024
02d451e
✨ feat: Run on windows with cache (#1161)
Seroxdesign Jul 9, 2024
8457a41
Merge branch 'new-dawn-dev' into feat/optional-cache
Seroxdesign Jul 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ playwright/.cache

**/ethereum-wallet-mock/cypress
**/metamask/cypress

### Cacheless

**/metamask/downloads
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"**/test-results",
"**/playwright-report",
"**/.cache-synpress",
"**/.vitepress/cache"
"**/.vitepress/cache",
"**/downloads"
]
},
"formatter": {
Expand Down
9 changes: 1 addition & 8 deletions docs/docs/platform-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
While in **alpha**, the compatibility of Synpress is limited, but we're working hard to support more frameworks and platforms as soon as possible.
:::

Synpress, in its current state, is only compatible with Playwright (>=1.39.0) and requires Node 18+. Synpress is compatible with MacOS and Linux.
Synpress, in its current state, is only compatible with Playwright (>=1.39.0) and requires Node 18+. Synpress is compatible with MacOS, Windows, and Linux.

## Supported CI Providers

Expand All @@ -17,10 +17,3 @@ See the [CI](./guides/ci) section for more information about how to set up Synpr
:::

- [GitHub Actions](https://github.com/features/actions)

## Windows

Currently, Synpress is not compatible with Windows. In the meantime, we recommend using WSL.
::: tip NOTE
If you're knowledgeable about working with Windows and the Node.js environment, and you'd like to help us make Synpress compatible with Windows, please reach out to us on our Discord.
:::
1 change: 1 addition & 0 deletions packages/cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"types:check": "tsc --noEmit"
},
"dependencies": {
"app-root-path": "3.1.0",
"axios": "1.6.7",
"chalk": "5.3.0",
"commander": "12.0.0",
Expand Down
13 changes: 0 additions & 13 deletions packages/cache/src/cli/cliEntrypoint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os from 'node:os'
import path from 'node:path'
import chalk from 'chalk'
import { Command } from 'commander'
Expand Down Expand Up @@ -50,18 +49,6 @@ export const cliEntrypoint = async () => {
console.log({ cacheDir: walletSetupDir, ...flags, headless: Boolean(process.env.HEADLESS) ?? false }, '\n')
}

if (os.platform() === 'win32') {
console.log(
[
chalk.redBright('🚨 Sorry, Windows is currently not supported. Please use WSL instead! 🚨'),
chalk.gray(
'If you want to give it a crack over a hot cup of coffee and add Windows support yourself, please get in touch with the team on Discord so we can offer some guidance! 😇'
)
].join('\n')
)
process.exit(1)
}

const compiledWalletSetupDirPath = await compileWalletSetupFunctions(walletSetupDir, flags.debug)

// TODO: We should be using `prepareExtension` function from the wallet itself!
Expand Down
58 changes: 33 additions & 25 deletions packages/cache/src/cli/compileWalletSetupFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import path from 'node:path'
import path, { posix, win32 } from 'node:path'
import { glob } from 'glob'
import { build } from 'tsup'
import { ensureCacheDirExists } from '../ensureCacheDirExists'
import { FIXES_BANNER } from './compilationFixes'

const OUT_DIR_NAME = 'wallet-setup-dist'

const createGlobPattern = (walletSetupDir: string) => path.join(walletSetupDir, '**', '*.setup.{ts,js,mjs}')

export async function compileWalletSetupFunctions(walletSetupDir: string, debug: boolean) {
const outDir = path.join(ensureCacheDirExists(), OUT_DIR_NAME)

const globPattern = createGlobPattern(walletSetupDir)
const fileList = await glob(globPattern)
// Use a normalized glob pattern
const globPattern = path.join(walletSetupDir, '**', '*.setup.{ts,js,mjs}')

// Use glob to find files, ensuring proper path handling
const fileList: string[] = await glob(globPattern, { absolute: false, windowsPathsNoEscape: true })

if (debug) {
console.log('[DEBUG] Found the following wallet setup files:')
Expand All @@ -29,27 +30,34 @@ export async function compileWalletSetupFunctions(walletSetupDir: string, debug:
)
}

await build({
name: 'cli-build',
silent: true,
entry: fileList,
clean: true,
outDir,
format: 'esm',
splitting: true,
sourcemap: false,
config: false,
// TODO: Make this list configurable.
external: ['@synthetixio/synpress', '@playwright/test', 'playwright-core', 'esbuild', 'tsup'],
banner: {
js: FIXES_BANNER
},
esbuildOptions(options) {
// TODO: In this step, if the debug file is present, we should modify `console.log` so it prints from which file the log is coming from.
// We're dropping `console.log` and `debugger` statements because they do not play nicely with the Playwright Test Runner.
options.drop = debug ? [] : ['console', 'debugger']
}
const normalized = fileList.map((file) => {
return file.split(win32.sep).join(posix.sep)
})

try {
await build({
name: 'cli-build',
silent: true,
entry: normalized,
clean: true,
outDir,
format: 'esm',
splitting: true,
sourcemap: false,
config: false,
// TODO: Make this list configurable.
external: ['@synthetixio/synpress', '@playwright/test', 'playwright-core', 'esbuild', 'tsup'],
banner: {
js: FIXES_BANNER
},
esbuildOptions(options) {
// TODO: In this step, if the debug file is present, we should modify `console.log` so it prints from which file the log is coming from.
// We're dropping `console.log` and `debugger` statements because they do not play nicely with the Playwright Test Runner.
options.drop = debug ? [] : ['console', 'debugger']
}
})
} catch (e) {
console.log('error within compile', e)
}
return outDir
}
3 changes: 0 additions & 3 deletions packages/cache/src/createCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import { triggerCacheCreation } from './utils/triggerCacheCreation'

export async function createCache(walletSetupDirPath: string, downloadExtension: () => Promise<string>, force = false) {
const setupFunctions = await getUniqueWalletSetupFunctions(walletSetupDirPath)

const cacheCreationPromises = await triggerCacheCreation(setupFunctions, downloadExtension, force)

if (cacheCreationPromises.length === 0) {
console.log('No new setup functions to cache. Exiting...')
return
}

// TODO: This line has no unit test. Not sure how to do it. Look into it later.
await Promise.all(cacheCreationPromises)

Expand Down
2 changes: 1 addition & 1 deletion packages/cache/src/defineWalletSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getWalletSetupFuncHash } from './utils/getWalletSetupFuncHash'
// TODO: Should we export this type in the `release` package?
export type WalletSetupFunction = (context: BrowserContext, walletPage: Page) => Promise<void>

// TODO: This runs at least twice. Should we cache it somehow?
// This runs once for each setup file on building cache and setting up fixtures, then it runs once for each worker on e2e:test. Should we cache it somehow?
/**
* This function is used to define how a wallet should be set up.
* Based on the contents of this function, a browser with the wallet extension is set up and cached so that it can be used by the tests later.
Expand Down
1 change: 0 additions & 1 deletion packages/cache/src/utils/getWalletSetupFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ export async function getWalletSetupFiles(walletSetupDirPath: string) {
].join('\n')
)
}

return fileList
}
4 changes: 2 additions & 2 deletions packages/cache/src/utils/importWalletSetupFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const WalletSetupModule = z.object({
})

export async function importWalletSetupFile(walletSetupFilePath: string) {
const walletSetupModule = await import(walletSetupFilePath)

const fileToImport = process.platform === 'win32' ? `file:\\\\\\${walletSetupFilePath}` : walletSetupFilePath
const walletSetupModule = await import(fileToImport)
const result = WalletSetupModule.safeParse(walletSetupModule)
if (!result.success) {
throw new Error(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"types:check": "tsc --noEmit"
},
"devDependencies": {
"@synthetixio/synpress-tsconfig": "0.0.1-alpha.7",
"@synthetixio/synpress-tsconfig": "workspace:*",
"@types/node": "20.11.17",
"rimraf": "5.0.5",
"tsup": "8.0.2",
Expand Down
63 changes: 58 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions release/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
},
"dependencies": {
"@synthetixio/ethereum-wallet-mock": "0.0.1-alpha.7",
"@synthetixio/synpress-cache": "0.0.1-alpha.7",
"@synthetixio/synpress-core": "0.0.1-alpha.7",
"@synthetixio/synpress-cache": "workspace:*",
"@synthetixio/synpress-core": "workspace:*",
"@synthetixio/synpress-metamask": "0.0.1-alpha.7"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions wallets/metamask/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ declare global {
interface ProcessEnv {
CI: boolean
HEADLESS: boolean
USE_CACHE: string
}
}
}
Expand Down
Loading
Loading