为何使用eslint-plugin-jest时,跳过的测试未触发jest/no-disabled-tests报错?
解决Playwright跳过测试无法被ESLint检测的问题
你遇到的问题核心是:eslint-plugin-jest 是专门为Jest测试框架设计的规则集,它的jest/no-disabled-tests规则只能识别Jest生态下的禁用测试语法,无法识别Playwright的test.skip。
要解决这个问题,你需要改用Playwright官方的ESLint插件:
步骤1:安装Playwright ESLint插件
执行以下命令安装依赖:
npm install eslint-plugin-playwright --save-dev # 或用yarn yarn add eslint-plugin-playwright --dev # 或用pnpm pnpm add eslint-plugin-playwright --save-dev
步骤2:配置ESLint规则
在你的ESLint配置文件(比如.eslintrc.js、.eslintrc.json)中,添加Playwright插件的规则:
方式1:启用全部推荐规则
module.exports = { extends: [ // 保留你已有的其他extends配置 'plugin:playwright/recommended' ], plugins: ['playwright'] };
方式2:单独启用禁用测试检测规则
如果你不想启用所有推荐规则,可单独开启playwright/no-skipped-tests:
module.exports = { plugins: ['playwright'], rules: { // 其他规则... 'playwright/no-skipped-tests': 'error' // 设为"warn"或"error"均可 } };
步骤3:验证效果
重新运行ESLint检查:
eslint .
此时被test.skip标记的跳过测试应该会被检测并报告为违规项。
内容的提问来源于stack exchange,提问作者Michael Durrant
相关产品推荐
相关产品推荐

