diff --git a/pythonExtensionApi/src/main.js b/pythonExtensionApi/src/main.js new file mode 100644 index 000000000000..27aa8b9c601b --- /dev/null +++ b/pythonExtensionApi/src/main.js @@ -0,0 +1,38 @@ +"use strict"; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.PythonExtension = exports.PVSC_EXTENSION_ID = void 0; +const vscode_1 = require("vscode"); +exports.PVSC_EXTENSION_ID = 'ms-python.python'; +// eslint-disable-next-line @typescript-eslint/no-namespace +var PythonExtension; +(function (PythonExtension) { + /** + * Returns the API exposed by the Python extension in VS Code. + */ + function api() { + return __awaiter(this, void 0, void 0, function* () { + const extension = vscode_1.extensions.getExtension(exports.PVSC_EXTENSION_ID); + if (extension === undefined) { + throw new Error(`Python extension is not installed or is disabled`); + } + if (!extension.isActive) { + yield extension.activate(); + } + const pythonApi = extension.exports; + return pythonApi; + }); + } + PythonExtension.api = api; +})(PythonExtension || (exports.PythonExtension = PythonExtension = {})); +//# sourceMappingURL=main.js.map \ No newline at end of file diff --git a/pythonExtensionApi/src/main.js.map b/pythonExtensionApi/src/main.js.map new file mode 100644 index 000000000000..5484d48698c8 --- /dev/null +++ b/pythonExtensionApi/src/main.js.map @@ -0,0 +1 @@ +{"version":3,"file":"main.js","sourceRoot":"","sources":["main.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;;;;;;;;;;AAElC,mCAAoF;AAsUvE,QAAA,iBAAiB,GAAG,kBAAkB,CAAC;AAEpD,2DAA2D;AAC3D,IAAiB,eAAe,CAe/B;AAfD,WAAiB,eAAe;IAC5B;;OAEG;IACH,SAAsB,GAAG;;YACrB,MAAM,SAAS,GAAG,mBAAU,CAAC,YAAY,CAAC,yBAAiB,CAAC,CAAC;YAC7D,IAAI,SAAS,KAAK,SAAS,EAAE;gBACzB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;aACvE;YACD,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;gBACrB,MAAM,SAAS,CAAC,QAAQ,EAAE,CAAC;aAC9B;YACD,MAAM,SAAS,GAAoB,SAAS,CAAC,OAAO,CAAC;YACrD,OAAO,SAAS,CAAC;QACrB,CAAC;KAAA;IAVqB,mBAAG,MAUxB,CAAA;AACL,CAAC,EAfgB,eAAe,+BAAf,eAAe,QAe/B"} \ No newline at end of file diff --git a/src/client/testing/utils.ts b/src/client/testing/utils.ts index c1027d4a8dc1..667bca40f316 100644 --- a/src/client/testing/utils.ts +++ b/src/client/testing/utils.ts @@ -7,7 +7,7 @@ export async function writeTestIdToClipboard(testItem: TestItem): Promise // Convert the id to a module.class.method format as this is a unittest const moduleClassMethod = idToModuleClassMethod(testItem.id); if (moduleClassMethod) { - await env.clipboard.writeText(moduleClassMethod); + await clipboardWriteText(moduleClassMethod); traceLog('Testing: Copied test id to clipboard, id: ' + moduleClassMethod); return; } diff --git a/src/test/testing/utils.unit.test.ts b/src/test/testing/utils.unit.test.ts index 8efa0cee0e65..4cf920b7929e 100644 --- a/src/test/testing/utils.unit.test.ts +++ b/src/test/testing/utils.unit.test.ts @@ -2,13 +2,14 @@ import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; import * as utils from '../../client/testing/utils'; import sinon from 'sinon'; +import { env } from 'vscode'; use(chaiAsPromised.default); function test_idToModuleClassMethod() { try { expect(utils.idToModuleClassMethod('foo')).to.equal('foo'); - expect(utils.idToModuleClassMethod('a/b/c.pyMyClass')).to.equal('c.MyClass'); - expect(utils.idToModuleClassMethod('a/b/c.pyMyClassmy_method')).to.equal('c.MyClass.my_method'); + expect(utils.idToModuleClassMethod('a/b/c.py\\MyClass')).to.equal('c.MyClass'); + expect(utils.idToModuleClassMethod('a/b/c.py\\MyClass\\my_method')).to.equal('c.MyClass.my_method'); expect(utils.idToModuleClassMethod('\\MyClass')).to.be.undefined; console.log('test_idToModuleClassMethod passed'); } catch (e) { @@ -17,23 +18,22 @@ function test_idToModuleClassMethod() { } async function test_writeTestIdToClipboard() { - let clipboardStub = sinon.stub(utils, 'clipboardWriteText').resolves(); - const { writeTestIdToClipboard } = utils; + let clipboardStub = sinon.stub(env.clipboard, 'writeText').resolves(); try { // unittest id - const testItem = { id: 'a/b/c.pyMyClass\\my_method' }; - await writeTestIdToClipboard(testItem as any); + const testItem = { id: 'a/b/c.py\\MyClass\\my_method' }; + await utils.writeTestIdToClipboard(testItem as any); sinon.assert.calledOnceWithExactly(clipboardStub, 'c.MyClass.my_method'); clipboardStub.resetHistory(); // pytest id const testItem2 = { id: 'tests/test_foo.py::TestClass::test_method' }; - await writeTestIdToClipboard(testItem2 as any); + await utils.writeTestIdToClipboard(testItem2 as any); sinon.assert.calledOnceWithExactly(clipboardStub, 'tests/test_foo.py::TestClass::test_method'); clipboardStub.resetHistory(); // undefined - await writeTestIdToClipboard(undefined as any); + await utils.writeTestIdToClipboard(undefined as any); sinon.assert.notCalled(clipboardStub); console.log('test_writeTestIdToClipboard passed');