Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/sanity/src/serverWeb.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 { spawn } from 'child_process';
7
import os from 'os';
8
import { TestContext } from './context';
9
import { UITest } from './uiTest';
10
11
export function setup(context: TestContext) {
12
describe('Server Web', () => {
13
if (context.platform === 'linux-arm64') {
14
it('server-web-alpine-arm64', async () => {
15
const dir = await context.downloadAndUnpack('server-alpine-arm64-web');
16
const entryPoint = context.getServerEntryPoint(dir);
17
await testServer(entryPoint);
18
});
19
}
20
21
if (context.platform === 'linux-x64') {
22
it('server-web-alpine-x64', async () => {
23
const dir = await context.downloadAndUnpack('server-linux-alpine-web');
24
const entryPoint = context.getServerEntryPoint(dir);
25
await testServer(entryPoint);
26
});
27
}
28
29
if (context.platform === 'darwin-arm64') {
30
it('server-web-darwin-arm64', async () => {
31
const dir = await context.downloadAndUnpack('server-darwin-arm64-web');
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-web-darwin-x64', async () => {
40
const dir = await context.downloadAndUnpack('server-darwin-web');
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-web-linux-arm64', async () => {
49
const dir = await context.downloadAndUnpack('server-linux-arm64-web');
50
const entryPoint = context.getServerEntryPoint(dir);
51
await testServer(entryPoint);
52
});
53
}
54
55
if (context.platform === 'linux-arm') {
56
it('server-web-linux-armhf', async () => {
57
const dir = await context.downloadAndUnpack('server-linux-armhf-web');
58
const entryPoint = context.getServerEntryPoint(dir);
59
await testServer(entryPoint);
60
});
61
}
62
63
if (context.platform === 'linux-x64') {
64
it('server-web-linux-x64', async () => {
65
const dir = await context.downloadAndUnpack('server-linux-x64-web');
66
const entryPoint = context.getServerEntryPoint(dir);
67
await testServer(entryPoint);
68
});
69
}
70
71
if (context.platform === 'win32-arm64') {
72
it('server-web-win32-arm64', async () => {
73
const dir = await context.downloadAndUnpack('server-win32-arm64-web');
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-web-win32-x64', async () => {
82
const dir = await context.downloadAndUnpack('server-win32-x64-web');
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 token = context.getRandomToken();
91
const test = new UITest(context);
92
const args = [
93
'--accept-server-license-terms',
94
'--port', context.getRandomPort(),
95
'--connection-token', token,
96
'--server-data-dir', context.createTempDir(),
97
'--extensions-dir', test.extensionsDir,
98
'--user-data-dir', test.userDataDir
99
];
100
101
context.log(`Starting server ${entryPoint} with args ${args.join(' ')}`);
102
const server = spawn(entryPoint, args, { shell: true, detached: os.platform() !== 'win32' });
103
104
let testError: Error | undefined;
105
106
server.stderr.on('data', (data) => {
107
context.error(`[Server Error] ${data.toString().trim()}`);
108
});
109
110
server.stdout.on('data', (data) => {
111
const text = data.toString().trim();
112
text.split('\n').forEach((line: string) => {
113
context.log(`[Server Output] ${line}`);
114
});
115
116
const port = /Extension host agent listening on (\d+)/.exec(text)?.[1];
117
if (port) {
118
const url = context.getWebServerUrl(port, token, test.workspaceDir).toString();
119
runUITest(url, test)
120
.catch((error) => { testError = error; })
121
.finally(() => context.killProcessTree(server.pid!));
122
}
123
});
124
125
await new Promise<void>((resolve, reject) => {
126
server.on('error', reject);
127
server.on('exit', resolve);
128
});
129
130
if (testError) {
131
throw testError;
132
}
133
}
134
135
async function runUITest(url: string, test: UITest) {
136
const browser = await context.launchBrowser();
137
const page = await browser.newPage();
138
139
context.log(`Navigating to ${url}`);
140
await page.goto(url, { waitUntil: 'networkidle' });
141
142
context.log('Waiting for the workbench to load');
143
await page.waitForSelector('.monaco-workbench');
144
145
await test.run(page);
146
147
context.log('Closing browser');
148
await browser.close();
149
150
test.validate();
151
}
152
});
153
}
154
155