|
| 1 | +// @ts-check |
| 2 | +import { test, expect } from '@playwright/test'; |
| 3 | + |
| 4 | +/** |
| 5 | + * Hello-World smoke tests for every executable code-block language. |
| 6 | + * Each test types a minimal "Hello, World!" snippet, clicks the per-block |
| 7 | + * Run button, and asserts that the output area shows the expected text. |
| 8 | + * |
| 9 | + * These act as a permanent canary — if any runtime breaks, this suite |
| 10 | + * will catch it immediately. |
| 11 | + */ |
| 12 | + |
| 13 | +const EDITOR_SELECTOR = '#markdown-editor'; |
| 14 | + |
| 15 | +/** Helper: hover over a container to reveal the toolbar, then click Run. |
| 16 | + * Each language uses a different class: code-run-btn, python-run-btn, |
| 17 | + * js-run-btn, sql-run-btn — so we match any of them. |
| 18 | + */ |
| 19 | +async function clickRunButton(container) { |
| 20 | + // Hover to reveal the toolbar (it may be hidden by default) |
| 21 | + await container.hover(); |
| 22 | + const runBtn = container.locator('.code-run-btn, .python-run-btn, .js-run-btn, .sql-run-btn'); |
| 23 | + await runBtn.waitFor({ state: 'visible', timeout: 10_000 }); |
| 24 | + await runBtn.click(); |
| 25 | +} |
| 26 | + |
| 27 | +test.describe('Hello World — Code Block Execution', () => { |
| 28 | + // Give runtimes (Pyodide, sql.js, just-bash) plenty of time to load |
| 29 | + test.setTimeout(120_000); |
| 30 | + |
| 31 | + test.beforeEach(async ({ page }) => { |
| 32 | + await page.goto('/'); |
| 33 | + await page.waitForSelector(EDITOR_SELECTOR, { state: 'visible' }); |
| 34 | + await page.waitForFunction( |
| 35 | + () => window.MDView && window.MDView.currentViewMode === 'split', |
| 36 | + ); |
| 37 | + // Wait for all exec-engine modules + runtimes to initialise |
| 38 | + await page.waitForTimeout(5000); |
| 39 | + }); |
| 40 | + |
| 41 | + // ─── Bash ──────────────────────────────────────────────── |
| 42 | + test('bash: echo Hello, World!', async ({ page }) => { |
| 43 | + const md = [ |
| 44 | + '```bash', |
| 45 | + '# Your bash commands', |
| 46 | + 'echo "Hello, World!"', |
| 47 | + '```', |
| 48 | + ].join('\n'); |
| 49 | + |
| 50 | + await page.locator(EDITOR_SELECTOR).fill(md); |
| 51 | + await page.waitForTimeout(1500); |
| 52 | + |
| 53 | + const container = page.locator('.executable-code-container').first(); |
| 54 | + await expect(container).toBeVisible(); |
| 55 | + |
| 56 | + // Click the per-block Run button |
| 57 | + await clickRunButton(container); |
| 58 | + |
| 59 | + // Wait for .code-output to appear with content |
| 60 | + const output = container.locator('.code-output'); |
| 61 | + await expect(output).toBeVisible({ timeout: 30_000 }); |
| 62 | + await expect(output).toContainText('Hello, World!', { timeout: 15_000 }); |
| 63 | + |
| 64 | + // No errors |
| 65 | + const errorSpan = container.locator('.code-output-error'); |
| 66 | + await expect(errorSpan).toHaveCount(0); |
| 67 | + }); |
| 68 | + |
| 69 | + // ─── Python ────────────────────────────────────────────── |
| 70 | + test('python: print Hello, World!', async ({ page }) => { |
| 71 | + const md = [ |
| 72 | + '```python', |
| 73 | + '# Your Python code', |
| 74 | + 'print("Hello, World!")', |
| 75 | + '```', |
| 76 | + ].join('\n'); |
| 77 | + |
| 78 | + await page.locator(EDITOR_SELECTOR).fill(md); |
| 79 | + await page.waitForTimeout(1500); |
| 80 | + |
| 81 | + const container = page.locator('.executable-python-container').first(); |
| 82 | + await expect(container).toBeVisible(); |
| 83 | + |
| 84 | + await clickRunButton(container); |
| 85 | + |
| 86 | + const output = container.locator('.code-output'); |
| 87 | + await expect(output).toBeVisible({ timeout: 60_000 }); |
| 88 | + await expect(output).toContainText('Hello, World!', { timeout: 30_000 }); |
| 89 | + |
| 90 | + const errorSpan = container.locator('.code-output-error'); |
| 91 | + await expect(errorSpan).toHaveCount(0); |
| 92 | + }); |
| 93 | + |
| 94 | + // ─── JavaScript ────────────────────────────────────────── |
| 95 | + test('javascript: console.log Hello, World!', async ({ page }) => { |
| 96 | + const md = [ |
| 97 | + '```javascript', |
| 98 | + '// Your JavaScript', |
| 99 | + 'console.log("Hello, World!");', |
| 100 | + '```', |
| 101 | + ].join('\n'); |
| 102 | + |
| 103 | + await page.locator(EDITOR_SELECTOR).fill(md); |
| 104 | + await page.waitForTimeout(1500); |
| 105 | + |
| 106 | + const container = page.locator('.executable-js-container').first(); |
| 107 | + await expect(container).toBeVisible(); |
| 108 | + |
| 109 | + await clickRunButton(container); |
| 110 | + |
| 111 | + const output = container.locator('.code-output'); |
| 112 | + await expect(output).toBeVisible({ timeout: 15_000 }); |
| 113 | + await expect(output).toContainText('Hello, World!', { timeout: 10_000 }); |
| 114 | + |
| 115 | + const errorSpan = container.locator('.code-output-error'); |
| 116 | + await expect(errorSpan).toHaveCount(0); |
| 117 | + }); |
| 118 | + |
| 119 | + // ─── SQL ───────────────────────────────────────────────── |
| 120 | + test('sql: CREATE, INSERT, SELECT', async ({ page }) => { |
| 121 | + const md = [ |
| 122 | + '```sql', |
| 123 | + 'CREATE TABLE IF NOT EXISTS greetings (id INTEGER PRIMARY KEY, message TEXT);', |
| 124 | + "INSERT INTO greetings VALUES (1, 'Hello, World!');", |
| 125 | + 'SELECT * FROM greetings;', |
| 126 | + '```', |
| 127 | + ].join('\n'); |
| 128 | + |
| 129 | + await page.locator(EDITOR_SELECTOR).fill(md); |
| 130 | + await page.waitForTimeout(1500); |
| 131 | + |
| 132 | + const container = page.locator('.executable-sql-container').first(); |
| 133 | + await expect(container).toBeVisible(); |
| 134 | + |
| 135 | + await clickRunButton(container); |
| 136 | + |
| 137 | + const output = container.locator('.code-output'); |
| 138 | + await expect(output).toBeVisible({ timeout: 30_000 }); |
| 139 | + // SQL output renders as a table; assert the data row appears |
| 140 | + await expect(output).toContainText('Hello, World!', { timeout: 15_000 }); |
| 141 | + |
| 142 | + const errorSpan = container.locator('.code-output-error'); |
| 143 | + await expect(errorSpan).toHaveCount(0); |
| 144 | + }); |
| 145 | + |
| 146 | + // ─── Combined: all four in one document ────────────────── |
| 147 | + test('all four languages in a single document', async ({ page }) => { |
| 148 | + const md = [ |
| 149 | + '```bash', |
| 150 | + 'echo "Hello, World!"', |
| 151 | + '```', |
| 152 | + '', |
| 153 | + '```python', |
| 154 | + 'print("Hello, World!")', |
| 155 | + '```', |
| 156 | + '', |
| 157 | + '```javascript', |
| 158 | + 'console.log("Hello, World!");', |
| 159 | + '```', |
| 160 | + '', |
| 161 | + '```sql', |
| 162 | + 'CREATE TABLE IF NOT EXISTS greetings (id INTEGER PRIMARY KEY, message TEXT);', |
| 163 | + "INSERT INTO greetings VALUES (1, 'Hello, World!');", |
| 164 | + 'SELECT * FROM greetings;', |
| 165 | + '```', |
| 166 | + ].join('\n'); |
| 167 | + |
| 168 | + await page.locator(EDITOR_SELECTOR).fill(md); |
| 169 | + await page.waitForTimeout(2000); |
| 170 | + |
| 171 | + // All four containers should render |
| 172 | + const bashContainer = page.locator('.executable-code-container').first(); |
| 173 | + const pythonContainer = page.locator('.executable-python-container').first(); |
| 174 | + const jsContainer = page.locator('.executable-js-container').first(); |
| 175 | + const sqlContainer = page.locator('.executable-sql-container').first(); |
| 176 | + |
| 177 | + await expect(bashContainer).toBeVisible(); |
| 178 | + await expect(pythonContainer).toBeVisible(); |
| 179 | + await expect(jsContainer).toBeVisible(); |
| 180 | + await expect(sqlContainer).toBeVisible(); |
| 181 | + |
| 182 | + // Run each block individually in document order |
| 183 | + await clickRunButton(bashContainer); |
| 184 | + const bashOutput = bashContainer.locator('.code-output'); |
| 185 | + await expect(bashOutput).toContainText('Hello, World!', { timeout: 30_000 }); |
| 186 | + |
| 187 | + await clickRunButton(pythonContainer); |
| 188 | + const pythonOutput = pythonContainer.locator('.code-output'); |
| 189 | + await expect(pythonOutput).toContainText('Hello, World!', { timeout: 60_000 }); |
| 190 | + |
| 191 | + await clickRunButton(jsContainer); |
| 192 | + const jsOutput = jsContainer.locator('.code-output'); |
| 193 | + await expect(jsOutput).toContainText('Hello, World!', { timeout: 15_000 }); |
| 194 | + |
| 195 | + await clickRunButton(sqlContainer); |
| 196 | + const sqlOutput = sqlContainer.locator('.code-output'); |
| 197 | + await expect(sqlOutput).toContainText('Hello, World!', { timeout: 30_000 }); |
| 198 | + |
| 199 | + // Zero errors across all containers |
| 200 | + const errors = page.locator('.code-output-error'); |
| 201 | + await expect(errors).toHaveCount(0); |
| 202 | + }); |
| 203 | +}); |
0 commit comments