Skip to content

Commit f2d87cb

Browse files
committed
Fix typing
1 parent b584792 commit f2d87cb

18 files changed

Lines changed: 703 additions & 441 deletions

File tree

packages/bun-plugin/src/__tests__/plugin.test.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ let setDebugSpy: ReturnType<typeof spyOn>
2626
let hasDevupUISpy: ReturnType<typeof spyOn>
2727
let codeExtractSpy: ReturnType<typeof spyOn>
2828

29+
type CodeExtractResult = ReturnType<typeof wasm.codeExtract>
30+
31+
function createCodeExtractResult(): CodeExtractResult {
32+
return {
33+
code: 'code',
34+
css: '',
35+
cssFile: null,
36+
map: null,
37+
updatedBaseStyle: false,
38+
free: mock(),
39+
[Symbol.dispose]: mock(),
40+
} as unknown as CodeExtractResult
41+
}
42+
2943
beforeEach(() => {
3044
getDefaultThemeSpy = spyOn(wasm, 'getDefaultTheme').mockReturnValue('default')
3145
existsSyncSpy = spyOn(fs, 'existsSync').mockReturnValue(false)
@@ -38,15 +52,9 @@ beforeEach(() => {
3852
consoleErrorSpy = spyOn(console, 'error').mockImplementation(() => {})
3953
setDebugSpy = spyOn(wasm, 'setDebug').mockReturnValue(undefined)
4054
hasDevupUISpy = spyOn(wasm, 'hasDevupUI').mockReturnValue(false)
41-
codeExtractSpy = spyOn(wasm, 'codeExtract').mockReturnValue({
42-
code: 'code',
43-
css: '',
44-
cssFile: null,
45-
map: null,
46-
updatedBaseStyle: false,
47-
free: mock(),
48-
[Symbol.dispose]: mock(),
49-
} as any)
55+
codeExtractSpy = spyOn(wasm, 'codeExtract').mockReturnValue(
56+
createCodeExtractResult(),
57+
)
5058
})
5159

5260
afterEach(() => {

packages/components/src/components/Button/__tests__/index.browser.test.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,21 @@ describe('Button', () => {
6161
})
6262

6363
it('should not have px when a wrong size variable is provided', () => {
64-
const { container } = render(
65-
// @ts-expect-error
66-
<Button size="big">Click me</Button>,
67-
)
64+
const invalidSizeProps = {
65+
size: 'big',
66+
children: 'Click me',
67+
} as unknown as React.ComponentProps<typeof Button>
68+
const { container } = render(<Button {...invalidSizeProps} />)
6869
expect(container).toMatchSnapshot()
6970
expect(container.querySelector('button')).not.toHaveClass('px-0-16px--1')
7071
})
7172

7273
it('should not have bg when a wrong size variable is provided', () => {
73-
const { container } = render(
74-
// @ts-expect-error
75-
<Button variant="red">Click me</Button>,
76-
)
74+
const invalidVariantProps = {
75+
variant: 'red',
76+
children: 'Click me',
77+
} as unknown as React.ComponentProps<typeof Button>
78+
const { container } = render(<Button {...invalidVariantProps} />)
7779
expect(container).toMatchSnapshot()
7880
expect(container.querySelector('button')).not.toHaveClass(
7981
'bg-0-color-mix(in srgb,var(--primary,#8163E1) 10%,#FFF 90%)-8380715471663921674-1',

packages/components/src/components/Select/__tests__/index.browser.test.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,11 @@ describe('Select', () => {
223223
})
224224

225225
it('should have undefined gap when type is not right', () => {
226-
// @ts-expect-error - test for wrong type
227-
const { container } = render(<Select type="no-type">{children}</Select>)
226+
const invalidTypeProps = {
227+
type: 'no-type',
228+
children,
229+
} as unknown as React.ComponentProps<typeof Select>
230+
const { container } = render(<Select {...invalidTypeProps} />)
228231
const selectToggle = container.querySelector('[aria-label="Select toggle"]')
229232
fireEvent.click(selectToggle!)
230233
const option2 = container.querySelector('[data-value="Option 2"]')

packages/next-plugin/src/__tests__/css-loader.test.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515

1616
import devupUICssLoader, { resetInit } from '../css-loader'
1717

18+
type CssLoaderThis = ThisParameterType<typeof devupUICssLoader>
19+
1820
let getCssSpy: ReturnType<typeof spyOn>
1921
let registerThemeSpy: ReturnType<typeof spyOn>
2022
let importSheetSpy: ReturnType<typeof spyOn>
@@ -75,7 +77,7 @@ describe('devupUICssLoader', () => {
7577
addContextDependency,
7678
resourcePath: 'devup-ui.css',
7779
getOptions: () => ({ ...defaultOptions, watch: false }),
78-
} as any)(Buffer.from('data'), '')
80+
} as unknown as CssLoaderThis)(Buffer.from('data'), '')
7981
expect(callback).toHaveBeenCalledWith(
8082
null,
8183
Buffer.from('data'),
@@ -97,7 +99,7 @@ describe('devupUICssLoader', () => {
9799
addContextDependency,
98100
getOptions: () => ({ ...defaultOptions, watch: true }),
99101
resourcePath: 'devup-ui.css',
100-
} as any)(Buffer.from('data'), '')
102+
} as unknown as CssLoaderThis)(Buffer.from('data'), '')
101103
expect(callback).toHaveBeenCalledTimes(1)
102104
expect(getCssSpy).toHaveBeenCalledTimes(1)
103105
getCssSpy.mockClear()
@@ -106,7 +108,7 @@ describe('devupUICssLoader', () => {
106108
addContextDependency,
107109
getOptions: () => ({ ...defaultOptions, watch: true }),
108110
resourcePath: 'devup-ui.css',
109-
} as any)(Buffer.from('data'), '')
111+
} as unknown as CssLoaderThis)(Buffer.from('data'), '')
110112

111113
expect(getCssSpy).toHaveBeenCalledTimes(1)
112114

@@ -117,7 +119,7 @@ describe('devupUICssLoader', () => {
117119
addContextDependency,
118120
getOptions: () => ({ ...defaultOptions, watch: true }),
119121
resourcePath: 'devup-ui-10.css',
120-
} as any)(Buffer.from(''), '')
122+
} as unknown as CssLoaderThis)(Buffer.from(''), '')
121123

122124
expect(getCssSpy).toHaveBeenCalledTimes(1)
123125
})
@@ -133,7 +135,7 @@ describe('devupUICssLoader', () => {
133135
addContextDependency,
134136
getOptions: () => ({ ...defaultOptions, watch: true }),
135137
resourcePath: 'devup-ui.css',
136-
} as any)(Buffer.from('data'), '')
138+
} as unknown as CssLoaderThis)(Buffer.from('data'), '')
137139

