Skip to content

Commit 606283a

Browse files
committed
Made E2E tests that depend on Tinybird optional outside of CI
refs https://linear.app/ghost/issue/BER-3077/improve-e2e-testing-integration The yarn dev:forward command won't start Tinybird by default since it's expensive to run. These changes mean that we automatically skip tests that depend on Tinybird when running locally and that service isn't available.
1 parent d7a27db commit 606283a

File tree

10 files changed

+60
-4
lines changed

10 files changed

+60
-4
lines changed

e2e/helpers/environment/service-availability.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,30 @@ export async function isTinybirdAvailable(): Promise<boolean> {
4242
}
4343
}
4444

45+
/**
46+
* Check if we're running in CI environment.
47+
*/
48+
export function isCI(): boolean {
49+
return process.env.CI === 'true';
50+
}
51+
52+
/**
53+
* Determine if analytics tests should be skipped.
54+
* Returns true if Tinybird is not available AND we're not in CI.
55+
* In CI, we want tests to fail if Tinybird isn't available.
56+
*/
57+
export async function shouldSkipAnalyticsTests(): Promise<boolean> {
58+
if (isCI()) {
59+
// In CI, never skip - let tests fail if Tinybird isn't available
60+
return false;
61+
}
62+
63+
const available = await isTinybirdAvailable();
64+
if (!available) {
65+
debug('Skipping analytics tests: Tinybird not available (non-CI)');
66+
return true;
67+
}
68+
69+
return false;
70+
}
71+

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { shouldSkipAnalyticsTests } from '@/helpers/environment/service-availability';
12
import {BasePage, pageGotoOptions} from '@/helpers/pages';
23
import {Locator, Page, Response} from '@playwright/test';
34

@@ -86,13 +87,17 @@ export class PublicPage extends BasePage {
8687

8788
async goto(url?: string, options?: pageGotoOptions): Promise<void> {
8889
await this.enableAnalyticsRequests();
89-
const pageHitPromise = this.pageHitRequestPromise();
90+
const pageHitPromise = this.waitForPageHitRequest();
9091
await super.goto(url, options);
9192
await pageHitPromise;
9293
}
93-
94-
pageHitRequestPromise(): Promise<Response> {
95-
return this.page.waitForResponse((response) => {
94+
95+
async waitForPageHitRequest(): Promise<void> {
96+
if (await shouldSkipAnalyticsTests()) {
97+
return;
98+
}
99+
100+
await this.page.waitForResponse((response) => {
96101
return response
97102
.url()
98103
.includes('/.ghost/analytics/api/v1/page_hit') && response.request().method() === 'POST';

e2e/tests/admin/analytics/growth.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import {AnalyticsGrowthPage} from '@/admin-pages';
22
import {expect, test} from '@/helpers/playwright';
3+
import { shouldSkipAnalyticsTests } from '@/helpers/environment/service-availability';
4+
5+
test.skip(await shouldSkipAnalyticsTests(), 'Tinybird not available');
36

47
test.describe('Ghost Admin - Growth', () => {
58
let growthPage: AnalyticsGrowthPage;

e2e/tests/admin/analytics/location.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import {AnalyticsLocationsPage} from '@/admin-pages';
22
import {expect, test} from '@/helpers/playwright';
3+
import { shouldSkipAnalyticsTests } from '@/helpers/environment/service-availability';
4+
5+
test.skip(await shouldSkipAnalyticsTests(), 'Tinybird not available');
36

47
test.describe('Ghost Admin - Locations', () => {
58
test('empty sources card', async ({page}) => {

e2e/tests/admin/analytics/newsletters.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import {AnalyticsNewslettersPage} from '@/admin-pages';
2+
import { shouldSkipAnalyticsTests } from '@/helpers/environment/service-availability';
23
import {MembersImportService} from '@/helpers/services/members-import';
34
import {expect, test} from '@/helpers/playwright';
45

6+
test.skip(await shouldSkipAnalyticsTests(), 'Tinybird not available');
7+
58
function getDateDaysAgo(days: number): string {
69
const date = new Date();
710
date.setDate(date.getDate() - days);

e2e/tests/admin/analytics/overview.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import {
55
} from '@/admin-pages';
66
import {HomePage} from '@/public-pages';
77
import {expect, test, withIsolatedPage} from '@/helpers/playwright';
8+
import { shouldSkipAnalyticsTests } from '@/helpers/environment/service-availability';
9+
10+
test.skip(await shouldSkipAnalyticsTests(), 'Tinybird not available');
811

912
test.describe('Ghost Admin - Analytics Overview', () => {
1013
test('records visitor when homepage is visited', async ({page, browser, baseURL}) => {

e2e/tests/admin/analytics/post-analytics/growth.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import {
55
PostAnalyticsPage
66
} from '@/admin-pages';
77
import {expect, test} from '@/helpers/playwright';
8+
import { shouldSkipAnalyticsTests } from '@/helpers/environment/service-availability';
9+
10+
test.skip(await shouldSkipAnalyticsTests(), 'Tinybird not available');
811

912
test.describe('Ghost Admin - Post Analytics - Growth', () => {
1013
test.beforeEach(async ({page}) => {

e2e/tests/admin/analytics/post-analytics/overview.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import {
55
PostAnalyticsWebTrafficPage
66
} from '@/admin-pages';
77
import {expect, test} from '@/helpers/playwright';
8+
import { shouldSkipAnalyticsTests } from '@/helpers/environment/service-availability';
9+
10+
test.skip(await shouldSkipAnalyticsTests(), 'Tinybird not available');
811

912
test.describe('Ghost Admin - Post Analytics - Overview', () => {
1013
test.beforeEach(async ({page}) => {

e2e/tests/admin/analytics/utm-tracking.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import {AnalyticsWebTrafficPage} from '@/admin-pages';
22
import {HomePage} from '@/public-pages';
33
import {expect, test, withIsolatedPage} from '@/helpers/playwright';
4+
import { shouldSkipAnalyticsTests } from '@/helpers/environment/service-availability';
5+
6+
test.skip(await shouldSkipAnalyticsTests(), 'Tinybird not available');
47

58
test.describe('Ghost Admin - Analytics UTM Tracking', () => {
69
test.describe('utmTracking flag disabled', () => {

e2e/tests/admin/analytics/web-traffic.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import {AnalyticsWebTrafficPage} from '@/admin-pages';
2+
import { shouldSkipAnalyticsTests } from '@/helpers/environment/service-availability';
23
import {expect, test} from '@/helpers/playwright';
34

5+
test.skip(await shouldSkipAnalyticsTests(), 'Tinybird not available');
6+
47
test.describe('Ghost Admin - Analytics Web Traffic', () => {
58
let analyticsWebTrafficPage: AnalyticsWebTrafficPage;
69

0 commit comments

Comments
 (0)