-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiagnostics.spec.ts
More file actions
672 lines (536 loc) · 20.7 KB
/
Copy pathdiagnostics.spec.ts
File metadata and controls
672 lines (536 loc) · 20.7 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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
import { expect, test } from '@playwright/test'
import {
addWorkspaceTab,
ensurePanelToolsVisible,
ensureDiagnosticsDrawerOpen,
getActiveComponentEditorLineNumber,
getActiveStylesEditorLineNumber,
setWorkspaceTabSource,
runComponentLint,
runStylesLint,
runTypecheck,
setComponentEditorSource,
setStylesEditorSource,
waitForLintDiagnosticsIssues,
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 expect(
page.locator('.editor-panel[data-editor-kind="component"] .cm-content').first(),
).toContainText("const count: number = 'oops'")
await runTypecheck(page)
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 types' }).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('typecheck recognizes css module class maps in React mode', async ({ page }) => {
await waitForInitialRender(page)
await ensurePanelToolsVisible(page, 'component')
await addWorkspaceTab(page, { type: 'style' })
await page.getByRole('button', { name: 'Rename tab module.css' }).click()
const renameInput = page.getByLabel('Rename module.css')
await renameInput.fill('app.module.css')
await renameInput.press('Enter')
await setWorkspaceTabSource(page, {
fileName: 'app.module.css',
kind: 'styles',
source: ['.btn {', ' color: #fff;', '}'].join('\n'),
})
await setComponentEditorSource(
page,
[
"import styles from '../styles/app.module.css'",
'',
'const App = () => <button className={styles.btn}>ok</button>',
'',
].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("Property 'btn' does not exist on type 'string'")
})
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('component lint reports missing button type prop', async ({ page }) => {
await waitForInitialRender(page)
await setComponentEditorSource(page, 'const App = () => <button>lint me</button>')
await runComponentLint(page)
await waitForLintDiagnosticsIssues(page, {
rerunLint: async () => {
await runComponentLint(page)
},
})
await expect(page.getByText(/a11y\/useButtonType/)).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 waitForLintDiagnosticsIssues(page, {
rerunLint: async () => {
await runStylesLint(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('styles lint reports CSS syntax errors', async ({ page }) => {
await waitForInitialRender(page)
await ensurePanelToolsVisible(page, 'styles')
await setStylesEditorSource(page, ['p {', ' color green;', '}'].join('\n'))
await runStylesLint(page)
await waitForLintDiagnosticsIssues(page, {
rerunLint: async () => {
await runStylesLint(page)
},
})
await expect(page.locator('#diagnostics-styles')).toContainText(
'Biome reported issues.',
)
})
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 lint' }).click()
await expect(page.locator('#diagnostics-styles')).toContainText('No diagnostics yet.')
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 becomes stale and waits for manual rerun', 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--neutral/)
await expect(diagnosticsToggle).toHaveAttribute('aria-busy', 'false')
await ensureDiagnosticsDrawerOpen(page)
await expect(page.locator('#diagnostics-styles')).toContainText(
'Source changed. Click Lint to run diagnostics.',
)
await expect(page.getByText('Rendered', { exact: true })).toBeVisible()
})
test('styles active tab shows lint-only diagnostics drawer actions', async ({ page }) => {
await waitForInitialRender(page)
await ensurePanelToolsVisible(page, 'styles')
await ensureDiagnosticsDrawerOpen(page)
await expect(page.locator('[data-diagnostics-scope="component"]')).toBeHidden()
await expect(page.locator('#diagnostics-clear-styles')).toHaveText('Reset lint')
await expect(page.locator('#diagnostics-clear-styles')).toBeVisible()
await expect(page.locator('#diagnostics-clear-component')).toBeHidden()
await expect(page.locator('#diagnostics-clear-all')).toBeHidden()
})
test('component lint completion is ignored after switching to another component tab', async ({
page,
}) => {
await waitForInitialRender(page)
await ensurePanelToolsVisible(page, 'component')
await addWorkspaceTab(page)
const heavyLintSource = [
...Array.from({ length: 120 }, (_, index) => `const unused${index} = ${index}`),
'const App = () => <button>module tab</button>',
].join('\n')
await setWorkspaceTabSource(page, {
fileName: 'module.tsx',
kind: 'component',
source: heavyLintSource,
})
const lintTrigger = page.getByRole('button', { name: 'Lint' }).first()
await lintTrigger.click()
await setComponentEditorSource(
page,
'const App = () => <button type="button">A</button>',
)
await expect(page.locator('#diagnostics-styles')).toContainText(
'Source changed. Click Lint to run diagnostics.',
)
await expect(page.locator('#diagnostics-styles')).not.toContainText(
'Biome reported issues.',
)
await expect(page.getByRole('button', { name: /^Diagnostics/ })).toHaveClass(
/diagnostics-toggle--neutral/,
)
})
test('switching tabs clears diagnostics while drawer is open', async ({ page }) => {
await waitForInitialRender(page)
await setComponentEditorSource(page, 'const App = () => <button>lint me</button>')
await runComponentLint(page)
await ensureDiagnosticsDrawerOpen(page)
await expect(page.locator('#diagnostics-styles')).toContainText(
'Biome reported issues.',
)
await page.getByRole('button', { name: 'Open tab app.css' }).click()
await expect(page.locator('#diagnostics-styles')).toContainText('No diagnostics yet.')
await expect(page.getByRole('button', { name: /^Diagnostics/ })).toHaveClass(
/diagnostics-toggle--neutral/,
)
})
test('same-tab edits with drawer open replace lint issues with stale state', async ({
page,
}) => {
await waitForInitialRender(page)
await setComponentEditorSource(
page,
['const count: string = 1', 'const App = () => <button>Inactive</button>'].join('\n'),
)
await runTypecheck(page)
await runComponentLint(page)
await ensureDiagnosticsDrawerOpen(page)
await expect(page.locator('#diagnostics-component')).toContainText('TypeScript found')
await expect(page.locator('#diagnostics-styles')).toContainText(
'Biome reported issues.',
)
await setComponentEditorSource(
page,
[
'const count: string = "ok"',
'const App = () => <button type="button">Inactive</button>',
].join('\n'),
)
await expect(page.locator('#diagnostics-component')).not.toContainText('TS2322')
await expect(page.locator('#diagnostics-styles')).toContainText(
'Source changed. Click Lint to run diagnostics.',
)
await expect(page.locator('#diagnostics-styles')).not.toContainText(
'Biome reported issues.',
)
})
test('reset lint on styles tab clears in-flight component lint state', async ({
page,
}) => {
await waitForInitialRender(page)
const heavyLintSource = [
...Array.from({ length: 120 }, (_, index) => `const unused${index} = ${index}`),
'const App = () => <button>component tab</button>',
].join('\n')
await setComponentEditorSource(page, heavyLintSource)
await ensureDiagnosticsDrawerOpen(page)
await page.getByRole('button', { name: 'Lint' }).first().click()
await page.getByRole('button', { name: 'Open tab app.css' }).click()
await page.locator('#diagnostics-clear-styles').click()
await expect(page.getByRole('button', { name: /^Diagnostics/ })).toHaveAttribute(
'aria-busy',
'false',
)
await expect(page.locator('#diagnostics-styles')).toContainText('No diagnostics yet.')
await expect(page.locator('#diagnostics-styles')).not.toContainText(
'Biome reported issues.',
)
})