138140
// Should read files from disk
139141
expect(existsSyncSpy).toHaveBeenCalledTimes(4)
@@ -155,7 +157,7 @@ describe('devupUICssLoader', () => {
155157
addContextDependency,
156158
getOptions: () => ({ ...defaultOptions, watch: true }),
157159
resourcePath: 'devup-ui.css',
158-
} as any)(Buffer.from('data'), '')
160+
} as unknown as CssLoaderThis)(Buffer.from('data'), '')
159161

160162
// Should call registerTheme with empty object when theme is missing
161163
expect(registerThemeSpy).toHaveBeenCalledWith({})
@@ -190,7 +192,11 @@ describe('devupUICssLoader', () => {
190192
coordinatorPortFile: portFile,
191193
}),
192194
resourcePath: 'devup-ui-1.css',
193-
} as any)(Buffer.from('stale content'), 'existing-map', 'meta')
195+
} as unknown as CssLoaderThis)(
196+
Buffer.from('stale content'),
197+
'existing-map',
198+
'meta',
199+
)
194200
})
195201

196202
expect(result).toBe('.a{color:red}')
@@ -235,7 +241,7 @@ describe('devupUICssLoader', () => {
235241
coordinatorPortFile: portFile,
236242
}),
237243
resourcePath: 'devup-ui.css',
238-
} as any)(Buffer.from('stale'), '', '')
244+
} as unknown as CssLoaderThis)(Buffer.from('stale'), '', '')
239245
})
240246

241247
expect(result).toBe('.full{display:flex}')
@@ -278,7 +284,11 @@ describe('devupUICssLoader', () => {
278284
}),
279285
// Turbopack embeds query in resourcePath
280286
resourcePath: '/path/to/df/devup-ui/devup-ui.css?fileNum=79',
281-
} as any)(Buffer.from('stale content'), 'existing-map', 'meta')
287+
} as unknown as CssLoaderThis)(
288+
Buffer.from('stale content'),
289+
'existing-map',
290+
'meta',
291+
)
282292
})
283293

284294
expect(result).toBe('.file79{color:blue}')
@@ -320,7 +330,7 @@ describe('devupUICssLoader', () => {
320330
// resourcePath without query, query in separate property
321331
resourcePath: '/path/to/df/devup-ui/devup-ui.css',
322332
resourceQuery: '?fileNum=3',
323-
} as any)(Buffer.from('stale'), '', '')
333+
} as unknown as CssLoaderThis)(Buffer.from('stale'), '', '')
324334
})
325335

326336
expect(result).toBe('.file3{color:green}')
@@ -344,7 +354,7 @@ describe('devupUICssLoader', () => {
344354
coordinatorPortFile: 'nonexistent.port',
345355
}),
346356
resourcePath: 'devup-ui.css',
347-
} as any)(Buffer.from(''), '', '')
357+
} as unknown as CssLoaderThis)(Buffer.from(''), '', '')
348358
})
349359

350360
expect(error.message).toBe('Coordinator port file not found')
@@ -376,7 +386,7 @@ describe('devupUICssLoader', () => {
376386
coordinatorPortFile: portFile,
377387
}),
378388
resourcePath: 'devup-ui.css',
379-
} as any)(Buffer.from(''), '', '')
389+
} as unknown as CssLoaderThis)(Buffer.from(''), '', '')
380390
})
381391

382392
expect(error.message).toBe('Coordinator CSS error: 500')
@@ -404,7 +414,7 @@ describe('devupUICssLoader', () => {
404414
coordinatorPortFile: portFile,
405415
}),
406416
resourcePath: 'devup-ui.css',
407-
} as any)(Buffer.from(''), '', '')
417+
} as unknown as CssLoaderThis)(Buffer.from(''), '', '')
408418
})
409419

410420
expect(error.message).toBe('EACCES: permission denied')
@@ -431,7 +441,7 @@ describe('devupUICssLoader', () => {
431441
coordinatorPortFile: portFile,
432442
}),
433443
resourcePath: 'devup-ui.css',
434-
} as any)(Buffer.from(''), '', '')
444+
} as unknown as CssLoaderThis)(Buffer.from(''), '', '')
435445
})
436446

437447
expect(error).toBeInstanceOf(Error)

0 commit comments

Comments
 (0)