11import type { ResolvedConfig } from 'vite'
2- import { describe , expect , it } from 'vitest'
2+ import { describe , expect , it , vi } from 'vitest'
33import { createDevToolsContext } from '../context'
44
55async function emptyHandler ( ) { /* empty */ }
@@ -15,15 +15,19 @@ async function failingHandler() {
1515
1616describe ( 'registration Safety Integration Tests' , ( ) => {
1717 // Mock Vite config
18- const mockViteConfig = {
19- root : process . cwd ( ) ,
20- command : 'build' ,
21- plugins : [ ] ,
22- } as unknown as ResolvedConfig
18+ async function createContext ( ) {
19+ const ctx = await createDevToolsContext ( {
20+ root : process . cwd ( ) ,
21+ command : 'build' ,
22+ plugins : [ ] ,
23+ } as unknown as ResolvedConfig )
24+ ctx . rpc . boardcast = vi . fn ( )
25+ return ctx
26+ }
2327
2428 describe ( 'scenario 1: RPC Collision Detection' , ( ) => {
2529 it ( 'should detect and prevent duplicate RPC function registrations' , async ( ) => {
26- const ctx = await createDevToolsContext ( mockViteConfig )
30+ const ctx = await createContext ( )
2731
2832 // Register first function
2933 ctx . rpc . register ( {
@@ -46,7 +50,7 @@ describe('registration Safety Integration Tests', () => {
4650 } )
4751
4852 it ( 'should allow different plugins to register different function names' , async ( ) => {
49- const ctx = await createDevToolsContext ( mockViteConfig )
53+ const ctx = await createContext ( )
5054 const initialSize = ctx . rpc . definitions . size
5155
5256 ctx . rpc . register ( {
@@ -67,7 +71,7 @@ describe('registration Safety Integration Tests', () => {
6771
6872 describe ( 'scenario 2: Dock Update Method' , ( ) => {
6973 it ( 'should fail to update non-existent dock' , async ( ) => {
70- const ctx = await createDevToolsContext ( mockViteConfig )
74+ const ctx = await createContext ( )
7175
7276 const updateNonexistentDock = ( ) =>
7377 ctx . docks . update ( {
@@ -81,7 +85,7 @@ describe('registration Safety Integration Tests', () => {
8185 } )
8286
8387 it ( 'should successfully update existing dock' , async ( ) => {
84- const ctx = await createDevToolsContext ( mockViteConfig )
88+ const ctx = await createContext ( )
8589
8690 // Register
8791 ctx . docks . register ( {
@@ -111,7 +115,7 @@ describe('registration Safety Integration Tests', () => {
111115
112116 describe ( 'scenario 3: RPC Error Handling Without Context Crash' , ( ) => {
113117 it ( 'should handle RPC errors gracefully without crashing context' , async ( ) => {
114- const ctx = await createDevToolsContext ( mockViteConfig )
118+ const ctx = await createContext ( )
115119 const initialSize = ctx . rpc . definitions . size
116120
117121 // Register stable function
@@ -153,7 +157,7 @@ describe('registration Safety Integration Tests', () => {
153157 } )
154158
155159 it ( 'should allow context operations after registration errors' , async ( ) => {
156- const ctx = await createDevToolsContext ( mockViteConfig )
160+ const ctx = await createContext ( )
157161 const initialSize = ctx . rpc . definitions . size
158162
159163 ctx . rpc . register ( {
@@ -187,7 +191,7 @@ describe('registration Safety Integration Tests', () => {
187191
188192 describe ( 'scenario 4: Cross-Host Collision Detection' , ( ) => {
189193 it ( 'should detect collisions across all host types' , async ( ) => {
190- const ctx = await createDevToolsContext ( mockViteConfig )
194+ const ctx = await createContext ( )
191195
192196 // Test RPC collision
193197 ctx . rpc . register ( {
@@ -225,7 +229,7 @@ describe('registration Safety Integration Tests', () => {
225229 } )
226230
227231 it ( 'should allow same ID across different host types' , async ( ) => {
228- const ctx = await createDevToolsContext ( mockViteConfig )
232+ const ctx = await createContext ( )
229233
230234 // Same ID "shared" can exist in both RPC and Docks
231235 ctx . rpc . register ( {
@@ -247,7 +251,7 @@ describe('registration Safety Integration Tests', () => {
247251 } )
248252
249253 it ( 'should provide clear error messages for each host type' , async ( ) => {
250- const ctx = await createDevToolsContext ( mockViteConfig )
254+ const ctx = await createContext ( )
251255
252256 ctx . rpc . register ( {
253257 name : 'rpc-test' ,
0 commit comments