Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit ddaa75b

Browse files
committed
test: test stopPreviousClient behavior
1 parent a9f84ba commit ddaa75b

File tree

5 files changed

+49
-18
lines changed

5 files changed

+49
-18
lines changed

src/qmlls/client.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ type CreateClientArgs = {
134134
readonly outputChannel: OutputChannel
135135
}
136136

137-
// TODO: Unit test this behavior.
138-
function stopPreviousClient() {
137+
export function stopPreviousClient() {
139138
return (source$: Observable<LanguageClient | undefined>) =>
140139
source$.pipe(
141140
startWith(undefined),

src/test/mocks/extension.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import * as assert from 'node:assert'
2+
import type { Subscription } from 'rxjs'
3+
import { ReplaySubject } from 'rxjs'
4+
import * as sinon from 'sinon'
5+
import { LanguageClient } from 'vscode-languageclient/node'
6+
import { stopPreviousClient } from '../../../qmlls/client'
7+
import { waitFor } from '../test-utils'
8+
9+
suite('qmlls/client', () => {
10+
suite('stopPreviousClient', () => {
11+
suite('when a new client is created', () => {
12+
const client$ = new ReplaySubject<LanguageClient>(1)
13+
const observable$ = client$.pipe(stopPreviousClient())
14+
15+
const client1 = new LanguageClient(
16+
'client1',
17+
{ command: 'mock-command' },
18+
{},
19+
)
20+
const client2 = new LanguageClient(
21+
'client2',
22+
{ command: 'mock-command' },
23+
{},
24+
)
25+
26+
let disposeSpy: sinon.SinonSpy
27+
let subscription: Subscription
28+
29+
setup(() => {
30+
disposeSpy = sinon.spy(client1, 'dispose')
31+
subscription = observable$.subscribe()
32+
client$.next(client1)
33+
client$.next(client2)
34+
})
35+
36+
teardown(() => {
37+
subscription.unsubscribe()
38+
sinon.restore()
39+
})
40+
41+
test('should stop previous client', async () =>
42+
waitFor(() => assert.ok(disposeSpy.calledOnce)))
43+
})
44+
})
45+
})

src/test/suite/run.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as path from 'node:path'
33
import * as process from 'node:process'
44
import type { RunResult } from '../../run'
55
import { run, wrapAndJoinCommandArgsWithQuotes } from '../../run'
6+
import { TEST_ASSETS_PATH } from './test-utils'
67

78
suite('run', () => {
89
let result: RunResult
@@ -19,8 +20,8 @@ suite('run', () => {
1920
() => {
2021
setup(async () => {
2122
const filePath = path.resolve(
22-
__dirname,
23-
'../../../src/test/assets/filename with spaces.txt',
23+
TEST_ASSETS_PATH,
24+
'filename with spaces.txt',
2425
)
2526

2627
if (process.platform === 'win32')

0 commit comments

Comments
 (0)