From 6a1e4f73ace541882d36e1f395e97bbef8d55163 Mon Sep 17 00:00:00 2001 From: Piotr Jarosz Date: Fri, 22 Jan 2021 19:31:21 +0100 Subject: [PATCH 01/13] First implementation --- utils/automaticTest.js | 23 +++++++--- utils/webview.js | 95 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 6 deletions(-) create mode 100644 utils/webview.js diff --git a/utils/automaticTest.js b/utils/automaticTest.js index 5f70547..b2ab91e 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; @@ -55,6 +56,8 @@ const startAutomaticTest = () => { !testRunningFlag ) { const terminalWriter = await startTestTerminal(); + let webviewPanel; + let html = "

Automatic test results will show below:

"; testProcess = { process: child_process.spawn("/bin/bash"), @@ -67,6 +70,8 @@ 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` ); @@ -79,9 +84,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}

`; + reloadWebview({ panel: webviewPanel, html }); + terminalWriter.fire(response); }); testProcess.process.stderr.on("data", (buffer) => { @@ -92,9 +100,12 @@ 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}

`; + reloadWebview({ panel: webviewPanel, html }); + terminalWriter.fire(response); }); // Handle Closure diff --git a/utils/webview.js b/utils/webview.js new file mode 100644 index 0000000..7dde192 --- /dev/null +++ b/utils/webview.js @@ -0,0 +1,95 @@ +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" }); + + panel.webview.html = fs.readFileSync(pathUri.fsPath, "utf8"); + } + + 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" }); + + panel.webview.html = fs.readFileSync(pathUri.fsPath, "utf8"); + } + + 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); + }); + } +}; + +module.exports = { + createWebview, + reloadWebview, +}; From 48bdd31c9412b81aa697cf6a3b2782de1a0f9f86 Mon Sep 17 00:00:00 2001 From: Piotr Jarosz Date: Fri, 22 Jan 2021 19:52:51 +0100 Subject: [PATCH 02/13] quick test --- utils/automaticTest.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/utils/automaticTest.js b/utils/automaticTest.js index b2ab91e..7e79511 100644 --- a/utils/automaticTest.js +++ b/utils/automaticTest.js @@ -57,7 +57,7 @@ const startAutomaticTest = () => { ) { const terminalWriter = await startTestTerminal(); let webviewPanel; - let html = "

Automatic test results will show below:

"; + let html = "

Automatic test results will be visible below:

"; testProcess = { process: child_process.spawn("/bin/bash"), @@ -87,8 +87,12 @@ const startAutomaticTest = () => { response = response.length > 1 ? response.join("\r\n") : response[0]; - html += `

${response}

`; - reloadWebview({ panel: webviewPanel, html }); + // html += `

${response}

`; + html += `\r\n${response}`; + reloadWebview({ + panel: webviewPanel, + html: `
${html}
`, + }); terminalWriter.fire(response); }); From 0a8dfb36b7f1b8ee8a087f78301b1e739ef0db10 Mon Sep 17 00:00:00 2001 From: Piotr Jarosz Date: Fri, 22 Jan 2021 19:57:45 +0100 Subject: [PATCH 03/13] test --- utils/automaticTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/automaticTest.js b/utils/automaticTest.js index 7e79511..7fbdd41 100644 --- a/utils/automaticTest.js +++ b/utils/automaticTest.js @@ -88,7 +88,7 @@ const startAutomaticTest = () => { response.length > 1 ? response.join("\r\n") : response[0]; // html += `

${response}

