Skip to content

Commit 39e7210

Browse files
authored
test(devtools-ui): split type assertions into '*.test-d' files and enable vitest 'typecheck' (#611)
1 parent bd94643 commit 39e7210

8 files changed

Lines changed: 46 additions & 42 deletions

File tree

‎knip.json‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
"**/src/svelte/**"
2525
]
2626
},
27-
"packages/devtools-ui": {
28-
"entry": ["**/tests/**/*.ts"]
29-
},
3027
"packages/angular-devtools": {
3128
"ignoreDependencies": ["tslib"],
3229
"entry": ["provider/**/*.ts", "src/**/*.ts"]
File renamed without changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { describe, expectTypeOf, it } from 'vitest'
2+
import { CopiedCopier } from '../src/components/icons'
3+
import type { TanStackDevtoolsTheme } from '../src'
4+
5+
describe('CopiedCopier', () => {
6+
it('keeps theme required', () => {
7+
expectTypeOf<Parameters<typeof CopiedCopier>[0]>().toEqualTypeOf<{
8+
theme: TanStackDevtoolsTheme
9+
}>()
10+
})
11+
})

‎packages/devtools-ui/tests/index.test.ts‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { readFile } from 'node:fs/promises'
22
import { resolve } from 'node:path'
33
import { render } from '@solidjs/web'
44
import { createComponent } from 'solid-js'
5-
import { afterEach, describe, expect, expectTypeOf, it } from 'vitest'
5+
import { afterEach, describe, expect, it } from 'vitest'
66
import {
77
Button,
88
Checkbox,
@@ -19,7 +19,6 @@ import {
1919
Tag,
2020
TanStackLogo,
2121
} from '../src'
22-
import { CopiedCopier } from '../src/components/icons'
2322
import { ThemeContextProvider } from '../src/components/theme'
2423
import {
2524
DEVTOOLS_FORCED_COLORS_STYLE_ID,
@@ -29,7 +28,6 @@ import {
2928
resolveSemanticTheme,
3029
} from '../src/internal'
3130
import { tokens } from '../src/styles/tokens'
32-
import type { TanStackDevtoolsTheme } from '../src'
3331
import type { ButtonVariant } from '../src/components/button'
3432

3533
const disposers: Array<() => void> = []
@@ -257,12 +255,6 @@ describe.each(['light', 'dark'] as const)('%s Tag legacy matrix', (theme) => {
257255
})
258256
})
259257

260-
it('keeps CopiedCopier theme required', () => {
261-
expectTypeOf<Parameters<typeof CopiedCopier>[0]>().toEqualTypeOf<{
262-
theme: TanStackDevtoolsTheme
263-
}>()
264-
})
265-
266258
it('keeps the authored Check icon signature and uses current color for both states', async () => {
267259
const iconsSource = await readFile(
268260
resolve(process.cwd(), 'src/components/icons.tsx'),
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { describe, expectTypeOf, it } from 'vitest'
2+
import { semanticThemes } from '../src/internal'
3+
import type { SemanticTheme } from '../src/internal'
4+
5+
describe('semantic themes', () => {
6+
it('retains literal structural token types', () => {
7+
expectTypeOf(semanticThemes.light.space[1]).toEqualTypeOf<'4px'>()
8+
expectTypeOf(semanticThemes.light.gap.sectionLarge).toEqualTypeOf<'16px'>()
9+
expectTypeOf(
10+
semanticThemes.light.padding.controlBlock,
11+
).toEqualTypeOf<'6px'>()
12+
expectTypeOf(
13+
semanticThemes.light.type.labelSm.tracking,
14+
).toEqualTypeOf<'0.5px'>()
15+
expectTypeOf(semanticThemes.light.type.bodyMd.weight).toEqualTypeOf<300>()
16+
expectTypeOf(semanticThemes.light.radius.overlay).toEqualTypeOf<'8px'>()
17+
expectTypeOf(semanticThemes.light.motion.graceMs).toEqualTypeOf<400>()
18+
expectTypeOf<SemanticTheme['space']>().toEqualTypeOf<
19+
Readonly<{ 1: '4px'; 2: '8px'; 3: '12px'; 4: '16px' }>
20+
>()
21+
expectTypeOf<SemanticTheme['color']['surface']>().toEqualTypeOf<
22+
Readonly<{
23+
app: string
24+
workspace: string
25+
subtle: string
26+
elevated: string
27+
brand: string
28+
}>
29+
>()
30+
})
31+
})

‎packages/devtools-ui/tests/semantic-theme.test.ts‎

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { describe, expect, expectTypeOf, it } from 'vitest'
1+
import { describe, expect, it } from 'vitest'
22
import { resolveSemanticTheme, semanticThemes } from '../src/internal'
33
import { tokens } from '../src/styles/tokens'
4-
import type { SemanticTheme } from '../src/internal'
54

65
const commonTheme = {
76
font: {
@@ -210,32 +209,6 @@ describe('semantic themes', () => {
210209
expect(resolveSemanticTheme('dark')).toEqual(expectedDark)
211210
})
212211

213-
it('retains literal structural token types', () => {
214-
expectTypeOf(semanticThemes.light.space[1]).toEqualTypeOf<'4px'>()
215-
expectTypeOf(semanticThemes.light.gap.sectionLarge).toEqualTypeOf<'16px'>()
216-
expectTypeOf(
217-
semanticThemes.light.padding.controlBlock,
218-
).toEqualTypeOf<'6px'>()
219-
expectTypeOf(
220-
semanticThemes.light.type.labelSm.tracking,
221-
).toEqualTypeOf<'0.5px'>()
222-
expectTypeOf(semanticThemes.light.type.bodyMd.weight).toEqualTypeOf<300>()
223-
expectTypeOf(semanticThemes.light.radius.overlay).toEqualTypeOf<'8px'>()
224-
expectTypeOf(semanticThemes.light.motion.graceMs).toEqualTypeOf<400>()
225-
expectTypeOf<SemanticTheme['space']>().toEqualTypeOf<
226-
Readonly<{ 1: '4px'; 2: '8px'; 3: '12px'; 4: '16px' }>
227-
>()
228-
expectTypeOf<SemanticTheme['color']['surface']>().toEqualTypeOf<
229-
Readonly<{
230-
app: string
231-
workspace: string
232-
subtle: string
233-
elevated: string
234-
brand: string
235-
}>
236-
>()
237-
})
238-
239212
it('freezes every object in both theme graphs', () => {
240213
expectDeeplyFrozen(semanticThemes)
241214
})

‎packages/devtools-ui/vite.config.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ const config = defineConfig({
1717
test: {
1818
name: packageJson.name,
1919
dir: './',
20-
include: ['tests/**/*.{ts,tsx}'],
21-
exclude: ['tests/test-setup.ts', '**/node_modules/**'],
20+
include: ['tests/**/*.test.{ts,tsx}'],
2221
watch: false,
2322
environment: 'jsdom',
2423
setupFiles: ['./tests/test-setup.ts'],
@@ -30,6 +29,7 @@ const config = defineConfig({
3029
// are unaffected.
3130
testTimeout: 30_000,
3231
hookTimeout: 30_000,
32+
typecheck: { enabled: true },
3333
},
3434
})
3535

0 commit comments

Comments
 (0)