Skip to content

Commit

Permalink
Reconfigure playwright, fix tests, update test:e2e and .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
atomicgamedeveloper committed Jul 30, 2024
1 parent a8d9a76 commit d85490a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ build/
# Test reports
coverage/
playwright-report/
playwright/
client/playwright/
test_results/

# Mac temp files
Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"stop": "npx kill-port 4000",
"syntax": "npx eslint . --fix",
"test:all": "yarn test:unit && yarn test:int && yarn test:e2e",
"test:e2e": "yarn build && yarn config:test && npx kill-port 4000 && yarn start >/dev/null & playwright test && npx kill-port 4000",
"test:e2e": "yarn build && yarn config:test && playwright test",
"test:int": "jest -c ./jest.integration.config.json ../test/integration --coverage",
"test:unit": "jest -c ./jest.config.json ../test/unitTests --coverage"
},
Expand Down
18 changes: 12 additions & 6 deletions client/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@ dotenv.config({ path: './test/.env' });
const BASE_URI = process.env.REACT_APP_URL.toString() ?? '';

export default defineConfig({
webServer: {
command: 'yarn start',
port: 4000,
},
timeout: 45000,
globalTimeout: 600000,
testDir: './test/e2e',
testMatch: /.*\.test\.ts/,
reporter: [
['html', { outputFile: 'playwright-report/index.html' }],
['list'],
['junit', { outputFile: 'playwright-report/results.xml' }],
['json', { outputFile: 'playwright-report/results.json' }],
],
reporter: process.env.CI
? 'github'
: [
['html', { outputFile: 'playwright-report/index.html' }],
['list'],
['junit', { outputFile: 'playwright-report/results.xml' }],
['json', { outputFile: 'playwright-report/results.json' }],
],
use: {
baseURL: BASE_URI,
},
Expand Down
4 changes: 3 additions & 1 deletion client/test/e2e/playwright/Auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// src: https://playwright.dev/docs/writing-tests

import { test, expect } from '@playwright/test';
import links from './Links.ts'; // Extension is required with Playwright import
import links from './Links'; // Extension is required with Playwright import

test.describe('Tests on Authentication Flow', () => {
test.beforeEach(async ({ page }) => {
Expand All @@ -12,6 +12,7 @@ test.describe('Tests on Authentication Flow', () => {
await page
.getByRole('button', { name: 'GitLab logo Sign In with GitLab' })
.click();
await page.getByRole('button', { name: 'Authorize' }).click();
await expect(
page.getByRole('button', { name: 'Open settings' }),
).toBeVisible();
Expand All @@ -22,6 +23,7 @@ test.describe('Tests on Authentication Flow', () => {
await page
.getByRole('button', { name: 'GitLab logo Sign In with GitLab' })
.click();
await page.getByRole('button', { name: 'Authorize' }).click();
await expect(
page.getByRole('button', { name: 'Open settings' }),
).toBeVisible();
Expand Down
3 changes: 2 additions & 1 deletion client/test/e2e/playwright/Menu.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// src: https://playwright.dev/docs/writing-tests

import { test, expect } from '@playwright/test';
import links from './Links.ts'; // Extension is required with Playwright import
import links from './Links'; // Extension is required with Playwright import

test.describe('Menu Links from first page (Layout)', () => {
test.beforeEach(async ({ page }) => {
await page.goto('./');
await page
.getByRole('button', { name: 'GitLab logo Sign In with GitLab' })
.click();
await page.getByRole('button', { name: 'Authorize' }).click();
await expect(
page.getByRole('button', { name: 'Open settings' }),
).toBeVisible();
Expand Down
6 changes: 2 additions & 4 deletions client/test/e2e/playwright/auth.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ setup('authenticate', async ({ page }) => {
}
await page.fill('#user_login', testUsername.toString()); // Insert valid GitLab testing username.
await page.fill('#user_password', testPassword.toString()); // Insert valid GitLab testing password.
await page.locator('label').filter({ hasText: 'Remember me' }).click();
await page.getByRole('button', { name: 'Sign in' }).click();
try {
await page.waitForSelector('input[type="submit"][value="Authorize"]', {
timeout: 10000,
});
await page.click('input[type="submit"][value="Authorize"]');
await page.getByRole('button', { name: 'Authorize' }).click();
} catch (error) {
// 'Authorize' button did not appear within 4 seconds, so just ignore and continue.
}
Expand Down

0 comments on commit d85490a

Please sign in to comment.