diff --git a/src/test/common/variables/envVarsProvider.multiroot.test.ts b/src/test/common/variables/envVarsProvider.multiroot.test.ts index 7b7c61b44f3e..fc49cb6fea23 100644 --- a/src/test/common/variables/envVarsProvider.multiroot.test.ts +++ b/src/test/common/variables/envVarsProvider.multiroot.test.ts @@ -317,7 +317,10 @@ suite('Multiroot Environment Variables Provider', () => { expect(newVars).to.not.to.have.property('PYTHONPATH', '../workspace5', 'PYTHONPATH value is invalid'); }); + // Check https://github.com/Microsoft/vscode-python/issues/4067 test('Custom variables will be refreshed when .env file is created, modified and deleted', async function () { + // tslint:disable-next-line:no-invalid-this + return this.skip(); // tslint:disable-next-line:no-invalid-this this.timeout(20000); const env3 = path.join(workspace4Path.fsPath, '.env3'); diff --git a/src/test/linters/lint.args.test.ts b/src/test/linters/lint.args.test.ts index e90e0c15ca15..7d7b7fc26c83 100644 --- a/src/test/linters/lint.args.test.ts +++ b/src/test/linters/lint.args.test.ts @@ -150,7 +150,7 @@ suite('Linting - Arguments', () => { document.setup(d => d.uri).returns(() => fileUri); let invoked = false; - (linter as any).run = (args, doc, token) => { + (linter as any).run = (args: any[], doc: any, token: any) => { expect(args[args.length - 1]).to.equal(fileUri.fsPath); invoked = true; return Promise.resolve([]); diff --git a/src/test/linters/lint.multiroot.test.ts b/src/test/linters/lint.multiroot.test.ts index 36a4b7c2a0c6..e41cecdbc674 100644 --- a/src/test/linters/lint.multiroot.test.ts +++ b/src/test/linters/lint.multiroot.test.ts @@ -70,7 +70,7 @@ suite('Multiroot Linting', () => { const errorMessage = mustHaveErrors ? 'No errors returned by linter' : 'Errors returned by linter'; assert.equal(messages.length > 0, mustHaveErrors, errorMessage); } - async function enableDisableSetting(workspaceFolder, configTarget: ConfigurationTarget, setting: string, value: boolean): Promise { + async function enableDisableSetting(workspaceFolder: string, configTarget: ConfigurationTarget, setting: string, value: boolean): Promise { const config = ioc.serviceContainer.get(IConfigurationService); await config.updateSetting(setting, value, Uri.file(workspaceFolder), configTarget); } diff --git a/src/test/linters/lint.test.ts b/src/test/linters/lint.test.ts index 77748733ef21..5463e26a8d57 100644 --- a/src/test/linters/lint.test.ts +++ b/src/test/linters/lint.test.ts @@ -30,7 +30,7 @@ suite('Linting Settings', () => { let linterManager: ILinterManager; let configService: IConfigurationService; - suiteSetup(async function() { + suiteSetup(async function () { // These tests are still consistently failing during teardown. // See gh-4326. // tslint:disable-next-line:no-invalid-this @@ -96,14 +96,17 @@ suite('Linting Settings', () => { const settings = configService.getSettings(); await resetSettings(); - assert.equal(settings.linting[`${Product[product]}Enabled`], false, 'mismatch'); + // tslint:disable-next-line:no-any + assert.equal((settings.linting as any)[`${Product[product]}Enabled`], false, 'mismatch'); await linterManager.setActiveLintersAsync([product]); - assert.equal(settings.linting[`${Product[product]}Enabled`], true, 'mismatch'); + // tslint:disable-next-line:no-any + assert.equal((settings.linting as any)[`${Product[product]}Enabled`], true, 'mismatch'); linterManager.getAllLinterInfos().forEach(async (x) => { if (x.product !== product) { - assert.equal(settings.linting[x.enabledSettingName], false, 'mismatch'); + // tslint:disable-next-line:no-any + assert.equal((settings.linting as any)[x.enabledSettingName], false, 'mismatch'); } }); }); diff --git a/src/test/linters/lint.unit.test.ts b/src/test/linters/lint.unit.test.ts index aa7fc60f3b8d..5832764fef50 100644 --- a/src/test/linters/lint.unit.test.ts +++ b/src/test/linters/lint.unit.test.ts @@ -269,7 +269,7 @@ suite('Linting Scenarios', () => { } for (const product of LINTERID_BY_PRODUCT.keys()) { for (const enabled of [false, true]) { - test(`${enabled ? 'Enable' : 'Disable'} ${getProductName(product)} and run linter`, async function() { + test(`${enabled ? 'Enable' : 'Disable'} ${getProductName(product)} and run linter`, async function () { // tslint:disable-next-line:no-suspicious-comment // TODO: Add coverage for these linters. if ([Product.bandit, Product.mypy, Product.pylama, Product.prospector].some(p => p === product)) { @@ -315,7 +315,7 @@ suite('Linting Scenarios', () => { } } for (const product of LINTERID_BY_PRODUCT.keys()) { - test(`Check ${getProductName(product)} messages`, async function() { + test(`Check ${getProductName(product)} messages`, async function () { // tslint:disable-next-line:no-suspicious-comment // TODO: Add coverage for these linters. if ([Product.bandit, Product.mypy, Product.pylama, Product.prospector].some(p => p === product)) { @@ -323,7 +323,7 @@ suite('Linting Scenarios', () => { this.skip(); } - const fixture = new TestFixture(); + const fixture = new TestFixture(); await testLinterMessages(fixture, product); }); } @@ -353,8 +353,10 @@ suite('Linting Scenarios', () => { }); const PRODUCTS = Object.keys(Product) - .filter(key => !isNaN(Number(Product[key]))) - .map(key => Product[key]); + // tslint:disable-next-line:no-any + .filter(key => !isNaN(Number(Product[key as any]))) + // tslint:disable-next-line:no-any + .map(key => Product[key as any]); // tslint:disable-next-line:max-func-body-length suite('Linting Products', () => { @@ -362,11 +364,14 @@ suite('Linting Products', () => { test('All linting products are represented by linters', async () => { for (const product of PRODUCTS) { - if (prodService.getProductType(product) !== ProductType.Linter) { + // tslint:disable-next-line:no-any + if (prodService.getProductType(product as any) !== ProductType.Linter) { continue; } - const found = LINTERID_BY_PRODUCT.get(product); - assert.notEqual(found, undefined, `did find linter ${Product[product]}`); + // tslint:disable-next-line:no-any + const found = LINTERID_BY_PRODUCT.get(product as any); + // tslint:disable-next-line:no-any + assert.notEqual(found, undefined, `did find linter ${Product[product as any]}`); } }); diff --git a/src/test/refactor/extension.refactor.extract.method.test.ts b/src/test/refactor/extension.refactor.extract.method.test.ts index 0ba255b3bc01..a220af3c3c6a 100644 --- a/src/test/refactor/extension.refactor.extract.method.test.ts +++ b/src/test/refactor/extension.refactor.extract.method.test.ts @@ -40,7 +40,7 @@ suite('Method Extraction', () => { refactorTargetFile = path.join(refactorTargetFileDir, `refactor${new Date().getTime()}.py`); fs.copySync(refactorSourceFile, refactorTargetFile, { overwrite: true }); await initializeTest(); - (commands as any).executeCommand = (cmd) => Promise.resolve(); + (commands as any).executeCommand = (cmd: any) => Promise.resolve(); }); teardown(async () => { commands.executeCommand = oldExecuteCommand; diff --git a/src/test/refactor/extension.refactor.extract.var.test.ts b/src/test/refactor/extension.refactor.extract.var.test.ts index 753b6ba16307..d6fdc6eaac48 100644 --- a/src/test/refactor/extension.refactor.extract.var.test.ts +++ b/src/test/refactor/extension.refactor.extract.var.test.ts @@ -36,7 +36,7 @@ suite('Variable Extraction', () => { refactorTargetFile = path.join(refactorTargetFileDir, `refactor${new Date().getTime()}.py`); fs.copySync(refactorSourceFile, refactorTargetFile, { overwrite: true }); await initializeTest(); - (commands).executeCommand = (cmd) => Promise.resolve(); + (commands).executeCommand = (cmd: any) => Promise.resolve(); }); teardown(async () => { commands.executeCommand = oldExecuteCommand; diff --git a/src/test/testRunner.ts b/src/test/testRunner.ts index a59c05312425..7ea84aa9bbeb 100644 --- a/src/test/testRunner.ts +++ b/src/test/testRunner.ts @@ -43,7 +43,7 @@ type TestCallback = (error?: Error, failures?: number) => void; // Since we are not running in a tty environment, we just implement the method statically. const tty = require('tty'); if (!tty.getWindowSize) { - tty.getWindowSize = function(): number[] { + tty.getWindowSize = function (): number[] { return [80, 75]; }; } @@ -240,7 +240,7 @@ class CoverageRunner { // When instrumenting the code, istanbul will give each FunctionDeclaration a value of 1 in coverState.s, // presumably to compensate for function hoisting. We need to reset this, as the function was not hoisted, // as it was never loaded. - Object.keys(this.instrumenter.coverState.s).forEach(key => (this.instrumenter.coverState.s[key] = 0)); + Object.keys(this.instrumenter.coverState.s).forEach(key => ((this.instrumenter.coverState.s as any)[key] = 0)); coverage[file] = this.instrumenter.coverState; }); @@ -252,7 +252,7 @@ class CoverageRunner { fs.writeFileSync(coverageFile, JSON.stringify(coverage), 'utf8'); const remappedCollector: istanbul.Collector = remapIstanbul.remap(coverage, { - warn: warning => { + warn: (warning: any) => { // We expect some warnings as any JS file without a typescript mapping will cause this. // By default, we'll skip printing these to the console as it clutters it up. if (this.options.verbose) { diff --git a/src/test/unittests.ts b/src/test/unittests.ts index a295f2938212..9536fcdfcde0 100644 --- a/src/test/unittests.ts +++ b/src/test/unittests.ts @@ -22,10 +22,10 @@ const Module = require('module'); // tslint:disable-next-line:no-function-expression (function () { const origRequire = Module.prototype.require; - const _require = (context, filepath) => { + const _require = (context: any, filepath: any) => { return origRequire.call(context, filepath); }; - Module.prototype.require = function (filepath) { + Module.prototype.require = function (filepath: any) { if (filepath.endsWith('.css') || filepath.endsWith('.svg')) { return ''; } diff --git a/src/test/unittests/argsService.test.ts b/src/test/unittests/argsService.test.ts index be8f205ab135..019dd533cd14 100644 --- a/src/test/unittests/argsService.test.ts +++ b/src/test/unittests/argsService.test.ts @@ -22,109 +22,109 @@ import { PYTHON_PATH } from '../common'; suite('ArgsService: Common', () => { UNIT_TEST_PRODUCTS.forEach(product => { - const productNames = getNamesAndValues(Product); - const productName = productNames.find(item => item.value === product)!.name; - suite(productName, () => { - let argumentsService: IArgumentsService; - let moduleName = ''; - let expectedWithArgs: string[] = []; - let expectedWithoutArgs: string[] = []; - - setup(function () { - // Take the spawning of process into account. - // tslint:disable-next-line:no-invalid-this - this.timeout(5000); - const serviceContainer = typeMoq.Mock.ofType(); - const logger = typeMoq.Mock.ofType(); - - serviceContainer - .setup(s => s.get(typeMoq.It.isValue(ILogger), typeMoq.It.isAny())) - .returns(() => logger.object); - - const argsHelper = new ArgumentsHelper(serviceContainer.object); - - serviceContainer - .setup(s => s.get(typeMoq.It.isValue(IArgumentsHelper), typeMoq.It.isAny())) - .returns(() => argsHelper); - - switch (product) { - case Product.unittest: { - argumentsService = new UnitTestArgumentsService(serviceContainer.object); - moduleName = 'unittest'; - break; - } - case Product.nosetest: { - argumentsService = new NoseTestArgumentsService(serviceContainer.object); - moduleName = 'nose'; - break; - } - case Product.pytest: { - moduleName = 'pytest'; - argumentsService = new PyTestArgumentsService(serviceContainer.object); - break; - } - default: { - throw new Error('Unrecognized Test Framework'); - } + const productNames = getNamesAndValues(Product); + const productName = productNames.find(item => item.value === product)!.name; + suite(productName, () => { + let argumentsService: IArgumentsService; + let moduleName = ''; + let expectedWithArgs: string[] = []; + let expectedWithoutArgs: string[] = []; + + setup(function () { + // Take the spawning of process into account. + // tslint:disable-next-line:no-invalid-this + this.timeout(5000); + const serviceContainer = typeMoq.Mock.ofType(); + const logger = typeMoq.Mock.ofType(); + + serviceContainer + .setup(s => s.get(typeMoq.It.isValue(ILogger), typeMoq.It.isAny())) + .returns(() => logger.object); + + const argsHelper = new ArgumentsHelper(serviceContainer.object); + + serviceContainer + .setup(s => s.get(typeMoq.It.isValue(IArgumentsHelper), typeMoq.It.isAny())) + .returns(() => argsHelper); + + switch (product) { + case Product.unittest: { + argumentsService = new UnitTestArgumentsService(serviceContainer.object); + moduleName = 'unittest'; + break; } + case Product.nosetest: { + argumentsService = new NoseTestArgumentsService(serviceContainer.object); + moduleName = 'nose'; + break; + } + case Product.pytest: { + moduleName = 'pytest'; + argumentsService = new PyTestArgumentsService(serviceContainer.object); + break; + } + default: { + throw new Error('Unrecognized Test Framework'); + } + } - expectedWithArgs = getOptions(product, moduleName, true); - expectedWithoutArgs = getOptions(product, moduleName, false); - }); + expectedWithArgs = getOptions(product, moduleName, true); + expectedWithoutArgs = getOptions(product, moduleName, false); + }); - test('Check for new/unrecognized options with values', () => { - const options = argumentsService.getKnownOptions(); - const optionsNotFound = expectedWithArgs.filter(item => options.withArgs.indexOf(item) === -1); + test('Check for new/unrecognized options with values', () => { + const options = argumentsService.getKnownOptions(); + const optionsNotFound = expectedWithArgs.filter(item => options.withArgs.indexOf(item) === -1); - if (optionsNotFound.length > 0) { - fail('', optionsNotFound.join(', '), 'Options not found'); - } - }); - test('Check for new/unrecognized options without values', () => { - const options = argumentsService.getKnownOptions(); - const optionsNotFound = expectedWithoutArgs.filter(item => options.withoutArgs.indexOf(item) === -1); + if (optionsNotFound.length > 0) { + fail('', optionsNotFound.join(', '), 'Options not found'); + } + }); + test('Check for new/unrecognized options without values', () => { + const options = argumentsService.getKnownOptions(); + const optionsNotFound = expectedWithoutArgs.filter(item => options.withoutArgs.indexOf(item) === -1); - if (optionsNotFound.length > 0) { - fail('', optionsNotFound.join(', '), 'Options not found'); - } - }); - test('Test getting value for an option with a single value', () => { - for (const option of expectedWithArgs) { - const args = ['--some-option-with-a-value', '1234', '--another-value-with-inline=1234', option, 'abcd']; - const value = argumentsService.getOptionValue(args, option); - expect(value).to.equal('abcd'); - } - }); - test('Test getting value for an option with a multiple value', () => { - for (const option of expectedWithArgs) { - const args = ['--some-option-with-a-value', '1234', '--another-value-with-inline=1234', option, 'abcd', option, 'xyz']; - const value = argumentsService.getOptionValue(args, option); - expect(value).to.deep.equal(['abcd', 'xyz']); - } - }); - test('Test filtering of arguments', () => { - const args: string[] = []; - const knownOptions = argumentsService.getKnownOptions(); - const argumentsToRemove: string[] = []; - const expectedFilteredArgs: string[] = []; - // Generate some random arguments. - for (let i = 0; i < 5; i += 1) { - args.push(knownOptions.withArgs[i], `Random Value ${i}`); - args.push(knownOptions.withoutArgs[i]); - - if (i % 2 === 0) { - argumentsToRemove.push(knownOptions.withArgs[i], knownOptions.withoutArgs[i]); - } else { - expectedFilteredArgs.push(knownOptions.withArgs[i], `Random Value ${i}`); - expectedFilteredArgs.push(knownOptions.withoutArgs[i]); - } + if (optionsNotFound.length > 0) { + fail('', optionsNotFound.join(', '), 'Options not found'); + } + }); + test('Test getting value for an option with a single value', () => { + for (const option of expectedWithArgs) { + const args = ['--some-option-with-a-value', '1234', '--another-value-with-inline=1234', option, 'abcd']; + const value = argumentsService.getOptionValue(args, option); + expect(value).to.equal('abcd'); + } + }); + test('Test getting value for an option with a multiple value', () => { + for (const option of expectedWithArgs) { + const args = ['--some-option-with-a-value', '1234', '--another-value-with-inline=1234', option, 'abcd', option, 'xyz']; + const value = argumentsService.getOptionValue(args, option); + expect(value).to.deep.equal(['abcd', 'xyz']); + } + }); + test('Test filtering of arguments', () => { + const args: string[] = []; + const knownOptions = argumentsService.getKnownOptions(); + const argumentsToRemove: string[] = []; + const expectedFilteredArgs: string[] = []; + // Generate some random arguments. + for (let i = 0; i < 5; i += 1) { + args.push(knownOptions.withArgs[i], `Random Value ${i}`); + args.push(knownOptions.withoutArgs[i]); + + if (i % 2 === 0) { + argumentsToRemove.push(knownOptions.withArgs[i], knownOptions.withoutArgs[i]); + } else { + expectedFilteredArgs.push(knownOptions.withArgs[i], `Random Value ${i}`); + expectedFilteredArgs.push(knownOptions.withoutArgs[i]); } + } - const filteredArgs = argumentsService.filterArguments(args, argumentsToRemove); - expect(filteredArgs).to.be.deep.equal(expectedFilteredArgs); - }); + const filteredArgs = argumentsService.filterArguments(args, argumentsToRemove); + expect(filteredArgs).to.be.deep.equal(expectedFilteredArgs); }); }); + }); }); function getOptions(product: Product, moduleName: string, withValues: boolean) { @@ -160,7 +160,8 @@ function getOptionsWithArguments(output: string) { return getMatches('\\s{1,}(-{1,2}[A-Za-z0-9-]+)(?:=|\\s{0,1}[A-Z])', output); } -function getMatches(pattern, str) { +// tslint:disable-next-line:no-any +function getMatches(pattern: any, str: string) { const matches: string[] = []; const regex = new RegExp(pattern, 'gm'); let result: RegExpExecArray | null = regex.exec(str); diff --git a/src/test/unittests/banners/languageServerSurvey.unit.test.ts b/src/test/unittests/banners/languageServerSurvey.unit.test.ts index c77fe4682b7e..388178100291 100644 --- a/src/test/unittests/banners/languageServerSurvey.unit.test.ts +++ b/src/test/unittests/banners/languageServerSurvey.unit.test.ts @@ -10,11 +10,10 @@ import { SemVer } from 'semver'; import * as typemoq from 'typemoq'; import { FolderVersionPair, ILanguageServerFolderService } from '../../../client/activation/types'; import { IApplicationShell } from '../../../client/common/application/types'; -import { IBrowserService, IConfigurationService, IPersistentState, IPersistentStateFactory } from '../../../client/common/types'; +import { IBrowserService, IPersistentState, IPersistentStateFactory } from '../../../client/common/types'; import { LanguageServerSurveyBanner, LSSurveyStateKeys } from '../../../client/languageServices/languageServerSurveyBanner'; suite('Language Server Survey Banner', () => { - let config: typemoq.IMock; let appShell: typemoq.IMock; let browser: typemoq.IMock; let lsService: typemoq.IMock; @@ -24,7 +23,6 @@ suite('Language Server Survey Banner', () => { const no = 'No, thanks'; setup(() => { - config = typemoq.Mock.ofType(); appShell = typemoq.Mock.ofType(); browser = typemoq.Mock.ofType(); lsService = typemoq.Mock.ofType(); diff --git a/src/test/unittests/nosetest/nosetest.run.test.ts b/src/test/unittests/nosetest/nosetest.run.test.ts index e3b15ed6ec19..1d53d3011e70 100644 --- a/src/test/unittests/nosetest/nosetest.run.test.ts +++ b/src/test/unittests/nosetest/nosetest.run.test.ts @@ -4,7 +4,6 @@ import * as assert from 'assert'; import * as fs from 'fs'; import * as path from 'path'; -import { instance, mock } from 'ts-mockito'; import * as vscode from 'vscode'; import { EXTENSION_ROOT_DIR } from '../../../client/common/constants'; import { IProcessServiceFactory } from '../../../client/common/process/types'; diff --git a/src/test/unittests/nosetest/nosetest.test.ts b/src/test/unittests/nosetest/nosetest.test.ts index 28898f0843a6..9f7fc11859e6 100644 --- a/src/test/unittests/nosetest/nosetest.test.ts +++ b/src/test/unittests/nosetest/nosetest.test.ts @@ -1,7 +1,6 @@ import * as assert from 'assert'; import * as fs from 'fs'; import * as path from 'path'; -import { instance, mock } from 'ts-mockito'; import * as vscode from 'vscode'; import { EXTENSION_ROOT_DIR } from '../../../client/common/constants'; import { ICondaService, IInterpreterService } from '../../../client/interpreter/contracts'; diff --git a/src/test/unittests/pytest/pytest_run_tests_data.ts b/src/test/unittests/pytest/pytest_run_tests_data.ts index d82f8483f76b..b6062920bf4b 100644 --- a/src/test/unittests/pytest/pytest_run_tests_data.ts +++ b/src/test/unittests/pytest/pytest_run_tests_data.ts @@ -392,7 +392,7 @@ export interface ITestScenarioDetails { scenarioName: string; discoveryOutput: string; runOutput: string; - testsToRun: TestsToRun; + testsToRun?: TestsToRun; testDetails?: ITestDetails[]; testSuiteIndex?: number; testFunctionIndex?: number;