`; - html += `\r\n${response}`; + html += `${response}`; reloadWebview({ panel: webviewPanel, html: `
${html}
`, From bafee4d869e1530f772397140eb8c38edb6265a4 Mon Sep 17 00:00:00 2001 From: Piotr Jarosz Date: Fri, 22 Jan 2021 20:08:54 +0100 Subject: [PATCH 04/13] test --- utils/automaticTest.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/utils/automaticTest.js b/utils/automaticTest.js index 7fbdd41..ed8b195 100644 --- a/utils/automaticTest.js +++ b/utils/automaticTest.js @@ -59,6 +59,8 @@ const startAutomaticTest = () => { let webviewPanel; let html = "

Automatic test results will be visible below:

"; + let interval; + testProcess = { process: child_process.spawn("/bin/bash"), send: () => { @@ -75,6 +77,15 @@ const startAutomaticTest = () => { testProcess.process.stdin.write( `cd ${automaticTest.folderName} && ${automaticTest.testStartCommand} ; exit\n` ); + + interval = setInterval( + () => + reloadWebview({ + panel: webviewPanel, + html: `
${html}
`, + }), + 1000 + ); }, initEvents: () => { // Handle Data @@ -88,11 +99,11 @@ const startAutomaticTest = () => { response.length > 1 ? response.join("\r\n") : response[0]; // html += `

${response}

`; - html += `${response}`; - reloadWebview({ - panel: webviewPanel, - html: `
${html}
`, - }); + html += response; + // reloadWebview({ + // panel: webviewPanel, + // html: `
${html}
`, + // }); terminalWriter.fire(response); }); @@ -107,14 +118,18 @@ const startAutomaticTest = () => { response = response.length > 1 ? response.join("\r\n") : response[0]; - html += `

${response}

`; - reloadWebview({ panel: webviewPanel, html }); + html += response; + // reloadWebview({ + // panel: webviewPanel, + // html: `
${html}
`, + // }); terminalWriter.fire(response); }); // Handle Closure testProcess.process.on("exit", (exitCode) => { sendLog(`startAutomaticTest - exit: ${exitCode}`); + clearInterval(interval); if (exitCode === 0) { sendOutput("Test Passed."); From a9dc7e3362bd9222517868ef3ef6ca084d3a2db0 Mon Sep 17 00:00:00 2001 From: Piotr Jarosz Date: Fri, 22 Jan 2021 20:11:08 +0100 Subject: [PATCH 05/13] test --- utils/automaticTest.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/utils/automaticTest.js b/utils/automaticTest.js index ed8b195..d027720 100644 --- a/utils/automaticTest.js +++ b/utils/automaticTest.js @@ -137,6 +137,11 @@ const startAutomaticTest = () => { sendOutput("Test Failed."); } + reloadWebview({ + panel: webviewPanel, + html: `
${html}
`, + }); + testRunningFlag = false; }); }, From aa067ae0ed529d851b255d36e8a6189a4dd36f89 Mon Sep 17 00:00:00 2001 From: Piotr Jarosz Date: Mon, 25 Jan 2021 17:35:27 +0100 Subject: [PATCH 06/13] test --- utils/automaticTest.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/utils/automaticTest.js b/utils/automaticTest.js index d027720..9665a9b 100644 --- a/utils/automaticTest.js +++ b/utils/automaticTest.js @@ -59,7 +59,7 @@ const startAutomaticTest = () => { let webviewPanel; let html = "

Automatic test results will be visible below:

"; - let interval; + let refreshWebviewInterval; testProcess = { process: child_process.spawn("/bin/bash"), @@ -78,13 +78,13 @@ const startAutomaticTest = () => { `cd ${automaticTest.folderName} && ${automaticTest.testStartCommand} ; exit\n` ); - interval = setInterval( + refreshWebviewInterval = setInterval( () => reloadWebview({ panel: webviewPanel, html: `
${html}
`, }), - 1000 + 500 ); }, initEvents: () => { @@ -98,12 +98,8 @@ const startAutomaticTest = () => { response = response.length > 1 ? response.join("\r\n") : response[0]; - // html += `

${response}

