mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Initial VS Code 1.19 source merge (#571)
* Initial 1.19 xcopy * Fix yarn build * Fix numerous build breaks * Next batch of build break fixes * More build break fixes * Runtime breaks * Additional post merge fixes * Fix windows setup file * Fix test failures. * Update license header blocks to refer to source eula
This commit is contained in:
@@ -6,99 +6,93 @@
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { join } from 'vs/base/common/paths';
|
||||
import { FolderConfigurationModel, ScopedConfigurationModel, FolderSettingsModel, WorkspaceConfigurationChangeEvent } from 'vs/workbench/services/configuration/common/configurationModels';
|
||||
import { ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { FolderSettingsModelParser, WorkspaceConfigurationChangeEvent, StandaloneConfigurationModelParser, AllKeysConfigurationChangeEvent, Configuration } from 'vs/workbench/services/configuration/common/configurationModels';
|
||||
import { Workspace, WorkspaceFolder } from 'vs/platform/workspace/common/workspace';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { ConfigurationChangeEvent } from 'vs/platform/configuration/common/configurationModels';
|
||||
import { ConfigurationChangeEvent, ConfigurationModel } from 'vs/platform/configuration/common/configurationModels';
|
||||
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
|
||||
import { IConfigurationRegistry, Extensions as ConfigurationExtensions, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { StrictResourceMap } from 'vs/base/common/map';
|
||||
|
||||
suite('ConfigurationService - Model', () => {
|
||||
suite('FolderSettingsModelParser', () => {
|
||||
|
||||
test('Test scoped configs are undefined', () => {
|
||||
const settingsConfig = new FolderSettingsModel(JSON.stringify({
|
||||
awesome: true
|
||||
}));
|
||||
|
||||
const testObject = new FolderConfigurationModel(settingsConfig, [], ConfigurationScope.WINDOW);
|
||||
|
||||
assert.equal(testObject.getSectionContents('task'), undefined);
|
||||
suiteSetup(() => {
|
||||
const configurationRegistry = <IConfigurationRegistry>Registry.as(ConfigurationExtensions.Configuration);
|
||||
configurationRegistry.registerConfiguration({
|
||||
'id': 'FolderSettingsModelParser_1',
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'FolderSettingsModelParser.window': {
|
||||
'type': 'string',
|
||||
'default': 'isSet'
|
||||
},
|
||||
'FolderSettingsModelParser.resource': {
|
||||
'type': 'string',
|
||||
'default': 'isSet',
|
||||
scope: ConfigurationScope.RESOURCE
|
||||
},
|
||||
'FolderSettingsModelParser.executable': {
|
||||
'type': 'string',
|
||||
'default': 'isSet',
|
||||
isExecutable: true
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('Test consolidate (settings and tasks)', () => {
|
||||
const settingsConfig = new FolderSettingsModel(JSON.stringify({
|
||||
awesome: true
|
||||
}));
|
||||
test('parse all folder settings', () => {
|
||||
const testObject = new FolderSettingsModelParser('settings');
|
||||
|
||||
const tasksConfig = new ScopedConfigurationModel(JSON.stringify({
|
||||
awesome: false
|
||||
}), '', 'tasks');
|
||||
testObject.parse(JSON.stringify({ 'FolderSettingsModelParser.window': 'window', 'FolderSettingsModelParser.resource': 'resource', 'FolderSettingsModelParser.executable': 'executable' }));
|
||||
|
||||
const expected = {
|
||||
awesome: true,
|
||||
tasks: {
|
||||
awesome: false
|
||||
}
|
||||
};
|
||||
|
||||
assert.deepEqual(new FolderConfigurationModel(settingsConfig, [tasksConfig], ConfigurationScope.WINDOW).contents, expected);
|
||||
assert.deepEqual(testObject.configurationModel.contents, { 'FolderSettingsModelParser': { 'window': 'window', 'resource': 'resource' } });
|
||||
});
|
||||
|
||||
test('Test consolidate (settings and launch)', () => {
|
||||
const settingsConfig = new FolderSettingsModel(JSON.stringify({
|
||||
awesome: true
|
||||
}));
|
||||
test('parse resource folder settings', () => {
|
||||
const testObject = new FolderSettingsModelParser('settings', ConfigurationScope.RESOURCE);
|
||||
|
||||
const launchConfig = new ScopedConfigurationModel(JSON.stringify({
|
||||
awesome: false
|
||||
}), '', 'launch');
|
||||
testObject.parse(JSON.stringify({ 'FolderSettingsModelParser.window': 'window', 'FolderSettingsModelParser.resource': 'resource', 'FolderSettingsModelParser.executable': 'executable' }));
|
||||
|
||||
const expected = {
|
||||
awesome: true,
|
||||
launch: {
|
||||
awesome: false
|
||||
}
|
||||
};
|
||||
|
||||
assert.deepEqual(new FolderConfigurationModel(settingsConfig, [launchConfig], ConfigurationScope.WINDOW).contents, expected);
|
||||
assert.deepEqual(testObject.configurationModel.contents, { 'FolderSettingsModelParser': { 'resource': 'resource' } });
|
||||
});
|
||||
|
||||
test('Test consolidate (settings and launch and tasks) - launch/tasks wins over settings file', () => {
|
||||
const settingsConfig = new FolderSettingsModel(JSON.stringify({
|
||||
awesome: true,
|
||||
launch: {
|
||||
launchConfig: 'defined',
|
||||
otherLaunchConfig: 'alsoDefined'
|
||||
},
|
||||
tasks: {
|
||||
taskConfig: 'defined',
|
||||
otherTaskConfig: 'alsoDefined'
|
||||
test('reprocess folder settings excludes executable', () => {
|
||||
const testObject = new FolderSettingsModelParser('settings');
|
||||
|
||||
testObject.parse(JSON.stringify({ 'FolderSettingsModelParser.resource': 'resource', 'FolderSettingsModelParser.anotherExecutable': 'executable' }));
|
||||
|
||||
assert.deepEqual(testObject.configurationModel.contents, { 'FolderSettingsModelParser': { 'resource': 'resource', 'anotherExecutable': 'executable' } });
|
||||
|
||||
const configurationRegistry = <IConfigurationRegistry>Registry.as(ConfigurationExtensions.Configuration);
|
||||
configurationRegistry.registerConfiguration({
|
||||
'id': 'FolderSettingsModelParser_2',
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'FolderSettingsModelParser.anotherExecutable': {
|
||||
'type': 'string',
|
||||
'default': 'isSet',
|
||||
isExecutable: true
|
||||
}
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
const tasksConfig = new ScopedConfigurationModel(JSON.stringify({
|
||||
taskConfig: 'overwritten',
|
||||
}), '', 'tasks');
|
||||
|
||||
const launchConfig = new ScopedConfigurationModel(JSON.stringify({
|
||||
launchConfig: 'overwritten',
|
||||
}), '', 'launch');
|
||||
|
||||
const expected = {
|
||||
awesome: true,
|
||||
launch: {
|
||||
launchConfig: 'overwritten',
|
||||
otherLaunchConfig: 'alsoDefined'
|
||||
},
|
||||
tasks: {
|
||||
taskConfig: 'overwritten',
|
||||
otherTaskConfig: 'alsoDefined'
|
||||
}
|
||||
};
|
||||
|
||||
assert.deepEqual(new FolderConfigurationModel(settingsConfig, [launchConfig, tasksConfig], ConfigurationScope.WINDOW).contents, expected);
|
||||
assert.deepEqual(new FolderConfigurationModel(settingsConfig, [tasksConfig, launchConfig], ConfigurationScope.WINDOW).contents, expected);
|
||||
testObject.reprocess();
|
||||
assert.deepEqual(testObject.configurationModel.contents, { 'FolderSettingsModelParser': { 'resource': 'resource' } });
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
suite('StandaloneConfigurationModelParser', () => {
|
||||
|
||||
test('parse tasks stand alone configuration model', () => {
|
||||
const testObject = new StandaloneConfigurationModelParser('tasks', 'tasks');
|
||||
|
||||
testObject.parse(JSON.stringify({ 'version': '1.1.1', 'tasks': [] }));
|
||||
|
||||
assert.deepEqual(testObject.configurationModel.contents, { 'tasks': { 'version': '1.1.1', 'tasks': [] } });
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
suite('WorkspaceConfigurationChangeEvent', () => {
|
||||
@@ -194,4 +188,50 @@ suite('WorkspaceConfigurationChangeEvent', () => {
|
||||
assert.ok(!testObject.affectsConfiguration('files', URI.file(join('folder3', 'file3'))));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
suite('AllKeysConfigurationChangeEvent', () => {
|
||||
|
||||
test('changeEvent affects keys for any resource', () => {
|
||||
const configuraiton = new Configuration(new ConfigurationModel({}, ['window.title', 'window.zoomLevel', 'window.restoreFullscreen', 'workbench.editor.enablePreview', 'window.restoreWindows']),
|
||||
new ConfigurationModel(), new ConfigurationModel(), new StrictResourceMap(), new ConfigurationModel(), new StrictResourceMap(), null);
|
||||
let testObject = new AllKeysConfigurationChangeEvent(configuraiton, ConfigurationTarget.USER, null);
|
||||
|
||||
assert.deepEqual(testObject.affectedKeys, ['window.title', 'window.zoomLevel', 'window.restoreFullscreen', 'workbench.editor.enablePreview', 'window.restoreWindows']);
|
||||
|
||||
assert.ok(testObject.affectsConfiguration('window.zoomLevel'));
|
||||
assert.ok(testObject.affectsConfiguration('window.zoomLevel', URI.file('file1')));
|
||||
assert.ok(testObject.affectsConfiguration('window.zoomLevel', URI.file('file2')));
|
||||
|
||||
assert.ok(testObject.affectsConfiguration('window.restoreFullscreen'));
|
||||
assert.ok(testObject.affectsConfiguration('window.restoreFullscreen', URI.file('file1')));
|
||||
assert.ok(testObject.affectsConfiguration('window.restoreFullscreen', URI.file('file2')));
|
||||
|
||||
assert.ok(testObject.affectsConfiguration('window.restoreWindows'));
|
||||
assert.ok(testObject.affectsConfiguration('window.restoreWindows', URI.file('file2')));
|
||||
assert.ok(testObject.affectsConfiguration('window.restoreWindows', URI.file('file1')));
|
||||
|
||||
assert.ok(testObject.affectsConfiguration('window.title'));
|
||||
assert.ok(testObject.affectsConfiguration('window.title', URI.file('file1')));
|
||||
assert.ok(testObject.affectsConfiguration('window.title', URI.file('file2')));
|
||||
|
||||
assert.ok(testObject.affectsConfiguration('window'));
|
||||
assert.ok(testObject.affectsConfiguration('window', URI.file('file1')));
|
||||
assert.ok(testObject.affectsConfiguration('window', URI.file('file2')));
|
||||
|
||||
assert.ok(testObject.affectsConfiguration('workbench.editor.enablePreview'));
|
||||
assert.ok(testObject.affectsConfiguration('workbench.editor.enablePreview', URI.file('file2')));
|
||||
assert.ok(testObject.affectsConfiguration('workbench.editor.enablePreview', URI.file('file1')));
|
||||
|
||||
assert.ok(testObject.affectsConfiguration('workbench.editor'));
|
||||
assert.ok(testObject.affectsConfiguration('workbench.editor', URI.file('file2')));
|
||||
assert.ok(testObject.affectsConfiguration('workbench.editor', URI.file('file1')));
|
||||
|
||||
assert.ok(testObject.affectsConfiguration('workbench'));
|
||||
assert.ok(testObject.affectsConfiguration('workbench', URI.file('file2')));
|
||||
assert.ok(testObject.affectsConfiguration('workbench', URI.file('file1')));
|
||||
|
||||
assert.ok(!testObject.affectsConfiguration('files'));
|
||||
assert.ok(!testObject.affectsConfiguration('files', URI.file('file1')));
|
||||
});
|
||||
});
|
||||
@@ -18,7 +18,7 @@ import { parseArgs } from 'vs/platform/environment/node/argv';
|
||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
|
||||
import extfs = require('vs/base/node/extfs');
|
||||
import { TestTextFileService, TestTextResourceConfigurationService, workbenchInstantiationService } from 'vs/workbench/test/workbenchTestServices';
|
||||
import { TestTextFileService, TestTextResourceConfigurationService, workbenchInstantiationService, TestLifecycleService } from 'vs/workbench/test/workbenchTestServices';
|
||||
import uuid = require('vs/base/common/uuid');
|
||||
import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { WorkspaceService } from 'vs/workbench/services/configuration/node/configurationService';
|
||||
@@ -33,12 +33,12 @@ import { ITextModelService } from 'vs/editor/common/services/resolverService';
|
||||
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
|
||||
import { IChoiceService } from 'vs/platform/message/common/message';
|
||||
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
|
||||
import { IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { IWindowConfiguration } from 'vs/platform/windows/common/windows';
|
||||
import { mkdirp } from 'vs/base/node/pfs';
|
||||
|
||||
class SettingsTestEnvironmentService extends EnvironmentService {
|
||||
|
||||
constructor(args: ParsedArgs, _execPath: string, private customAppSettingsHome) {
|
||||
constructor(args: ParsedArgs, _execPath: string, private customAppSettingsHome: string) {
|
||||
super(args, _execPath);
|
||||
}
|
||||
|
||||
@@ -49,9 +49,9 @@ suite('ConfigurationEditingService', () => {
|
||||
|
||||
let instantiationService: TestInstantiationService;
|
||||
let testObject: ConfigurationEditingService;
|
||||
let parentDir;
|
||||
let workspaceDir;
|
||||
let globalSettingsFile;
|
||||
let parentDir: string;
|
||||
let workspaceDir: string;
|
||||
let globalSettingsFile: string;
|
||||
let workspaceSettingsDir;
|
||||
|
||||
suiteSetup(() => {
|
||||
@@ -81,22 +81,15 @@ suite('ConfigurationEditingService', () => {
|
||||
.then(() => setUpServices());
|
||||
});
|
||||
|
||||
function setUpWorkspace(): TPromise<void> {
|
||||
return new TPromise<void>((c, e) => {
|
||||
const id = uuid.generateUuid();
|
||||
parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
workspaceDir = path.join(parentDir, 'workspaceconfig', id);
|
||||
globalSettingsFile = path.join(workspaceDir, 'config.json');
|
||||
// {{SQL CARBON EDIT}}
|
||||
workspaceSettingsDir = path.join(workspaceDir, '.sqlops');
|
||||
extfs.mkdirp(workspaceSettingsDir, 493, (error) => {
|
||||
if (error) {
|
||||
e(error);
|
||||
} else {
|
||||
c(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
function setUpWorkspace(): TPromise<boolean> {
|
||||
const id = uuid.generateUuid();
|
||||
parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
workspaceDir = path.join(parentDir, 'workspaceconfig', id);
|
||||
globalSettingsFile = path.join(workspaceDir, 'config.json');
|
||||
// {{SQL CARBON EDIT}}
|
||||
workspaceSettingsDir = path.join(workspaceDir, '.sqlops');
|
||||
|
||||
return mkdirp(workspaceSettingsDir, 493);
|
||||
}
|
||||
|
||||
function setUpServices(noWorkspace: boolean = false): TPromise<void> {
|
||||
@@ -106,12 +99,11 @@ suite('ConfigurationEditingService', () => {
|
||||
instantiationService = <TestInstantiationService>workbenchInstantiationService();
|
||||
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
|
||||
instantiationService.stub(IEnvironmentService, environmentService);
|
||||
const workspacesService = instantiationService.stub(IWorkspacesService, {});
|
||||
const workspaceService = new WorkspaceService(environmentService, workspacesService);
|
||||
const workspaceService = new WorkspaceService(environmentService);
|
||||
instantiationService.stub(IWorkspaceContextService, workspaceService);
|
||||
return workspaceService.initialize(noWorkspace ? <IWindowConfiguration>{} : workspaceDir).then(() => {
|
||||
return workspaceService.initialize(noWorkspace ? {} as IWindowConfiguration : workspaceDir).then(() => {
|
||||
instantiationService.stub(IConfigurationService, workspaceService);
|
||||
instantiationService.stub(IFileService, new FileService(workspaceService, new TestTextResourceConfigurationService(), new TestConfigurationService(), { disableWatcher: true }));
|
||||
instantiationService.stub(IFileService, new FileService(workspaceService, new TestTextResourceConfigurationService(), new TestConfigurationService(), new TestLifecycleService(), { disableWatcher: true }));
|
||||
instantiationService.stub(ITextFileService, instantiationService.createInstance(TestTextFileService));
|
||||
instantiationService.stub(ITextModelService, <ITextModelService>instantiationService.createInstance(TextModelResolverService));
|
||||
testObject = instantiationService.createInstance(ConfigurationEditingService);
|
||||
@@ -214,6 +206,28 @@ suite('ConfigurationEditingService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('remove an existing setting - existing file', () => {
|
||||
fs.writeFileSync(globalSettingsFile, '{ "my.super.setting": "my.super.value", "configurationEditing.service.testSetting": "value" }');
|
||||
return testObject.writeConfiguration(ConfigurationTarget.USER, { key: 'configurationEditing.service.testSetting', value: undefined })
|
||||
.then(() => {
|
||||
const contents = fs.readFileSync(globalSettingsFile).toString('utf8');
|
||||
const parsed = json.parse(contents);
|
||||
assert.deepEqual(Object.keys(parsed), ['my.super.setting']);
|
||||
assert.equal(parsed['my.super.setting'], 'my.super.value');
|
||||
});
|
||||
});
|
||||
|
||||
test('remove non existing setting - existing file', () => {
|
||||
fs.writeFileSync(globalSettingsFile, '{ "my.super.setting": "my.super.value" }');
|
||||
return testObject.writeConfiguration(ConfigurationTarget.USER, { key: 'configurationEditing.service.testSetting', value: undefined })
|
||||
.then(() => {
|
||||
const contents = fs.readFileSync(globalSettingsFile).toString('utf8');
|
||||
const parsed = json.parse(contents);
|
||||
assert.deepEqual(Object.keys(parsed), ['my.super.setting']);
|
||||
assert.equal(parsed['my.super.setting'], 'my.super.value');
|
||||
});
|
||||
});
|
||||
|
||||
test('write workspace standalone setting - empty file', () => {
|
||||
return testObject.writeConfiguration(ConfigurationTarget.WORKSPACE, { key: 'tasks.service.testSetting', value: 'value' })
|
||||
.then(() => {
|
||||
@@ -249,11 +263,10 @@ suite('ConfigurationEditingService', () => {
|
||||
});
|
||||
|
||||
test('write workspace standalone setting - existing file - full JSON', () => {
|
||||
const target = path.join(workspaceDir, WORKSPACE_STANDALONE_CONFIGURATIONS['launch']);
|
||||
const target = path.join(workspaceDir, WORKSPACE_STANDALONE_CONFIGURATIONS['tasks']);
|
||||
fs.writeFileSync(target, '{ "my.super.setting": "my.super.value" }');
|
||||
return testObject.writeConfiguration(ConfigurationTarget.WORKSPACE, { key: 'tasks', value: { 'version': '1.0.0', tasks: [{ 'taskName': 'myTask' }] } })
|
||||
.then(() => {
|
||||
const target = path.join(workspaceDir, WORKSPACE_STANDALONE_CONFIGURATIONS['tasks']);
|
||||
const contents = fs.readFileSync(target).toString('utf8');
|
||||
const parsed = json.parse(contents);
|
||||
|
||||
@@ -263,11 +276,10 @@ suite('ConfigurationEditingService', () => {
|
||||
});
|
||||
|
||||
test('write workspace standalone setting - existing file with JSON errors - full JSON', () => {
|
||||
const target = path.join(workspaceDir, WORKSPACE_STANDALONE_CONFIGURATIONS['launch']);
|
||||
const target = path.join(workspaceDir, WORKSPACE_STANDALONE_CONFIGURATIONS['tasks']);
|
||||
fs.writeFileSync(target, '{ "my.super.setting": '); // invalid JSON
|
||||
return testObject.writeConfiguration(ConfigurationTarget.WORKSPACE, { key: 'tasks', value: { 'version': '1.0.0', tasks: [{ 'taskName': 'myTask' }] } })
|
||||
.then(() => {
|
||||
const target = path.join(workspaceDir, WORKSPACE_STANDALONE_CONFIGURATIONS['tasks']);
|
||||
const contents = fs.readFileSync(target).toString('utf8');
|
||||
const parsed = json.parse(contents);
|
||||
|
||||
@@ -275,4 +287,25 @@ suite('ConfigurationEditingService', () => {
|
||||
assert.equal(parsed['tasks'][0]['taskName'], 'myTask');
|
||||
});
|
||||
});
|
||||
|
||||
test('write workspace standalone setting should replace complete file', () => {
|
||||
const target = path.join(workspaceDir, WORKSPACE_STANDALONE_CONFIGURATIONS['tasks']);
|
||||
fs.writeFileSync(target, `{
|
||||
"version": "1.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "myTask1"
|
||||
},
|
||||
{
|
||||
"taskName": "myTask2"
|
||||
}
|
||||
]
|
||||
}`);
|
||||
return testObject.writeConfiguration(ConfigurationTarget.WORKSPACE, { key: 'tasks', value: { 'version': '1.0.0', tasks: [{ 'taskName': 'myTask1' }] } })
|
||||
.then(() => {
|
||||
const actual = fs.readFileSync(target).toString('utf8');
|
||||
const expected = JSON.stringify({ 'version': '1.0.0', tasks: [{ 'taskName': 'myTask1' }] }, null, '\t');
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,8 +23,8 @@ import { WorkspaceService } from 'vs/workbench/services/configuration/node/confi
|
||||
import { ConfigurationEditingErrorCode } from 'vs/workbench/services/configuration/node/configurationEditingService';
|
||||
import { FileChangeType, FileChangesEvent, IFileService } from 'vs/platform/files/common/files';
|
||||
import { IWorkspaceContextService, WorkbenchState, IWorkspaceFoldersChangeEvent } from 'vs/platform/workspace/common/workspace';
|
||||
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { workbenchInstantiationService, TestTextResourceConfigurationService, TestTextFileService } from 'vs/workbench/test/workbenchTestServices';
|
||||
import { ConfigurationTarget, IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
|
||||
import { workbenchInstantiationService, TestTextResourceConfigurationService, TestTextFileService, TestLifecycleService } from 'vs/workbench/test/workbenchTestServices';
|
||||
import { FileService } from 'vs/workbench/services/files/node/fileService';
|
||||
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
|
||||
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
|
||||
@@ -32,6 +32,9 @@ import { ITextModelService } from 'vs/editor/common/services/resolverService';
|
||||
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
|
||||
import { IJSONEditingService } from 'vs/workbench/services/configuration/common/jsonEditing';
|
||||
import { JSONEditingService } from 'vs/workbench/services/configuration/node/jsonEditingService';
|
||||
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
|
||||
import { IWindowConfiguration } from 'vs/platform/windows/common/windows';
|
||||
import { mkdirp } from 'vs/base/node/pfs';
|
||||
|
||||
class SettingsTestEnvironmentService extends EnvironmentService {
|
||||
|
||||
@@ -53,13 +56,7 @@ function setUpFolder(folderName: string, parentDir: string): TPromise<string> {
|
||||
// {{SQL CARBON EDIT}}
|
||||
const workspaceSettingsDir = path.join(folderDir, '.sqlops');
|
||||
return new TPromise((c, e) => {
|
||||
extfs.mkdirp(workspaceSettingsDir, 493, (error) => {
|
||||
if (error) {
|
||||
e(error);
|
||||
return null;
|
||||
}
|
||||
c(folderDir);
|
||||
});
|
||||
extfs.mkdirp(workspaceSettingsDir, 493);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -68,7 +65,7 @@ function setUpWorkspace(folders: string[]): TPromise<{ parentDir: string, config
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
|
||||
return createDir(parentDir)
|
||||
return mkdirp(parentDir, 493)
|
||||
.then(() => {
|
||||
const configPath = path.join(parentDir, 'vsctests.code-workspace');
|
||||
const workspace = { folders: folders.map(path => ({ path })) };
|
||||
@@ -80,617 +77,10 @@ function setUpWorkspace(folders: string[]): TPromise<{ parentDir: string, config
|
||||
|
||||
}
|
||||
|
||||
function createDir(dir: string): TPromise<void> {
|
||||
return new TPromise((c, e) => {
|
||||
extfs.mkdirp(dir, 493, (error) => {
|
||||
if (error) {
|
||||
e(error);
|
||||
return null;
|
||||
}
|
||||
c(null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
suite('WorkspaceContextService - Folder', () => {
|
||||
|
||||
let workspaceName = `testWorkspace${uuid.generateUuid()}`, parentResource: string, workspaceResource: string, workspaceContextService: IWorkspaceContextService;
|
||||
|
||||
setup(() => {
|
||||
return setUpFolderWorkspace(workspaceName)
|
||||
.then(({ parentDir, folderDir }) => {
|
||||
parentResource = parentDir;
|
||||
workspaceResource = folderDir;
|
||||
const globalSettingsFile = path.join(parentDir, 'settings.json');
|
||||
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
|
||||
workspaceContextService = new WorkspaceService(environmentService, null);
|
||||
return (<WorkspaceService>workspaceContextService).initialize(folderDir);
|
||||
});
|
||||
});
|
||||
|
||||
teardown(done => {
|
||||
if (workspaceContextService) {
|
||||
(<WorkspaceService>workspaceContextService).dispose();
|
||||
}
|
||||
if (parentResource) {
|
||||
extfs.del(parentResource, os.tmpdir(), () => { }, done);
|
||||
}
|
||||
});
|
||||
|
||||
test('getWorkspace()', () => {
|
||||
const actual = workspaceContextService.getWorkspace();
|
||||
|
||||
assert.equal(actual.folders.length, 1);
|
||||
assert.equal(actual.folders[0].uri.fsPath, URI.file(workspaceResource).fsPath);
|
||||
assert.equal(actual.folders[0].name, workspaceName);
|
||||
assert.equal(actual.folders[0].index, 0);
|
||||
assert.ok(!actual.configuration);
|
||||
});
|
||||
|
||||
test('getWorkbenchState()', () => {
|
||||
const actual = workspaceContextService.getWorkbenchState();
|
||||
|
||||
assert.equal(actual, WorkbenchState.FOLDER);
|
||||
});
|
||||
|
||||
test('getWorkspaceFolder()', () => {
|
||||
const actual = workspaceContextService.getWorkspaceFolder(URI.file(path.join(workspaceResource, 'a')));
|
||||
|
||||
assert.equal(actual, workspaceContextService.getWorkspace().folders[0]);
|
||||
});
|
||||
|
||||
test('isCurrentWorkspace() => true', () => {
|
||||
assert.ok(workspaceContextService.isCurrentWorkspace(workspaceResource));
|
||||
});
|
||||
|
||||
test('isCurrentWorkspace() => false', () => {
|
||||
assert.ok(!workspaceContextService.isCurrentWorkspace(workspaceResource + 'abc'));
|
||||
});
|
||||
});
|
||||
|
||||
suite('WorkspaceContextService - Workspace', () => {
|
||||
|
||||
let parentResource: string, testObject: WorkspaceService;
|
||||
|
||||
setup(() => {
|
||||
return setUpWorkspace(['a', 'b'])
|
||||
.then(({ parentDir, configPath }) => {
|
||||
|
||||
parentResource = parentDir;
|
||||
|
||||
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, path.join(parentDir, 'settings.json'));
|
||||
const workspaceService = new WorkspaceService(environmentService, null);
|
||||
|
||||
const instantiationService = <TestInstantiationService>workbenchInstantiationService();
|
||||
instantiationService.stub(IWorkspaceContextService, workspaceService);
|
||||
instantiationService.stub(IConfigurationService, workspaceService);
|
||||
instantiationService.stub(IEnvironmentService, environmentService);
|
||||
|
||||
return workspaceService.initialize({ id: configPath, configPath }).then(() => {
|
||||
|
||||
instantiationService.stub(IFileService, new FileService(<IWorkspaceContextService>workspaceService, new TestTextResourceConfigurationService(), workspaceService, { disableWatcher: true }));
|
||||
instantiationService.stub(ITextFileService, instantiationService.createInstance(TestTextFileService));
|
||||
instantiationService.stub(ITextModelService, <ITextModelService>instantiationService.createInstance(TextModelResolverService));
|
||||
workspaceService.setInstantiationService(instantiationService);
|
||||
|
||||
testObject = workspaceService;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
teardown(done => {
|
||||
if (testObject) {
|
||||
(<WorkspaceService>testObject).dispose();
|
||||
}
|
||||
if (parentResource) {
|
||||
extfs.del(parentResource, os.tmpdir(), () => { }, done);
|
||||
}
|
||||
});
|
||||
|
||||
test('workspace folders', () => {
|
||||
const actual = testObject.getWorkspace().folders;
|
||||
|
||||
assert.equal(actual.length, 2);
|
||||
assert.equal(path.basename(actual[0].uri.fsPath), 'a');
|
||||
assert.equal(path.basename(actual[1].uri.fsPath), 'b');
|
||||
});
|
||||
|
||||
test('add folders', () => {
|
||||
const workspaceDir = path.dirname(testObject.getWorkspace().folders[0].uri.fsPath);
|
||||
return testObject.addFolders([{ uri: URI.file(path.join(workspaceDir, 'd')) }, { uri: URI.file(path.join(workspaceDir, 'c')) }])
|
||||
.then(() => {
|
||||
const actual = testObject.getWorkspace().folders;
|
||||
|
||||
assert.equal(actual.length, 4);
|
||||
assert.equal(path.basename(actual[0].uri.fsPath), 'a');
|
||||
assert.equal(path.basename(actual[1].uri.fsPath), 'b');
|
||||
assert.equal(path.basename(actual[2].uri.fsPath), 'd');
|
||||
assert.equal(path.basename(actual[3].uri.fsPath), 'c');
|
||||
});
|
||||
});
|
||||
|
||||
test('add folders (with name)', () => {
|
||||
const workspaceDir = path.dirname(testObject.getWorkspace().folders[0].uri.fsPath);
|
||||
return testObject.addFolders([{ uri: URI.file(path.join(workspaceDir, 'd')), name: 'DDD' }, { uri: URI.file(path.join(workspaceDir, 'c')), name: 'CCC' }])
|
||||
.then(() => {
|
||||
const actual = testObject.getWorkspace().folders;
|
||||
|
||||
assert.equal(actual.length, 4);
|
||||
assert.equal(path.basename(actual[0].uri.fsPath), 'a');
|
||||
assert.equal(path.basename(actual[1].uri.fsPath), 'b');
|
||||
assert.equal(path.basename(actual[2].uri.fsPath), 'd');
|
||||
assert.equal(path.basename(actual[3].uri.fsPath), 'c');
|
||||
assert.equal(actual[2].name, 'DDD');
|
||||
assert.equal(actual[3].name, 'CCC');
|
||||
});
|
||||
});
|
||||
|
||||
test('add folders triggers change event', () => {
|
||||
const target = sinon.spy();
|
||||
testObject.onDidChangeWorkspaceFolders(target);
|
||||
const workspaceDir = path.dirname(testObject.getWorkspace().folders[0].uri.fsPath);
|
||||
const addedFolders = [{ uri: URI.file(path.join(workspaceDir, 'd')) }, { uri: URI.file(path.join(workspaceDir, 'c')) }];
|
||||
return testObject.addFolders(addedFolders)
|
||||
.then(() => {
|
||||
assert.ok(target.calledOnce);
|
||||
const actual = <IWorkspaceFoldersChangeEvent>target.args[0][0];
|
||||
assert.deepEqual(actual.added.map(r => r.uri.toString()), addedFolders.map(a => a.uri.toString()));
|
||||
assert.deepEqual(actual.removed, []);
|
||||
assert.deepEqual(actual.changed, []);
|
||||
});
|
||||
});
|
||||
|
||||
test('remove folders', () => {
|
||||
return testObject.removeFolders([testObject.getWorkspace().folders[0].uri])
|
||||
.then(() => {
|
||||
const actual = testObject.getWorkspace().folders;
|
||||
assert.equal(actual.length, 1);
|
||||
assert.equal(path.basename(actual[0].uri.fsPath), 'b');
|
||||
});
|
||||
});
|
||||
|
||||
test('remove folders triggers change event', () => {
|
||||
const target = sinon.spy();
|
||||
testObject.onDidChangeWorkspaceFolders(target);
|
||||
const removedFolder = testObject.getWorkspace().folders[0];
|
||||
return testObject.removeFolders([removedFolder.uri])
|
||||
.then(() => {
|
||||
assert.ok(target.calledOnce);
|
||||
const actual = <IWorkspaceFoldersChangeEvent>target.args[0][0];
|
||||
assert.deepEqual(actual.added, []);
|
||||
assert.deepEqual(actual.removed.map(r => r.uri.toString()), [removedFolder.uri.toString()]);
|
||||
assert.deepEqual(actual.changed.map(c => c.uri.toString()), [testObject.getWorkspace().folders[0].uri.toString()]);
|
||||
});
|
||||
});
|
||||
|
||||
test('reorder folders trigger change event', () => {
|
||||
const target = sinon.spy();
|
||||
testObject.onDidChangeWorkspaceFolders(target);
|
||||
const workspace = { folders: [{ path: testObject.getWorkspace().folders[1].uri.fsPath }, { path: testObject.getWorkspace().folders[0].uri.fsPath }] };
|
||||
fs.writeFileSync(testObject.getWorkspace().configuration.fsPath, JSON.stringify(workspace, null, '\t'));
|
||||
return testObject.reloadConfiguration()
|
||||
.then(() => {
|
||||
assert.ok(target.calledOnce);
|
||||
const actual = <IWorkspaceFoldersChangeEvent>target.args[0][0];
|
||||
assert.deepEqual(actual.added, []);
|
||||
assert.deepEqual(actual.removed, []);
|
||||
assert.deepEqual(actual.changed.map(c => c.uri.toString()), testObject.getWorkspace().folders.map(f => f.uri.toString()).reverse());
|
||||
});
|
||||
});
|
||||
|
||||
test('rename folders trigger change event', () => {
|
||||
const target = sinon.spy();
|
||||
testObject.onDidChangeWorkspaceFolders(target);
|
||||
const workspace = { folders: [{ path: testObject.getWorkspace().folders[0].uri.fsPath, name: '1' }, { path: testObject.getWorkspace().folders[1].uri.fsPath }] };
|
||||
fs.writeFileSync(testObject.getWorkspace().configuration.fsPath, JSON.stringify(workspace, null, '\t'));
|
||||
return testObject.reloadConfiguration()
|
||||
.then(() => {
|
||||
assert.ok(target.calledOnce);
|
||||
const actual = <IWorkspaceFoldersChangeEvent>target.args[0][0];
|
||||
assert.deepEqual(actual.added, []);
|
||||
assert.deepEqual(actual.removed, []);
|
||||
assert.deepEqual(actual.changed.map(c => c.uri.toString()), [testObject.getWorkspace().folders[0].uri.toString()]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
suite('WorkspaceConfigurationService - Folder', () => {
|
||||
|
||||
let workspaceName = `testWorkspace${uuid.generateUuid()}`, parentResource: string, workspaceDir: string, testObject: IConfigurationService, globalSettingsFile: string;
|
||||
|
||||
suiteSetup(() => {
|
||||
const configurationRegistry = <IConfigurationRegistry>Registry.as(ConfigurationExtensions.Configuration);
|
||||
configurationRegistry.registerConfiguration({
|
||||
'id': '_test',
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'configurationService.folder.testSetting': {
|
||||
'type': 'string',
|
||||
'default': 'isSet'
|
||||
},
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
setup(() => {
|
||||
return setUpFolderWorkspace(workspaceName)
|
||||
.then(({ parentDir, folderDir }) => {
|
||||
|
||||
parentResource = parentDir;
|
||||
workspaceDir = folderDir;
|
||||
globalSettingsFile = path.join(parentDir, 'settings.json');
|
||||
|
||||
const instantiationService = <TestInstantiationService>workbenchInstantiationService();
|
||||
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
|
||||
const workspaceService = new WorkspaceService(environmentService, null);
|
||||
instantiationService.stub(IWorkspaceContextService, workspaceService);
|
||||
instantiationService.stub(IConfigurationService, workspaceService);
|
||||
instantiationService.stub(IEnvironmentService, environmentService);
|
||||
|
||||
return workspaceService.initialize(folderDir).then(() => {
|
||||
instantiationService.stub(IFileService, new FileService(<IWorkspaceContextService>workspaceService, new TestTextResourceConfigurationService(), workspaceService, { disableWatcher: true }));
|
||||
instantiationService.stub(ITextFileService, instantiationService.createInstance(TestTextFileService));
|
||||
instantiationService.stub(ITextModelService, <ITextModelService>instantiationService.createInstance(TextModelResolverService));
|
||||
workspaceService.setInstantiationService(instantiationService);
|
||||
testObject = workspaceService;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
teardown(done => {
|
||||
if (testObject) {
|
||||
(<WorkspaceService>testObject).dispose();
|
||||
}
|
||||
if (parentResource) {
|
||||
extfs.del(parentResource, os.tmpdir(), () => { }, done);
|
||||
}
|
||||
});
|
||||
|
||||
test('defaults', () => {
|
||||
assert.deepEqual(testObject.getValue('configurationService'), { 'folder': { 'testSetting': 'isSet' } });
|
||||
});
|
||||
|
||||
test('globals override defaults', () => {
|
||||
fs.writeFileSync(globalSettingsFile, '{ "configurationService.folder.testSetting": "userValue" }');
|
||||
return testObject.reloadConfiguration()
|
||||
.then(() => assert.equal(testObject.getValue('configurationService.folder.testSetting'), 'userValue'));
|
||||
});
|
||||
|
||||
test('globals', () => {
|
||||
fs.writeFileSync(globalSettingsFile, '{ "testworkbench.editor.tabs": true }');
|
||||
return testObject.reloadConfiguration()
|
||||
.then(() => assert.equal(testObject.getValue('testworkbench.editor.tabs'), true));
|
||||
});
|
||||
|
||||
test('workspace settings', () => {
|
||||
// {{SQL CARBON EDIT}}
|
||||
fs.writeFileSync(path.join(workspaceDir, '.sqlops', 'settings.json'), '{ "testworkbench.editor.icons": true }');
|
||||
return testObject.reloadConfiguration()
|
||||
.then(() => assert.equal(testObject.getValue('testworkbench.editor.icons'), true));
|
||||
});
|
||||
|
||||
test('workspace settings override user settings', () => {
|
||||
fs.writeFileSync(globalSettingsFile, '{ "configurationService.folder.testSetting": "userValue" }');
|
||||
// {{SQL CARBON EDIT}}
|
||||
fs.writeFileSync(path.join(workspaceDir, '.sqlops', 'settings.json'), '{ "configurationService.folder.testSetting": "workspaceValue" }');
|
||||
return testObject.reloadConfiguration()
|
||||
.then(() => assert.equal(testObject.getValue('configurationService.folder.testSetting'), 'workspaceValue'));
|
||||
});
|
||||
|
||||
test('workspace change triggers event', () => {
|
||||
// {{SQL CARBON EDIT}}
|
||||
const settingsFile = path.join(workspaceDir, '.sqlops', 'settings.json');
|
||||
fs.writeFileSync(settingsFile, '{ "configurationService.folder.testSetting": "workspaceValue" }');
|
||||
const event = new FileChangesEvent([{ resource: URI.file(settingsFile), type: FileChangeType.ADDED }]);
|
||||
const target = sinon.spy();
|
||||
testObject.onDidChangeConfiguration(target);
|
||||
return (<WorkspaceService>testObject).handleWorkspaceFileEvents(event)
|
||||
.then(() => {
|
||||
assert.equal(testObject.getValue('configurationService.folder.testSetting'), 'workspaceValue');
|
||||
assert.ok(target.called);
|
||||
});
|
||||
});
|
||||
|
||||
test('reload configuration emits events after global configuraiton changes', () => {
|
||||
fs.writeFileSync(globalSettingsFile, '{ "testworkbench.editor.tabs": true }');
|
||||
const target = sinon.spy();
|
||||
testObject.onDidChangeConfiguration(target);
|
||||
return testObject.reloadConfiguration().then(() => assert.ok(target.called));
|
||||
});
|
||||
|
||||
test('reload configuration emits events after workspace configuraiton changes', () => {
|
||||
// {{SQL CARBON EDIT}}
|
||||
fs.writeFileSync(path.join(workspaceDir, '.sqlops', 'settings.json'), '{ "configurationService.folder.testSetting": "workspaceValue" }');
|
||||
const target = sinon.spy();
|
||||
testObject.onDidChangeConfiguration(target);
|
||||
return testObject.reloadConfiguration().then(() => assert.ok(target.called));
|
||||
});
|
||||
|
||||
test('reload configuration should not emit event if no changes', () => {
|
||||
fs.writeFileSync(globalSettingsFile, '{ "testworkbench.editor.tabs": true }');
|
||||
// {{SQL CARBON EDIT}}
|
||||
fs.writeFileSync(path.join(workspaceDir, '.sqlops', 'settings.json'), '{ "configurationService.folder.testSetting": "workspaceValue" }');
|
||||
return testObject.reloadConfiguration()
|
||||
.then(() => {
|
||||
const target = sinon.spy();
|
||||
testObject.onDidChangeConfiguration(() => { target(); });
|
||||
return testObject.reloadConfiguration()
|
||||
.then(() => assert.ok(!target.called));
|
||||
});
|
||||
});
|
||||
|
||||
test('inspect', () => {
|
||||
let actual = testObject.inspect('something.missing');
|
||||
assert.equal(actual.default, void 0);
|
||||
assert.equal(actual.user, void 0);
|
||||
assert.equal(actual.workspace, void 0);
|
||||
assert.equal(actual.workspaceFolder, void 0);
|
||||
assert.equal(actual.value, void 0);
|
||||
|
||||
actual = testObject.inspect('configurationService.folder.testSetting');
|
||||
assert.equal(actual.default, 'isSet');
|
||||
assert.equal(actual.user, void 0);
|
||||
assert.equal(actual.workspace, void 0);
|
||||
assert.equal(actual.workspaceFolder, void 0);
|
||||
assert.equal(actual.value, 'isSet');
|
||||
|
||||
fs.writeFileSync(globalSettingsFile, '{ "configurationService.folder.testSetting": "userValue" }');
|
||||
return testObject.reloadConfiguration()
|
||||
.then(() => {
|
||||
actual = testObject.inspect('configurationService.folder.testSetting');
|
||||
assert.equal(actual.default, 'isSet');
|
||||
assert.equal(actual.user, 'userValue');
|
||||
assert.equal(actual.workspace, void 0);
|
||||
assert.equal(actual.workspaceFolder, void 0);
|
||||
assert.equal(actual.value, 'userValue');
|
||||
|
||||
// {{SQL CARBON EDIT}}
|
||||
fs.writeFileSync(path.join(workspaceDir, '.sqlops', 'settings.json'), '{ "configurationService.folder.testSetting": "workspaceValue" }');
|
||||
|
||||
return testObject.reloadConfiguration()
|
||||
.then(() => {
|
||||
actual = testObject.inspect('configurationService.folder.testSetting');
|
||||
assert.equal(actual.default, 'isSet');
|
||||
assert.equal(actual.user, 'userValue');
|
||||
assert.equal(actual.workspace, 'workspaceValue');
|
||||
assert.equal(actual.workspaceFolder, void 0);
|
||||
assert.equal(actual.value, 'workspaceValue');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('keys', () => {
|
||||
let actual = testObject.keys();
|
||||
assert.ok(actual.default.indexOf('configurationService.folder.testSetting') !== -1);
|
||||
assert.deepEqual(actual.user, []);
|
||||
assert.deepEqual(actual.workspace, []);
|
||||
assert.deepEqual(actual.workspaceFolder, []);
|
||||
|
||||
fs.writeFileSync(globalSettingsFile, '{ "configurationService.folder.testSetting": "userValue" }');
|
||||
return testObject.reloadConfiguration()
|
||||
.then(() => {
|
||||
actual = testObject.keys();
|
||||
assert.ok(actual.default.indexOf('configurationService.folder.testSetting') !== -1);
|
||||
assert.deepEqual(actual.user, ['configurationService.folder.testSetting']);
|
||||
assert.deepEqual(actual.workspace, []);
|
||||
assert.deepEqual(actual.workspaceFolder, []);
|
||||
|
||||
// {{SQL CARBON EDIT}}
|
||||
fs.writeFileSync(path.join(workspaceDir, '.sqlops', 'settings.json'), '{ "configurationService.folder.testSetting": "workspaceValue" }');
|
||||
|
||||
return testObject.reloadConfiguration()
|
||||
.then(() => {
|
||||
actual = testObject.keys();
|
||||
assert.ok(actual.default.indexOf('configurationService.folder.testSetting') !== -1);
|
||||
assert.deepEqual(actual.user, ['configurationService.folder.testSetting']);
|
||||
assert.deepEqual(actual.workspace, ['configurationService.folder.testSetting']);
|
||||
assert.deepEqual(actual.workspaceFolder, []);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('update user configuration', () => {
|
||||
return testObject.updateValue('configurationService.folder.testSetting', 'value', ConfigurationTarget.USER)
|
||||
.then(() => assert.equal(testObject.getValue('configurationService.folder.testSetting'), 'value'));
|
||||
});
|
||||
|
||||
test('update workspace configuration', () => {
|
||||
return testObject.updateValue('tasks.service.testSetting', 'value', ConfigurationTarget.WORKSPACE)
|
||||
.then(() => assert.equal(testObject.getValue('tasks.service.testSetting'), 'value'));
|
||||
});
|
||||
|
||||
test('update tasks configuration', () => {
|
||||
return testObject.updateValue('tasks', { 'version': '1.0.0', tasks: [{ 'taskName': 'myTask' }] }, ConfigurationTarget.WORKSPACE)
|
||||
.then(() => assert.deepEqual(testObject.getValue('tasks'), { 'version': '1.0.0', tasks: [{ 'taskName': 'myTask' }] }));
|
||||
});
|
||||
|
||||
test('update user configuration should trigger change event before promise is resolve', () => {
|
||||
const target = sinon.spy();
|
||||
testObject.onDidChangeConfiguration(target);
|
||||
return testObject.updateValue('configurationService.folder.testSetting', 'value', ConfigurationTarget.USER)
|
||||
.then(() => assert.ok(target.called));
|
||||
});
|
||||
|
||||
test('update workspace configuration should trigger change event before promise is resolve', () => {
|
||||
const target = sinon.spy();
|
||||
testObject.onDidChangeConfiguration(target);
|
||||
return testObject.updateValue('configurationService.folder.testSetting', 'value', ConfigurationTarget.WORKSPACE)
|
||||
.then(() => assert.ok(target.called));
|
||||
});
|
||||
|
||||
test('update task configuration should trigger change event before promise is resolve', () => {
|
||||
const target = sinon.spy();
|
||||
testObject.onDidChangeConfiguration(target);
|
||||
return testObject.updateValue('tasks', { 'version': '1.0.0', tasks: [{ 'taskName': 'myTask' }] }, ConfigurationTarget.WORKSPACE)
|
||||
.then(() => assert.ok(target.called));
|
||||
});
|
||||
|
||||
test('initialize with different folder triggers configuration event if there are changes', () => {
|
||||
return setUpFolderWorkspace(`testWorkspace${uuid.generateUuid()}`)
|
||||
.then(({ folderDir }) => {
|
||||
const target = sinon.spy();
|
||||
testObject.onDidChangeConfiguration(target);
|
||||
|
||||
// {{SQL CARBON EDIT}}
|
||||
fs.writeFileSync(path.join(folderDir, '.sqlops', 'settings.json'), '{ "configurationService.folder.testSetting": "workspaceValue2" }');
|
||||
return (<WorkspaceService>testObject).initialize(folderDir)
|
||||
.then(() => {
|
||||
assert.equal(testObject.getValue('configurationService.folder.testSetting'), 'workspaceValue2');
|
||||
assert.ok(target.called);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('initialize with different folder triggers configuration event if there are no changes', () => {
|
||||
fs.writeFileSync(globalSettingsFile, '{ "configurationService.folder.testSetting": "workspaceValue2" }');
|
||||
return testObject.reloadConfiguration()
|
||||
.then(() => setUpFolderWorkspace(`testWorkspace${uuid.generateUuid()}`))
|
||||
.then(({ folderDir }) => {
|
||||
const target = sinon.spy();
|
||||
testObject.onDidChangeConfiguration(() => target());
|
||||
// {{SQL CARBON EDIT}}
|
||||
fs.writeFileSync(path.join(folderDir, '.sqlops', 'settings.json'), '{ "configurationService.folder.testSetting": "workspaceValue2" }');
|
||||
return (<WorkspaceService>testObject).initialize(folderDir)
|
||||
.then(() => {
|
||||
assert.equal(testObject.getValue('configurationService.folder.testSetting'), 'workspaceValue2');
|
||||
assert.ok(!target.called);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('WorkspaceConfigurationService - Update (Multiroot)', () => {
|
||||
|
||||
let parentResource: string, workspaceContextService: IWorkspaceContextService, jsonEditingServce: IJSONEditingService, testObject: IConfigurationService;
|
||||
|
||||
suiteSetup(() => {
|
||||
const configurationRegistry = <IConfigurationRegistry>Registry.as(ConfigurationExtensions.Configuration);
|
||||
configurationRegistry.registerConfiguration({
|
||||
'id': '_test',
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'configurationService.workspace.testSetting': {
|
||||
'type': 'string',
|
||||
'default': 'isSet'
|
||||
},
|
||||
'configurationService.workspace.testResourceSetting': {
|
||||
'type': 'string',
|
||||
'default': 'isSet',
|
||||
scope: ConfigurationScope.RESOURCE
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
setup(() => {
|
||||
return setUpWorkspace(['1', '2'])
|
||||
.then(({ parentDir, configPath }) => {
|
||||
|
||||
parentResource = parentDir;
|
||||
|
||||
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, path.join(parentDir, 'settings.json'));
|
||||
const workspaceService = new WorkspaceService(environmentService, null);
|
||||
|
||||
const instantiationService = <TestInstantiationService>workbenchInstantiationService();
|
||||
instantiationService.stub(IWorkspaceContextService, workspaceService);
|
||||
instantiationService.stub(IConfigurationService, workspaceService);
|
||||
instantiationService.stub(IEnvironmentService, environmentService);
|
||||
|
||||
return workspaceService.initialize({ id: configPath, configPath }).then(() => {
|
||||
|
||||
instantiationService.stub(IFileService, new FileService(<IWorkspaceContextService>workspaceService, new TestTextResourceConfigurationService(), workspaceService, { disableWatcher: true }));
|
||||
instantiationService.stub(ITextFileService, instantiationService.createInstance(TestTextFileService));
|
||||
instantiationService.stub(ITextModelService, <ITextModelService>instantiationService.createInstance(TextModelResolverService));
|
||||
workspaceService.setInstantiationService(instantiationService);
|
||||
|
||||
workspaceContextService = workspaceService;
|
||||
jsonEditingServce = instantiationService.createInstance(JSONEditingService);
|
||||
testObject = workspaceService;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
teardown(done => {
|
||||
if (testObject) {
|
||||
(<WorkspaceService>testObject).dispose();
|
||||
}
|
||||
if (parentResource) {
|
||||
extfs.del(parentResource, os.tmpdir(), () => { }, done);
|
||||
}
|
||||
});
|
||||
|
||||
test('update user configuration', () => {
|
||||
return testObject.updateValue('configurationService.workspace.testSetting', 'userValue', ConfigurationTarget.USER)
|
||||
.then(() => assert.equal(testObject.getValue('configurationService.workspace.testSetting'), 'userValue'));
|
||||
});
|
||||
|
||||
test('update user configuration should trigger change event before promise is resolve', () => {
|
||||
const target = sinon.spy();
|
||||
testObject.onDidChangeConfiguration(target);
|
||||
return testObject.updateValue('configurationService.workspace.testSetting', 'userValue', ConfigurationTarget.USER)
|
||||
.then(() => assert.ok(target.called));
|
||||
});
|
||||
|
||||
test('update workspace configuration', () => {
|
||||
return testObject.updateValue('configurationService.workspace.testSetting', 'workspaceValue', ConfigurationTarget.WORKSPACE)
|
||||
.then(() => assert.equal(testObject.getValue('configurationService.workspace.testSetting'), 'workspaceValue'));
|
||||
});
|
||||
|
||||
test('update workspace configuration should trigger change event before promise is resolve', () => {
|
||||
const target = sinon.spy();
|
||||
testObject.onDidChangeConfiguration(target);
|
||||
return testObject.updateValue('configurationService.workspace.testSetting', 'workspaceValue', ConfigurationTarget.WORKSPACE)
|
||||
.then(() => assert.ok(target.called));
|
||||
});
|
||||
|
||||
test('update workspace folder configuration', () => {
|
||||
const workspace = workspaceContextService.getWorkspace();
|
||||
return testObject.updateValue('configurationService.workspace.testResourceSetting', 'workspaceFolderValue', { resource: workspace.folders[0].uri }, ConfigurationTarget.WORKSPACE_FOLDER)
|
||||
.then(() => assert.equal(testObject.getValue('configurationService.workspace.testResourceSetting', { resource: workspace.folders[0].uri }), 'workspaceFolderValue'));
|
||||
});
|
||||
|
||||
test('update workspace folder configuration should trigger change event before promise is resolve', () => {
|
||||
const workspace = workspaceContextService.getWorkspace();
|
||||
const target = sinon.spy();
|
||||
testObject.onDidChangeConfiguration(target);
|
||||
return testObject.updateValue('configurationService.workspace.testResourceSetting', 'workspaceFolderValue', { resource: workspace.folders[0].uri }, ConfigurationTarget.WORKSPACE_FOLDER)
|
||||
.then(() => assert.ok(target.called));
|
||||
});
|
||||
|
||||
test('update tasks configuration in a folder', () => {
|
||||
const workspace = workspaceContextService.getWorkspace();
|
||||
return testObject.updateValue('tasks', { 'version': '1.0.0', tasks: [{ 'taskName': 'myTask' }] }, { resource: workspace.folders[0].uri }, ConfigurationTarget.WORKSPACE_FOLDER)
|
||||
.then(() => assert.deepEqual(testObject.getValue('tasks', { resource: workspace.folders[0].uri }), { 'version': '1.0.0', tasks: [{ 'taskName': 'myTask' }] }));
|
||||
});
|
||||
|
||||
test('update tasks configuration in a workspace is not supported', () => {
|
||||
const workspace = workspaceContextService.getWorkspace();
|
||||
return testObject.updateValue('tasks', { 'version': '1.0.0', tasks: [{ 'taskName': 'myTask' }] }, { resource: workspace.folders[0].uri }, ConfigurationTarget.WORKSPACE, true)
|
||||
.then(() => assert.fail('Should not be supported'), (e) => assert.equal(e.code, ConfigurationEditingErrorCode.ERROR_INVALID_WORKSPACE_TARGET));
|
||||
});
|
||||
|
||||
test('update launch configuration in a workspace is not supported', () => {
|
||||
const workspace = workspaceContextService.getWorkspace();
|
||||
return testObject.updateValue('launch', { 'version': '1.0.0', configurations: [{ 'name': 'myLaunch' }] }, { resource: workspace.folders[0].uri }, ConfigurationTarget.WORKSPACE, true)
|
||||
.then(() => assert.fail('Should not be supported'), (e) => assert.equal(e.code, ConfigurationEditingErrorCode.ERROR_INVALID_WORKSPACE_TARGET));
|
||||
});
|
||||
|
||||
test('task configurations are not read from workspace', () => {
|
||||
return jsonEditingServce.write(workspaceContextService.getWorkspace().configuration, { key: 'tasks', value: { 'version': '1.0' } }, true)
|
||||
.then(() => testObject.reloadConfiguration())
|
||||
.then(() => {
|
||||
const actual = testObject.inspect('tasks.version');
|
||||
assert.equal(actual.workspace, void 0);
|
||||
});
|
||||
});
|
||||
|
||||
test('launch configurations are not read from workspace', () => {
|
||||
return jsonEditingServce.write(workspaceContextService.getWorkspace().configuration, { key: 'launch', value: { 'version': '1.0' } }, true)
|
||||
.then(() => testObject.reloadConfiguration())
|
||||
.then(() => {
|
||||
const actual = testObject.inspect('launch.version');
|
||||
assert.equal(actual.workspace, void 0);
|
||||
});
|
||||
assert.equal(0, 0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user