forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlint.test.ts
More file actions
143 lines (127 loc) · 5.78 KB
/
lint.test.ts
File metadata and controls
143 lines (127 loc) · 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import * as assert from 'assert';
import * as path from 'path';
import { ConfigurationTarget, Uri } from 'vscode';
import { WorkspaceService } from '../../client/common/application/workspace';
import { Product } from '../../client/common/installer/productInstaller';
import {
CTagsProductPathService,
DataScienceProductPathService,
FormatterProductPathService,
LinterProductPathService,
RefactoringLibraryProductPathService,
TestFrameworkProductPathService
} from '../../client/common/installer/productPath';
import { ProductService } from '../../client/common/installer/productService';
import { IProductPathService, IProductService } from '../../client/common/installer/types';
import { IConfigurationService, ProductType } from '../../client/common/types';
import { LINTERID_BY_PRODUCT } from '../../client/linters/constants';
import { LinterManager } from '../../client/linters/linterManager';
import { ILinterManager } from '../../client/linters/types';
import { rootWorkspaceUri } from '../common';
import { closeActiveWindows, initialize, initializeTest, IS_MULTI_ROOT_TEST } from '../initialize';
import { UnitTestIocContainer } from '../testing/serviceRegistry';
const workspaceDir = path.join(__dirname, '..', '..', '..', 'src', 'test');
const workspaceUri = Uri.file(workspaceDir);
// tslint:disable-next-line:max-func-body-length
suite('Linting Settings', () => {
let ioc: UnitTestIocContainer;
let linterManager: ILinterManager;
let configService: IConfigurationService;
suiteSetup(async function() {
// These tests are still consistently failing during teardown.
// See gh-4326.
// tslint:disable-next-line:no-invalid-this
this.skip();
await initialize();
});
setup(async () => {
initializeDI();
await initializeTest();
});
suiteTeardown(closeActiveWindows);
teardown(async () => {
await ioc.dispose();
await closeActiveWindows();
await resetSettings();
});
function initializeDI() {
ioc = new UnitTestIocContainer();
ioc.registerCommonTypes(false);
ioc.registerProcessTypes();
ioc.registerLinterTypes();
ioc.registerVariableTypes();
ioc.registerPlatformTypes();
linterManager = new LinterManager(ioc.serviceContainer, new WorkspaceService());
configService = ioc.serviceContainer.get<IConfigurationService>(IConfigurationService);
ioc.serviceManager.addSingletonInstance<IProductService>(IProductService, new ProductService());
ioc.serviceManager.addSingleton<IProductPathService>(
IProductPathService,
CTagsProductPathService,
ProductType.WorkspaceSymbols
);
ioc.serviceManager.addSingleton<IProductPathService>(
IProductPathService,
FormatterProductPathService,
ProductType.Formatter
);
ioc.serviceManager.addSingleton<IProductPathService>(
IProductPathService,
LinterProductPathService,
ProductType.Linter
);
ioc.serviceManager.addSingleton<IProductPathService>(
IProductPathService,
TestFrameworkProductPathService,
ProductType.TestFramework
);
ioc.serviceManager.addSingleton<IProductPathService>(
IProductPathService,
RefactoringLibraryProductPathService,
ProductType.RefactoringLibrary
);
ioc.serviceManager.addSingleton<IProductPathService>(
IProductPathService,
DataScienceProductPathService,
ProductType.DataScience
);
}
async function resetSettings(lintingEnabled = true) {
// Don't run these updates in parallel, as they are updating the same file.
const target = IS_MULTI_ROOT_TEST ? ConfigurationTarget.WorkspaceFolder : ConfigurationTarget.Workspace;
await configService.updateSetting('linting.enabled', lintingEnabled, rootWorkspaceUri, target);
await configService.updateSetting('linting.lintOnSave', false, rootWorkspaceUri, target);
await configService.updateSetting('linting.pylintUseMinimalCheckers', false, workspaceUri);
linterManager.getAllLinterInfos().forEach(async x => {
const settingKey = `linting.${x.enabledSettingName}`;
await configService.updateSetting(settingKey, false, rootWorkspaceUri, target);
});
}
test('enable through manager (global)', async () => {
const settings = configService.getSettings();
await resetSettings(false);
await linterManager.enableLintingAsync(false);
assert.equal(settings.linting.enabled, false, 'mismatch');
await linterManager.enableLintingAsync(true);
assert.equal(settings.linting.enabled, true, 'mismatch');
});
for (const product of LINTERID_BY_PRODUCT.keys()) {
test(`enable through manager (${Product[product]})`, async () => {
const settings = configService.getSettings();
await resetSettings();
// tslint:disable-next-line:no-any
assert.equal((settings.linting as any)[`${Product[product]}Enabled`], false, 'mismatch');
await linterManager.setActiveLintersAsync([product]);
// 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) {
// tslint:disable-next-line:no-any
assert.equal((settings.linting as any)[x.enabledSettingName], false, 'mismatch');
}
});
});
}
});