From e5ae4c6c9588819c7c34758161295807f9e578ec Mon Sep 17 00:00:00 2001 From: Ilona Shishov Date: Thu, 15 Feb 2024 13:01:08 +0200 Subject: [PATCH] test: use rewire to test exhort services Signed-off-by: Ilona Shishov --- package-lock.json | 185 ++++++++++++++++--------------- package.json | 3 +- src/config.ts | 2 + src/dependencyReportPanel.ts | 2 + src/exhortServices.ts | 2 +- src/stackAnalysis.ts | 2 + test/caStatusBarProvider.test.ts | 1 - test/exhortServices.test.ts | 104 +++++++++++++++++ test/index.ts | 3 +- test/redhatTelemetry.test.ts | 64 +++++++++++ test/utils.ts | 37 +++++++ webpack.config.ts | 6 - 12 files changed, 312 insertions(+), 99 deletions(-) create mode 100644 test/exhortServices.test.ts create mode 100644 test/redhatTelemetry.test.ts create mode 100644 test/utils.ts diff --git a/package-lock.json b/package-lock.json index f2d27216f..6f2e55b62 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.9.2", "license": "Apache-2.0", "dependencies": { - "@fabric8-analytics/fabric8-analytics-lsp-server": "^0.9.3", + "@fabric8-analytics/fabric8-analytics-lsp-server": "^0.9.4-ea.0", "@redhat-developer/vscode-redhat-telemetry": "^0.7.0", "@RHEcosystemAppEng/exhort-javascript-api": "^0.1.1-ea.14", "fs": "^0.0.1-security", @@ -25,6 +25,7 @@ "@typescript-eslint/eslint-plugin": "^6.8.0", "@typescript-eslint/parser": "^6.8.0", "@vscode/test-electron": "^2.3.5", + "babel-plugin-rewire": "^1.2.0", "chai": "^4.3.10", "decache": "^4.6.2", "eslint": "^8.51.0", @@ -81,11 +82,11 @@ }, "../fabric8-analytics-lsp-server": { "name": "@fabric8-analytics/fabric8-analytics-lsp-server", - "version": "0.9.0", + "version": "0.9.2", "extraneous": true, "license": "Apache-2.0", "dependencies": { - "@RHEcosystemAppEng/exhort-javascript-api": "^0.1.1-ea.5", + "@RHEcosystemAppEng/exhort-javascript-api": "^0.1.1-ea.14", "@xml-tools/ast": "^5.0.5", "@xml-tools/parser": "^1.0.11", "json-to-ast": "^2.1.0", @@ -135,11 +136,11 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.22.13", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz", - "integrity": "sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==", + "version": "7.23.5", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.23.5.tgz", + "integrity": "sha512-CgH3s1a96LipHCmSUmYFPwY7MNx8C3avkq7i4Wl3cfa662ldtUe4VM1TPXX70pfmrlWTb6jLqTYrZyT2ZTJBgA==", "dependencies": { - "@babel/highlight": "^7.22.13", + "@babel/highlight": "^7.23.4", "chalk": "^2.4.2" }, "engines": { @@ -147,28 +148,28 @@ } }, "node_modules/@babel/compat-data": { - "version": "7.23.2", - "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.23.2.tgz", - "integrity": "sha512-0S9TQMmDHlqAZ2ITT95irXKfxN9bncq8ZCoJhun3nHL/lLUxd2NKBJYoNGWH7S0hz6fRQwWlAWn/ILM0C70KZQ==", + "version": "7.23.5", + "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.23.5.tgz", + "integrity": "sha512-uU27kfDRlhfKl+w1U6vp16IuvSLtjAxdArVXPa9BvLkrr7CYIsxH5adpHObeAGY/41+syctUWOZ140a2Rvkgjw==", "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/core": { - "version": "7.23.2", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.23.2.tgz", - "integrity": "sha512-n7s51eWdaWZ3vGT2tD4T7J6eJs3QoBXydv7vkUM06Bf1cbVD2Kc2UrkzhiQwobfV7NwOnQXYL7UBJ5VPU+RGoQ==", + "version": "7.23.9", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.23.9.tgz", + "integrity": "sha512-5q0175NOjddqpvvzU+kDiSOAk4PfdO6FvwCWoQ6RO7rTzEe8vlo+4HVfcnAREhD4npMs0e9uZypjTwzZPCf/cw==", "dependencies": { "@ampproject/remapping": "^2.2.0", - "@babel/code-frame": "^7.22.13", - "@babel/generator": "^7.23.0", - "@babel/helper-compilation-targets": "^7.22.15", - "@babel/helper-module-transforms": "^7.23.0", - "@babel/helpers": "^7.23.2", - "@babel/parser": "^7.23.0", - "@babel/template": "^7.22.15", - "@babel/traverse": "^7.23.2", - "@babel/types": "^7.23.0", + "@babel/code-frame": "^7.23.5", + "@babel/generator": "^7.23.6", + "@babel/helper-compilation-targets": "^7.23.6", + "@babel/helper-module-transforms": "^7.23.3", + "@babel/helpers": "^7.23.9", + "@babel/parser": "^7.23.9", + "@babel/template": "^7.23.9", + "@babel/traverse": "^7.23.9", + "@babel/types": "^7.23.9", "convert-source-map": "^2.0.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", @@ -184,11 +185,11 @@ } }, "node_modules/@babel/generator": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.0.tgz", - "integrity": "sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.6.tgz", + "integrity": "sha512-qrSfCYxYQB5owCmGLbl8XRpX1ytXlpueOb0N0UmQwA073KZxejgQTzAmJezxvpwQD9uGtK2shHdi55QT+MbjIw==", "dependencies": { - "@babel/types": "^7.23.0", + "@babel/types": "^7.23.6", "@jridgewell/gen-mapping": "^0.3.2", "@jridgewell/trace-mapping": "^0.3.17", "jsesc": "^2.5.1" @@ -198,13 +199,13 @@ } }, "node_modules/@babel/helper-compilation-targets": { - "version": "7.22.15", - "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.22.15.tgz", - "integrity": "sha512-y6EEzULok0Qvz8yyLkCvVX+02ic+By2UdOhylwUOvOn9dvYc9mKICJuuU1n1XBI02YWsNsnrY1kc6DVbjcXbtw==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.23.6.tgz", + "integrity": "sha512-9JB548GZoQVmzrFgp8o7KxdgkTGm6xs9DW0o/Pim72UDjzr5ObUQ6ZzYPqA+g9OTS2bBQoctLJrky0RDCAWRgQ==", "dependencies": { - "@babel/compat-data": "^7.22.9", - "@babel/helper-validator-option": "^7.22.15", - "browserslist": "^4.21.9", + "@babel/compat-data": "^7.23.5", + "@babel/helper-validator-option": "^7.23.5", + "browserslist": "^4.22.2", "lru-cache": "^5.1.1", "semver": "^6.3.1" }, @@ -255,9 +256,9 @@ } }, "node_modules/@babel/helper-module-transforms": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.23.0.tgz", - "integrity": "sha512-WhDWw1tdrlT0gMgUJSlX0IQvoO1eN279zrAUbVB+KpV2c3Tylz8+GnKOLllCS6Z/iZQEyVYxhZVUdPTqs2YYPw==", + "version": "7.23.3", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.23.3.tgz", + "integrity": "sha512-7bBs4ED9OmswdfDzpz4MpWgSrV7FXlc3zIagvLFjS5H+Mk7Snr21vQ6QwrsoCGMfNC4e4LQPdoULEt4ykz0SRQ==", "dependencies": { "@babel/helper-environment-visitor": "^7.22.20", "@babel/helper-module-imports": "^7.22.15", @@ -295,9 +296,9 @@ } }, "node_modules/@babel/helper-string-parser": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz", - "integrity": "sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==", + "version": "7.23.4", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.23.4.tgz", + "integrity": "sha512-803gmbQdqwdf4olxrX4AJyFBV/RTr3rSmOj0rKwesmzlfhYNDEs+/iOcznzpNWlJlIlTJC2QfPFcHB6DlzdVLQ==", "engines": { "node": ">=6.9.0" } @@ -311,30 +312,30 @@ } }, "node_modules/@babel/helper-validator-option": { - "version": "7.22.15", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.22.15.tgz", - "integrity": "sha512-bMn7RmyFjY/mdECUbgn9eoSY4vqvacUnS9i9vGAGttgFWesO6B4CYWA7XlpbWgBt71iv/hfbPlynohStqnu5hA==", + "version": "7.23.5", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.23.5.tgz", + "integrity": "sha512-85ttAOMLsr53VgXkTbkx8oA6YTfT4q7/HzXSLEYmjcSTJPMPQtvq1BD79Byep5xMUYbGRzEpDsjUf3dyp54IKw==", "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helpers": { - "version": "7.23.2", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.23.2.tgz", - "integrity": "sha512-lzchcp8SjTSVe/fPmLwtWVBFC7+Tbn8LGHDVfDp9JGxpAY5opSaEFgt8UQvrnECWOTdji2mOWMz1rOhkHscmGQ==", + "version": "7.23.9", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.23.9.tgz", + "integrity": "sha512-87ICKgU5t5SzOT7sBMfCOZQ2rHjRU+Pcb9BoILMYz600W6DkVRLFBPwQ18gwUVvggqXivaUakpnxWQGbpywbBQ==", "dependencies": { - "@babel/template": "^7.22.15", - "@babel/traverse": "^7.23.2", - "@babel/types": "^7.23.0" + "@babel/template": "^7.23.9", + "@babel/traverse": "^7.23.9", + "@babel/types": "^7.23.9" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/highlight": { - "version": "7.22.20", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.20.tgz", - "integrity": "sha512-dkdMCN3py0+ksCgYmGG8jKeGA/8Tk+gJwSYYlFGxG5lmhfKNoAy004YpLxpS1W2J8m/EK2Ew+yOs9pVRwO89mg==", + "version": "7.23.4", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.23.4.tgz", + "integrity": "sha512-acGdbYSfp2WheJoJm/EBBBLh/ID8KDc64ISZ9DYtBmC8/Q204PZJLHyzeB5qMzJ5trcOkybd78M4x2KWsUq++A==", "dependencies": { "@babel/helper-validator-identifier": "^7.22.20", "chalk": "^2.4.2", @@ -345,9 +346,9 @@ } }, "node_modules/@babel/parser": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.0.tgz", - "integrity": "sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==", + "version": "7.23.9", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.9.tgz", + "integrity": "sha512-9tcKgqKbs3xGJ+NtKF2ndOBBLVwPjl1SHxPQkd36r3Dlirw3xWUeGaTbqr7uGZcTaxkVNwc+03SVP7aCdWrTlA==", "bin": { "parser": "bin/babel-parser.js" }, @@ -356,32 +357,32 @@ } }, "node_modules/@babel/template": { - "version": "7.22.15", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.22.15.tgz", - "integrity": "sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==", + "version": "7.23.9", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.23.9.tgz", + "integrity": "sha512-+xrD2BWLpvHKNmX2QbpdpsBaWnRxahMwJjO+KZk2JOElj5nSmKezyS1B4u+QbHMTX69t4ukm6hh9lsYQ7GHCKA==", "dependencies": { - "@babel/code-frame": "^7.22.13", - "@babel/parser": "^7.22.15", - "@babel/types": "^7.22.15" + "@babel/code-frame": "^7.23.5", + "@babel/parser": "^7.23.9", + "@babel/types": "^7.23.9" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/traverse": { - "version": "7.23.2", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.2.tgz", - "integrity": "sha512-azpe59SQ48qG6nu2CzcMLbxUudtN+dOM9kDbUqGq3HXUJRlo7i8fvPoxQUzYgLZ4cMVmuZgm8vvBpNeRhd6XSw==", + "version": "7.23.9", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.9.tgz", + "integrity": "sha512-I/4UJ9vs90OkBtY6iiiTORVMyIhJ4kAVmsKo9KFc8UOxMeUfi2hvtIBsET5u9GizXE6/GFSuKCTNfgCswuEjRg==", "dependencies": { - "@babel/code-frame": "^7.22.13", - "@babel/generator": "^7.23.0", + "@babel/code-frame": "^7.23.5", + "@babel/generator": "^7.23.6", "@babel/helper-environment-visitor": "^7.22.20", "@babel/helper-function-name": "^7.23.0", "@babel/helper-hoist-variables": "^7.22.5", "@babel/helper-split-export-declaration": "^7.22.6", - "@babel/parser": "^7.23.0", - "@babel/types": "^7.23.0", - "debug": "^4.1.0", + "@babel/parser": "^7.23.9", + "@babel/types": "^7.23.9", + "debug": "^4.3.1", "globals": "^11.1.0" }, "engines": { @@ -389,11 +390,11 @@ } }, "node_modules/@babel/types": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.0.tgz", - "integrity": "sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg==", + "version": "7.23.9", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.9.tgz", + "integrity": "sha512-dQjSq/7HaSjRM43FFGnv5keM2HsxpmyV1PfaSVm0nzzjwwTmjOe6J4bC8e3+pTEIgHaHj+1ZlLThRJ2auc/w1Q==", "dependencies": { - "@babel/helper-string-parser": "^7.22.5", + "@babel/helper-string-parser": "^7.23.4", "@babel/helper-validator-identifier": "^7.22.20", "to-fast-properties": "^2.0.0" }, @@ -567,9 +568,9 @@ } }, "node_modules/@fabric8-analytics/fabric8-analytics-lsp-server": { - "version": "0.9.3", - "resolved": "https://npm.pkg.github.com/download/@fabric8-analytics/fabric8-analytics-lsp-server/0.9.3/7032ee5390644c734c78d171a8b6164cc348854d", - "integrity": "sha512-t1U8escvm580KY2vttmPQyMtmf/9xftPpVkB7z56nf1ZoUc9PJJJBQaNKeI+pHKsH1YE0OISFzm1A8AFUCmGbg==", + "version": "0.9.4-ea.0", + "resolved": "https://npm.pkg.github.com/download/@fabric8-analytics/fabric8-analytics-lsp-server/0.9.4-ea.0/a68219c111cf780da2e2cd724f3f7d31e51e7ed7", + "integrity": "sha512-b+g3LAZ2D5rdcPJJg77z1vKSpdhl9sySpzfSgm8dTmBKjeieJGlDLbZR6+kAOEhh3u0JdfhejT2rrMO4rpO0Qw==", "license": "Apache-2.0", "dependencies": { "@RHEcosystemAppEng/exhort-javascript-api": "^0.1.1-ea.14", @@ -1996,6 +1997,12 @@ "proxy-from-env": "^1.1.0" } }, + "node_modules/babel-plugin-rewire": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/babel-plugin-rewire/-/babel-plugin-rewire-1.2.0.tgz", + "integrity": "sha512-JBZxczHw3tScS+djy6JPLMjblchGhLI89ep15H3SyjujIzlxo5nr6Yjo7AXotdeVczeBmWs0tF8PgJWDdgzAkQ==", + "dev": true + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -2048,9 +2055,9 @@ "dev": true }, "node_modules/browserslist": { - "version": "4.22.1", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.22.1.tgz", - "integrity": "sha512-FEVc202+2iuClEhZhrWy6ZiAcRLvNMyYcxZ8raemul1DYVOVdFsbqckWLdsixQZCpJlwe77Z3UTalE7jsjnKfQ==", + "version": "4.22.3", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.22.3.tgz", + "integrity": "sha512-UAp55yfwNv0klWNapjs/ktHoguxuQNGnOzxYmfnXIS+8AsRDZkSDxg7R1AX3GKzn078SBI5dzwzj/Yx0Or0e3A==", "funding": [ { "type": "opencollective", @@ -2066,9 +2073,9 @@ } ], "dependencies": { - "caniuse-lite": "^1.0.30001541", - "electron-to-chromium": "^1.4.535", - "node-releases": "^2.0.13", + "caniuse-lite": "^1.0.30001580", + "electron-to-chromium": "^1.4.648", + "node-releases": "^2.0.14", "update-browserslist-db": "^1.0.13" }, "bin": { @@ -2127,9 +2134,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001558", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001558.tgz", - "integrity": "sha512-/Et7DwLqpjS47JPEcz6VnxU9PwcIdVi0ciLXRWBQdj1XFye68pSQYpV0QtPTfUKWuOaEig+/Vez2l74eDc1tPQ==", + "version": "1.0.30001584", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001584.tgz", + "integrity": "sha512-LOz7CCQ9M1G7OjJOF9/mzmqmj3jE/7VOmrfw6Mgs0E8cjOsbRXQJHsPBfmBOXDskXKrHLyyW3n7kpDW/4BsfpQ==", "funding": [ { "type": "opencollective", @@ -2548,9 +2555,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.569", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.569.tgz", - "integrity": "sha512-LsrJjZ0IbVy12ApW3gpYpcmHS3iRxH4bkKOW98y1/D+3cvDUWGcbzbsFinfUS8knpcZk/PG/2p/RnkMCYN7PVg==" + "version": "1.4.657", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.657.tgz", + "integrity": "sha512-On2ymeleg6QbRuDk7wNgDdXtNqlJLM2w4Agx1D/RiTmItiL+a9oq5p7HUa2ZtkAtGBe/kil2dq/7rPfkbe0r5w==" }, "node_modules/emoji-regex": { "version": "8.0.0", @@ -4700,9 +4707,9 @@ } }, "node_modules/node-releases": { - "version": "2.0.13", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.13.tgz", - "integrity": "sha512-uYr7J37ae/ORWdZeQ1xxMJe3NtdmqMC/JZK+geofDrkLUApKRHPd18/TxtBOJ4A0/+uUIliorNrfYV6s1b02eQ==" + "version": "2.0.14", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.14.tgz", + "integrity": "sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==" }, "node_modules/nopt": { "version": "5.0.0", diff --git a/package.json b/package.json index 8f72511df..2370af0b5 100644 --- a/package.json +++ b/package.json @@ -262,6 +262,7 @@ "@typescript-eslint/eslint-plugin": "^6.8.0", "@typescript-eslint/parser": "^6.8.0", "@vscode/test-electron": "^2.3.5", + "babel-plugin-rewire": "^1.2.0", "chai": "^4.3.10", "decache": "^4.6.2", "eslint": "^8.51.0", @@ -278,7 +279,7 @@ "webpack-cli": "^5.1.4" }, "dependencies": { - "@fabric8-analytics/fabric8-analytics-lsp-server": "^0.9.3", + "@fabric8-analytics/fabric8-analytics-lsp-server": "^0.9.4-ea.0", "@redhat-developer/vscode-redhat-telemetry": "^0.7.0", "@RHEcosystemAppEng/exhort-javascript-api": "^0.1.1-ea.14", "fs": "^0.0.1-security", diff --git a/src/config.ts b/src/config.ts index b9d7f3809..e64f6aace 100644 --- a/src/config.ts +++ b/src/config.ts @@ -62,8 +62,10 @@ class Config { this.triggerRHRepositoryRecommendationNotification = commands.TRIGGER_REDHAT_REPOSITORY_RECOMMENDATION_NOTIFICATION; this.utmSource = GlobalState.UTM_SOURCE; this.exhortSnykToken = rhdaConfig.exhortSnykToken; + /* istanbul ignore next */ this.matchManifestVersions = rhdaConfig.matchManifestVersions ? 'true' : 'false'; this.vulnerabilityAlertSeverity = rhdaConfig.vulnerabilityAlertSeverity; + /* istanbul ignore next */ this.rhdaReportFilePath = rhdaConfig.reportFilePath || defaultRhdaReportFilePath; this.exhortMvnPath = rhdaConfig.mvn.executable.path || this.DEFAULT_MVN_EXECUTABLE; this.exhortNpmPath = rhdaConfig.npm.executable.path || this.DEFAULT_NPM_EXECUTABLE; diff --git a/src/dependencyReportPanel.ts b/src/dependencyReportPanel.ts index 81e47606f..51e4d14cc 100644 --- a/src/dependencyReportPanel.ts +++ b/src/dependencyReportPanel.ts @@ -26,6 +26,7 @@ export class DependencyReportPanel { * Creates or shows the webview panel. */ public static createOrShowWebviewPanel() { + /* istanbul ignore next */ const column = vscode.window.activeTextEditor ? vscode.window.activeTextEditor.viewColumn : undefined; @@ -113,6 +114,7 @@ export class DependencyReportPanel { DependencyReportPanel.data = null; while (this._disposables.length) { const x = this._disposables.pop(); + /* istanbul ignore else */ if (x) { x.dispose(); } diff --git a/src/exhortServices.ts b/src/exhortServices.ts index f7d5fc325..984908361 100644 --- a/src/exhortServices.ts +++ b/src/exhortServices.ts @@ -57,7 +57,7 @@ async function tokenValidationService(options, source) { vscode.window.showWarningMessage(`Failed to validate token. Status: ${tokenValidationStatus}`); } } catch (error) { - vscode.window.showErrorMessage(`Failed to validate token, Error: ${error}`); + vscode.window.showErrorMessage(`Failed to validate token, Error: ${error.message}`); } } diff --git a/src/stackAnalysis.ts b/src/stackAnalysis.ts index d901fbd14..bcbd210ae 100644 --- a/src/stackAnalysis.ts +++ b/src/stackAnalysis.ts @@ -21,6 +21,7 @@ const supportedFiles = [ * @param data The data to update the panel with. */ function updateWebviewPanel(data) { + /* istanbul ignore else */ if (DependencyReportPanel.currentPanel) { DependencyReportPanel.currentPanel.doUpdatePanel(data); } @@ -133,6 +134,7 @@ async function generateRHDAReport(context, uri) { await triggerWebviewPanel(context); const resp = await executeStackAnalysis(uri.fsPath); + /* istanbul ignore else */ if (DependencyReportPanel.currentPanel) { await writeReportToFile(resp); } diff --git a/test/caStatusBarProvider.test.ts b/test/caStatusBarProvider.test.ts index d381a8911..683339b45 100644 --- a/test/caStatusBarProvider.test.ts +++ b/test/caStatusBarProvider.test.ts @@ -26,7 +26,6 @@ suite('CAStatusBarProvider module', () => { const uri = 'file:///mock/path'; caStatusBarProvider.showSummary(text, uri); - console.log(caStatusBarProvider['statusBarItem'].command); expect(caStatusBarProvider['statusBarItem'].text).to.equal(text); expect(caStatusBarProvider['statusBarItem'].tooltip).to.equal(PromptText.FULL_STACK_PROMPT_TEXT); diff --git a/test/exhortServices.test.ts b/test/exhortServices.test.ts new file mode 100644 index 000000000..6e68f327d --- /dev/null +++ b/test/exhortServices.test.ts @@ -0,0 +1,104 @@ +import * as chai from 'chai'; +import * as sinon from 'sinon'; +import * as sinonChai from 'sinon-chai'; +import { rewireModule, cleanupRewireFiles } from './utils'; + +const expect = chai.expect; +chai.use(sinonChai); + +suite('ExhortServices module', async () => { + let sandbox: sinon.SinonSandbox; + + const compiledFilePath = 'out/src/exhortServices'; + const stackAnalysisReportHtmlMock = 'RHDA Report Mock'; + + let exhortMock = { + default: { + stackAnalysis: async () => stackAnalysisReportHtmlMock, + validateToken: async (statusCode) => statusCode, + } + }; + + let vscodeMock = { + window: { + showInformationMessage: sinon.spy(), + showWarningMessage: sinon.spy(), + showErrorMessage: sinon.spy(), + } + }; + + let exhortServicesRewire; + + setup(async () => { + sandbox = sinon.createSandbox(); + exhortServicesRewire = await rewireModule(compiledFilePath); + exhortServicesRewire.__Rewire__('exhort_javascript_api_1', exhortMock); + exhortServicesRewire.__Rewire__('vscode', vscodeMock); + }); + + teardown(() => { + sandbox.restore(); + cleanupRewireFiles(compiledFilePath); + }); + + test('should generate RHDA report HTML from Exhort Stack Analysis service', async () => { + await exhortServicesRewire.stackAnalysisService('mock/path/to/manifest', {}) + .then((result) => { + expect(result).to.equal(stackAnalysisReportHtmlMock); + }) + }); + + test('should perform token validation with Exhort Validate Token service', async () => { + await exhortServicesRewire.tokenValidationService(200, 'provider'); + await exhortServicesRewire.tokenValidationService(400, 'provider'); + await exhortServicesRewire.tokenValidationService(401, 'provider'); + await exhortServicesRewire.tokenValidationService(403, 'provider'); + await exhortServicesRewire.tokenValidationService(429, 'provider'); + await exhortServicesRewire.tokenValidationService(500, 'provider'); + + expect(vscodeMock.window.showInformationMessage).to.have.been.calledWith('provider Token Validated Successfully'); + expect(vscodeMock.window.showWarningMessage).to.have.been.calledWith('Missing token. Please provide a valid provider Token in the extension workspace settings. Status: 400'); + expect(vscodeMock.window.showWarningMessage).to.have.been.calledWith('Invalid token. Please provide a valid provider Token in the extension workspace settings. Status: 401'); + expect(vscodeMock.window.showWarningMessage).to.have.been.calledWith('Forbidden. The token does not have permissions. Please provide a valid provider Token in the extension workspace settings. Status: 403'); + expect(vscodeMock.window.showWarningMessage).to.have.been.calledWith('Too many requests. Rate limit exceeded. Please try again in a little while. Status: 429'); + expect(vscodeMock.window.showWarningMessage).to.have.been.calledWith('Failed to validate token. Status: 500'); + }); + + test('should fail to generate RHDA report HTML from Exhort Stack Analysis service and reject with error', async () => { + + let exhortMock = { + default: { + stackAnalysis: async () => { + throw new Error('Analysis Error'); + }, + } + }; + + exhortServicesRewire.__Rewire__('exhort_javascript_api_1', exhortMock); + + await exhortServicesRewire.stackAnalysisService('mock/path/to/manifest', {}) + .then(() => { + throw new Error('should have thrown Analysis Error') + }) + .catch((error) => { + expect(error.message).to.equal('Analysis Error'); + }) + }); + + test('should fail to perform token validation with Exhort Validate Token service and display error message', async () => { + + let exhortMock = { + default: { + validateToken: async () => { + throw new Error('Validation Error'); + }, + } + }; + + exhortServicesRewire.__Rewire__('exhort_javascript_api_1', exhortMock); + + await exhortServicesRewire.tokenValidationService(500, 'provider'); + + expect(vscodeMock.window.showErrorMessage).to.have.been.calledWith('Failed to validate token, Error: Validation Error'); + }); +}); \ No newline at end of file diff --git a/test/index.ts b/test/index.ts index 7d5c97373..7fa7eda43 100644 --- a/test/index.ts +++ b/test/index.ts @@ -25,6 +25,7 @@ export async function run(): Promise { hookRunInThisContext: true, reportDir: join(__dirname, "..", "..", 'coverage'), // remove attribute for report to be saved in ./out/src/ tempDir: join(__dirname, "..", "..", '.nyc_output'), // remove attribute for output to be saved in ./out/src/ + exclude: ['exhortServices.js', 'exhortServices_rewire.js', 'redhatTelemetry.js', 'redhatTelemetry_rewire.js'] }) await nyc.wrap() @@ -39,7 +40,7 @@ export async function run(): Promise { }) // Add all files to the test suite - const files = sync("**/**.test.js", { cwd: testsRoot, ignore: ['**/stackAnalysisService.test.js'] }) + const files = sync("**/**.test.js", { cwd: testsRoot }) files.forEach(f => mocha.addFile(resolve(testsRoot, f))) const failures: number = await new Promise(executor => mocha.run(executor)) diff --git a/test/redhatTelemetry.test.ts b/test/redhatTelemetry.test.ts new file mode 100644 index 000000000..9c7bc6d05 --- /dev/null +++ b/test/redhatTelemetry.test.ts @@ -0,0 +1,64 @@ +import * as chai from 'chai'; +import * as sinon from 'sinon'; +import * as sinonChai from 'sinon-chai'; +import { rewireModule, cleanupRewireFiles } from './utils'; + +const expect = chai.expect; +chai.use(sinonChai); + +suite('RedhatTelemetry module', async () => { + let sandbox: sinon.SinonSandbox; + + const compiledFilePath = 'out/src/redhatTelemetry'; + const redHatUUIDMock = 'Mock UUID'; + + let getRedHatUUIDMock = { + getRedHatUUID: async () => redHatUUIDMock + } + + let sendEventMock = { + sendStartupEvent: sinon.spy(), + send: sinon.spy() + } + + let getIdProviderMock = { + getIdProvider: async () => getRedHatUUIDMock, + getTelemetryService: async () => sendEventMock + } + + let getRedHatServiceMock = { + getRedHatService: async () => getIdProviderMock + }; + + let redhatTelemetryRewire; + + setup(async () => { + sandbox = sinon.createSandbox(); + redhatTelemetryRewire = await rewireModule(compiledFilePath); + redhatTelemetryRewire.__Rewire__('vscode_redhat_telemetry_1', getRedHatServiceMock); + }); + + teardown(() => { + sandbox.restore(); + cleanupRewireFiles(compiledFilePath); + }); + + test('should get UUID from vscode redhat telemetry service', async () => { + let telemetryId = await redhatTelemetryRewire.getTelemetryId({}) + expect(telemetryId).to.equal(redHatUUIDMock); + }); + + test('should send statup telemetry event', async () => { + await redhatTelemetryRewire.startUp({}) + expect(sendEventMock.sendStartupEvent).to.have.been.calledOnce; + }); + + test('should record telemetry event', async () => { + await redhatTelemetryRewire.record({}, 'telemetry_event_mock', { mockProp: 'mockValue' }) + expect(sendEventMock.send).to.have.been.calledWith({ + type: 'track', + name: 'telemetry_event_mock', + properties: { mockProp: 'mockValue' } + }); + }); +}); \ No newline at end of file diff --git a/test/utils.ts b/test/utils.ts new file mode 100644 index 000000000..ecdfd236f --- /dev/null +++ b/test/utils.ts @@ -0,0 +1,37 @@ +import * as babelCore from "@babel/core"; +import * as fs from "fs"; + +/** + * Asynchronously imports a module. + * + * @param filepath Path to the module to be imported. + * @returns A promise that resolves to the module's exports. + */ +async function dynamicImportProvider(filepath) { + return await import(filepath) +} + +/** + * Rewires a module for testing purposes. + * @param filepath path to the compiled JavaScript file of the tested module. + * @return A module instance that exposes private methods/functions/properties to be mocked/stubbed. + */ +export function rewireModule(filepath) { + let moduleBuffeer = fs.readFileSync(filepath + ".js") + let moduleSource = babelCore.transform(moduleBuffeer, { plugins: ["babel-plugin-rewire"] }).code; + fs.writeFileSync(filepath + "_rewire.js", moduleSource) + return dynamicImportProvider("../../" + filepath + "_rewire.js") +} + +/** + * Removes rewired modules from file system. + * @param filepath path to the compiled JavaScript file of the tested module. + */ +export function cleanupRewireFiles(filepath) { + const fileToRemove = filepath + "_rewire.js" + try { + fs.unlinkSync(fileToRemove); + } catch (err) { + console.error(`Error deleting rewire module ${fileToRemove}: ${err.message}`); + } +} \ No newline at end of file diff --git a/webpack.config.ts b/webpack.config.ts index a865ab04c..c9ec7b450 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -41,14 +41,8 @@ module.exports = (env, argv) => { }, { test: /\.ts$/, - exclude: /node_modules/, use: [{ loader: 'ts-loader', - options: { - compilerOptions: { - "module": "es6" // override `tsconfig.json` so that TypeScript emits native JavaScript modules. - } - } }] }] },