diff --git a/.vscode/launch.json b/.vscode/launch.json index 969614a9..de40dc03 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -71,19 +71,11 @@ "name": "frontend unit tests", "type": "node", "request": "launch", - "runtimeArgs": [ - "--inspect-brk", - "./node_modules/@vue/cli-service/bin/vue-cli-service.js", - "test:unit", - "--runInBand" - ], + "runtimeArgs": ["--inspect-brk", "./node_modules/jest/bin/jest.js", "-w 1", "--colors"], "cwd": "${workspaceFolder}/packages/frontend", - "protocol": "inspector", - "disableOptimisticBPs": true, "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", - "outFiles": ["${workspaceFolder}/packages/frontend/src/**/*.js"], - "port": 9229 + "outFiles": ["${workspaceFolder}/packages/frontend/src/**/*.js"] } ] } diff --git a/packages/backend/package.json b/packages/backend/package.json index 839d5c38..ea1c2bb0 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -37,7 +37,7 @@ "coverage": "nyc mocha", "coverage:copy": "shx mkdir -p ../../coverage && shx cp -u ./coverage/lcov.info ../../coverage/lcov_backend.info", "frontend:copy": "npm-run-all clean:frontend && shx cp -r ../frontend/dist/. ./dist/media/", - "package": "vsce package --yarn --allow-star-activation", + "package": "vsce package --yarn", "test": "mocha", "webpack": "webpack --mode development", "webpack-dev:watch": "webpack --mode development --watch", @@ -167,9 +167,7 @@ ] } }, - "activationEvents": [ - "onStartupFinished" - ], + "activationEvents": [], "husky": { "hooks": { "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" @@ -220,7 +218,7 @@ "string-replace-loader": "3.0.3", "ts-loader": "^9.2.3", "ts-node": "^9.1.1", - "vsce": "2.15.0", + "@vscode/vsce": "2.24.0", "webpack": "^5.90.1", "webpack-cli": "^5.1.4", "ws": "8.2.3" diff --git a/packages/backend/src/extension.ts b/packages/backend/src/extension.ts index 5aa3e341..55a6603f 100644 --- a/packages/backend/src/extension.ts +++ b/packages/backend/src/extension.ts @@ -1,5 +1,5 @@ import { ExtensionContext, window, WebviewPanel } from "vscode"; -import { createExtensionLoggerAndSubscribeToLogSettingsChanges, getLogger } from "./logger/logger-wrapper"; +import { createExtensionLoggerAndSubscribeToLogSettingsChanges } from "./logger/logger-wrapper"; import { AnalyticsWrapper } from "./usage-report/usage-analytics-wrapper"; import * as shellJsWorkarounds from "./utils/shellJsWorkarounds"; import { ExtCommands } from "./extCommands"; @@ -17,7 +17,7 @@ export function activate(context: ExtensionContext) { try { createExtensionLoggerAndSubscribeToLogSettingsChanges(context); - AnalyticsWrapper.createTracker(getLogger()); + AnalyticsWrapper.createTracker(context); } catch (error) { console.error("Extension activation failed.", error.message); return; @@ -25,17 +25,21 @@ export function activate(context: ExtensionContext) { extCommands.registerAndSubscribeCommands(); - window.registerWebviewPanelSerializer("yeomanui", { - async deserializeWebviewPanel(webViewPanel: WebviewPanel, state?: unknown) { - (await extCommands.getYeomanUIPanel()).setWebviewPanel(webViewPanel, state); - }, - }); - - window.registerWebviewPanelSerializer("exploreGens", { - async deserializeWebviewPanel(webViewPanel: WebviewPanel, state?: unknown) { - (await extCommands.getExploreGensPanel()).setWebviewPanel(webViewPanel, state); - }, - }); + context.subscriptions.push( + window.registerWebviewPanelSerializer("yeomanui", { + async deserializeWebviewPanel(webViewPanel: WebviewPanel, state?: unknown) { + (await extCommands.getYeomanUIPanel()).setWebviewPanel(webViewPanel, state); + }, + }), + ); + + context.subscriptions.push( + window.registerWebviewPanelSerializer("exploreGens", { + async deserializeWebviewPanel(webViewPanel: WebviewPanel, state?: unknown) { + (await extCommands.getExploreGensPanel()).setWebviewPanel(webViewPanel, state); + }, + }), + ); } export function deactivate() { diff --git a/packages/backend/src/panels/AbstractWebviewPanel.ts b/packages/backend/src/panels/AbstractWebviewPanel.ts index 03d672eb..18a76456 100644 --- a/packages/backend/src/panels/AbstractWebviewPanel.ts +++ b/packages/backend/src/panels/AbstractWebviewPanel.ts @@ -124,7 +124,6 @@ export abstract class AbstractWebviewPanel { wizardStepName, currentPromptCount, numOfPromopts, - this.logger, ); } } diff --git a/packages/backend/src/usage-report/usage-analytics-wrapper.ts b/packages/backend/src/usage-report/usage-analytics-wrapper.ts index 067916cb..a3c7dff0 100644 --- a/packages/backend/src/usage-report/usage-analytics-wrapper.ts +++ b/packages/backend/src/usage-report/usage-analytics-wrapper.ts @@ -1,5 +1,6 @@ +import type { ExtensionContext } from "vscode"; import { initTelemetrySettings, BASClientFactory, BASTelemetryClient } from "@sap/swa-for-sapbas-vsx"; -import { IChildLogger } from "@vscode-logging/logger"; +import { getLogger } from "../logger/logger-wrapper"; import * as path from "path"; /** @@ -26,54 +27,54 @@ export class AnalyticsWrapper { return BASClientFactory.getBASTelemetryClient(); } - public static createTracker(logger?: IChildLogger): void { + public static createTracker(context: ExtensionContext): void { try { - const packageJson = require(path.join(__dirname, "..", "package.json")); + const packageJson = require(path.join(context.extensionPath, "package.json")); const vscodeExtentionFullName = `${packageJson.publisher}.${packageJson.name}`; initTelemetrySettings(vscodeExtentionFullName, packageJson.version); - logger?.info(`SAP Web Analytics tracker was created for ${vscodeExtentionFullName}`); + getLogger().info(`SAP Web Analytics tracker was created for ${vscodeExtentionFullName}`); } catch (error) { - logger?.error(error); + getLogger().error(error); } } - private static report(opt: { eventName: string; properties?: any; logger?: IChildLogger }): void { + private static report(opt: { eventName: string; properties?: any }): void { // We want to report only if we are not in Local VSCode environment const eventName = opt.eventName; if (process.env.LANDSCAPE_ENVIRONMENT) { void AnalyticsWrapper.getTracker().report(opt.eventName, opt.properties); - opt.logger?.trace("SAP Web Analytics tracker was called", { + getLogger().trace("SAP Web Analytics tracker was called", { eventName, }); } else { - opt.logger?.trace("SAP Web Analytics tracker was not called because LANDSCAPE_ENVIRONMENT is not set", { + getLogger().trace("SAP Web Analytics tracker was not called because LANDSCAPE_ENVIRONMENT is not set", { eventName, }); } } - public static updateGeneratorStarted(logger?: IChildLogger): void { + public static updateGeneratorStarted(): void { try { const eventName = AnalyticsWrapper.EVENT_TYPES.PROJECT_GENERATION_STARTED; AnalyticsWrapper.startTime = Date.now(); - AnalyticsWrapper.report({ eventName, logger }); + AnalyticsWrapper.report({ eventName }); } catch (error) { - logger?.error(error); + getLogger().error(error); } } - public static updateGeneratorSelected(generatorName: string, logger?: IChildLogger): void { + public static updateGeneratorSelected(generatorName: string): void { try { const eventName = AnalyticsWrapper.EVENT_TYPES.PROJECT_GENERATOR_SELECTED; AnalyticsWrapper.startTime = Date.now(); const properties = { generatorName }; - AnalyticsWrapper.report({ eventName, properties, logger }); + AnalyticsWrapper.report({ eventName, properties }); } catch (error) { - logger?.error(error); + getLogger().error(error); } } - public static updateGeneratorEnded(generatorName: string, logger?: IChildLogger): void { + public static updateGeneratorEnded(generatorName: string): void { try { const eventName = AnalyticsWrapper.EVENT_TYPES.PROJECT_GENERATED_SUCCESSFULLY; const endTime = Date.now(); @@ -83,9 +84,9 @@ export class AnalyticsWrapper { generatorName, generationTime: generationTimeSec.toString(), }; - AnalyticsWrapper.report({ eventName, properties, logger }); + AnalyticsWrapper.report({ eventName, properties }); } catch (error) { - logger?.error(error); + getLogger().error(error); } } @@ -94,7 +95,6 @@ export class AnalyticsWrapper { wizardStepName: string, currentStep: number, totalNumOfSteps: number, - logger?: IChildLogger, ): void { try { const eventName = AnalyticsWrapper.EVENT_TYPES.PROJECT_GENERATOR_CLOSED; @@ -104,9 +104,9 @@ export class AnalyticsWrapper { currentStep, totalNumOfSteps, }; - AnalyticsWrapper.report({ eventName, properties, logger }); + AnalyticsWrapper.report({ eventName, properties }); } catch (error) { - logger?.error(error); + getLogger().error(error); } } } diff --git a/packages/backend/src/yeomanui.ts b/packages/backend/src/yeomanui.ts index 7c1355d0..9a4b321f 100644 --- a/packages/backend/src/yeomanui.ts +++ b/packages/backend/src/yeomanui.ts @@ -331,12 +331,12 @@ export class YeomanUI { this.resetHeaderTitle(); const generators: IQuestionsPrompt = await this.getGeneratorsPrompt(); await this._notifyGeneratorsInstall(this.uiOptions.installGens, true); - AnalyticsWrapper.updateGeneratorStarted(this.logger); + AnalyticsWrapper.updateGeneratorStarted(); const response: any = await this.rpc.invoke("showPrompt", [generators.questions, "select_generator"]); generatorId = response.generator; } this.replayUtils.clear(); - AnalyticsWrapper.updateGeneratorSelected(generatorId, this.logger); + AnalyticsWrapper.updateGeneratorSelected(generatorId); await this.runGenerator(generatorId); } catch (error) { this.logError(error, "receiveIsWebviewReady"); @@ -446,7 +446,7 @@ export class YeomanUI { const message = this.uiOptions.messages.artifact_with_name_generated(generatorName); const generatedTemplatePath = targetFolderPath ? targetFolderPath : targetFolderPathBeforeGen; this.logger.debug(`done running yeomanui! ${message} You can find it at ${generatedTemplatePath}`); - AnalyticsWrapper.updateGeneratorEnded(generatorName, this.logger); + AnalyticsWrapper.updateGeneratorEnded(generatorName); this.youiEvents.doGeneratorDone(true, message, selectedWorkspace, type, targetFolderPath); this.setInitialProcessDir(); this.flowState.resolve(); diff --git a/packages/backend/test/extension.spec.ts b/packages/backend/test/extension.spec.ts index 082860c9..8807a47e 100644 --- a/packages/backend/test/extension.spec.ts +++ b/packages/backend/test/extension.spec.ts @@ -43,7 +43,6 @@ describe("extension unit test", () => { describe("activate", () => { it("commands registration", () => { loggerWrapperMock.expects("createExtensionLoggerAndSubscribeToLogSettingsChanges"); - loggerWrapperMock.expects("getLogger"); trackerWrapperMock.expects("createTracker"); const applySpy = sandbox.spy(shellJsWorkarounds, "apply"); diff --git a/packages/backend/test/yeomanui.spec.ts b/packages/backend/test/yeomanui.spec.ts index 2728cec0..b2c0a803 100644 --- a/packages/backend/test/yeomanui.spec.ts +++ b/packages/backend/test/yeomanui.spec.ts @@ -1125,7 +1125,7 @@ describe("yeomanui unit test", () => { targetFolderPath: "testDestinationRoot", childDirs: ["dirparh1", "dirpath2"], }; - trackerWrapperMock.expects("updateGeneratorEnded").withArgs("testGenName", testLogger).resolves(); + trackerWrapperMock.expects("updateGeneratorEnded").withArgs("testGenName").resolves(); yeomanUi["onGeneratorSuccess"]("testGenName", beforeGen, afterGen); expect( doGeneratorDoneSpy.calledWith( @@ -1148,7 +1148,7 @@ describe("yeomanui unit test", () => { targetFolderPath: "testDestinationRoot", childDirs: ["dirparh1", "dirpath2", "dirpath3"], }; - trackerWrapperMock.expects("updateGeneratorEnded").withArgs("testGenName", testLogger).resolves(); + trackerWrapperMock.expects("updateGeneratorEnded").withArgs("testGenName").resolves(); yeomanUi["onGeneratorSuccess"]("testGenName", beforeGen, afterGen); expect( doGeneratorDoneSpy.calledWith( @@ -1171,7 +1171,7 @@ describe("yeomanui unit test", () => { targetFolderPath: "testDestinationRoot", childDirs: ["dirparh1"], }; - trackerWrapperMock.expects("updateGeneratorEnded").withArgs("testGenName", testLogger).resolves(); + trackerWrapperMock.expects("updateGeneratorEnded").withArgs("testGenName").resolves(); yeomanUi["onGeneratorSuccess"]("testGenName", beforeGen, afterGen); expect( doGeneratorDoneSpy.calledWith( @@ -1190,7 +1190,7 @@ describe("yeomanui unit test", () => { const afterGen = { targetFolderPath: "testDestinationRoot/generatedProject", }; - trackerWrapperMock.expects("updateGeneratorEnded").withArgs("testGenName", testLogger).resolves(); + trackerWrapperMock.expects("updateGeneratorEnded").withArgs("testGenName").resolves(); yeomanUi["onGeneratorSuccess"]("testGenName", beforeGen, afterGen); expect( doGeneratorDoneSpy.calledWith( @@ -1219,7 +1219,7 @@ describe("yeomanui unit test", () => { const afterGen = { targetFolderPath: "testDestinationRoot/generatedProject", }; - trackerWrapperMock.expects("updateGeneratorEnded").withArgs("foodq:app", testLogger).resolves(); + trackerWrapperMock.expects("updateGeneratorEnded").withArgs("foodq:app").resolves(); yeomanUi["onGeneratorSuccess"]("foodq:app", beforeGen, afterGen); expect( doGeneratorDoneSpy.calledWith( @@ -1241,7 +1241,7 @@ describe("yeomanui unit test", () => { const afterGen = { targetFolderPath: "testDestinationRoot/generatedProject", }; - trackerWrapperMock.expects("updateGeneratorEnded").withArgs("fiori-generator:app", testLogger).resolves(); + trackerWrapperMock.expects("updateGeneratorEnded").withArgs("fiori-generator:app").resolves(); yeomanUi["onGeneratorSuccess"]("fiori-generator:app", beforeGen, afterGen); expect( doGeneratorDoneSpy.calledWith( diff --git a/packages/frontend/jest.config.js b/packages/frontend/jest.config.js index e1b5e0e3..4b60e0ae 100644 --- a/packages/frontend/jest.config.js +++ b/packages/frontend/jest.config.js @@ -10,7 +10,6 @@ module.exports = { collectCoverageFrom: [ "src/**/*.{js,vue}", "!**/node_modules/**", - "!/src/utils/utils.js", "!/src/exploregens/**", "!/src/youi/main.js", "!/src/plugins/**", @@ -31,7 +30,7 @@ module.exports = { coverageThreshold: { global: { branches: 91, - functions: 98, + functions: 97, lines: 97, statements: 97, }, diff --git a/yarn.lock b/yarn.lock index c6c7b339..f15d9cfa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2863,6 +2863,34 @@ resolved "https://registry.yarnpkg.com/@vscode-logging/types/-/types-2.0.0.tgz#0cce9d0a3700e96ffbaaa31de0d764d9f7a22dba" integrity sha512-P42r5SPYeJKgMDYb5Ez9rjPlpnGEZ1eDFVjT0azxueaJ65iE259hpROmvSPUd80HAALn9/59L+CgcGLmwZcCmg== +"@vscode/vsce@2.24.0": + version "2.24.0" + resolved "https://registry.yarnpkg.com/@vscode/vsce/-/vsce-2.24.0.tgz#7f835b9fdd5bfedcecd62a6c4d684841a74974d4" + integrity sha512-p6CIXpH5HXDqmUkgFXvIKTjZpZxy/uDx4d/UsfhS9vQUun43KDNUbYeZocyAHgqcJlPEurgArHz9te1PPiqPyA== + dependencies: + azure-devops-node-api "^11.0.1" + chalk "^2.4.2" + cheerio "^1.0.0-rc.9" + commander "^6.2.1" + glob "^7.0.6" + hosted-git-info "^4.0.2" + jsonc-parser "^3.2.0" + leven "^3.1.0" + markdown-it "^12.3.2" + mime "^1.3.4" + minimatch "^3.0.3" + parse-semver "^1.1.1" + read "^1.0.7" + semver "^7.5.2" + tmp "^0.2.1" + typed-rest-client "^1.8.4" + url-join "^4.0.1" + xml2js "^0.5.0" + yauzl "^2.3.1" + yazl "^2.2.2" + optionalDependencies: + keytar "^7.7.0" + "@vue/compiler-core@3.3.4": version "3.3.4" resolved "https://registry.yarnpkg.com/@vue/compiler-core/-/compiler-core-3.3.4.tgz#7fbf591c1c19e1acd28ffd284526e98b4f581128" @@ -4500,7 +4528,7 @@ commander@^2.20.0: resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== -commander@^6.1.0: +commander@^6.2.1: version "6.2.1" resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.1.tgz#0792eb682dfbc325999bb2b84fddddba110ac73c" integrity sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA== @@ -8436,6 +8464,11 @@ jsonc-parser@3.2.0: resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.2.0.tgz#31ff3f4c2b9793f89c67212627c51c6394f88e76" integrity sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w== +jsonc-parser@^3.2.0: + version "3.2.1" + resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.2.1.tgz#031904571ccf929d7670ee8c547545081cb37f1a" + integrity sha512-AilxAyFOAcK5wA1+LeaySVBrHsGQvUFCDWXKpZjzaL0PqW+xfBOttn8GNtWKFWqneyMZj41MWF9Kl6iPWLwgOA== + jsonfile@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb" @@ -11516,7 +11549,7 @@ semver-regex@^2.0.0: resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.2.tgz#48d55db737c3287cd4835e17fa13feace1c41ef8" integrity sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g== -semver@7.6.0, semver@^7.0.0, semver@^7.1.1, semver@^7.1.3, semver@^7.2.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5, semver@^7.3.6, semver@^7.3.7, semver@^7.3.8, semver@^7.5.1, semver@^7.5.3, semver@^7.5.4: +semver@7.6.0, semver@^7.0.0, semver@^7.1.1, semver@^7.1.3, semver@^7.2.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5, semver@^7.3.6, semver@^7.3.7, semver@^7.3.8, semver@^7.5.1, semver@^7.5.2, semver@^7.5.3, semver@^7.5.4: version "7.6.0" resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.0.tgz#1a46a4db4bffcccd97b743b5005c8325f23d4e2d" integrity sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg== @@ -13135,32 +13168,6 @@ vite@4.5.2: optionalDependencies: fsevents "~2.3.2" -vsce@2.15.0: - version "2.15.0" - resolved "https://registry.yarnpkg.com/vsce/-/vsce-2.15.0.tgz#4a992e78532092a34a755143c6b6c2cabcb7d729" - integrity sha512-P8E9LAZvBCQnoGoizw65JfGvyMqNGlHdlUXD1VAuxtvYAaHBKLBdKPnpy60XKVDAkQCfmMu53g+gq9FM+ydepw== - dependencies: - azure-devops-node-api "^11.0.1" - chalk "^2.4.2" - cheerio "^1.0.0-rc.9" - commander "^6.1.0" - glob "^7.0.6" - hosted-git-info "^4.0.2" - keytar "^7.7.0" - leven "^3.1.0" - markdown-it "^12.3.2" - mime "^1.3.4" - minimatch "^3.0.3" - parse-semver "^1.1.1" - read "^1.0.7" - semver "^5.1.0" - tmp "^0.2.1" - typed-rest-client "^1.8.4" - url-join "^4.0.1" - xml2js "^0.4.23" - yauzl "^2.3.1" - yazl "^2.2.2" - vue-component-type-helpers@1.8.4: version "1.8.4" resolved "https://registry.yarnpkg.com/vue-component-type-helpers/-/vue-component-type-helpers-1.8.4.tgz#302d85fac912519cdf0dd2fb51402e5215d85628" @@ -13613,10 +13620,10 @@ xml-name-validator@^4.0.0: resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-4.0.0.tgz#79a006e2e63149a8600f15430f0a4725d1524835" integrity sha512-ICP2e+jsHvAj2E2lIHxa5tjXRlKDJo4IdvPvCXbXQGdzSfmSpNVyIKMvoZHjDY9DP0zV17iI85o90vRFXNccRw== -xml2js@^0.4.23: - version "0.4.23" - resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.23.tgz#a0c69516752421eb2ac758ee4d4ccf58843eac66" - integrity sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug== +xml2js@^0.5.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.5.0.tgz#d9440631fbb2ed800203fad106f2724f62c493b7" + integrity sha512-drPFnkQJik/O+uPKpqSgr22mpuFHqKdbS835iAQrUC73L2F5WkboIRd63ai/2Yg6I1jzifPFKH2NTK+cfglkIA== dependencies: sax ">=0.6.0" xmlbuilder "~11.0.0"