This repository has been archived by the owner on Mar 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
command.start.test.ts
137 lines (122 loc) · 5.28 KB
/
command.start.test.ts
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
"use strict";
import * as atlasMapWebView from "../atlasMapWebView";
import * as chai from "chai";
import * as child_process from 'child_process';
import * as sinon from "sinon";
import * as sinonChai from "sinon-chai";
import * as testUtils from "./command.test.utils";
import * as vscode from "vscode";
import { BrowserType } from "../utils";
const expect = chai.expect;
chai.use(sinonChai);
testUtils.BROWSER_TYPES.forEach(function (browserConfig) {
describe("Start AtlasMap Command Tests with browser type: " + browserConfig, function() {
let sandbox: sinon.SinonSandbox;
let executeCommandSpy: sinon.SinonSpy;
let showInformationMessageSpy: sinon.SinonSpy;
let createOutputChannelSpy: sinon.SinonSpy;
let spawnChildProcessSpy: sinon.SinonSpy;
let port: string;
before(function() {
sandbox = sinon.createSandbox();
executeCommandSpy = sinon.spy(vscode.commands, "executeCommand");
showInformationMessageSpy = sinon.spy(vscode.window, "showInformationMessage");
createOutputChannelSpy = sinon.spy(vscode.window, "createOutputChannel");
spawnChildProcessSpy = sinon.spy(child_process, "spawn");
testUtils.switchSettingsToType(browserConfig);
});
after(function() {
executeCommandSpy.restore();
showInformationMessageSpy.restore();
createOutputChannelSpy.restore();
spawnChildProcessSpy.restore();
sandbox.restore();
port = undefined;
testUtils.switchSettingsToType(undefined);
});
afterEach(function(done) {
testUtils.stopAtlasMapInstance(port, showInformationMessageSpy)
.then( () => {
executeCommandSpy.resetHistory();
showInformationMessageSpy.resetHistory();
createOutputChannelSpy.resetHistory();
spawnChildProcessSpy.resetHistory();
sandbox.resetHistory();
port = undefined;
done();
})
.catch( (err) => {
console.error(err);
done(err);
});
});
it("Test Start Command invocation without running AtlasMap instance", function(done) {
expect(port).to.be.undefined;
testUtils.startAtlasMapInstance(showInformationMessageSpy, spawnChildProcessSpy)
.then( _port => {
expect(executeCommandSpy.withArgs("atlasmap.start").calledOnce, "AtlasMap start command was not issued").to.be.true;
port = _port;
expect(port, "Unable to determine used port for AtlasMap server").to.not.be.undefined;
expect(port, "Port for AtlasMap server seems to be NaN").to.not.be.NaN;
expect(createOutputChannelSpy.calledOnce);
done();
})
.catch( err => {
console.error(err);
done(err);
});
});
it("Test Start Command invocation with running AtlasMap instance (DO NOT SPAWN MORE THAN ONE ATLASMAP)", function(done) {
expect(port).to.be.undefined;
testUtils.startAtlasMapInstance(showInformationMessageSpy, spawnChildProcessSpy)
.then( async (_port) => {
expect(executeCommandSpy.withArgs("atlasmap.start").calledOnce, "AtlasMap start command was not issued").to.be.true;
port = _port;
expect(port, "Unable to determine used port for AtlasMap server").to.not.be.undefined;
expect(port, "Port for AtlasMap server seems to be NaN").to.not.be.NaN;
expect(createOutputChannelSpy.calledOnce);
await vscode.commands.executeCommand("atlasmap.start");
expect(executeCommandSpy.withArgs("atlasmap.start").callCount, "AtlasMap start command was not issued").to.be.greaterThan(1);
expect(showInformationMessageSpy.getCalls()[showInformationMessageSpy.callCount-1].args[0], "No detection message for running instance found!").to.equal("Running AtlasMap instance found at port " + port);
await vscode.commands.executeCommand("atlasmap.start");
expect(executeCommandSpy.withArgs("atlasmap.start").callCount, "AtlasMap start command was not issued").to.be.greaterThan(2);
expect(showInformationMessageSpy.getCalls()[showInformationMessageSpy.callCount-1].args[0], "No detection message for running instance found!").to.equal("Running AtlasMap instance found at port " + port);
// wait a bit for the web ui to be ready - not nice but works fine
await new Promise(resolve => setTimeout(resolve, 3000));
done();
})
.catch( err => {
console.error(err);
done(err);
});
});
it("Test Web UI availability after startup of server", function(done) {
expect(port).to.be.undefined;
testUtils.startAtlasMapInstance(showInformationMessageSpy, spawnChildProcessSpy)
.then( async (_port) => {
expect(executeCommandSpy.withArgs("atlasmap.start").calledOnce, "AtlasMap start command was not issued").to.be.true;
port = _port;
expect(port, "Unable to determine used port for AtlasMap server").to.not.be.undefined;
expect(port, "Port for AtlasMap server seems to be NaN").to.not.be.NaN;
expect(createOutputChannelSpy.calledOnce);
let url:string = "http://localhost:" + port;
await testUtils.getWebUI(url)
.then( (body) => {
expect(body, "Unexpected html response body").to.contain("AtlasMap");
if (browserConfig === BrowserType.Internal) {
expect(atlasMapWebView.default.currentPanel._panel.webview.html).to.contain(url).and.to.contain('<body style="padding: 0">');
}
done();
})
.catch( (err) => {
console.error(err);
done(err);
});
})
.catch( err => {
console.error(err);
done(err);
});
});
});
});