Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/parts/ipc/test/node/ipc.cp.integrationTest.ts
4780 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import { Event } from '../../../../common/event.js';
8
import { IChannel } from '../../common/ipc.js';
9
import { Client } from '../../node/ipc.cp.js';
10
import { ITestService, TestServiceClient } from './testService.js';
11
import { FileAccess } from '../../../../common/network.js';
12
13
function createClient(): Client {
14
return new Client(FileAccess.asFileUri('bootstrap-fork').fsPath, {
15
serverName: 'TestServer',
16
env: { VSCODE_ESM_ENTRYPOINT: 'vs/base/parts/ipc/test/node/testApp', verbose: true }
17
});
18
}
19
20
suite('IPC, Child Process', function () {
21
this.slow(2000);
22
this.timeout(10000);
23
24
let client: Client;
25
let channel: IChannel;
26
let service: ITestService;
27
28
setup(() => {
29
client = createClient();
30
channel = client.getChannel('test');
31
service = new TestServiceClient(channel);
32
});
33
34
teardown(() => {
35
client.dispose();
36
});
37
38
test('createChannel', async () => {
39
const result = await service.pong('ping');
40
assert.strictEqual(result.incoming, 'ping');
41
assert.strictEqual(result.outgoing, 'pong');
42
});
43
44
test('events', async () => {
45
const event = Event.toPromise(Event.once(service.onMarco));
46
const promise = service.marco();
47
48
const [promiseResult, eventResult] = await Promise.all([promise, event]);
49
50
assert.strictEqual(promiseResult, 'polo');
51
assert.strictEqual(eventResult.answer, 'polo');
52
});
53
54
test('event dispose', async () => {
55
let count = 0;
56
const disposable = service.onMarco(() => count++);
57
58
const answer = await service.marco();
59
assert.strictEqual(answer, 'polo');
60
assert.strictEqual(count, 1);
61
62
const answer_1 = await service.marco();
63
assert.strictEqual(answer_1, 'polo');
64
assert.strictEqual(count, 2);
65
disposable.dispose();
66
67
const answer_2 = await service.marco();
68
assert.strictEqual(answer_2, 'polo');
69
assert.strictEqual(count, 2);
70
});
71
});
72
73