Skip to content

Commit 89eeb17

Browse files
committed
Support using multiple fixtures in a single test file
1 parent f7e2de5 commit 89eeb17

File tree

1 file changed

+12
-29
lines changed
  • packages/tailwindcss-language-server/tests

1 file changed

+12
-29
lines changed

packages/tailwindcss-language-server/tests/common.js

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ import * as cp from 'node:child_process'
33
import * as rpc from 'vscode-jsonrpc'
44
import { beforeAll } from 'vitest'
55

6-
let settings = {}
7-
let initPromise
8-
let childProcess
9-
let docSettings = new Map()
10-
116
async function init(fixture) {
12-
childProcess = cp.fork('./bin/tailwindcss-language-server', { silent: true })
7+
let settings = {}
8+
let docSettings = new Map()
9+
10+
let childProcess = cp.fork('./bin/tailwindcss-language-server', { silent: true })
1311

1412
const capabilities = {
1513
textDocument: {
@@ -116,7 +114,7 @@ async function init(fixture) {
116114
})
117115
})
118116

119-
initPromise = new Promise((resolve) => {
117+
let initPromise = new Promise((resolve) => {
120118
connection.onRequest(new rpc.RequestType('client/registerCapability'), ({ registrations }) => {
121119
if (registrations.findIndex((r) => r.method === 'textDocument/completion') > -1) {
122120
resolve()
@@ -177,33 +175,18 @@ async function init(fixture) {
177175
}
178176

179177
export function withFixture(fixture, callback) {
180-
let c
178+
let c = {}
181179

182180
beforeAll(async () => {
183-
c = await init(fixture)
181+
// Using the connection object as the prototype lets us access the connection
182+
// without defining getters for all the methods and also lets us add helpers
183+
// to the connection object without having to resort to using a Proxy
184+
Object.setPrototypeOf(c, await init(fixture))
185+
184186
return () => c.connection.end()
185187
})
186188

187-
callback({
188-
get connection() {
189-
return c.connection
190-
},
191-
get sendRequest() {
192-
return c.sendRequest
193-
},
194-
get onNotification() {
195-
return c.onNotification
196-
},
197-
get openDocument() {
198-
return c.openDocument
199-
},
200-
get updateSettings() {
201-
return c.updateSettings
202-
},
203-
get updateFile() {
204-
return c.updateFile
205-
},
206-
})
189+
callback(c)
207190
}
208191

209192
// let counter = 0

0 commit comments

Comments
 (0)