Skip to content

Commit af7b30f

Browse files
committed
Move tests together with source files
1 parent d229454 commit af7b30f

9 files changed

Lines changed: 88 additions & 101 deletions

File tree

packages/debugger/src/dependency/test/collect.test.ts renamed to packages/debugger/src/dependency/collect.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import '../../setup.ts'
1+
import '../setup.ts'
22

33
import * as s from 'solid-js'
44
import * as test from 'vitest'
5-
import {NodeType} from '../../main/constants.ts'
6-
import {ObjectType, getSdtId} from '../../main/id.ts'
7-
import setup from '../../main/setup.ts'
8-
import type {NodeID, Solid} from '../../main/types.ts'
9-
import {type SerializedDGraph, collectDependencyGraph} from '../collect.ts'
5+
import {NodeType} from '../main/constants.ts'
6+
import {ObjectType, getSdtId} from '../main/id.ts'
7+
import setup from '../main/setup.ts'
8+
import type {NodeID, Solid} from '../main/types.ts'
9+
import {type SerializedDGraph, collectDependencyGraph} from './collect.ts'
1010

1111
let mockLAST_ID = 0
1212
test.beforeEach(() => {
1313
mockLAST_ID = 0
1414
})
15-
test.vi.mock('../../main/get-id', () => ({getNewSdtId: () => '#' + mockLAST_ID++}))
15+
test.vi.mock('../main/get-id.ts', () => ({getNewSdtId: () => '#' + mockLAST_ID++}))
1616

