Skip to content

Commit 5110b20

Browse files
committed
test
1 parent b4c8327 commit 5110b20

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

packages/devtools-utils/src/solid/class.test.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** @jsxImportSource solid-js - we use Solid.js as JSX here */
12
import { beforeEach, describe, expect, it, vi } from 'vitest'
23
import { constructCoreClass } from './class'
34

@@ -28,22 +29,22 @@ describe('constructCoreClass', () => {
2829
})
2930
it('should export DevtoolsCore and NoOpDevtoolsCore classes and make no calls to Solid.js primitives', () => {
3031
const [DevtoolsCore, NoOpDevtoolsCore] = constructCoreClass(
31-
'@test/devtools-mock-package',
32+
() => <div>Test Component</div>,
3233
)
3334
expect(DevtoolsCore).toBeDefined()
3435
expect(NoOpDevtoolsCore).toBeDefined()
3536
expect(lazyImportMock).not.toHaveBeenCalled()
3637
})
3738

3839
it('DevtoolsCore should call solid primitives when mount is called', async () => {
39-
const [DevtoolsCore, _] = constructCoreClass('@test/devtools-mock-package')
40+
const [DevtoolsCore, _] = constructCoreClass(() => <div>Test Component</div>)
4041
const instance = new DevtoolsCore()
4142
await instance.mount(document.createElement('div'), 'dark')
4243
expect(renderMock).toHaveBeenCalled()
4344
})
4445

4546
it('DevtoolsCore should throw if mount is called twice without unmounting', async () => {
46-
const [DevtoolsCore, _] = constructCoreClass('@test/devtools-mock-package')
47+
const [DevtoolsCore, _] = constructCoreClass(() => <div>Test Component</div>)
4748
const instance = new DevtoolsCore()
4849
await instance.mount(document.createElement('div'), 'dark')
4950
await expect(
@@ -52,13 +53,13 @@ describe('constructCoreClass', () => {
5253
})
5354

5455
it('DevtoolsCore should throw if unmount is called before mount', () => {
55-
const [DevtoolsCore, _] = constructCoreClass('@test/devtools-mock-package')
56+
const [DevtoolsCore, _] = constructCoreClass(() => <div>Test Component</div>)
5657
const instance = new DevtoolsCore()
5758
expect(() => instance.unmount()).toThrow('Devtools is not mounted')
5859
})
5960

6061
it('DevtoolsCore should allow mount after unmount', async () => {
61-
const [DevtoolsCore, _] = constructCoreClass('@test/devtools-mock-package')
62+
const [DevtoolsCore, _] = constructCoreClass(() => <div>Test Component</div>)
6263
const instance = new DevtoolsCore()
6364
await instance.mount(document.createElement('div'), 'dark')
6465
instance.unmount()
@@ -69,7 +70,7 @@ describe('constructCoreClass', () => {
6970

7071
it('NoOpDevtoolsCore should not call any solid primitives when mount is called', async () => {
7172
const [_, NoOpDevtoolsCore] = constructCoreClass(
72-
'@test/devtools-mock-package',
73+
() => <div>Test Component</div>,
7374
)
7475
const noOpInstance = new NoOpDevtoolsCore()
7576
await noOpInstance.mount(document.createElement('div'), 'dark')
@@ -81,7 +82,7 @@ describe('constructCoreClass', () => {
8182

8283
it('NoOpDevtoolsCore should not throw if mount is called multiple times', async () => {
8384
const [_, NoOpDevtoolsCore] = constructCoreClass(
84-
'@test/devtools-mock-package',
85+
() => <div>Test Component</div>,
8586
)
8687
const noOpInstance = new NoOpDevtoolsCore()
8788
await noOpInstance.mount(document.createElement('div'), 'dark')
@@ -92,15 +93,15 @@ describe('constructCoreClass', () => {
9293

9394
it('NoOpDevtoolsCore should not throw if unmount is called before mount', () => {
9495
const [_, NoOpDevtoolsCore] = constructCoreClass(
95-
'@test/devtools-mock-package',
96+
() => <div>Test Component</div>,
9697
)
9798
const noOpInstance = new NoOpDevtoolsCore()
9899
expect(() => noOpInstance.unmount()).not.toThrow()
99100
})
100101

101102
it('NoOpDevtoolsCore should not throw if unmount is called after mount', async () => {
102103
const [_, NoOpDevtoolsCore] = constructCoreClass(
103-
'@test/devtools-mock-package',
104+
() => <div>Test Component</div>,
104105
)
105106
const noOpInstance = new NoOpDevtoolsCore()
106107
await noOpInstance.mount(document.createElement('div'), 'dark')

packages/devtools-utils/src/solid/class.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/** @jsxImportSource solid-js - we use Solid.js as JSX here */
22

3+
import type { JSX, } from 'solid-js'
4+
35
/**
46
* Constructs the core class for the Devtools.
57
* This utility is used to construct a lazy loaded Solid component for the Devtools.
@@ -9,14 +11,14 @@
911
* @param importPath The path to the Solid component to be lazily imported
1012
* @returns Tuple containing the DevtoolsCore class and a NoOpDevtoolsCore class
1113
*/
12-
export function constructCoreClass(importPath: string) {
14+
export function constructCoreClass(Component: () => JSX.Element) {
1315
class DevtoolsCore {
1416
#isMounted = false
1517
#dispose?: () => void
1618
#Component: any
1719
#ThemeProvider: any
1820

19-
constructor() {}
21+
constructor() { }
2022

2123
async mount<T extends HTMLElement>(el: T, theme: 'light' | 'dark') {
2224
const { lazy } = await import('solid-js')
@@ -26,7 +28,8 @@ export function constructCoreClass(importPath: string) {
2628
}
2729
const mountTo = el
2830
const dispose = render(() => {
29-
this.#Component = lazy(() => import(/** @vite-ignore */ importPath))
31+
// eslint-disable-next-line @typescript-eslint/require-await
32+
this.#Component = lazy(async () => ({ default: Component }))
3033
const Devtools = this.#Component
3134
this.#ThemeProvider = lazy(() =>
3235
import('@tanstack/devtools-ui').then((mod) => ({
@@ -61,8 +64,8 @@ export function constructCoreClass(importPath: string) {
6164
constructor() {
6265
super()
6366
}
64-
async mount<T extends HTMLElement>(_el: T, _theme: 'light' | 'dark') {}
65-
unmount() {}
67+
async mount<T extends HTMLElement>(_el: T, _theme: 'light' | 'dark') { }
68+
unmount() { }
6669
}
6770
return [DevtoolsCore, NoOpDevtoolsCore] as const
6871
}

0 commit comments

Comments
 (0)