ARTICLE DETAIL

资讯详情

深耕编程入门与网站建设的一线实战洞察。

MetaMask Extension 如何运行单个 E2E 测试用例?

MetaMask Extension 如何运行单个 E2E 测试用例? MetaMask Extension 如何运行单个 E2E 测试用例【免费下载链接】metamask-extension:globe_with_meridians: :electric_plug: The MetaMask browser extension enables browsing Ethereum blockchain enabled websites项目地址: https://gitcode.com/GitHub_Trending/me/metamask-extension在 MetaMask Extension 仓库里调试某个 E2E 场景时跑完整套测试耗时很长而你往往只想验证某一个 spec 文件。仓库提供两条单测运行路径主体 E2E 套件Selenium Mochaspec 文件为*.spec.ts/*.spec.js通过yarn test:e2e:single 测试文件路径运行已经迁移到 Playwright 的 spec*.pw.spec.ts则通过yarn test:e2e:playwright:chrome/yarn test:e2e:playwright:firefox把 spec 路径作为位置参数传入。两条路径都要求先准备一个测试版扩展构建。准备条件开始之前需要完成两件事安装依赖和准备测试构建。先执行yarn install下载依赖。然后准备测试构建README 给出了 3 个选项# 方式一快速下载现成的测试构建解包到 ./dist/适合标准测试 yarn download-builds --build-type test# 方式二本地 Webpack 构建 yarn build:test # 主构建 yarn build:test:flask # flask 构建 yarn build:test:mv2 # mv2 构建# 方式三带热更新的开发式构建代码修改后自动重编译适合迭代调试 yarn start:test注意yarn start:test会关闭 LavaMoat 和 Snow 以加快迭代速度如果需要生产级别的 LavaMoat 验证应该用yarn build:test。Playwright 路径还需要一次性浏览器安装每台机器一次Playwright 版本变化后需重新执行yarn # 安装 Playwright 包 yarn playwright install chromium firefox # 下载浏览器二进制判断你的 spec 走哪条运行路径spec 文件全部位于test/e2e/tests/下按文件后缀选择 runner普通 spec*.spec.ts/*.spec.js如test/e2e/tests/settings/state-logs.spec.ts走 Selenium runner以.pw.spec.ts结尾的文件是迁移到 Playwright 的版本如test/e2e/tests/settings/auto-lock.pw.spec.ts、test/e2e/tests/settings/terms-of-use.pw.spec.ts必须走 Playwright runner。Selenium 全量 runnerrun-all.mts和 changed-file filter 会显式跳过*.pw.spec.ts避免双重执行所以不要拿test:e2e:single去跑.pw.spec.ts文件。运行单个 Selenium spec命令形式为yarn test:e2e:single test/e2e/tests/TEST_NAME.spec.jsTEST_NAME替换为你要运行的 spec 文件名带目录。可用选项--browser 指定浏览器chrome、firefox 或 all不设置时默认在 all 上运行。 [string] [default: all] --debug 以调试模式运行记录每次 driver 交互。 [boolean] [default: true] --retries 测试失败后的重试次数。 [number] [default: 0] --leave-running 测试失败后保留浏览器运行同时保留测试用到的其他资源 本地 node、测试 dapp 等。 [boolean] [default: false] --update-snapshot 更新 E2E 测试快照 [alias: -u] [boolean] [default: false]例如用 Chrome 运行一个 spec、开启调试日志、并在失败时保留浏览器不关闭README 中的示例命令yarn test:e2e:single test/e2e/tests/account-menu/account-details.spec.js --browserchrome --leave-running--leave-running的副作用要注意它会保留浏览器以及测试用到的本地 node、测试 dapp 等进程用于失败后的现场排查排查完毕需自行清理。运行单个 Playwright spec把 spec 路径作为位置参数传给 Playwright runner即可只跑这一个 spec# 跑单个 spec有头模式 yarn test:e2e:playwright:chrome test/e2e/tests/settings/terms-of-use.pw.spec.ts # 无头模式运行 PLAYWRIGHT_HEADLESS1 yarn test:e2e:playwright:chrome test/e2e/tests/settings/terms-of-use.pw.spec.ts # 用 Playwright Inspector 调试逐步查看每个 driver 动作 PWDEBUG1 yarn test:e2e:playwright:chrome test/e2e/tests/settings/terms-of-use.pw.spec.tsFirefox 上则使用yarn test:e2e:playwright:firefox spec 路径。本地直接调用 Playwright CLI 时也可以用--project指定浏览器项目chrome-e2e/firefox-e2e来跑单个 spec例如PWDEBUG1 yarn playwright test --projectchrome-e2e auto-lock.pw.spec.ts。本地未设置GITHUB_ACTION环境变量时run-all-pw.mtsrunner 会跳过矩阵切分与质量门把发现的 spec或你传入的位置参数过滤器放在单次 Playwright 调用里执行不产生 JUnit 输出--retries参数会透传给这次调用。调试与结果判断两条路径共用同一套调试手段Selenium 单测的--debug选项默认为true等价于设置E2E_DEBUGtrue会输出每次 driver 交互日志Playwright 路径同样识别E2E_DEBUGtrue由helpers.js的 driver 代理包装器处理例如E2E_DEBUGtrue yarn test:e2e:playwright:chrome auto-lock.pw.spec.ts。Playwright 侧的可视化调试用PWDEBUG1对应 Selenium 的调试能力快照更新用--update-snapshots对应--update-snapshot保留现场用--headed等参数映射关系见 test/e2e/playwright/README.md 末尾的对照表。结果判断方面Selenium 单测 runnertest/e2e/run-e2e-test.js会先校验你传入的路径路径不存在时报Test path specified does not exist不是文件时报Test path must be a file权限不足报Access to test path is forbidden by file access permissions。也就是说命令能启动本身就说明路径合法后续失败会以Error occurred while running tests on browser退出。Playwright 单个 spec 的执行结果由 Playwright 自身的 list reporter 输出HTML 报告配置在 playwright.config.ts 中public/playwright/playwright-reports/html/失败时自动打开CI 下 JUnit 结果写入test/test-results/e2e/每个 spec 一个文件。已知限制PlaywrightDriver shim 只实现了已迁移 spec 实际用到的方法其他方法会抛出明确的not yet implemented错误而不是静默执行——迁移 spec 时如果遇到缺口需要在同一个 PR 里参照 Selenium 的driver.js契约补齐见 driver-playwright.ts。*.pw.spec.ts只能由 Playwright runner 执行test:e2e:single是 Selenium 路径专用入口反过来也不适用。全量运行命令yarn test:e2e:chrome/yarn test:e2e:firefox支持--help查看额外调试选项Linux 上以 snap 包方式运行 Firefox 时全量运行需加FIREFOX_SNAPtrue。下一步单个 spec 验证通过后如果要把它合入迁移流程按照 test/e2e/playwright/README.md 的约定在 CI 的test-e2e-chrome-playwright/test-e2e-firefox-playwrightjob 下确认新 spec 通过然后在同一个 PR或快速跟进 PR中删除对应的 Selenium 版本文件。【免费下载链接】metamask-extension:globe_with_meridians: :electric_plug: The MetaMask browser extension enables browsing Ethereum blockchain enabled websites项目地址: https://gitcode.com/GitHub_Trending/me/metamask-extension创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表