diff --git a/README.md b/README.md index e42c622..b109078 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package.json b/package.json index b726f18..304a78f 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/utils/automaticTest.js b/utils/automaticTest.js index 5f70547..0046b8d 100644 --- a/utils/automaticTest.js +++ b/utils/automaticTest.js @@ -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; @@ -54,7 +55,11 @@ const startAutomaticTest = () => { ) && !testRunningFlag ) { - const terminalWriter = await startTestTerminal(); + // const terminalWriter = await startTestTerminal(); + let webviewPanel; + let html = "
${html}`, + }), + 500 + ); }, initEvents: () => { // Handle Data @@ -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) => { @@ -92,14 +111,18 @@ 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."); @@ -107,6 +130,18 @@ const startAutomaticTest = () => { 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: `
${html}`, + }); + } + testRunningFlag = false; }); }, diff --git a/utils/webview.js b/utils/webview.js new file mode 100644 index 0000000..77f2fb7 --- /dev/null +++ b/utils/webview.js @@ -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 = `
${fileContent}`; + } + } + + 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 = `
${fileContent}`; + } + } + + 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, +};