-
Notifications
You must be signed in to change notification settings - Fork 697
Expand file tree
/
Copy pathindex.ts
More file actions
66 lines (51 loc) · 2.32 KB
/
Copy pathindex.ts
File metadata and controls
66 lines (51 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as assert from 'node:assert';
import * as vscode from 'vscode';
const EXTENSION_ID: string = 'ms-RushStack.playwright-local-browser-server';
const COMMAND_START_TUNNEL: string = 'playwright-local-browser-server.start';
const COMMAND_STOP_TUNNEL: string = 'playwright-local-browser-server.stop';
function sleepAsync(milliseconds: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, milliseconds));
}
async function promiseSettledWithinAsync(promise: Thenable<unknown>, milliseconds: number): Promise<boolean> {
let settled: boolean = false;
promise.then(
() => {
settled = true;
},
() => {
settled = true;
}
);
await sleepAsync(milliseconds);
return settled;
}
export async function run(): Promise<void> {
const extension: vscode.Extension<unknown> | undefined = vscode.extensions.getExtension(EXTENSION_ID);
assert.ok(extension, `Expected ${EXTENSION_ID} to be installed in the VS Code test host.`);
await extension.activate();
const commands: string[] = await vscode.commands.getCommands(true);
assert.ok(commands.includes(COMMAND_START_TUNNEL), `Missing command: ${COMMAND_START_TUNNEL}`);
assert.ok(commands.includes(COMMAND_STOP_TUNNEL), `Missing command: ${COMMAND_STOP_TUNNEL}`);
await vscode.workspace
.getConfiguration('playwright-local-browser-server')
.update('autoStart', true, vscode.ConfigurationTarget.Global);
await vscode.commands.executeCommand(COMMAND_START_TUNNEL, true);
await sleepAsync(250);
const stopPromise: Thenable<unknown> = vscode.commands.executeCommand(COMMAND_STOP_TUNNEL);
await sleepAsync(250);
const restartPromise: Thenable<unknown> = vscode.commands.executeCommand(COMMAND_START_TUNNEL, true);
assert.strictEqual(
await promiseSettledWithinAsync(restartPromise, 1000),
false,
'Start resolved while the previous Stop command was still pending.'
);
assert.strictEqual(
await promiseSettledWithinAsync(stopPromise, 1),
false,
'Stop unexpectedly settled before the restart guard could be observed.'
);
// eslint-disable-next-line no-console
console.log('Playwright tunnel restart remained pending behind the in-progress stop.');
}