Skip to content

Commit 7fecd9f

Browse files
authored
Merge pull request #22 from stroveio/newTestResults
New test results
2 parents 68bf68a + ad90f78 commit 7fecd9f

File tree

4 files changed

+159
-9
lines changed

4 files changed

+159
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Liveshare toolkit for strove.io.
44

55
Note: This extension is required for liveshare to work properly inside strove.io. It will do nothing outside of the platform.
66

7-
Current version: 0.2.3
7+
Current version: 0.2.5

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "stroveteams",
33
"displayName": "stroveTeams",
44
"description": "Teams support for Strove",
5-
"version": "0.2.4",
5+
"version": "0.2.5",
66
"engines": {
77
"vscode": "^1.39.2"
88
},

utils/automaticTest.js

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {
88
} = require("./queries");
99
const child_process = require("child_process");
1010
const { sendLog } = require("./debugger");
11+
const { createWebview, reloadWebview } = require("./webview");
1112

1213
const environment = process.env.STROVE_ENVIRONMENT;
1314

@@ -54,7 +55,11 @@ const startAutomaticTest = () => {
5455
) &&
5556
!testRunningFlag
5657
) {
57-
const terminalWriter = await startTestTerminal();
58+
// const terminalWriter = await startTestTerminal();
59+
let webviewPanel;
60+
let html = "<h3>Automatic test results will be visible below:</h3>";
61+
62+
let refreshWebviewInterval;
5863

5964
testProcess = {
6065
process: child_process.spawn("/bin/bash"),
@@ -67,9 +72,20 @@ const startAutomaticTest = () => {
6772
// Locking the ability to run the test again before previous instance finishes
6873
testRunningFlag = true;
6974

75+
webviewPanel = createWebview({ html });
76+
7077
testProcess.process.stdin.write(
7178
`cd ${automaticTest.folderName} && ${automaticTest.testStartCommand} ; exit\n`
7279
);
80+
81+
refreshWebviewInterval = setInterval(
82+
() =>
83+
reloadWebview({
84+
panel: webviewPanel,
85+
html: `<pre>${html}</pre>`,
86+
}),
87+
500
88+
);
7389
},
7490
initEvents: () => {
7591
// Handle Data
@@ -79,9 +95,12 @@ const startAutomaticTest = () => {
7995
sendLog(`startAutomaticTest - STDOUT: ${response}`);
8096

8197
response = response.split(/[\r\n\t]+/g);
82-
terminalWriter.fire(
83-
response.length > 1 ? response.join("\r\n") : response[0]
84-
);
98+
response =
99+
response.length > 1 ? response.join("\r\n") : response[0];
100+
101+
html += response;
102+
103+
// terminalWriter.fire(response);
85104
});
86105

87106
testProcess.process.stderr.on("data", (buffer) => {
@@ -92,21 +111,37 @@ const startAutomaticTest = () => {
92111
);
93112

94113
response = response.split(/[\r\n\t]+/g);
95-
terminalWriter.fire(
96-
response.length > 1 ? response.join("\r\n") : response[0]
97-
);
114+
response =
115+
response.length > 1 ? response.join("\r\n") : response[0];
116+
117+
html += response;
118+
119+
// terminalWriter.fire(response);
98120
});
99121

100122
// Handle Closure
101123
testProcess.process.on("exit", (exitCode) => {
102124
sendLog(`startAutomaticTest - exit: ${exitCode}`);
125+
clearInterval(refreshWebviewInterval);
103126

104127
if (exitCode === 0) {
105128
sendOutput("Test Passed.");
106129
} else {
107130
sendOutput("Test Failed.");
108131
}
109132

133+
if (process.env.TEST_REPORT_PATH) {
134+
reloadWebview({
135+
panel: webviewPanel,
136+
path: `/home/strove/project/${process.env.TEST_REPORT_PATH}`,
137+
});
138+
} else {
139+
reloadWebview({
140+
panel: webviewPanel,
141+
html: `<pre>${html}</pre>`,
142+
});
143+
}
144+
110145
testRunningFlag = false;
111146
});
112147
},

utils/webview.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
const vscode = require("vscode");
2+
const path = require("path");
3+
const fs = require("fs");
4+
const Sentry = require("@sentry/node");
5+
6+
const { sendLog } = require("./debugger");
7+
8+
const environment = process.env.STROVE_ENVIRONMENT;
9+
10+
Sentry.init({
11+
beforeSend(event) {
12+
if (environment === "production") {
13+
return event;
14+
}
15+
return null;
16+
},
17+
dsn:
18+
"https://8acd5bf9eafc402b8666e9d55186f620@o221478.ingest.sentry.io/5285294",
19+
maxValueLength: 1000,
20+
normalizeDepth: 10,
21+
});
22+
23+
const createWebview = ({ path, html, title = "Test Results" }) => {
24+
try {
25+
const panel = vscode.window.createWebviewPanel(
26+
"html",
27+
title,
28+
vscode.ViewColumn.One,
29+
{}
30+
);
31+
32+
if (path) {
33+
const pathToHtml = vscode.Uri.file(path);
34+
35+
const pathUri = pathToHtml.with({ scheme: "vscode-resource" });
36+
37+
const fileContent = fs.readFileSync(pathUri.fsPath, "utf8");
38+
39+
if (checkIfHTMLFile(path)) {
40+
panel.webview.html = fileContent;
41+
} else {
42+
panel.webview.html = `<pre>${fileContent}</pre>`;
43+
}
44+
}
45+
46+
if (html) {
47+
panel.webview.html = html;
48+
}
49+
50+
return panel;
51+
} catch (e) {
52+
console.log(
53+
`received error in webview -> createWebview ${JSON.stringify(e)}`
54+
);
55+
56+
sendLog(`received error in webview -> createWebview ${JSON.stringify(e)}`);
57+
58+
Sentry.withScope((scope) => {
59+
scope.setExtras({
60+
data: path,
61+
location: "webview -> createWebview",
62+
});
63+
Sentry.captureException(e);
64+
});
65+
}
66+
};
67+
68+
const reloadWebview = ({ path, html, panel }) => {
69+
try {
70+
if (path) {
71+
const pathToHtml = vscode.Uri.file(path);
72+
73+
const pathUri = pathToHtml.with({ scheme: "vscode-resource" });
74+
75+
const fileContent = fs.readFileSync(pathUri.fsPath, "utf8");
76+
77+
if (checkIfHTMLFile(path)) {
78+
panel.webview.html = fileContent;
79+
} else {
80+
panel.webview.html = `<pre>${fileContent}</pre>`;
81+
}
82+
}
83+
84+
if (html) {
85+
panel.webview.html = html;
86+
}
87+
} catch (e) {
88+
console.log(
89+
`received error in webview -> reloadWebview ${JSON.stringify(e)}`
90+
);
91+
92+
sendLog(`received error in webview -> reloadWebview ${JSON.stringify(e)}`);
93+
94+
Sentry.withScope((scope) => {
95+
scope.setExtras({
96+
data: path,
97+
location: "webview -> reloadWebview",
98+
});
99+
Sentry.captureException(e);
100+
});
101+
}
102+
};
103+
104+
const checkIfHTMLFile = (path) => {
105+
const temp = path.slice(path.length - 4);
106+
107+
if (temp === "html") return true;
108+
109+
return false;
110+
};
111+
112+
module.exports = {
113+
createWebview,
114+
reloadWebview,
115+
};

0 commit comments

Comments
 (0)