Skip to content

Commit 7077979

Browse files
committed
test: Fix flaky Editor and Context Memory DOM assertions and TS typing
1 parent a50d845 commit 7077979

3 files changed

Lines changed: 45 additions & 25 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Flaky Assertions and Typing Fixes
2+
3+
## Summary
4+
Fixed false-passes and flaky tests in `editor.spec.js` caused by missing elements being masked by improper testing patterns, and silenced JSDoc typing errors in `context-memory.spec.js` and `editor.spec.js`.
5+
6+
## 1. DOM Assertion Stability
7+
**When:** The editor is evaluating emojis and GitHub callouts.
8+
**What:** Replaced hardcoded `waitForTimeout(500)` combined with `.innerHTML()` parsing for native Playwright `.toBeVisible()` and `.toContainText()` matchers.
9+
**Impact:** Solves race conditions caused by MathJax and Joypixels fetching fonts and stylesheets asynchronously over the network, which previously led tests to evaluate incomplete views.
10+
11+
## 2. JSDoc Typing Adjustments
12+
**What:** Applied `/** @type {any[]} */` and `/** @type {any} */` casts to `errors` arrays and `window` assignments within Playwright `page.on` listeners and `page.evaluate` blocks.
13+
**Impact:** Prevents TypeScript's strict type checker from discarding Playwright scripts due to missing explicit variable typing.
14+
15+
---
16+
17+
## Files Changed
18+
19+
| File | Type |
20+
|------|------|
21+
| `tests/feature/editor.spec.js` | Test Assertion Fixes |
22+
| `tests/feature/context-memory.spec.js` | Test Typing Fixes |

tests/feature/context-memory.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ test.describe('Memory Tag — Preview Card Rendering', () => {
418418
const removeBtn = page.locator('.ai-remove-tag').first();
419419
await expect(removeBtn).toBeVisible();
420420

421+
/** @type {string[]} */
421422
const errors = [];
422423
page.on('pageerror', err => errors.push(err.message));
423424

tests/feature/editor.spec.js

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,56 @@ test.describe('Editor Features', () => {
55
test.beforeEach(async ({ page }) => {
66
await page.goto('/');
77
await page.waitForSelector('#markdown-editor', { state: 'visible' });
8-
await page.waitForFunction(() => window.MDView && window.MDView.currentViewMode === 'split');
8+
await page.waitForFunction(() => {
9+
const w = /** @type {any} */ (window);
10+
return w.MDView && w.MDView.currentViewMode === 'split';
11+
});
912
});
1013

1114
test('editor renders markdown in preview', async ({ page }) => {
1215
await page.locator('#markdown-editor').fill('# Hello World\n\nThis is **bold** text.');
13-
await page.waitForTimeout(500);
14-
const html = await page.locator('#markdown-preview').innerHTML();
15-
expect(html).toContain('Hello World');
16-
expect(html).toContain('<strong>bold</strong>');
16+
const preview = page.locator('#markdown-preview');
17+
await expect(preview).toContainText('Hello World');
18+
await expect(preview.locator('strong')).toHaveText('bold');
1719
});
1820

1921
test('editor supports code blocks with syntax highlighting', async ({ page }) => {
2022
await page.locator('#markdown-editor').fill('```javascript\nconst x = 42;\n```');
21-
await page.waitForTimeout(500);
22-
const html = await page.locator('#markdown-preview').innerHTML();
23-
expect(html).toContain('const');
24-
expect(html).toContain('<code');
23+
const preview = page.locator('#markdown-preview');
24+
await expect(preview).toContainText('const');
25+
await expect(preview.locator('code')).toBeVisible({ timeout: 10000 });
2526
});
2627

2728
test('editor supports LaTeX math rendering', async ({ page }) => {
2829
await page.locator('#markdown-editor').fill('$$E = mc^2$$');
29-
await page.waitForTimeout(500);
30-
const html = await page.locator('#markdown-preview').innerHTML();
31-
expect(html).toContain('E');
30+
const preview = page.locator('#markdown-preview');
31+
await expect(preview.locator('mjx-container, .math')).toBeVisible({ timeout: 10000 });
3232
});
3333

3434
test('editor supports task lists', async ({ page }) => {
3535
await page.locator('#markdown-editor').fill('- [x] Done\n- [ ] Todo');
36-
await page.waitForTimeout(500);
37-
const html = await page.locator('#markdown-preview').innerHTML();
38-
expect(html).toContain('type="checkbox"');
36+
const preview = page.locator('#markdown-preview');
37+
await expect(preview.locator('input[type="checkbox"]')).toHaveCount(2, { timeout: 10000 });
3938
});
4039

4140
test('editor supports tables', async ({ page }) => {
4241
await page.locator('#markdown-editor').fill('| A | B |\n|---|---|\n| 1 | 2 |');
43-
await page.waitForTimeout(500);
44-
const html = await page.locator('#markdown-preview').innerHTML();
45-
expect(html).toContain('<table');
46-
expect(html).toContain('<td');
42+
const preview = page.locator('#markdown-preview');
43+
await expect(preview.locator('table')).toBeVisible({ timeout: 10000 });
44+
await expect(preview.locator('td')).toHaveCount(2);
4745
});
4846

4947
test('editor supports emoji shortcodes', async ({ page }) => {
5048
await page.locator('#markdown-editor').fill(':rocket: :star:');
51-
await page.waitForTimeout(500);
52-
const html = await page.locator('#markdown-preview').innerHTML();
53-
expect(html.length).toBeGreaterThan(0);
49+
const preview = page.locator('#markdown-preview');
50+
await expect(preview).toContainText('🚀', { timeout: 10000 });
51+
await expect(preview).toContainText('⭐', { timeout: 10000 });
5452
});
5553

5654
test('editor supports GitHub-style callouts', async ({ page }) => {
5755
await page.locator('#markdown-editor').fill('> [!NOTE]\n> This is a note.');
58-
await page.waitForTimeout(500);
59-
const html = await page.locator('#markdown-preview').innerHTML();
60-
expect(html).toContain('note');
56+
const preview = page.locator('#markdown-preview');
57+
await expect(preview.locator('.markdown-callout.callout-note')).toBeVisible({ timeout: 10000 });
6158
});
6259

6360
test('word count and stats update on input', async ({ page }) => {

0 commit comments

Comments
 (0)