Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Liveshare toolkit for strove.io.

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

Current version: 0.2.3
Current version: 0.2.5
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "stroveteams",
"displayName": "stroveTeams",
"description": "Teams support for Strove",
"version": "0.2.4",
"version": "0.2.5",
"engines": {
"vscode": "^1.39.2"
},
Expand Down
49 changes: 42 additions & 7 deletions utils/automaticTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
} = require("./queries");
const child_process = require("child_process");
const { sendLog } = require("./debugger");
const { createWebview, reloadWebview } = require("./webview");

const environment = process.env.STROVE_ENVIRONMENT;

Expand Down Expand Up @@ -54,7 +55,11 @@ const startAutomaticTest = () => {
) &&
!testRunningFlag
) {
const terminalWriter = await startTestTerminal();
// const terminalWriter = await startTestTerminal();
let webviewPanel;
let html = "<h3>Automatic test results will be visible below:</h3>";

let refreshWebviewInterval;

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

webviewPanel = createWebview({ html });

testProcess.process.stdin.write(
`cd ${automaticTest.folderName} && ${automaticTest.testStartCommand} ; exit\n`
);

refreshWebviewInterval = setInterval(
() =>
reloadWebview({
panel: webviewPanel,
html: `<pre>${html}</pre>`,
}),
500
);
},
initEvents: () => {
// Handle Data
Expand All @@ -79,9 +95,12 @@ const startAutomaticTest = () => {
sendLog(`startAutomaticTest - STDOUT: ${response}`);

response = response.split(/[\r\n\t]+/g);
terminalWriter.fire(
response.length > 1 ? response.join("\r\n") : response[0]
);
response =
response.length > 1 ? response.join("\r\n") : response[0];

html += response;

// terminalWriter.fire(response);
});

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

response = response.split(/[\r\n\t]+/g);
terminalWriter.fire(
response.length > 1 ? response.join("\r\n") : response[0]
);
response =
response.length > 1 ? response.join("\r\n") : response[0];

html += response;

// terminalWriter.fire(response);
});

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

if (exitCode === 0) {
sendOutput("Test Passed.");
} else {
sendOutput("Test Failed.");
}

if (process.env.TEST_REPORT_PATH) {
reloadWebview({
panel: webviewPanel,
path: `/home/strove/project/${process.env.TEST_REPORT_PATH}`,
});
} else {
reloadWebview({
panel: webviewPanel,
html: `<pre>${html}</pre>`,
});
}

testRunningFlag = false;
});
},
Expand Down
115 changes: 115 additions & 0 deletions utils/webview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
const vscode = require("vscode");
const path = require("path");
const fs = require("fs");
const Sentry = require("@sentry/node");

const { sendLog } = require("./debugger");

const environment = process.env.STROVE_ENVIRONMENT;

Sentry.init({
beforeSend(event) {
if (environment === "production") {
return event;
}
return null;
},
dsn:
"https://8acd5bf9eafc402b8666e9d55186f620@o221478.ingest.sentry.io/5285294",
maxValueLength: 1000,
normalizeDepth: 10,
});

const createWebview = ({ path, html, title = "Test Results" }) => {
try {
const panel = vscode.window.createWebviewPanel(
"html",
title,
vscode.ViewColumn.One,
{}
);

if (path) {
const pathToHtml = vscode.Uri.file(path);

const pathUri = pathToHtml.with({ scheme: "vscode-resource" });

const fileContent = fs.readFileSync(pathUri.fsPath, "utf8");

if (checkIfHTMLFile(path)) {
panel.webview.html = fileContent;
} else {
panel.webview.html = `<pre>${fileContent}</pre>`;
}
}

if (html) {
panel.webview.html = html;
}

return panel;
} catch (e) {
console.log(
`received error in webview -> createWebview ${JSON.stringify(e)}`
);

sendLog(`received error in webview -> createWebview ${JSON.stringify(e)}`);

Sentry.withScope((scope) => {
scope.setExtras({
data: path,
location: "webview -> createWebview",
});
Sentry.captureException(e);
});
}
};

const reloadWebview = ({ path, html, panel }) => {
try {
if (path) {
const pathToHtml = vscode.Uri.file(path);

const pathUri = pathToHtml.with({ scheme: "vscode-resource" });

const fileContent = fs.readFileSync(pathUri.fsPath, "utf8");

if (checkIfHTMLFile(path)) {
panel.webview.html = fileContent;
} else {
panel.webview.html = `<pre>${fileContent}</pre>`;
}
}

if (html) {
panel.webview.html = html;
}
} catch (e) {
console.log(
`received error in webview -> reloadWebview ${JSON.stringify(e)}`
);

sendLog(`received error in webview -> reloadWebview ${JSON.stringify(e)}`);

Sentry.withScope((scope) => {
scope.setExtras({
data: path,
location: "webview -> reloadWebview",
});
Sentry.captureException(e);
});
}
};

const checkIfHTMLFile = (path) => {
const temp = path.slice(path.length - 4);

if (temp === "html") return true;

return false;
};

module.exports = {
createWebview,
reloadWebview,
};