mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-06 14:24:04 -05:00
Fix #25508
- Let workspace configuration service fire change event during reload configuration and if configuration changes - Tests
This commit is contained in:
@@ -167,7 +167,16 @@ export class WorkspaceConfigurationService extends Disposable implements IWorksp
|
||||
|
||||
// Load configuration
|
||||
return this.baseConfigurationService.reloadConfiguration().then(() => {
|
||||
const current = this.cachedConfig;
|
||||
return this.doLoadConfiguration().then(configuration => {
|
||||
// emit this as update to listeners if changed
|
||||
if (!objects.equals(current, this.cachedConfig)) {
|
||||
this._onDidUpdateConfiguration.fire({
|
||||
config: configuration.consolidated,
|
||||
source: ConfigurationSource.Workspace,
|
||||
sourceConfig: configuration.workspace
|
||||
});
|
||||
}
|
||||
return section ? configuration.consolidated[section] : configuration.consolidated;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,6 +9,7 @@ import assert = require('assert');
|
||||
import os = require('os');
|
||||
import path = require('path');
|
||||
import fs = require('fs');
|
||||
import * as sinon from 'sinon';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { Registry } from 'vs/platform/platform';
|
||||
import { ParsedArgs } from 'vs/platform/environment/common/environment';
|
||||
@@ -227,6 +228,75 @@ suite('WorkspaceConfigurationService - Node', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('workspace reload should triggers event if content changed', (done: () => void) => {
|
||||
createWorkspace((workspaceDir, globalSettingsFile, cleanUp) => {
|
||||
const workspaceContextService = new WorkspaceContextService({ resource: URI.file(workspaceDir) });
|
||||
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
|
||||
const service = new WorkspaceConfigurationService(workspaceContextService, environmentService);
|
||||
|
||||
return service.initialize().then(() => {
|
||||
const settingsFile = path.join(workspaceDir, '.vscode', 'settings.json');
|
||||
fs.writeFileSync(settingsFile, '{ "testworkbench.editor.icons": true }');
|
||||
|
||||
const target = sinon.stub();
|
||||
service.onDidUpdateConfiguration(event => target());
|
||||
|
||||
fs.writeFileSync(settingsFile, '{ "testworkbench.editor.icons": false }');
|
||||
|
||||
service.reloadConfiguration().done(() => {
|
||||
assert.ok(target.calledOnce);
|
||||
service.dispose();
|
||||
|
||||
cleanUp(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('workspace reload should not trigger event if nothing changed', (done: () => void) => {
|
||||
createWorkspace((workspaceDir, globalSettingsFile, cleanUp) => {
|
||||
const workspaceContextService = new WorkspaceContextService({ resource: URI.file(workspaceDir) });
|
||||
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
|
||||
const service = new WorkspaceConfigurationService(workspaceContextService, environmentService);
|
||||
|
||||
return service.initialize().then(() => {
|
||||
const settingsFile = path.join(workspaceDir, '.vscode', 'settings.json');
|
||||
fs.writeFileSync(settingsFile, '{ "testworkbench.editor.icons": true }');
|
||||
|
||||
service.reloadConfiguration().done(() => {
|
||||
const target = sinon.stub();
|
||||
service.onDidUpdateConfiguration(event => target());
|
||||
|
||||
service.reloadConfiguration().done(() => {
|
||||
assert.ok(!target.called);
|
||||
service.dispose();
|
||||
|
||||
cleanUp(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('workspace reload should not trigger event if there is no model', (done: () => void) => {
|
||||
createWorkspace((workspaceDir, globalSettingsFile, cleanUp) => {
|
||||
const workspaceContextService = new WorkspaceContextService({ resource: URI.file(workspaceDir) });
|
||||
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
|
||||
const service = new WorkspaceConfigurationService(workspaceContextService, environmentService);
|
||||
|
||||
return service.initialize().then(() => {
|
||||
const target = sinon.stub();
|
||||
service.onDidUpdateConfiguration(event => target());
|
||||
service.reloadConfiguration().done(() => {
|
||||
assert.ok(!target.called);
|
||||
service.dispose();
|
||||
cleanUp(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('lookup', (done: () => void) => {
|
||||
const configurationRegistry = <IConfigurationRegistry>Registry.as(ConfigurationExtensions.Configuration);
|
||||
configurationRegistry.registerConfiguration({
|
||||
|
||||
Reference in New Issue
Block a user