Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/sanity/src/server.test.ts
4772 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 { spawn } from 'child_process';
8
import os from 'os';
9
import { TestContext } from './context';
10
11
export function setup(context: TestContext) {
12
describe('Server', () => {
13
if (context.platform === 'linux-arm64') {
14
it('server-alpine-arm64', async () => {
15
const dir = await context.downloadAndUnpack('server-alpine-arm64');
16
const entryPoint = context.getServerEntryPoint(dir);
17
await testServer(entryPoint);
18
});
19
}
20
21
if (context.platform === 'linux-x64') {
22
it('server-alpine-x64', async () => {
23
const dir = await context.downloadAndUnpack('server-linux-alpine');
24
const entryPoint = context.getServerEntryPoint(dir);
25
await testServer(entryPoint);
26
});
27
}
28
29
if (context.platform === 'darwin-arm64') {
30
it('server-darwin-arm64', async () => {
31
const dir = await context.downloadAndUnpack('server-darwin-arm64');
32
context.validateAllCodesignSignatures(dir);
33
const entryPoint = context.getServerEntryPoint(dir);
34
await testServer(entryPoint);
35
});
36
}
37
38
if (context.platform === 'darwin-x64') {
39
it('server-darwin-x64', async () => {
40
const dir = await context.downloadAndUnpack('server-darwin');
41
context.validateAllCodesignSignatures(dir);
42
const entryPoint = context.getServerEntryPoint(dir);
43
await testServer(entryPoint);
44
});
45
}
46
47
if (context.platform === 'linux-arm64') {
48
it('server-linux-arm64', async () => {
49
const dir = await context.downloadAndUnpack('server-linux-arm64');
50
const entryPoint = context.getServerEntryPoint(dir);
51
await testServer(entryPoint);
52
});
53
}
54
55
if (context.platform === 'linux-arm') {
56
it('server-linux-armhf', async () => {
57
const dir = await context.downloadAndUnpack('server-linux-armhf');
58
const entryPoint = context.getServerEntryPoint(dir);
59
await testServer(entryPoint);
60
});
61
}
62
63
if (context.platform === 'linux-x64') {
64
it('server-linux-x64', async () => {
65
const dir = await context.downloadAndUnpack('server-linux-x64');
66
const entryPoint = context.getServerEntryPoint(dir);
67
await testServer(entryPoint);
68
});
69
}
70
71
if (context.platform === 'win32-arm64') {
72
it('server-win32-arm64', async () => {
73
const dir = await context.downloadAndUnpack('server-win32-arm64');
74
context.validateAllAuthenticodeSignatures(dir);
75
const entryPoint = context.getServerEntryPoint(dir);
76
await testServer(entryPoint);
77
});
78
}
79
80
if (context.platform === 'win32-x64') {
81
it('server-win32-x64', async () => {
82
const dir = await context.downloadAndUnpack('server-win32-x64');
83
context.validateAllAuthenticodeSignatures(dir);
84
const entryPoint = context.getServerEntryPoint(dir);
85
await testServer(entryPoint);
86
});
87
}
88
89
async function testServer(entryPoint: string) {
90
const args = [
91
'--accept-server-license-terms',
92
'--connection-token', context.getRandomToken(),
93
'--port', context.getRandomPort()
94
];
95
96
context.log(`Starting server ${entryPoint} with args ${args.join(' ')}`);
97
const server = spawn(entryPoint, args, { shell: true, detached: os.platform() !== 'win32' });
98
99
let testError: Error | undefined;
100
101
server.stderr.on('data', (data) => {
102
context.error(`[Server Error] ${data.toString().trim()}`);
103
});
104
105
server.stdout.on('data', (data) => {
106
const text = data.toString().trim();
107
text.split('\n').forEach((line: string) => {
108
context.log(`[Server Output] ${line}`);
109
});
110
111
const port = /Extension host agent listening on (\d+)/.exec(text)?.[1];
112
if (port) {
113
const url = context.getWebServerUrl(port);
114
url.pathname = '/version';
115
runWebTest(url.toString())
116
.catch((error) => { testError = error; })
117
.finally(() => context.killProcessTree(server.pid!));
118
}
119
});
120
121
await new Promise<void>((resolve, reject) => {
122
server.on('error', reject);
123
server.on('exit', resolve);
124
});
125
126
if (testError) {
127
throw testError;
128
}
129
}
130
131
async function runWebTest(url: string) {
132
context.log(`Fetching ${url}`);
133
const response = await fetch(url);
134
assert.strictEqual(response.status, 200, `Expected status 200 but got ${response.status}`);
135
136
const text = await response.text();
137
assert.strictEqual(text, context.commit, `Expected commit ${context.commit} but got ${text}`);
138
}
139
});
140
}
141
142