1717
test.describe('collectDependencyGraph', () => {
1818
test.it('should collect dependency graph', () => {

packages/debugger/src/inspector/test/index.test.tsx renamed to packages/debugger/src/inspector/index.test.tsx

Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
import '../../setup.ts'
1+
import '../setup.ts'
22

33
import * as s from 'solid-js'
4-
import {beforeEach, describe, expect, it, vi} from 'vitest'
5-
import {getObjectById, getSdtId, ObjectType} from '../../main/id.ts'
6-
import setup from '../../main/setup.ts'
7-
import {type Mapped, NodeType, PropGetterState, type Solid, ValueType} from '../../types.ts'
8-
import {collectOwnerDetails} from '../inspector.ts'
9-
10-
let mockLAST_ID = 0
11-
beforeEach(() => {
12-
mockLAST_ID = 0
13-
})
14-
vi.mock('../../main/get-id', () => ({getNewSdtId: () => '#' + mockLAST_ID++}))
15-
16-
describe('collectOwnerDetails', () => {
17-
it('collects focused owner details', () => {
4+
import * as test from 'vitest'
5+
import {getObjectById, getSdtId, ObjectType} from '../main/id.ts'
6+
import setup from '../main/setup.ts'
7+
import {type Mapped, NodeType, PropGetterState, type Solid, ValueType} from '../types.ts'
8+
import {collectOwnerDetails} from './inspector.ts'
9+
10+
test.describe('collectOwnerDetails', () => {
11+
test.it('collects focused owner details', () => {
1812
s.createRoot(dispose => {
1913
const [source] = s.createSignal(0, {name: 'source'})
2014

@@ -57,7 +51,7 @@ describe('collectOwnerDetails', () => {
5751
},
5852
})
5953

60-
expect(details).toEqual({
54+
test.expect(details).toEqual({
6155
id: getSdtId(memo, ObjectType.Owner),
6256
name: 'focused',
6357
type: NodeType.Memo,
@@ -84,26 +78,29 @@ describe('collectOwnerDetails', () => {
8478
],
8579
} satisfies Mapped.OwnerDetails)
8680

87-
expect(valueMap.get(`signal:${getSdtId(customValue, ObjectType.CustomValue)}`)).toBeTruthy()
88-
expect(valueMap.get(`signal:${getSdtId(signalB, ObjectType.Signal)}`)).toBeTruthy()
89-
expect(valueMap.get(`signal:${getSdtId(innerMemo, ObjectType.Owner)}`)).toBeTruthy()
81+
test.expect(valueMap.get(`signal:${getSdtId(customValue, ObjectType.CustomValue)}`)).toBeTruthy()
82+
test.expect(valueMap.get(`signal:${getSdtId(signalB, ObjectType.Signal)}`)).toBeTruthy()
83+
test.expect(valueMap.get(`signal:${getSdtId(innerMemo, ObjectType.Owner)}`)).toBeTruthy()
9084

91-
expect(getObjectById('#3', ObjectType.Element)).toBe(div)
85+
test.expect(getObjectById('#3', ObjectType.Element)).toBe(div)
9286

9387
dispose()
9488
})
9589
})
9690

97-
it('component props', () => {
91+
test.it('component props', () => {
9892
s.createRoot(dispose => {
93+
9994
let owner!: Solid.Owner
95+
let div_ref!: HTMLDivElement
96+
10097
const TestComponent = (props: {
10198
count: number
10299
children: s.JSX.Element
103100
nested: {foo: number; bar: string}
104101
}) => {
105102
owner = setup.solid.getOwner()!
106-
return <div>{props.children}</div>
103+
return <div ref={div_ref}>{props.children}</div>
107104
}
108105
s.createRenderEffect(() => (
109106
<TestComponent count={123} nested={{foo: 1, bar: '2'}}>
@@ -123,12 +120,12 @@ describe('collectOwnerDetails', () => {
123120

124121
dispose()
125122

126-
expect(details).toEqual({
127-
id: '#0',
123+
test.expect(details).toEqual({
124+
id: getSdtId(owner, ObjectType.Owner),
128125
name: 'TestComponent',
129126
type: NodeType.Component,
130127
signals: [],
131-
value: [[ValueType.Element, '#1:div']],
128+
value: [[ValueType.Element, `${getSdtId(div_ref, ObjectType.Element)}:div`]],
132129
props: {
133130
proxy: false,
134131
record: {
@@ -147,14 +144,15 @@ describe('collectOwnerDetails', () => {
147144
},
148145
},
149146
} satisfies Mapped.OwnerDetails)
150-
151-
expect(getObjectById('#1', ObjectType.Element)).toBeInstanceOf(HTMLDivElement)
152147
})
153148
})
154149

155-
it('dynamic component props', () => {
150+
test.it('dynamic component props', () => {
156151
s.createRoot(dispose => {
152+
157153
let owner!: Solid.Owner
154+
let el_ref!: HTMLDivElement
155+
158156
const Button = (props: s.JSX.ButtonHTMLAttributes<HTMLButtonElement>) => {
159157
owner = setup.solid.getOwner()!
160158
return <button {...props}>Click me</button>
@@ -167,7 +165,7 @@ describe('collectOwnerDetails', () => {
167165
},
168166
role: 'button',
169167
}) as const
170-
return <Button {...props()} />
168+
return (el_ref = <Button {...props()} /> as any)
171169
})
172170

173171
const {details} = collectOwnerDetails(owner, {
@@ -180,12 +178,12 @@ describe('collectOwnerDetails', () => {
180178
},
181179
})
182180

183-
expect(details).toEqual({
184-
id: '#0',
181+
test.expect(details).toEqual({
182+
id: getSdtId(owner, ObjectType.Owner),
185183
name: 'Button',
186184
type: NodeType.Component,
187185
signals: [],
188-
value: [[ValueType.Element, '#1:button']],
186+
value: [[ValueType.Element, `${getSdtId(el_ref, ObjectType.Element)}:button`]],
189187
props: {
190188
proxy: true,
191189
record: {
@@ -201,13 +199,11 @@ describe('collectOwnerDetails', () => {
201199
},
202200
} satisfies Mapped.OwnerDetails)
203201

204-
expect(getObjectById('#1', ObjectType.Element)).toBeInstanceOf(HTMLButtonElement)
205-
206202
dispose()
207203
})
208204
})
209205

210-
it('listens to value updates', () => {
206+
test.it('listens to value updates', () => {
211207
s.createRoot(dispose => {
212208
let owner!: Solid.Owner
213209

@@ -217,7 +213,7 @@ describe('collectOwnerDetails', () => {
217213
return count()
218214
})
219215

220-
const onValueUpdate = vi.fn()
216+
const onValueUpdate = test.vi.fn()
221217
collectOwnerDetails(owner, {
222218
observedPropsMap: new WeakMap(),
223219
onPropStateChange: () => {
@@ -226,30 +222,32 @@ describe('collectOwnerDetails', () => {
226222
onValueUpdate: onValueUpdate,
227223
})
228224

229-
expect(onValueUpdate).not.toBeCalled()
225+
test.expect(onValueUpdate).not.toBeCalled()
230226

231227
setCount(1)
232-
expect(onValueUpdate).toBeCalledTimes(1)
233-
expect(onValueUpdate).toHaveBeenLastCalledWith('value')
228+
test.expect(onValueUpdate).toBeCalledTimes(1)
229+
test.expect(onValueUpdate).toHaveBeenLastCalledWith('value')
234230

235231
setCount(2)
236-
expect(onValueUpdate).toBeCalledTimes(2)
237-
expect(onValueUpdate).toHaveBeenLastCalledWith('value')
232+
test.expect(onValueUpdate).toBeCalledTimes(2)
233+
test.expect(onValueUpdate).toHaveBeenLastCalledWith('value')
238234

239235
setCount(2)
240-
expect(onValueUpdate).toBeCalledTimes(2)
236+
test.expect(onValueUpdate).toBeCalledTimes(2)
241237

242238
dispose()
243239
})
244240
})
245241

246-
it('listens to signal updates', () => {
242+
test.it('listens to signal updates', () => {
247243
s.createRoot(dispose => {
248244
const owner = setup.solid.getOwner()!
249-
const [, setCount] = s.createSignal(0) // id: "0"
250-
const [, setCount2] = s.createSignal(0) // id: "1"
245+
const [, setCount1] = s.createSignal(0)
246+
const [, setCount2] = s.createSignal(0)
247+
248+
const [count1, count2] = owner.sourceMap as [Solid.Signal, Solid.Signal]
251249

252-
const onValueUpdate = vi.fn()
250+
const onValueUpdate = test.vi.fn()
253251
collectOwnerDetails(owner, {
254252
observedPropsMap: new WeakMap(),
255253
onPropStateChange: () => {
@@ -258,18 +256,18 @@ describe('collectOwnerDetails', () => {
258256
onValueUpdate: onValueUpdate,
259257
})
260258

261-
expect(onValueUpdate).not.toBeCalled()
259+
test.expect(onValueUpdate).not.toBeCalled()
262260

263-
setCount(1)
264-
expect(onValueUpdate).toBeCalledTimes(1)
265-
expect(onValueUpdate).toHaveBeenLastCalledWith('signal:#1')
261+
setCount1(1)
262+
test.expect(onValueUpdate).toBeCalledTimes(1)
263+
test.expect(onValueUpdate).toHaveBeenLastCalledWith(`signal:${getSdtId(count1, ObjectType.Signal)}`)
266264

267-
setCount(1)
268-
expect(onValueUpdate).toBeCalledTimes(1)
265+
setCount1(1)
266+
test.expect(onValueUpdate).toBeCalledTimes(1)
269267

270268
setCount2(1)
271-
expect(onValueUpdate).toBeCalledTimes(2)
272-
expect(onValueUpdate).toHaveBeenLastCalledWith('signal:#2')
269+
test.expect(onValueUpdate).toBeCalledTimes(2)
270+
test.expect(onValueUpdate).toHaveBeenLastCalledWith(`signal:${getSdtId(count2, ObjectType.Signal)}`)
273271

274272
dispose()
275273
})

packages/debugger/src/inspector/test/serialize.test.ts renamed to packages/debugger/src/inspector/serialize.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import '../../setup.ts'
1+
import '../setup.ts'
22

33
import {type Truthy} from '@solid-primitives/utils'
44
import {createMutable, createStore} from 'solid-js/store'
55
import {describe, expect, test, vi} from 'vitest'
6-
import {ObjectType, getObjectById} from '../../main/id.ts'
7-
import {encodeValue} from '../serialize.ts'
8-
import {type EncodedValue, INFINITY, NAN, NEGATIVE_INFINITY, UNDEFINED, ValueType} from '../types.ts'
6+
import {ObjectType, getObjectById} from '../main/id.ts'
7+
import {encodeValue} from './serialize.ts'
8+
import {type EncodedValue, INFINITY, NAN, NEGATIVE_INFINITY, UNDEFINED, ValueType} from './types.ts'
99

1010
let mockLAST_ID = 0
11-
vi.mock('../../main/get-id', () => ({getNewSdtId: () => '#' + mockLAST_ID++}))
11+
vi.mock('../main/get-id.ts', () => ({getNewSdtId: () => '#' + mockLAST_ID++}))
1212

1313
type Expectations = [name: string, data: unknown, encoded: EncodedValue[]][]
1414

packages/debugger/src/inspector/test/store.test.ts renamed to packages/debugger/src/inspector/store.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import '../../setup.ts'
1+
import '../setup.ts'
22

33
import {createRoot} from 'solid-js'
44
import {createMutable, createStore, modifyMutable, produce, reconcile, unwrap} from 'solid-js/store'
55
import {beforeEach, describe, expect, it, vi} from 'vitest'
6-
import {ObjectType, getSdtId} from '../../main/id.ts'
7-
import setup from '../../main/setup.ts'
8-
import {isSolidStore} from '../../main/utils.ts'
9-
import {type Solid} from '../../types.ts'
10-
import {type OnNodeUpdate, type StoreNodeProperty, observeStoreNode, setOnStoreNodeUpdate} from '../store.ts'
6+
import {ObjectType, getSdtId} from '../main/id.ts'
7+
import setup from '../main/setup.ts'
8+
import {isSolidStore} from '../main/utils.ts'
9+
import {type Solid} from '../types.ts'
10+
import {type OnNodeUpdate, type StoreNodeProperty, observeStoreNode, setOnStoreNodeUpdate} from './store.ts'
1111

1212
const getOwnerStore = () => {
1313
const owner = setup.solid.getOwner()
@@ -25,7 +25,7 @@ let mockLAST_ID = 0
2525
beforeEach(() => {
2626
mockLAST_ID = 0
2727
})
28-
vi.mock('../../main/get-id', () => ({getNewSdtId: () => '#' + mockLAST_ID++}))
28+
vi.mock('../main/get-id.ts', () => ({getNewSdtId: () => '#' + mockLAST_ID++}))
2929

3030
type UpdateParams = Parameters<OnNodeUpdate>
3131

packages/debugger/src/locator/test/index.test.ts renamed to packages/debugger/src/locator/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ vi.mock('@solid-primitives/platform', () => ({
88
},
99
}))
1010

11-
const fetchFunction = async () => (await import('../find-components.ts')).parseLocationString
11+
const fetchFunction = async () => (await import('./find-components.ts')).parseLocationString
1212

1313
describe('locator attribute pasting', () => {
1414
beforeEach(() => {

packages/debugger/src/main/test/update.test.ts renamed to packages/debugger/src/main/update.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import '../../setup.ts'
1+
import '../setup.ts'
22

33
import {createComputed, createRoot, createSignal, onCleanup} from 'solid-js'
44
import {describe, expect, it} from 'vitest'
@@ -7,8 +7,8 @@ import {
77
interceptComputationRerun,
88
observeValueUpdate,
99
removeValueUpdateObserver,
10-
} from '../observe.ts'
11-
import setup from '../setup.ts'
10+
} from './observe.ts'
11+
import setup from './setup.ts'
1212

1313
describe('addSolidUpdateListener', () => {
1414
it('listens to solid updates', () =>

packages/debugger/src/main/test/utils.test.ts renamed to packages/debugger/src/main/utils.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import '../../setup.ts'
1+
import '../setup.ts'
22

33
import * as s from 'solid-js'
44
import * as vi from 'vitest'
5-
import {NodeType} from '../constants.ts'
5+
import {NodeType} from './constants.ts'
66
import {type Solid} from '../types.ts'
7-
import * as utils from '../utils.ts'
8-
import setup from '../setup.ts'
7+
import * as utils from './utils.ts'
8+
import setup from './setup.ts'
99

1010
vi.describe('getOwnerType', () => {
1111
const tests = {

packages/debugger/src/structure/test/walker.test.tsx renamed to packages/debugger/src/structure/walker.test.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import '../../setup.ts'
1+
import '../setup.ts'
22

33
import * as s from 'solid-js'
44
import * as test from 'vitest'
5-
import {NodeType, TreeWalkerMode} from '../../main/constants.ts'
6-
import {$setSdtId} from '../../main/id.ts'
7-
import {type Mapped, type Solid} from '../../main/types.ts'
8-
import {getNodeName} from '../../main/utils.ts'
9-
import {type ComputationUpdateHandler, walkSolidTree} from '../walker.ts'
10-
import setup from '../../main/setup.ts'
11-
import {initRoots} from '../../main/roots.ts'
5+
import {NodeType, TreeWalkerMode} from '../main/constants.ts'
6+
import {$setSdtId} from '../main/id.ts'
7+
import {type Mapped, type Solid} from '../main/types.ts'
8+
import {getNodeName} from '../main/utils.ts'
9+
import {type ComputationUpdateHandler, walkSolidTree} from './walker.ts'
10+
import setup from '../main/setup.ts'
11+
import {initRoots} from '../main/roots.ts'
1212

1313
test.beforeAll(() => {
1414
initRoots()
@@ -18,7 +18,7 @@ let mockLAST_ID = 0
1818
test.beforeEach(() => {
1919
mockLAST_ID = 0
2020
})
21-
test.vi.mock('../../main/get-id', () => ({getNewSdtId: () => '#' + mockLAST_ID++}))
21+
test.vi.mock('../main/get-id.ts', () => ({getNewSdtId: () => '#' + mockLAST_ID++}))
2222

2323
test.describe('TreeWalkerMode.Owners', () => {
2424
test.it('default options', () => {

packages/debugger/test_setup.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)