Skip to content

Commit 3d75c7a

Browse files
authored
feat: create announcements banner (#617)
1 parent 524fe0f commit 3d75c7a

23 files changed

Lines changed: 875 additions & 321 deletions

File tree

.github/workflows/ci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,41 @@ jobs:
7878
with:
7979
files: ./junit.xml
8080
report_type: test_results
81+
82+
e2e:
83+
name: E2E Tests
84+
runs-on: ubuntu-latest
85+
86+
steps:
87+
- name: Harden Runner
88+
uses: step-security/harden-runner@fa2e9d605c4eeb9fcad4c99c224cee0c6c7f3594 # v2.16.0
89+
with:
90+
egress-policy: audit
91+
92+
- name: Checkout code
93+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
94+
95+
- name: Setup Node.js
96+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
97+
with:
98+
node-version-file: '.nvmrc'
99+
cache: 'npm'
100+
101+
- name: Install dependencies
102+
run: npm ci
103+
104+
- name: Checkout Node.js source
105+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
106+
with:
107+
repository: nodejs/node
108+
sparse-checkout: doc/api/assert.md
109+
path: node
110+
111+
- name: Build docs
112+
run: npx doc-kit generate -t web -i "./node/doc/api/assert.md" -o out
113+
114+
- name: Install Playwright browsers
115+
run: npx playwright install --with-deps
116+
117+
- name: Run E2E tests
118+
run: node --run test:e2e

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ isolate-*
1616

1717
# Node's Source Folder
1818
node
19+
20+
# Playwright
21+
playwright-report/
22+
test-results/

e2e/announcement-banner.spec.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { expect, test } from '@playwright/test';
2+
3+
const REMOTE_CONFIG_URL = 'https://nodejs.org/site.json';
4+
5+
test.describe('Announcement Banner', () => {
6+
test('renders a text-only banner', async ({ page }) => {
7+
await page.route(REMOTE_CONFIG_URL, route =>
8+
route.fulfill({
9+
contentType: 'application/json',
10+
body: JSON.stringify({
11+
websiteBanners: {
12+
index: { text: 'Important announcement for all users' },
13+
},
14+
}),
15+
})
16+
);
17+
18+
await page.goto('/assert.html');
19+
20+
const banner = page.getByRole('region', { name: 'Announcements' });
21+
await expect(banner).toBeVisible();
22+
await expect(banner).toContainText('Important announcement for all users');
23+
});
24+
25+
test('renders a banner with a link', async ({ page }) => {
26+
await page.route(REMOTE_CONFIG_URL, route =>
27+
route.fulfill({
28+
contentType: 'application/json',
29+
body: JSON.stringify({
30+
websiteBanners: {
31+
index: {
32+
text: 'Read the release notes',
33+
link: 'https://nodejs.org/releases',
34+
},
35+
},
36+
}),
37+
})
38+
);
39+
40+
await page.goto('/assert.html');
41+
42+
const banner = page.getByRole('region', { name: 'Announcements' });
43+
await expect(banner).toBeVisible();
44+
45+
const link = banner.getByRole('link', { name: 'Read the release notes' });
46+
await expect(link).toBeVisible();
47+
await expect(link).toHaveAttribute('href', 'https://nodejs.org/releases');
48+
await expect(link).toHaveAttribute('target', '_blank');
49+
});
50+
51+
test('does not render when there are no active banners', async ({ page }) => {
52+
await page.route(REMOTE_CONFIG_URL, route =>
53+
route.fulfill({
54+
contentType: 'application/json',
55+
body: JSON.stringify({ websiteBanners: {} }),
56+
})
57+
);
58+
59+
await page.goto('/assert.html');
60+
await page.waitForLoadState('networkidle');
61+
62+
await expect(
63+
page.getByRole('region', { name: 'Announcements' })
64+
).not.toBeAttached();
65+
});
66+
});

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default defineConfig([
1313
ignores: ['out/', 'src/generators/api-links/__tests__/fixtures/'],
1414
},
1515
{
16-
files: ['**/*.{mjs,jsx}'],
16+
files: ['**/*.{mjs,jsx,js}'],
1717
plugins: { jsdoc },
1818
languageOptions: {
1919
ecmaVersion: 'latest',

0 commit comments

Comments
 (0)