`; html += response; - // reloadWebview({ - // panel: webviewPanel, - // html: `
${html}
`, - // }); + terminalWriter.fire(response); }); @@ -119,17 +115,14 @@ const startAutomaticTest = () => { response.length > 1 ? response.join("\r\n") : response[0]; html += response; - // reloadWebview({ - // panel: webviewPanel, - // html: `
${html}
`, - // }); + terminalWriter.fire(response); }); // Handle Closure testProcess.process.on("exit", (exitCode) => { sendLog(`startAutomaticTest - exit: ${exitCode}`); - clearInterval(interval); + clearInterval(refreshWebviewInterval); if (exitCode === 0) { sendOutput("Test Passed."); @@ -137,10 +130,17 @@ const startAutomaticTest = () => { sendOutput("Test Failed."); } - reloadWebview({ - panel: webviewPanel, - html: `
${html}
`, - }); + if (process.env.TEST_REPORT_PATH) { + reloadWebview({ + panel: webviewPanel, + html: `
${html}
`, + }); + } else { + reloadWebview({ + panel: webviewPanel, + path: `/home/strove/project/${process.env.TEST_REPORT_PATH}`, + }); + } testRunningFlag = false; }); From 1452212ec73d64f69a0db1276b271dd97ce2f17a Mon Sep 17 00:00:00 2001 From: Piotr Jarosz Date: Mon, 25 Jan 2021 17:49:25 +0100 Subject: [PATCH 07/13] stash --- utils/automaticTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/automaticTest.js b/utils/automaticTest.js index 9665a9b..473324f 100644 --- a/utils/automaticTest.js +++ b/utils/automaticTest.js @@ -84,7 +84,7 @@ const startAutomaticTest = () => { panel: webviewPanel, html: `
${html}
`, }), - 500 + 1000 ); }, initEvents: () => { From d78012c6ac08e38a552f302d947f0ec6895debeb Mon Sep 17 00:00:00 2001 From: Piotr Jarosz Date: Mon, 25 Jan 2021 17:54:22 +0100 Subject: [PATCH 08/13] stash --- utils/automaticTest.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/automaticTest.js b/utils/automaticTest.js index 473324f..1332992 100644 --- a/utils/automaticTest.js +++ b/utils/automaticTest.js @@ -84,7 +84,7 @@ const startAutomaticTest = () => { panel: webviewPanel, html: `
${html}
`, }), - 1000 + 500 ); }, initEvents: () => { @@ -133,12 +133,12 @@ const startAutomaticTest = () => { if (process.env.TEST_REPORT_PATH) { reloadWebview({ panel: webviewPanel, - html: `
${html}
`, + path: `/home/strove/project/${process.env.TEST_REPORT_PATH}`, }); } else { reloadWebview({ panel: webviewPanel, - path: `/home/strove/project/${process.env.TEST_REPORT_PATH}`, + html: `
${html}
`, }); } From d8a8f7371240aaaaecbb3a58d98b1ef85de519da Mon Sep 17 00:00:00 2001 From: Piotr Jarosz Date: Mon, 25 Jan 2021 17:59:55 +0100 Subject: [PATCH 09/13] stash --- utils/automaticTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/automaticTest.js b/utils/automaticTest.js index 1332992..be455a4 100644 --- a/utils/automaticTest.js +++ b/utils/automaticTest.js @@ -57,7 +57,7 @@ const startAutomaticTest = () => { ) { const terminalWriter = await startTestTerminal(); let webviewPanel; - let html = "

Automatic test results will be visible below:

"; + let html = "
Automatic test results will be visible below:
"; let refreshWebviewInterval; From 4262c4523517194715ed8126b62caaba5820971f Mon Sep 17 00:00:00 2001 From: Piotr Jarosz Date: Mon, 25 Jan 2021 18:20:49 +0100 Subject: [PATCH 10/13] test --- utils/automaticTest.js | 2 +- utils/webview.js | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/utils/automaticTest.js b/utils/automaticTest.js index be455a4..958c032 100644 --- a/utils/automaticTest.js +++ b/utils/automaticTest.js @@ -57,7 +57,7 @@ const startAutomaticTest = () => { ) { const terminalWriter = await startTestTerminal(); let webviewPanel; - let html = "
Automatic test results will be visible below:
"; + let html = "

Automatic test results will be visible below:

"; let refreshWebviewInterval; diff --git a/utils/webview.js b/utils/webview.js index 7dde192..3fb8742 100644 --- a/utils/webview.js +++ b/utils/webview.js @@ -34,7 +34,11 @@ const createWebview = ({ path, html, title = "Test Results" }) => { const pathUri = pathToHtml.with({ scheme: "vscode-resource" }); - panel.webview.html = fs.readFileSync(pathUri.fsPath, "utf8"); + // panel.webview.html = fs.readFileSync(pathUri.fsPath, "utf8"); + panel.webview.html = `
${fs.readFileSync(
+        pathUri.fsPath,
+        "utf8"
+      )}
`; } if (html) { @@ -66,7 +70,10 @@ const reloadWebview = ({ path, html, panel }) => { const pathUri = pathToHtml.with({ scheme: "vscode-resource" }); - panel.webview.html = fs.readFileSync(pathUri.fsPath, "utf8"); + panel.webview.html = `
${fs.readFileSync(
+        pathUri.fsPath,
+        "utf8"
+      )}
`; } if (html) { From b3427eeaf0a79e9ae5173298af0ba08db7966254 Mon Sep 17 00:00:00 2001 From: Piotr Jarosz Date: Mon, 25 Jan 2021 19:19:04 +0100 Subject: [PATCH 11/13] last test --- utils/webview.js | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/utils/webview.js b/utils/webview.js index 3fb8742..77f2fb7 100644 --- a/utils/webview.js +++ b/utils/webview.js @@ -34,11 +34,13 @@ const createWebview = ({ path, html, title = "Test Results" }) => { const pathUri = pathToHtml.with({ scheme: "vscode-resource" }); - // panel.webview.html = fs.readFileSync(pathUri.fsPath, "utf8"); - panel.webview.html = `
${fs.readFileSync(
-        pathUri.fsPath,
-        "utf8"
-      )}
`; + const fileContent = fs.readFileSync(pathUri.fsPath, "utf8"); + + if (checkIfHTMLFile(path)) { + panel.webview.html = fileContent; + } else { + panel.webview.html = `
${fileContent}
`; + } } if (html) { @@ -70,10 +72,13 @@ const reloadWebview = ({ path, html, panel }) => { const pathUri = pathToHtml.with({ scheme: "vscode-resource" }); - panel.webview.html = `
${fs.readFileSync(
-        pathUri.fsPath,
-        "utf8"
-      )}
`; + const fileContent = fs.readFileSync(pathUri.fsPath, "utf8"); + + if (checkIfHTMLFile(path)) { + panel.webview.html = fileContent; + } else { + panel.webview.html = `
${fileContent}
`; + } } if (html) { @@ -96,6 +101,14 @@ const reloadWebview = ({ path, html, panel }) => { } }; +const checkIfHTMLFile = (path) => { + const temp = path.slice(path.length - 4); + + if (temp === "html") return true; + + return false; +}; + module.exports = { createWebview, reloadWebview, From 8c1ad628d1b1a1852c7b0bfbc9898c2a01b7d2a5 Mon Sep 17 00:00:00 2001 From: Piotr Jarosz Date: Mon, 25 Jan 2021 19:37:32 +0100 Subject: [PATCH 12/13] Disabled terminal --- utils/automaticTest.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/automaticTest.js b/utils/automaticTest.js index 958c032..0046b8d 100644 --- a/utils/automaticTest.js +++ b/utils/automaticTest.js @@ -55,7 +55,7 @@ const startAutomaticTest = () => { ) && !testRunningFlag ) { - const terminalWriter = await startTestTerminal(); + // const terminalWriter = await startTestTerminal(); let webviewPanel; let html = "

Automatic test results will be visible below:

"; @@ -100,7 +100,7 @@ const startAutomaticTest = () => { html += response; - terminalWriter.fire(response); + // terminalWriter.fire(response); }); testProcess.process.stderr.on("data", (buffer) => { @@ -116,7 +116,7 @@ const startAutomaticTest = () => { html += response; - terminalWriter.fire(response); + // terminalWriter.fire(response); }); // Handle Closure From ad90f7800c91fef4e5635ae4441efa84d8666f88 Mon Sep 17 00:00:00 2001 From: Piotr Jarosz Date: Mon, 25 Jan 2021 19:38:18 +0100 Subject: [PATCH 13/13] version bump --- README.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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" },