Skip to content

Commit

Permalink
Merge pull request #31 from meta-panic/feature/debug-header-autotests
Browse files Browse the repository at this point in the history
Feature/debug header autotests
  • Loading branch information
meta-panic authored Jan 8, 2025
2 parents 023f810 + 1e443af commit 92c0b88
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cms/tests/bruno-cms-collection/collection.bru
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
headers {
Debug-Header: [0_o] Hello from bruno autotests
}

tests {
test("check header x-powered-by Strapi", function() {
expect(res.headers['x-powered-by']).to.equal("Strapi <strapi.io>");
Expand Down
46 changes: 46 additions & 0 deletions cms/tests/playwright/baseTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { test as base, expect, Page } from '@playwright/test';

type CustomFixtures = {
page: Page;
consoleErrors: string[];
};

export const test = base.extend<CustomFixtures>({
consoleErrors: async ({}, use) => {
const errors: string[] = [];
await use(errors);
},

page: async ({ page, consoleErrors }, use) => {
// Catch errors in console
page.on('console', msg => {
if (msg.type() === 'error') {
consoleErrors.push(msg.text());
}
});

// Catch unhandled exceptions on page
page.on('pageerror', error => {
consoleErrors.push(error.message);
});

// Add custom header to all requests
page.route('**', route => {
const headers = {
...route.request().headers(),
'Debug-Header': '[0_o] Hello from playwright autotests'
};
route.continue({ headers });
});

await use(page);
}
});

// Existing console errors check
export const checkConsoleErrors = () => {
test('check console errors', async ({ consoleErrors, page }) => {
await page.waitForLoadState('networkidle');
expect(consoleErrors, 'Found errors on the page').toHaveLength(0);
});
};
5 changes: 4 additions & 1 deletion cms/tests/playwright/strapi-admin-ui-tests.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { test, checkConsoleErrors } from './baseTest';
import { expect } from '@playwright/test';

export const TEST_USERS = {
adminUser: {
Expand All @@ -11,6 +12,8 @@ test.beforeEach(async ({ page }) => {
await page.goto('/');
});

checkConsoleErrors();

test('unauthorized redirect from localhost:1337 to /admin/auth/login', async ({ page }) => {
await expect(page).toHaveURL('http://localhost:1337/admin/auth/login');
});
Expand Down
4 changes: 4 additions & 0 deletions frontend/tests/bruno-frontend-collection/collection.bru
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
headers {
Debug-Header: [0_o] Hello from bruno autotests
}

docs {
API Client - https://github.com/usebruno/bruno
}
9 changes: 9 additions & 0 deletions frontend/tests/playwright/baseTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ export const test = base.extend<CustomFixtures>({
consoleErrors.push(error.message);
});

// Add custom header to all requests
page.route('**', route => {
const headers = {
...route.request().headers(),
'Debug-Header': '[0_o] Hello from playwright autotests'
};
route.continue({ headers });
});

await use(page);
}
});
Expand Down

0 comments on commit 92c0b88

Please sign in to comment.