Skip to content

Commit eb7c099

Browse files
committed
Explicitly assert that analytics requests trigger
refs https://linear.app/ghost/issue/BER-3077/improve-e2e-testing-integration Always waiting for the analytics request to succeed means any public test will fail if Tinybird or the analytics service isn't running.
1 parent 72eac1e commit eb7c099

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

e2e/helpers/pages/public/public-page.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {BasePage, pageGotoOptions} from '@/helpers/pages';
2-
import {Locator, Page, Response} from '@playwright/test';
2+
import {Locator, Page} from '@playwright/test';
33

44
declare global {
55
interface Window {
@@ -86,13 +86,11 @@ export class PublicPage extends BasePage {
8686

8787
async goto(url?: string, options?: pageGotoOptions): Promise<void> {
8888
await this.enableAnalyticsRequests();
89-
const pageHitPromise = this.pageHitRequestPromise();
9089
await super.goto(url, options);
91-
await pageHitPromise;
9290
}
93-
94-
pageHitRequestPromise(): Promise<Response> {
95-
return this.page.waitForResponse((response) => {
91+
92+
async waitForPageHitRequest() {
93+
return await this.page.waitForResponse((response) => {
9694
return response
9795
.url()
9896
.includes('/.ghost/analytics/api/v1/page_hit') && response.request().method() === 'POST';

e2e/tests/public/homepage.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,15 @@ test.describe('Ghost Public - Homepage', () => {
99
await expect(homePage.title).toBeVisible();
1010
await expect(homePage.mainSubscribeButton).toBeVisible();
1111
});
12+
13+
test('sends page hit request', async ({page}) => {
14+
const homePage = new HomePage(page);
15+
16+
// Set up request expectation before navigation
17+
const response = homePage.waitForPageHitRequest();
18+
await homePage.goto();
19+
20+
// Wait for the request to be fulfilled
21+
await expect(response).resolves.toBeDefined();
22+
});
1223
});

0 commit comments

Comments
 (0)