Skip to content

Commit 8094646

Browse files
committed
Setup ESLint rules for Playwright tests and fix related issues
1 parent d828c97 commit 8094646

File tree

11 files changed

+43
-33
lines changed

11 files changed

+43
-33
lines changed

.eslintrc.cjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,12 @@ module.exports = {
101101
'testing-library/prefer-screen-queries': 'off',
102102
},
103103
},
104+
{
105+
files: ['tests/playwright/**/*.{api-test,e2e-test}.{js,ts}'],
106+
extends: ['plugin:playwright/recommended'],
107+
rules: {
108+
'playwright/expect-expect': 'off',
109+
},
110+
},
104111
],
105112
};

package-lock.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
"eslint": "8.53.0",
106106
"eslint-config-prettier": "9.0.0",
107107
"eslint-plugin-jest-dom": "5.1.0",
108+
"eslint-plugin-playwright": "1.5.4",
108109
"eslint-plugin-simple-import-sort": "12.0.0",
109110
"eslint-plugin-svelte": "2.34.1",
110111
"eslint-plugin-testing-library": "6.1.0",

tests/playwright/api/tests/index.api-setup.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import {
1010
} from '../../common/lib/setup';
1111

1212
setup('setup API', async ({ page, baseURL }) => {
13+
if (!baseURL) {
14+
throw new Error('Base URL is not set');
15+
}
16+
1317
seedDb();
1418
await saveVisitorRoleState(page);
1519

tests/playwright/api/tests/signed-in-user--before-sign-out/sign-out.api-test.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ test.describe('POST /profile?/sign-out', () => {
88
page,
99
baseURL,
1010
}) => {
11-
if (!baseURL) {
12-
throw new Error('Base URL is not set');
13-
}
14-
1511
const homePage = new HomePage(page);
1612
await homePage.doNavigateTo();
1713

@@ -20,7 +16,7 @@ test.describe('POST /profile?/sign-out', () => {
2016
const response = await page.request.post('/profile?/sign-out', {
2117
headers: {
2218
// Needed to pass CSRF check
23-
origin: baseURL,
19+
origin: baseURL!,
2420
},
2521
form: {},
2622
});
@@ -35,15 +31,11 @@ test.describe('POST /profile?/sign-out', () => {
3531
});
3632

3733
test('returns 401 if user is not logged in', async ({ page, baseURL }) => {
38-
if (!baseURL) {
39-
throw new Error('Base URL is not set');
40-
}
41-
4234
await page.context().clearCookies();
4335
const response = await page.request.post('/profile?/sign-out', {
4436
headers: {
4537
// Needed to pass CSRF check
46-
origin: baseURL,
38+
origin: baseURL!,
4739
},
4840
form: {},
4941
});

tests/playwright/api/tests/signed-in-user/code-snippets/create.api-test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@ test.describe('POST /code-snippets/create?/create', () => {
1010
page,
1111
baseURL,
1212
}) => {
13-
if (!baseURL) {
14-
throw new Error('Base URL is not set');
15-
}
16-
1713
const homePage = new HomePage(page);
1814
await homePage.doNavigateTo();
1915

2016
const response = await page.request.post('/code-snippets/create?/create', {
2117
headers: {
2218
// Needed to pass CSRF check
23-
origin: baseURL,
19+
origin: baseURL!,
2420
},
2521
multipart: {
2622
name: CODE_SNIPPET.name,

tests/playwright/api/tests/signed-in-user/code-snippets/delete.api-test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ test.describe('POST /code-snippets/:id?/delete', () => {
1010
page,
1111
baseURL,
1212
}) => {
13-
if (!baseURL) {
14-
throw new Error('Base URL is not set');
15-
}
16-
1713
const homePage = new HomePage(page);
1814
await homePage.doNavigateTo();
1915

@@ -22,7 +18,7 @@ test.describe('POST /code-snippets/:id?/delete', () => {
2218
{
2319
headers: {
2420
// Needed to pass CSRF check
25-
origin: baseURL,
21+
origin: baseURL!,
2622
},
2723
multipart: {},
2824
},

tests/playwright/api/tests/signed-in-user/code-snippets/edit.api-test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ test.describe('POST /code-snippets/:id/edit?/edit', () => {
1010
page,
1111
baseURL,
1212
}) => {
13-
if (!baseURL) {
14-
throw new Error('Base URL is not set');
15-
}
16-
1713
const homePage = new HomePage(page);
1814
await homePage.doNavigateTo();
1915

@@ -22,7 +18,7 @@ test.describe('POST /code-snippets/:id/edit?/edit', () => {
2218
{
2319
headers: {
2420
// Needed to pass CSRF check
25-
origin: baseURL,
21+
origin: baseURL!,
2622
},
2723
multipart: {
2824
name: CODE_SNIPPET.newName,

tests/playwright/api/tests/visitor/sign-in.api-test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@ test.describe('POST /sign-in?/google-auth', () => {
55
request,
66
baseURL,
77
}, testInfo) => {
8-
if (!baseURL) {
9-
throw new Error('Base URL is not set');
10-
}
11-
128
const response = await request.post('/sign-in?/google-auth', {
139
headers: {
1410
// Needed to pass CSRF check
15-
origin: baseURL,
11+
origin: baseURL!,
1612
},
1713
form: {},
1814
});

tests/playwright/e2e/tests/signed-in-user--before-sign-out/sign-out.e2e-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test.describe('Feature: Sign out', () => {
1212

1313
await expect(
1414
homePage.componentNavigationBar.getSignInButton(),
15-
).not.toBeVisible();
15+
).toBeHidden();
1616
await expect(
1717
homePage.componentNavigationBar.getProfileButton(),
1818
).toBeVisible();
@@ -29,6 +29,6 @@ test.describe('Feature: Sign out', () => {
2929
).toBeVisible();
3030
await expect(
3131
homePage.componentNavigationBar.getProfileButton(),
32-
).not.toBeVisible();
32+
).toBeHidden();
3333
});
3434
});

tests/playwright/e2e/tests/visitor/sign-in.e2e-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test.describe('Feature: Sign in/Sign up via Google', () => {
1414
).toBeVisible();
1515
await expect(
1616
homePage.componentNavigationBar.getProfileButton(),
17-
).not.toBeVisible();
17+
).toBeHidden();
1818

1919
await homePage.componentNavigationBar.doClickSignInButton();
2020

0 commit comments

Comments
 (0)