67 lines
2.7 KiB
TypeScript
67 lines
2.7 KiB
TypeScript
|
|
import assert from "node:assert/strict";
|
||
|
|
import * as vscode from "vscode";
|
||
|
|
import { control, spawnCounter, startImage } from "./server";
|
||
|
|
|
||
|
|
export async function run(): Promise<void> {
|
||
|
|
const image = await startImage();
|
||
|
|
try {
|
||
|
|
const actorRef = await spawnCounter(image.address);
|
||
|
|
await vscode.commands.executeCommand("runa.connect", image.address);
|
||
|
|
await vscode.commands.executeCommand("runa.refresh");
|
||
|
|
await vscode.commands.executeCommand("runa.inspect", { actor_ref: actorRef });
|
||
|
|
let document = vscode.window.activeTextEditor?.document;
|
||
|
|
assert.ok(document);
|
||
|
|
assert.equal(document.uri.scheme, "runa");
|
||
|
|
assert.equal(document.languageId, "json");
|
||
|
|
assert.match(document.getText(), /9223372036854775807/);
|
||
|
|
assert.match(document.getText(), /"connected": true/);
|
||
|
|
const firstUri = document.uri.toString();
|
||
|
|
assert.deepEqual(
|
||
|
|
await control(image.address, {
|
||
|
|
operation: "send",
|
||
|
|
parameters: {
|
||
|
|
actor_ref: actorRef,
|
||
|
|
message: { type: "string", data: "queued from another client" },
|
||
|
|
},
|
||
|
|
}),
|
||
|
|
{ version: 3, request_id: "integration-control", result: { Ok: { kind: "acknowledged" } } },
|
||
|
|
);
|
||
|
|
const refreshed = documentChanged(document);
|
||
|
|
await vscode.commands.executeCommand("runa.refresh");
|
||
|
|
await refreshed;
|
||
|
|
assert.match(document.getText(), /queued from another client/);
|
||
|
|
const disconnected = documentChanged(document);
|
||
|
|
await vscode.commands.executeCommand("runa.disconnect");
|
||
|
|
await disconnected;
|
||
|
|
assert.match(document.getText(), /"connected": false/);
|
||
|
|
await vscode.commands.executeCommand("runa.connect", image.address);
|
||
|
|
await vscode.commands.executeCommand("runa.inspect", { actor_ref: actorRef });
|
||
|
|
document = vscode.window.activeTextEditor?.document;
|
||
|
|
assert.ok(document);
|
||
|
|
assert.notEqual(document.uri.toString(), firstUri);
|
||
|
|
assert.match(document.getText(), /queued from another client/);
|
||
|
|
const old = await vscode.workspace.openTextDocument(vscode.Uri.parse(firstUri));
|
||
|
|
assert.match(old.getText(), /"connected": false/);
|
||
|
|
console.log("Runa extension host: connect, inspect, refresh, disconnect, reconnect passed");
|
||
|
|
} finally {
|
||
|
|
await vscode.commands.executeCommand("runa.disconnect");
|
||
|
|
await image.stop();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function documentChanged(document: vscode.TextDocument): Promise<void> {
|
||
|
|
return new Promise((resolve, reject) => {
|
||
|
|
const subscription = vscode.workspace.onDidChangeTextDocument((event) => {
|
||
|
|
if (event.document.uri.toString() === document.uri.toString()) {
|
||
|
|
clearTimeout(timeout);
|
||
|
|
subscription.dispose();
|
||
|
|
resolve();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
const timeout = setTimeout(() => {
|
||
|
|
subscription.dispose();
|
||
|
|
reject(new Error("Actor inspector did not refresh"));
|
||
|
|
}, 5000);
|
||
|
|
});
|
||
|
|
}
|