Skip to content

Commit df17ad4

Browse files
committed
test: remove separate socket runtime tests
1 parent b8ea409 commit df17ad4

3 files changed

Lines changed: 122 additions & 134 deletions

File tree

‎.github/workflows/bench.yml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ jobs:
3232

3333
- name: Run benchmarks
3434
uses: CodSpeedHQ/action@4348f634fa7309fe23aac9502e88b999ec90a164 # v4.3.1
35-
env:
36-
NUXT_SOCKET: 1
3735
with:
3836
run: pnpm vitest bench
3937
mode: instrumentation

‎.gitignore‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ nuxt-app
77
.pnpm-store
88
coverage
99
stats.json
10-
playground-bun-*
11-
playground-deno-*
12-
playground-node-*
10+
playground-bun*
11+
playground-deno*
12+
playground-node*

‎packages/nuxt-cli/test/e2e/runtimes.spec.ts‎

Lines changed: 119 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type SupportStatus = boolean | {
3535
websockets: boolean
3636
}
3737

38-
functioncreateIt(runtimeName: typeofruntimes[number],_socketsEnabled: boolean){
38+
functioncreateIt(runtimeName: typeofruntimes[number]){
3939
functionit(description: string,fn: ()=>Promise<void>): void
4040
functionit(description: string,options: TestOptions,fn: ()=>Promise<void>): void
4141
functionit(description: string,_options: TestOptions|(()=>Promise<void>),_fn?: ()=>Promise<void>): void{
@@ -89,176 +89,168 @@ function createIt(runtimeName: typeof runtimes[number], _socketsEnabled: boolean
8989
returnit
9090
}
9191

92-
constsocketConfigs=[
93-
{enabled: true,label: 'with sockets'},
94-
{enabled: false,label: 'without sockets'},
95-
]asconst
96-
9792
describe.sequential.each(runtimes)('dev server (%s)',(runtimeName)=>{
98-
describe.sequential.each(socketConfigs)('$label',({enabled: socketsEnabled})=>{
99-
letserver: DevServerInstance
93+
letserver: DevServerInstance
10094

101-
if(!isCI&&!runtime[runtimeName]){
102-
console.warn(`Not testing locally with ${runtimeName} as it is not installed.`)
103-
_it.skip(`should pass with ${runtimeName}`)
104-
return
105-
}
95+
if(!isCI&&!runtime[runtimeName]){
96+
console.warn(`Not testing locally with ${runtimeName} as it is not installed.`)
97+
_it.skip(`should pass with ${runtimeName}`)
98+
return
99+
}
106100

107-
constcwd=resolve(playgroundDir,`../playground-${runtimeName}-${socketsEnabled ? 'sockets' : 'nosockets'}`)
101+
constcwd=resolve(playgroundDir,`../playground-${runtimeName}`)
108102

109-
afterAll(async()=>{
110-
awaitserver?.close()
111-
awaitrm(cwd,{recursive: true,force: true}).catch(()=>null)
112-
})
103+
afterAll(async()=>{
104+
awaitserver?.close()
105+
awaitrm(cwd,{recursive: true,force: true}).catch(()=>null)
106+
})
113107

114-
constit=createIt(runtimeName,socketsEnabled)
108+
constit=createIt(runtimeName)
115109

116-
it('should start dev server',{timeout: isCI ? 120_000 : 30_000},async()=>{
117-
rmSync(cwd,{recursive: true,force: true})
118-
cpSync(playgroundDir,cwd,{
119-
recursive: true,
120-
filter: src=>!src.includes('.nuxt')&&!src.includes('.output')&&!src.includes('node_modules'),
121-
})
122-
server=awaitstartDevServer({
123-
cwd,
124-
runtime: runtimeName,
125-
socketsEnabled,
126-
})
110+
it('should start dev server',{timeout: isCI ? 120_000 : 30_000},async()=>{
111+
rmSync(cwd,{recursive: true,force: true})
112+
cpSync(playgroundDir,cwd,{
113+
recursive: true,
114+
filter: src=>!src.includes('.nuxt')&&!src.includes('.output')&&!src.includes('node_modules'),
127115
})
128-
129-
it('should serve the main page',async()=>{
130-
constresponse=awaitfetch(server.url)
131-
expect(response.status).toBe(200)
132-
133-
consthtml=awaitresponse.text()
134-
expect(html).toContain('Welcome to the Nuxt CLI playground')
135-
expect(html).toContain('<!DOCTYPE html>')
116+
server=awaitstartDevServer({
117+
cwd,
118+
runtime: runtimeName,
136119
})
120+
})
137121

138-
it('should serve static assets',async()=>{
139-
constresponse=awaitfetch(`${server.url}/favicon.ico`)
140-
expect(response.status).toBe(200)
141-
expect(response.headers.get('content-type')).toContain('image/')
142-
})
122+
it('should serve the main page',async()=>{
123+
constresponse=awaitfetch(server.url)
124+
expect(response.status).toBe(200)
143125

144-
it('should handle API routes',async()=>{
145-
constresponse=awaitfetch(`${server.url}/api/hello`)
146-
expect(response.status).toBe(200)
147-
})
126+
consthtml=awaitresponse.text()
127+
expect(html).toContain('Welcome to the Nuxt CLI playground')
128+
expect(html).toContain('<!DOCTYPE html>')
129+
})
148130

149-
it('should handle POST requests',async()=>{
150-
constresponse=awaitfetch(`${server.url}/api/echo`,{
151-
method: 'POST',
152-
headers: {'Content-Type': 'application/json'},
153-
body: JSON.stringify({test: 'data'}),
154-
})
131+
it('should serve static assets',async()=>{
132+
constresponse=awaitfetch(`${server.url}/favicon.ico`)
133+
expect(response.status).toBe(200)
134+
expect(response.headers.get('content-type')).toContain('image/')
135+
})
155136

156-
expect(response.status).toBe(200)
137+
it('should handle API routes',async()=>{
138+
constresponse=awaitfetch(`${server.url}/api/hello`)
139+
expect(response.status).toBe(200)
140+
})
141+
142+
it('should handle POST requests',async()=>{
143+
constresponse=awaitfetch(`${server.url}/api/echo`,{
144+
method: 'POST',
145+
headers: {'Content-Type': 'application/json'},
146+
body: JSON.stringify({test: 'data'}),
157147
})
158148

159-
it('should preserve request headers',async()=>{
160-
constheaders={
161-
'X-Custom-Header': 'test-value',
162-
'User-Agent': 'vitest',
163-
}
149+
expect(response.status).toBe(200)
150+
})
164151

165-
constres=awaitfetch(`${server.url}/api/echo`,{ headers })
166-
const{headers: receivedHeaders}=awaitres.json()
152+
it('should preserve request headers',async()=>{
153+
constheaders={
154+
'X-Custom-Header': 'test-value',
155+
'User-Agent': 'vitest',
156+
}
167157

168-
expect(receivedHeaders).toMatchObject({
169-
'user-agent': 'vitest',
170-
'x-custom-header': 'test-value',
171-
})
158+
constres=awaitfetch(`${server.url}/api/echo`,{ headers })
159+
const{headers: receivedHeaders}=awaitres.json()
172160

173-
expect(res.status).toBe(200)
161+
expect(receivedHeaders).toMatchObject({
162+
'user-agent': 'vitest',
163+
'x-custom-header': 'test-value',
174164
})
175165

176-
it('should handle concurrent requests',async()=>{
177-
constrequests=Array.from({length: 5},()=>fetch(server.url))
178-
constresponses=awaitPromise.all(requests)
166+
expect(res.status).toBe(200)
167+
})
179168

180-
for(constresponseofresponses){
181-
expect(response.status).toBe(200)
182-
expect(awaitresponse.text()).toContain('Welcome to the Nuxt CLI playground')
183-
}
169+
it('should handle concurrent requests',async()=>{
170+
constrequests=Array.from({length: 5},()=>fetch(server.url))
171+
constresponses=awaitPromise.all(requests)
172+
173+
for(constresponseofresponses){
174+
expect(response.status).toBe(200)
175+
expect(awaitresponse.text()).toContain('Welcome to the Nuxt CLI playground')
176+
}
177+
})
178+
179+
it('should handle large request payloads',async()=>{
180+
constlargePayload={data: 'x'.repeat(10_000)}
181+
constresponse=awaitfetch(`${server.url}/api/echo`,{
182+
method: 'POST',
183+
headers: {'Content-Type': 'application/json'},
184+
body: JSON.stringify(largePayload),
184185
})
185186

186-
it('should handle large request payloads',async()=>{
187-
constlargePayload={data: 'x'.repeat(10_000)}
188-
constresponse=awaitfetch(`${server.url}/api/echo`,{
189-
method: 'POST',
190-
headers: {'Content-Type': 'application/json'},
191-
body: JSON.stringify(largePayload),
192-
})
187+
expect(response.status).toBe(200)
188+
constresult=awaitresponse.json()
189+
expect(result.echoed.data).toBe(largePayload.data)
190+
})
191+
192+
it('should handle different HTTP methods',async()=>{
193+
constmethods=['GET','POST','PUT','DELETE']
193194

195+
for(constmethodofmethods){
196+
constresponse=awaitfetch(`${server.url}/api/hello`,{ method })
194197
expect(response.status).toBe(200)
198+
195199
constresult=awaitresponse.json()
196-
expect(result.echoed.data).toBe(largePayload.data)
197-
})
200+
expect(result.method).toBe(method)
201+
}
202+
})
198203

199-
it('should handle different HTTP methods',async()=>{
200-
constmethods=['GET','POST','PUT','DELETE']
204+
it('should establish websocket connection and handle ping/pong',async()=>{
205+
constwsUrl=`${server.url.replace('http','ws')}/_ws`
201206

202-
for(constmethodofmethods){
203-
constresponse=awaitfetch(`${server.url}/api/hello`,{ method })
204-
expect(response.status).toBe(200)
207+
letisConnected=false
208+
letreceivedPong=false
205209

206-
constresult=awaitresponse.json()
207-
expect(result.method).toBe(method)
208-
}
210+
awaitcreateWebSocketTest({
211+
url: wsUrl,
212+
timeout: 2_000,
213+
testId: 'ping/pong',
214+
onOpen: (ws)=>{
215+
isConnected=true
216+
ws.send('ping test message')
217+
},
218+
onMessage: (ws,event)=>{
219+
constmessage=event.data.toString()
220+
if(message==='pong'){
221+
receivedPong=true
222+
ws.close()
223+
}
224+
},
225+
onClose: ()=>isConnected&&receivedPong,
209226
})
227+
})
210228

211-
it('should establish websocket connection and handle ping/pong',async()=>{
212-
constwsUrl=`${server.url.replace('http','ws')}/_ws`
229+
it('should handle multiple concurrent websocket connections',async()=>{
230+
constwsUrl=`${server.url.replace('http','ws')}/_ws`
231+
constconnectionCount=2
213232

214-
letisConnected=false
233+
constconnectionPromises=Array.from({length: connectionCount},(_,index)=>{
215234
letreceivedPong=false
216235

217-
awaitcreateWebSocketTest({
236+
returncreateWebSocketTest({
218237
url: wsUrl,
219238
timeout: 2_000,
220-
testId: 'ping/pong',
239+
testId: `concurrent connection ${index}`,
221240
onOpen: (ws)=>{
222-
isConnected=true
223-
ws.send('ping test message')
241+
ws.send(`ping from connection ${index}`)
224242
},
225243
onMessage: (ws,event)=>{
226-
constmessage=event.data.toString()
227-
if(message==='pong'){
244+
if(event.data.toString()==='pong'){
228245
receivedPong=true
229246
ws.close()
230247
}
231248
},
232-
onClose: ()=>isConnected&&receivedPong,
249+
onClose: ()=>receivedPong,
233250
})
234251
})
235252

236-
it('should handle multiple concurrent websocket connections',async()=>{
237-
constwsUrl=`${server.url.replace('http','ws')}/_ws`
238-
constconnectionCount=2
239-
240-
constconnectionPromises=Array.from({length: connectionCount},(_,index)=>{
241-
letreceivedPong=false
242-
243-
returncreateWebSocketTest({
244-
url: wsUrl,
245-
timeout: 2_000,
246-
testId: `concurrent connection ${index}`,
247-
onOpen: (ws)=>{
248-
ws.send(`ping from connection ${index}`)
249-
},
250-
onMessage: (ws,event)=>{
251-
if(event.data.toString()==='pong'){
252-
receivedPong=true
253-
ws.close()
254-
}
255-
},
256-
onClose: ()=>receivedPong,
257-
})
258-
})
259-
260-
awaitPromise.all(connectionPromises)
261-
})
253+
awaitPromise.all(connectionPromises)
262254
})
263255
})
264256

@@ -274,9 +266,8 @@ async function startDevServer(options: {
274266
port?: number
275267
runtime?: 'node'|'bun'|'deno'
276268
env?: Record<string,string>
277-
socketsEnabled?: boolean
278269
}): Promise<DevServerInstance>{
279-
const{ cwd,port: preferredPort, runtime ='node', env ={}, socketsEnabled =true}=options
270+
const{ cwd,port: preferredPort, runtime ='node', env ={}}=options
280271
constport=preferredPort||awaitgetPort({port: 3100})
281272
consthost='127.0.0.1'
282273
consturl=`http://${host}:${port}`
@@ -305,7 +296,6 @@ async function startDevServer(options: {
305296
NUXT_TELEMETRY_DISABLED: '1',
306297
PORT: String(port),
307298
HOST: host,
308-
NUXT_SOCKET: socketsEnabled ? '1' : '0',
309299
},
310300
})
311301

0 commit comments

Comments
 (0)