@@ -9,6 +9,7 @@ import assert = require('assert');
99import os = require( 'os' ) ;
1010import path = require( 'path' ) ;
1111import fs = require( 'fs' ) ;
12+ import * as sinon from 'sinon' ;
1213import { TPromise } from 'vs/base/common/winjs.base' ;
1314import { Registry } from 'vs/platform/platform' ;
1415import { ParsedArgs } from 'vs/platform/environment/common/environment' ;
@@ -227,6 +228,75 @@ suite('WorkspaceConfigurationService - Node', () => {
227228 } ) ;
228229 } ) ;
229230
231+ test ( 'workspace reload should triggers event if content changed' , ( done : ( ) => void ) => {
232+ createWorkspace ( ( workspaceDir , globalSettingsFile , cleanUp ) => {
233+ const workspaceContextService = new WorkspaceContextService ( { resource : URI . file ( workspaceDir ) } ) ;
234+ const environmentService = new SettingsTestEnvironmentService ( parseArgs ( process . argv ) , process . execPath , globalSettingsFile ) ;
235+ const service = new WorkspaceConfigurationService ( workspaceContextService , environmentService ) ;
236+
237+ return service . initialize ( ) . then ( ( ) => {
238+ const settingsFile = path . join ( workspaceDir , '.vscode' , 'settings.json' ) ;
239+ fs . writeFileSync ( settingsFile , '{ "testworkbench.editor.icons": true }' ) ;
240+
241+ const target = sinon . stub ( ) ;
242+ service . onDidUpdateConfiguration ( event => target ( ) ) ;
243+
244+ fs . writeFileSync ( settingsFile , '{ "testworkbench.editor.icons": false }' ) ;
245+
246+ service . reloadConfiguration ( ) . done ( ( ) => {
247+ assert . ok ( target . calledOnce ) ;
248+ service . dispose ( ) ;
249+
250+ cleanUp ( done ) ;
251+ } ) ;
252+ } ) ;
253+ } ) ;
254+ } ) ;
255+
256+ test ( 'workspace reload should not trigger event if nothing changed' , ( done : ( ) => void ) => {
257+ createWorkspace ( ( workspaceDir , globalSettingsFile , cleanUp ) => {
258+ const workspaceContextService = new WorkspaceContextService ( { resource : URI . file ( workspaceDir ) } ) ;
259+ const environmentService = new SettingsTestEnvironmentService ( parseArgs ( process . argv ) , process . execPath , globalSettingsFile ) ;
260+ const service = new WorkspaceConfigurationService ( workspaceContextService , environmentService ) ;
261+
262+ return service . initialize ( ) . then ( ( ) => {
263+ const settingsFile = path . join ( workspaceDir , '.vscode' , 'settings.json' ) ;
264+ fs . writeFileSync ( settingsFile , '{ "testworkbench.editor.icons": true }' ) ;
265+
266+ service . reloadConfiguration ( ) . done ( ( ) => {
267+ const target = sinon . stub ( ) ;
268+ service . onDidUpdateConfiguration ( event => target ( ) ) ;
269+
270+ service . reloadConfiguration ( ) . done ( ( ) => {
271+ assert . ok ( ! target . called ) ;
272+ service . dispose ( ) ;
273+
274+ cleanUp ( done ) ;
275+ } ) ;
276+ } ) ;
277+ } ) ;
278+ } ) ;
279+ } ) ;
280+
281+ test ( 'workspace reload should not trigger event if there is no model' , ( done : ( ) => void ) => {
282+ createWorkspace ( ( workspaceDir , globalSettingsFile , cleanUp ) => {
283+ const workspaceContextService = new WorkspaceContextService ( { resource : URI . file ( workspaceDir ) } ) ;
284+ const environmentService = new SettingsTestEnvironmentService ( parseArgs ( process . argv ) , process . execPath , globalSettingsFile ) ;
285+ const service = new WorkspaceConfigurationService ( workspaceContextService , environmentService ) ;
286+
287+ return service . initialize ( ) . then ( ( ) => {
288+ const target = sinon . stub ( ) ;
289+ service . onDidUpdateConfiguration ( event => target ( ) ) ;
290+ service . reloadConfiguration ( ) . done ( ( ) => {
291+ assert . ok ( ! target . called ) ;
292+ service . dispose ( ) ;
293+ cleanUp ( done ) ;
294+ } ) ;
295+ } ) ;
296+ } ) ;
297+ } ) ;
298+
299+
230300 test ( 'lookup' , ( done : ( ) => void ) => {
231301 const configurationRegistry = < IConfigurationRegistry > Registry . as ( ConfigurationExtensions . Configuration ) ;
232302 configurationRegistry . registerConfiguration ( {
0 commit comments