-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiagnostics.spec.ts
More file actions
460 lines (367 loc) · 14.3 KB
/
diagnostics.spec.ts
File metadata and controls
460 lines (367 loc) · 14.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
import { expect, test } from '@playwright/test'
import {
addWorkspaceTab,
ensurePanelToolsVisible,
ensureDiagnosticsDrawerOpen,
getActiveComponentEditorLineNumber,
getActiveStylesEditorLineNumber,
setWorkspaceTabSource,
runComponentLint,
runStylesLint,
runTypecheck,
setComponentEditorSource,
setStylesEditorSource,
waitForInitialRender,
} from './helpers/app-test-helpers.js'
test('clear component action opens confirm dialog and can be canceled', async ({
page,
}) => {
await waitForInitialRender(page)
const dialog = page.getByRole('dialog')
const jsxEditor = page.getByRole('textbox', {
name: 'Component source editor fallback',
includeHidden: true,
})
const beforeValue = await jsxEditor.inputValue()
await page.getByLabel('Clear component source').click()
await expect(dialog).toHaveAttribute('open', '')
await expect(page.getByRole('heading', { level: 3 })).toHaveText(
'Clear Component source?',
)
await dialog.getByRole('button', { name: 'Cancel' }).click()
await expect(page.getByRole('dialog')).toBeHidden()
await expect(jsxEditor).toHaveValue(beforeValue)
})
test('clear component diagnostics removes type errors and restores rendered status', async ({
page,
}) => {
await waitForInitialRender(page)
await ensurePanelToolsVisible(page, 'component')
await setComponentEditorSource(
page,
["const count: number = 'oops'", 'const App = () => <button>ready</button>'].join(
'\n',
),
)
await page.getByRole('button', { name: 'Typecheck' }).click()
const diagnosticsToggle = page.getByRole('button', { name: /^Diagnostics/ })
await expect(diagnosticsToggle).toHaveClass(/diagnostics-toggle--error/)
await expect(page.getByText(/Rendered \(Type errors: [1-9]\d*\)/)).toBeVisible()
await ensureDiagnosticsDrawerOpen(page)
await page.getByRole('button', { name: 'Reset component' }).click()
await expect(page.getByText('No diagnostics yet.')).toHaveCount(2)
await expect(diagnosticsToggle).toHaveText('Diagnostics')
await expect(diagnosticsToggle).toHaveClass(/diagnostics-toggle--neutral/)
await expect(page.getByText('Rendered', { exact: true })).toHaveClass(/status--neutral/)
})
test('typecheck success reports ok diagnostics state in button and drawer', async ({
page,
}) => {
await waitForInitialRender(page)
await runTypecheck(page)
const diagnosticsToggle = page.getByRole('button', { name: /^Diagnostics/ })
await expect(page.getByText('Rendered', { exact: true })).toBeVisible()
await expect(diagnosticsToggle).toHaveClass(/diagnostics-toggle--ok/)
await expect(diagnosticsToggle).toHaveText('Diagnostics')
await ensureDiagnosticsDrawerOpen(page)
await expect(page.getByText('No TypeScript errors found.')).toBeVisible()
})
test('typecheck error reports diagnostics count in button and details in drawer', async ({
page,
}) => {
await waitForInitialRender(page)
await setComponentEditorSource(
page,
["const broken: number = 'oops'", 'const App = () => <button>hello</button>'].join(
'\n',
),
)
await runTypecheck(page)
const diagnosticsToggle = page.getByRole('button', { name: /^Diagnostics/ })
await expect(page.getByText(/Rendered \(Type errors: [1-9]\d*\)/)).toBeVisible()
await expect(diagnosticsToggle).toHaveClass(/diagnostics-toggle--error/)
await expect(diagnosticsToggle).toHaveText(/Diagnostics \([1-9]\d*\)/)
await expect(
page.getByRole('button', { name: 'Close diagnostics drawer' }),
).toBeVisible()
await expect(page.getByText('TypeScript found')).toBeVisible()
await expect(page.getByText(/TS\d+/)).toBeVisible()
})
test('dom mode typecheck resolves @knighted/jsx type-only imports', async ({ page }) => {
await waitForInitialRender(page)
await ensurePanelToolsVisible(page, 'component')
await page.getByRole('combobox', { name: 'Render mode' }).selectOption('dom')
await setComponentEditorSource(
page,
[
"import type { JsxChildren } from '@knighted/jsx'",
'',
'type DrawerProps = {',
' children?: JsxChildren',
'}',
'',
'const Drawer = ({ children }: DrawerProps) => {',
' return <div className="drawer">{children}</div>',
'}',
'',
'const App = () => {',
' return (',
' <Drawer>',
' <p>drawer</p>',
' </Drawer>',
' )',
'}',
].join('\n'),
)
await runTypecheck(page)
await ensureDiagnosticsDrawerOpen(page)
await expect(page.locator('#diagnostics-component')).toContainText(
'No TypeScript errors found.',
)
const diagnosticsText = await page.locator('#diagnostics-component').innerText()
expect(diagnosticsText).not.toContain("Cannot find module '@knighted/jsx'")
})
test('typecheck resolves .js import to workspace tsx module tab', async ({ page }) => {
await waitForInitialRender(page)
await ensurePanelToolsVisible(page, 'component')
await addWorkspaceTab(page)
await setWorkspaceTabSource(page, {
fileName: 'module.tsx',
kind: 'component',
source: [
'type ThingProps = { label: string }',
'export const Thing = ({ label }: ThingProps) => <p>{label}</p>',
].join('\n'),
})
await setComponentEditorSource(
page,
[
"import { Thing } from './module.js'",
'const App = () => <Thing label="ok" />',
'',
].join('\n'),
)
await runTypecheck(page)
await ensureDiagnosticsDrawerOpen(page)
await expect(page.locator('#diagnostics-component')).toContainText(
'No TypeScript errors found.',
)
const diagnosticsText = await page.locator('#diagnostics-component').innerText()
expect(diagnosticsText).not.toContain("Cannot find module './module.js'")
})
test('typecheck resolves parent-relative .js import to workspace tsx module tab', async ({
page,
}) => {
await waitForInitialRender(page)
await ensurePanelToolsVisible(page, 'component')
await addWorkspaceTab(page)
await setWorkspaceTabSource(page, {
fileName: 'module.tsx',
kind: 'component',
source: [
'type ThingProps = { label: string }',
'export const Thing = ({ label }: ThingProps) => <p>{label}</p>',
].join('\n'),
})
await setComponentEditorSource(
page,
[
"import { Thing } from '../components/module.js'",
'const App = () => <Thing label="ok" />',
'',
].join('\n'),
)
await runTypecheck(page)
await ensureDiagnosticsDrawerOpen(page)
await expect(page.locator('#diagnostics-component')).toContainText(
'No TypeScript errors found.',
)
const diagnosticsText = await page.locator('#diagnostics-component').innerText()
expect(diagnosticsText).not.toContain("Cannot find module '../components/module.js'")
})
test('typecheck does not report TS2307 for stylesheet side-effect imports', async ({
page,
}) => {
await waitForInitialRender(page)
await ensurePanelToolsVisible(page, 'component')
await setComponentEditorSource(
page,
["import '../styles/app.css'", '', 'const App = () => <p>style import</p>', ''].join(
'\n',
),
)
await runTypecheck(page)
await ensureDiagnosticsDrawerOpen(page)
await expect(page.locator('#diagnostics-component')).toContainText(
'No TypeScript errors found.',
)
const diagnosticsText = await page.locator('#diagnostics-component').innerText()
expect(diagnosticsText).not.toContain("Cannot find module '../styles/app.css'")
})
test('component diagnostics rows navigate editor to reported line', async ({ page }) => {
await waitForInitialRender(page)
await setComponentEditorSource(
page,
[
"const brokenCount: number = 'oops'",
'const App = () => <button>{brokenCount.toUpperCase()}</button>',
].join('\n'),
)
await runTypecheck(page)
await expect(page.getByRole('button', { name: /^Diagnostics/ })).toHaveClass(
/diagnostics-toggle--error/,
)
await ensureDiagnosticsDrawerOpen(page)
const targetDiagnostic = page.getByRole('button', { name: /^L2(:\d+)?\s/ }).first()
await expect(targetDiagnostic).toBeVisible()
await targetDiagnostic.click()
await expect(targetDiagnostic).toHaveClass(/diagnostic-line-button--active/)
await expect.poll(() => getActiveComponentEditorLineNumber(page)).toBe('2')
})
test('component diagnostics support arrow navigation and enter jump', async ({
page,
}) => {
await waitForInitialRender(page)
await setComponentEditorSource(
page,
[
"const broken: number = 'oops'",
'const App = () => <button>{missingName}</button>',
].join('\n'),
)
await runTypecheck(page)
await expect(page.getByRole('button', { name: /^Diagnostics/ })).toHaveClass(
/diagnostics-toggle--error/,
)
await ensureDiagnosticsDrawerOpen(page)
const diagnosticButtons = page.getByRole('button', { name: /^L\d+(:\d+)?\s/ })
const firstDiagnostic = diagnosticButtons.first()
const secondDiagnostic = diagnosticButtons.nth(1)
await expect(firstDiagnostic).toBeVisible()
await expect(secondDiagnostic).toBeVisible()
await firstDiagnostic.focus()
await firstDiagnostic.press('ArrowDown')
await expect(secondDiagnostic).toBeFocused()
await secondDiagnostic.press('Enter')
await expect(secondDiagnostic).toHaveClass(/diagnostic-line-button--active/)
await expect.poll(() => getActiveComponentEditorLineNumber(page)).toBe('2')
})
test('component lint error reports diagnostics count and details', async ({ page }) => {
await waitForInitialRender(page)
await setComponentEditorSource(
page,
['const unusedValue = 1', 'const App = () => <button>lint me</button>'].join('\n'),
)
await runComponentLint(page)
const diagnosticsToggle = page.getByRole('button', { name: /^Diagnostics/ })
await expect(page.getByText(/Rendered \(Lint issues: [1-9]\d*\)/)).toBeVisible()
await expect(diagnosticsToggle).toHaveClass(/diagnostics-toggle--error/)
await expect(diagnosticsToggle).toHaveText(/Diagnostics \([1-9]\d*\)/)
await expect(
page.getByRole('button', { name: 'Close diagnostics drawer' }),
).toBeVisible()
await expect(page.getByText('Biome reported issues.')).toBeVisible()
})
test('styles diagnostics rows navigate editor to reported line', async ({ page }) => {
await waitForInitialRender(page)
await ensurePanelToolsVisible(page, 'styles')
await setStylesEditorSource(
page,
['.card {', ' color: red', ' color: blue;', '}'].join('\n'),
)
await runStylesLint(page)
await expect(page.getByRole('button', { name: /^Diagnostics/ })).toHaveClass(
/diagnostics-toggle--error/,
)
await ensureDiagnosticsDrawerOpen(page)
const targetDiagnostic = page.getByRole('button', { name: /^L3(:\d+)?\s/ }).first()
await expect(targetDiagnostic).toBeVisible()
await targetDiagnostic.click()
await expect(targetDiagnostic).toHaveClass(/diagnostic-line-button--active/)
await expect.poll(() => getActiveStylesEditorLineNumber(page)).toBe('3')
})
test('sass compiler warnings surface in styles diagnostics', async ({ page }) => {
await waitForInitialRender(page)
await ensurePanelToolsVisible(page, 'styles')
await page.getByRole('combobox', { name: 'Style mode' }).selectOption('sass')
await setStylesEditorSource(
page,
['.card {', ' color: darken(#ff0000, 10%);', '}'].join('\n'),
)
await expect(page.getByRole('status', { name: 'App status' })).toHaveText('Rendered')
await ensureDiagnosticsDrawerOpen(page)
await expect(page.locator('#diagnostics-styles')).toContainText(
'Style compilation warnings.',
)
})
test('clear component diagnostics resets rendered lint-issue status pill', async ({
page,
}) => {
await waitForInitialRender(page)
await setComponentEditorSource(
page,
[
'const unusedValue = 1',
'const App = () => <button type="button">lint me</button>',
].join('\n'),
)
await runComponentLint(page)
const diagnosticsToggle = page.getByRole('button', { name: /^Diagnostics/ })
await expect(page.getByText(/Rendered \(Lint issues: [1-9]\d*\)/)).toHaveClass(
/status--error/,
)
await ensureDiagnosticsDrawerOpen(page)
await page.getByRole('button', { name: 'Reset component' }).click()
await expect(page.getByText('No diagnostics yet.')).toHaveCount(2)
await expect(diagnosticsToggle).toHaveText('Diagnostics')
await expect(diagnosticsToggle).toHaveClass(/diagnostics-toggle--neutral/)
await expect(page.getByText('Rendered', { exact: true })).toHaveClass(/status--neutral/)
})
test('component lint ignores only unused App binding', async ({ page }) => {
await waitForInitialRender(page)
await setComponentEditorSource(
page,
[
'function App() { return <button type="button">App</button> }',
'function View() { return <section>View</section> }',
'function render() { return null }',
].join('\n'),
)
await runComponentLint(page)
await ensureDiagnosticsDrawerOpen(page)
const diagnosticsToggle = page.getByRole('button', { name: /^Diagnostics/ })
await expect(page.getByText(/Rendered \(Lint issues: [1-9]\d*\)/)).toHaveClass(
/status--error/,
)
await expect(diagnosticsToggle).toHaveText(/Diagnostics \([1-9]\d*\)/)
await expect(diagnosticsToggle).toHaveClass(/diagnostics-toggle--error/)
const diagnosticsText = await page.getByRole('complementary').innerText()
expect(diagnosticsText).toContain('Biome reported issues.')
expect(diagnosticsText).not.toContain('This variable App is unused')
expect(diagnosticsText).not.toContain('This function App is unused')
expect(diagnosticsText).toContain('This function View is unused')
expect(diagnosticsText).toContain('This function render is unused')
})
test('component lint with unresolved issues enters pending diagnostics state while typing', async ({
page,
}) => {
await waitForInitialRender(page)
await setComponentEditorSource(
page,
['const unusedValue = 1', 'const App = () => <button>pending</button>'].join('\n'),
)
await runComponentLint(page)
const diagnosticsToggle = page.getByRole('button', { name: /^Diagnostics/ })
await expect(diagnosticsToggle).toHaveClass(/diagnostics-toggle--error/)
await setComponentEditorSource(
page,
['const unusedValue = 1', 'const App = () => <button>pending now</button>'].join(
'\n',
),
)
await expect(diagnosticsToggle).toHaveClass(/diagnostics-toggle--pending/)
await expect(diagnosticsToggle).toHaveAttribute('aria-busy', 'true')
await expect(page.getByText(/Rendered \(Lint issues: [1-9]\d*\)/)).toBeVisible()
await expect(diagnosticsToggle).toHaveClass(/diagnostics-toggle--error/)
await expect(diagnosticsToggle).toHaveAttribute('aria-busy', 'false')
})