From 19682d3005a79f0cdc2bf66395201abea12677b4 Mon Sep 17 00:00:00 2001 From: Balyam muralidhar narendra kumar Date: Tue, 4 Nov 2025 10:44:58 +0530 Subject: [PATCH] removing l10n lib and adding required changes . --- NOTICE | 12 +- THIRD_PARTY_LICENSES.txt | 69 ++++++----- vscode/package-lock.json | 7 -- vscode/package.json | 1 - vscode/src/localiser.ts | 106 +++++++++++----- vscode/src/logger.ts | 10 ++ .../suite/localisation/extension.test.ts | 13 +- .../test/unit/general/localiser.unit.test.ts | 114 ++++++++++++++++++ .../corrupt/l10n/bundle.l10n.en.json | 4 + .../resources/l10n/bundle.l10n.en.json | 4 + vscode/src/test/unit/mocks/init.ts | 7 +- .../src/test/unit/mocks/vscode/mockVscode.ts | 13 +- .../test/unit/mocks/vscode/namespaces/env.ts | 4 +- 13 files changed, 282 insertions(+), 82 deletions(-) create mode 100644 vscode/src/test/unit/general/localiser.unit.test.ts create mode 100644 vscode/src/test/unit/general/resources/corrupt/l10n/bundle.l10n.en.json create mode 100644 vscode/src/test/unit/general/resources/l10n/bundle.l10n.en.json diff --git a/NOTICE b/NOTICE index c9a3a108..324c9235 100644 --- a/NOTICE +++ b/NOTICE @@ -1,9 +1,9 @@ +Oracle Java Platform Extension for Visual Studio Code +Copyright (c) 2023-2025, Oracle and/or its affiliates. + This product includes software developed at The Apache Software Foundation (http://www.apache.org/). -Oracle Java Platform Extension for Visual Studio Code -Copyright (c) 2023-2024, Oracle and/or its affiliates. - Apache NetBeans Copyright 2017-2024 The Apache Software Foundation @@ -14,3 +14,9 @@ The code was Copyright 1997-2016 Oracle and/or its affiliates. The Initial Developer of the Original Software was Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun Microsystems, Inc. +--- + +vscode/src/localiser.ts +This file includes portions derived from the Localization tooling for Visual Studio Code +@vscode/l10n software developed at Microsoft Corporation licensed under the MIT License. +Copyright (c) Microsoft Corporation diff --git a/THIRD_PARTY_LICENSES.txt b/THIRD_PARTY_LICENSES.txt index c9442baf..ad37cd79 100644 --- a/THIRD_PARTY_LICENSES.txt +++ b/THIRD_PARTY_LICENSES.txt @@ -9448,37 +9448,6 @@ SOFTWARE. ------------------ END OF DEPENDENCY LICENSE -------------------- -Dependency: VS Code tooling for localizing Visual Studio Code extensions -======================================================================== - ------------------- START OF DEPENDENCY LICENCE -------------------- -- @vscode/l10n - - MIT License - - Copyright (c) Microsoft Corporation. - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE - ------------------- END OF DEPENDENCY LICENCE -------------------- - - Dependency: VS Code Debug Protocol and Debug Adapter ==================================================== @@ -9875,3 +9844,41 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ------------------ END OF DEPENDENCY LICENSE -------------------- + +vscode/src/localiser.ts +======================= +Accessible at: vscode/src/localiser.ts + +- @vscode/l10n +This file includes portions derived from the Localization tooling for Visual Studio Code +@vscode/l10n software developed at Microsoft Corporation licensed under the MIT License. + +Derived from source at: https://github.com/microsoft/vscode-l10n/blob/57b5918f3b247a03387432037669e8ae5aff886b/l10n/src/main.ts#L222 +License: MIT License + +------------------ START OF DEPENDENCY LICENSE -------------------- +MIT License + +Copyright (c) Microsoft Corporation. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE + +------------------ END OF DEPENDENCY LICENSE -------------------- + + diff --git a/vscode/package-lock.json b/vscode/package-lock.json index 77f78875..ac0315a8 100644 --- a/vscode/package-lock.json +++ b/vscode/package-lock.json @@ -10,7 +10,6 @@ "license": "Apache 2.0", "dependencies": { "@vscode/debugadapter": "^1.68.0", - "@vscode/l10n": "^0.0.18", "ajv": "^8.17.1", "jsonc-parser": "3.3.1", "vscode-languageclient": "^9.0.1" @@ -1070,12 +1069,6 @@ "integrity": "sha512-2J27dysaXmvnfuhFGhfeuxfHRXunqNPxtBoR3koiTOA9rdxWNDTa1zIFLCFMSHJ9MPTPKFcBeblsyaCJCIlQxg==", "license": "MIT" }, - "node_modules/@vscode/l10n": { - "version": "0.0.18", - "resolved": "https://registry.npmjs.org/@vscode/l10n/-/l10n-0.0.18.tgz", - "integrity": "sha512-KYSIHVmslkaCDyw013pphY+d7x1qV8IZupYfeIfzNA+nsaWHbn5uPuQRvdRFsa9zFzGeudPuoGoZ1Op4jrJXIQ==", - "license": "MIT" - }, "node_modules/@vscode/test-electron": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/@vscode/test-electron/-/test-electron-2.5.2.tgz", diff --git a/vscode/package.json b/vscode/package.json index cbb397ce..2d6a9eda 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -953,7 +953,6 @@ }, "dependencies": { "@vscode/debugadapter": "^1.68.0", - "@vscode/l10n": "^0.0.18", "ajv": "^8.17.1", "jsonc-parser": "3.3.1", "vscode-languageclient": "^9.0.1" diff --git a/vscode/src/localiser.ts b/vscode/src/localiser.ts index cf88c31a..17759d5f 100644 --- a/vscode/src/localiser.ts +++ b/vscode/src/localiser.ts @@ -1,5 +1,5 @@ /* - Copyright (c) 2023-2024, Oracle and/or its affiliates. + Copyright (c) 2023-2025, Oracle and/or its affiliates. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,49 +16,97 @@ 'use strict'; -import * as l10nLib from '@vscode/l10n' - import * as vscode from 'vscode'; +import * as fs from 'fs'; import { extConstants } from './constants'; import { FileUtils } from './utils'; +import { LOGGER } from './logger'; +import * as path from 'path'; -const DEFAULT_LANGAUGE = "en"; -const DEFAULT_BUNDLE_FILE = `l10n/bundle.l10n.${DEFAULT_LANGAUGE}.json`; - -type TranslatorFn = typeof vscode.l10n.t +const DEFAULT_LANGUAGE = "en"; +const DEFAULT_BUNDLE_FILE = path.join("l10n", `bundle.l10n.${DEFAULT_LANGUAGE}.json`); +const _format2Regexp = /{([^}]+)}/g; export interface l10n { value(key: string, placeholderMap?: Record): string - nbLocaleCode():string + nbLocaleCode(): string } class l10Wrapper implements l10n { - private defaultTranslation: TranslatorFn; - - constructor(extensionId: string, defaultBundlePath: string) { - let defaultBundleAbsoluteFsPath = FileUtils.toUri(`${vscode.extensions.getExtension(extensionId)?.extensionPath}/${defaultBundlePath}`).fsPath; - l10nLib.config({ - fsPath: defaultBundleAbsoluteFsPath - }); - this.defaultTranslation = l10nLib.t; + private defaultl10nMap: any; + constructor(extensionId: string, defaultBundlePath: string) { + let extnPath = vscode.extensions.getExtension(extensionId)!!.extensionPath; + let defaultBundleAbsoluteFsPath = FileUtils.toUri(path.join(extnPath,defaultBundlePath)).fsPath; + let fileContent: string = ""; + try { + fileContent = fs.readFileSync(defaultBundleAbsoluteFsPath, 'utf-8'); + } catch (err) { + LOGGER.logAndThrowError("error occured while reading bundle file : ", err); + } + try { + this.defaultl10nMap = JSON.parse(fileContent); + } catch (err) { + LOGGER.logAndThrowError("error occured while parsing bundle file : ", err); } - value(key: string, placeholderMap: Record): string { - const valueFromBundle:string = vscode.l10n.bundle ? vscode.l10n.t(key, placeholderMap) : key; - const isPresentInBundle = valueFromBundle !== key; - return isPresentInBundle ? valueFromBundle : this.defaultTranslation(key, placeholderMap); + } + + value(key: string, placeholderMap: Record): string { + const valueFromBundle: string = vscode.l10n.bundle ? vscode.l10n.t(key, placeholderMap) : key; + const isPresentInBundle = valueFromBundle !== key; + return isPresentInBundle ? valueFromBundle : this.defaultTranslation(key, placeholderMap); + } + defaultTranslation(key: string, placeholderMap: Record): string { + let value = this.defaultl10nMap[key]; + return value ? this.format(value, placeholderMap) : key; + } + nbLocaleCode() { + const vscodeLanguage = vscode.env.language; + if (!vscodeLanguage) return DEFAULT_LANGUAGE; + const localeParts = vscodeLanguage.split(/[-_]/g); + if (localeParts.length > 1) { + localeParts[1] = localeParts[1].toUpperCase(); } - nbLocaleCode(){ - const vscodeLanguage = vscode.env.language; - if (!vscodeLanguage) return DEFAULT_LANGAUGE; - const localeParts = vscodeLanguage.split(/[-_]/g); - if (localeParts.length > 1) { - localeParts[1] = localeParts[1].toUpperCase(); - } - var nbFormatLocale = localeParts.join(":"); - return nbFormatLocale; + var nbFormatLocale = localeParts.join(":"); + return nbFormatLocale; + } + + + //copied from: + //https://github.com/microsoft/vscode-l10n/blob/57b5918f3b247a03387432037669e8ae5aff886b/l10n/src/main.ts#L222 + //original license: MIT + /* + Copyright (c) Microsoft Corporation + + All rights reserved. + + MIT License + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE + */ + format(template: string, values: Record): string { + if (!values || Object.keys(values).length === 0) { + return template; } + return template.replace(_format2Regexp, (match, group) => (values[group] ?? match) as string); + } } diff --git a/vscode/src/logger.ts b/vscode/src/logger.ts index 660956a7..c4d1b355 100644 --- a/vscode/src/logger.ts +++ b/vscode/src/logger.ts @@ -15,6 +15,7 @@ */ import { OutputChannel, window } from "vscode"; import { extConstants } from "./constants"; +import { isError } from "./utils"; enum LogLevel { INFO = 'INFO', @@ -54,6 +55,15 @@ export class ExtensionLogger { } } + public logAndThrowError (message: string, err: unknown) { + let errMsg = ""; + if (isError(err)) { + errMsg = err?.message + } + LOGGER.error(message + errMsg); + throw err; + } + public logNoNL(message: string): void { this.outChannel.append(message); } diff --git a/vscode/src/test/integration/suite/localisation/extension.test.ts b/vscode/src/test/integration/suite/localisation/extension.test.ts index 7fa8bfde..70dbf1f4 100644 --- a/vscode/src/test/integration/suite/localisation/extension.test.ts +++ b/vscode/src/test/integration/suite/localisation/extension.test.ts @@ -27,13 +27,24 @@ import * as path from 'path'; import * as vscode from 'vscode'; import { extensions, window } from 'vscode'; +import { l10n } from '../../../../localiser' import { DEFAULT_BUNDLE_FILE_NAME, DEFAULT_PACKAGE_FILE_NAME, EXTENSION_NAME, SUPPORTED_LANGUAGES } from '../../constants'; import { checkCommandsLocalisation, checkConfigurationLocalisation, checkDebuggersLocalisation, checkL10nUsageInFiles, checkViewsLocalisation, getKeysFromJSON, matchKeys, matchValuesTemplate } from '../../testutils'; suite("Extension localisation tests", function () { window.showInformationMessage("Starting Localisation tests"); - // Check the consistency of the keys and value templates across the bundle files for the supported languages + test("localiser lib tests", async () => { + assert.equal( + l10n.value("jdk.downloader.message.downloadCompleted", { "jdkVersion": "25", "osType": "macOS", "jdkType": "OpenJDK" }), + "OpenJDK 25 for macOS download completed!" + ) + assert.equal( + l10n.value("jdk.downloader.error_message.installationCleanup"), + "Error while installation cleanup" + ) + }) + // Check the consistency of the keys and value templates across the bundle files for the supported languages test("Consistency of keys across bundle.l10n.lang.json files for supported languages", async () => { const extension = extensions.getExtension(EXTENSION_NAME); assert(extension); diff --git a/vscode/src/test/unit/general/localiser.unit.test.ts b/vscode/src/test/unit/general/localiser.unit.test.ts new file mode 100644 index 00000000..bdfe19ff --- /dev/null +++ b/vscode/src/test/unit/general/localiser.unit.test.ts @@ -0,0 +1,114 @@ +/* + Copyright (c) 2025, Oracle and/or its affiliates. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +import { expect } from 'chai'; +import { describe, it, beforeEach, before, after } from "mocha"; +import * as sinon from 'sinon'; +import * as vscode from 'vscode'; +import * as assert from 'assert'; +import { Extension } from 'vscode'; +import { LOGGER } from '../../../logger'; +import { mock, instance, when, reset } from "ts-mockito"; + +import * as path from 'path'; + +describe('localiser tests', () => { + let loggerLogStub: sinon.SinonStub; + let mockedExtns: typeof vscode.extensions; + let extMock: Extension; + let mockedEnv: typeof vscode.env; + let mockedL10n: typeof vscode.l10n; + let currentDir = __dirname.replace("/out/", "/src/"); + + before(() => { + let vscodeObj = (vscode as typeof vscode & { mockedExtns: typeof vscode.extensions, mockedEnv: typeof vscode.env, mockedL10n: typeof vscode.l10n }); + mockedExtns = vscodeObj.mockedExtns; + mockedEnv = vscodeObj.mockedEnv; + mockedL10n = vscodeObj.mockedL10n; + extMock = mock>(); + loggerLogStub = sinon.stub(LOGGER, "error"); + }); + after(() => { + sinon.reset(); + reset(mockedExtns); + reset(extMock); + reset(mockedEnv); + reset(mockedL10n); + }); + + beforeEach(() => { + sinon.reset(); + reset(mockedExtns); + reset(extMock); + reset(mockedEnv); + reset(mockedL10n); + }) + + + + describe('l10n tests', () => { + describe('issue while reading bundle', () => { + it('file not found error', () => { + let msg: string | null = null; + when(extMock?.extensionPath).thenReturn(path.join(currentDir, 'doesnt-exist')); + var mkInst = instance(extMock); + when(mockedExtns.getExtension("oracle.oracle-java")).thenReturn(mkInst); + try { + require('../../../localiser'); + } catch (e) { + msg = (e as any & { message: string }).message + } + assert.strictEqual(msg!!.includes("no such file or directory"), true); + expect(loggerLogStub.called).to.be.true; + }); + it('file parsing error', () => { + let msg: string | null = null; + when(extMock?.extensionPath).thenReturn(path.join(currentDir, 'resources', 'corrupt')); + var mkInst = instance(extMock); + when(mockedExtns.getExtension("oracle.oracle-java")).thenReturn(mkInst); + try { + require('../../../localiser'); + } catch (e) { + msg = (e as any & { message: string }).message + } + assert.strictEqual(msg!!.includes("Bad control character in string literal in JSON"), true); + expect(loggerLogStub.called).to.be.true; + }); + + }); + describe('l10n initialisation tests', () => { + it('l10n initialized', () => { + when(extMock?.extensionPath).thenReturn(path.join(currentDir, 'resources')); + var mkInst = instance(extMock); + when(mockedExtns.getExtension("oracle.oracle-java")).thenReturn(mkInst); + require('../../../localiser'); + expect(loggerLogStub.called).to.be.false; + }); + it('get nbLocaleCode and get value', () => { + when(extMock?.extensionPath).thenReturn(path.join(currentDir, 'resources')); + var mkExtInst = instance(extMock); + when(mockedEnv.language).thenReturn("en"); + when(mockedExtns.getExtension("oracle.oracle-java")).thenReturn(mkExtInst); + when(mockedL10n.bundle).thenReturn(undefined); + let l10n = require('../../../localiser'); + let l10nObj = l10n.l10n as { nbLocaleCode(): string, value(key: string, placeholderMap?: Record): string }; + assert.strictEqual(l10nObj.nbLocaleCode(), "en"); + assert.strictEqual(l10nObj.value("label1"), "label1 description"); + assert.strictEqual(l10nObj.value("label2", { "placeholder1": "sample data" }), "lable2 sample data description"); + expect(loggerLogStub.called).to.be.false; + }); + }); + }); +}); \ No newline at end of file diff --git a/vscode/src/test/unit/general/resources/corrupt/l10n/bundle.l10n.en.json b/vscode/src/test/unit/general/resources/corrupt/l10n/bundle.l10n.en.json new file mode 100644 index 00000000..fd07cdaa --- /dev/null +++ b/vscode/src/test/unit/general/resources/corrupt/l10n/bundle.l10n.en.json @@ -0,0 +1,4 @@ +{ + "label1":"label1 description", + "label2":"lable2 +} \ No newline at end of file diff --git a/vscode/src/test/unit/general/resources/l10n/bundle.l10n.en.json b/vscode/src/test/unit/general/resources/l10n/bundle.l10n.en.json new file mode 100644 index 00000000..b98639b2 --- /dev/null +++ b/vscode/src/test/unit/general/resources/l10n/bundle.l10n.en.json @@ -0,0 +1,4 @@ +{ + "label1":"label1 description", + "label2":"lable2 {placeholder1} description" +} \ No newline at end of file diff --git a/vscode/src/test/unit/mocks/init.ts b/vscode/src/test/unit/mocks/init.ts index aa8a4c74..925fdb1b 100644 --- a/vscode/src/test/unit/mocks/init.ts +++ b/vscode/src/test/unit/mocks/init.ts @@ -1,5 +1,5 @@ /* - Copyright (c) 2023-2024, Oracle and/or its affiliates. + Copyright (c) 2023-2025, Oracle and/or its affiliates. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -35,10 +35,11 @@ export const initMocks = () => { const replaceImportsWithMocks = (mocks: any) => { Module._load = function (request: any, _parent: any) { + var isLocaliserUnitTest = ['localiser.unit.test.ts','localiser.unit.test.js'].find(it=>request.includes(it)||_parent?.filename.includes(it)) if (request === 'vscode') { return mocks.vscode; - } else if (request.includes('localiser')) { - return mocks.localiser; + } else if (request.includes('localiser') && !isLocaliserUnitTest) { + return mocks.localiser; } if (/\.less$/.test(request)) { diff --git a/vscode/src/test/unit/mocks/vscode/mockVscode.ts b/vscode/src/test/unit/mocks/vscode/mockVscode.ts index 027f3e25..12186c2c 100644 --- a/vscode/src/test/unit/mocks/vscode/mockVscode.ts +++ b/vscode/src/test/unit/mocks/vscode/mockVscode.ts @@ -1,5 +1,5 @@ /* - Copyright (c) 2023-2024, Oracle and/or its affiliates. + Copyright (c) 2023-2025, Oracle and/or its affiliates. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -20,9 +20,9 @@ import { mockWindowNamespace } from './namespaces/window'; import { mockEnvNamespace } from './namespaces/env'; import { mockedEnums } from './vscodeHostedTypes'; import { NotebookCellOutputItem } from './notebookCellOutputItem'; - +import { mock,instance } from "ts-mockito"; type VSCode = typeof vscode; -const mockedVSCode: Partial = {}; +const mockedVSCode: Partial & { mockedExtns?: typeof vscode.extensions, mockedL10n?: typeof vscode.l10n } = {}; const mockedVscodeClassesAndTypes = () => { mockedVSCode.Uri = URI as any; @@ -33,12 +33,15 @@ const mockedVscodeClassesAndTypes = () => { const mockNamespaces = () => { mockWindowNamespace(mockedVSCode); mockEnvNamespace(mockedVSCode); + mockedVSCode.mockedExtns = mock(); + mockedVSCode.mockedL10n = mock(); + mockedVSCode.extensions = instance(mockedVSCode.mockedExtns); + mockedVSCode.l10n = instance(mockedVSCode.mockedL10n); } export const initMockedVSCode = () => { mockedVscodeClassesAndTypes(); - mockNamespaces(); - + mockNamespaces(); return mockedVSCode; } diff --git a/vscode/src/test/unit/mocks/vscode/namespaces/env.ts b/vscode/src/test/unit/mocks/vscode/namespaces/env.ts index 3546b363..aac57255 100644 --- a/vscode/src/test/unit/mocks/vscode/namespaces/env.ts +++ b/vscode/src/test/unit/mocks/vscode/namespaces/env.ts @@ -18,10 +18,10 @@ import * as vscode from 'vscode'; import { mock, when, anyString, anyOfClass, anything, instance } from "ts-mockito"; type VSCode = typeof vscode; - let mockedEnv: typeof vscode.env; -export const mockEnvNamespace = (mockedVSCode: Partial) => { +export const mockEnvNamespace = (mockedVSCode: Partial & { mockedEnv?: typeof vscode.env }) => { mockedEnv = mock(); + mockedVSCode.mockedEnv = mockedEnv; mockedVSCode.env = instance(mockedEnv); mockTelemetryFields(); }