我想更新我的
.eslintrc.js
以设置规则,它需要使用 Playwright测试代码中的
test.beforeAll
、
test.beforeEach
、
test
、
test.afterAll
、
test.afterEach
之间有一个空行。
// test-login.test.js
const { test, expect } = require('@playwright/test');
let context;
test.describe('test login', () => {
test.beforeAll(async ({ browser }) => {
context = await browser.newContext({ storageState: 'user1.json' });
});
test.beforeEach(async ({ browser }) => {
page = await context.newPage();
});
test.afterAll(async () => {
await context.close();
});
test.afterEach(async () => {
await context.close();
});
test('test login with valid account', async () => {
// test code...
});
test('test login with invalid account', async () => {
// test code...
});
test('test login with invalid password', async () => {
// test code...
});
});
我尝试按以下方式设置规则,但它不起作用
// .eslintrc.js
module.exports = {
env: {
es2021: true,
node: true
},
extends: [
'eslint:recommended',
'google',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'plugin:playwright/recommended',
'prettier'
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2021,
sourceType: 'module'
},
root: true,
plugins: ['@typescript-eslint', 'prettier'],
rules: {
'padding-line-between-statements': [
'warn',
{ blankLine: 'always', prev: '*', next: 'function' },
{ blankLine: 'always', prev: '*', next: 'block-like' },
{ blankLine: 'always', prev: '*', next: 'block' },
{ blankLine: 'always', prev: 'function', next: 'function' }
],
'@typescript-eslint/no-var-requires': 'off',
'playwright/no-wait-for-timeout': 'off',
'camelcase': 'off',
'@typescript-eslint/naming-convention': [
'warn',
{
selector: 'variable',
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
},
],
'prettier/prettier': [
'warn',
{
endOfLine: 'auto',
singleQuote: true,
parser: 'flow',
printWidth: 140
}
],
'new-cap': 'warn',
'max-len': 'off',
'valid-jsdoc': 'warn',
'require-jsdoc': 'off',
'linebreak-style': 'off',
'no-unused-vars': 'warn',
'spaced-comment': 'warn'
}
};
我实际上正在寻找同样的东西,我正在使用 vitest 作为测试运行程序,所以这可能对我不起作用,但如果你有机会使用 Jest,这可能对你有用: