configurationModels.test.ts 3.0 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

7
import * as assert from 'assert';
8
import { FolderConfigurationModel, ScopedConfigurationModel, FolderSettingsModel } from 'vs/workbench/services/configuration/common/configurationModels';
9
import { ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
E
Erich Gamma 已提交
10 11 12

suite('ConfigurationService - Model', () => {

S
Sandeep Somavarapu 已提交
13
	test('Test scoped configs are undefined', () => {
14
		const settingsConfig = new FolderSettingsModel(JSON.stringify({
S
Sandeep Somavarapu 已提交
15 16 17
			awesome: true
		}));

S
Sandeep Somavarapu 已提交
18
		const testObject = new FolderConfigurationModel(settingsConfig, [], ConfigurationScope.WINDOW);
S
Sandeep Somavarapu 已提交
19

S
Sandeep Somavarapu 已提交
20
		assert.equal(testObject.getContentsFor('task'), undefined);
S
Sandeep Somavarapu 已提交
21 22
	});

E
Erich Gamma 已提交
23
	test('Test consolidate (settings and tasks)', () => {
24
		const settingsConfig = new FolderSettingsModel(JSON.stringify({
25 26
			awesome: true
		}));
E
Erich Gamma 已提交
27

28
		const tasksConfig = new ScopedConfigurationModel(JSON.stringify({
29 30
			awesome: false
		}), '', 'tasks');
31 32

		const expected = {
E
Erich Gamma 已提交
33 34 35 36 37 38
			awesome: true,
			tasks: {
				awesome: false
			}
		};

S
Sandeep Somavarapu 已提交
39
		assert.deepEqual(new FolderConfigurationModel(settingsConfig, [tasksConfig], ConfigurationScope.WINDOW).contents, expected);
40 41 42
	});

	test('Test consolidate (settings and launch)', () => {
43
		const settingsConfig = new FolderSettingsModel(JSON.stringify({
44 45
			awesome: true
		}));
46

47
		const launchConfig = new ScopedConfigurationModel(JSON.stringify({
48 49
			awesome: false
		}), '', 'launch');
50 51 52 53 54 55 56 57

		const expected = {
			awesome: true,
			launch: {
				awesome: false
			}
		};

S
Sandeep Somavarapu 已提交
58
		assert.deepEqual(new FolderConfigurationModel(settingsConfig, [launchConfig], ConfigurationScope.WINDOW).contents, expected);
59 60 61
	});

	test('Test consolidate (settings and launch and tasks) - launch/tasks wins over settings file', () => {
62
		const settingsConfig = new FolderSettingsModel(JSON.stringify({
63 64 65 66 67 68 69 70
			awesome: true,
			launch: {
				launchConfig: 'defined',
				otherLaunchConfig: 'alsoDefined'
			},
			tasks: {
				taskConfig: 'defined',
				otherTaskConfig: 'alsoDefined'
71
			}
72
		}));
73

74
		const tasksConfig = new ScopedConfigurationModel(JSON.stringify({
75 76
			taskConfig: 'overwritten',
		}), '', 'tasks');
77

78
		const launchConfig = new ScopedConfigurationModel(JSON.stringify({
79 80
			launchConfig: 'overwritten',
		}), '', 'launch');
81 82 83 84 85 86 87 88 89 90 91 92 93

		const expected = {
			awesome: true,
			launch: {
				launchConfig: 'overwritten',
				otherLaunchConfig: 'alsoDefined'
			},
			tasks: {
				taskConfig: 'overwritten',
				otherTaskConfig: 'alsoDefined'
			}
		};

S
Sandeep Somavarapu 已提交
94 95
		assert.deepEqual(new FolderConfigurationModel(settingsConfig, [launchConfig, tasksConfig], ConfigurationScope.WINDOW).contents, expected);
		assert.deepEqual(new FolderConfigurationModel(settingsConfig, [tasksConfig, launchConfig], ConfigurationScope.WINDOW).contents, expected);
E
Erich Gamma 已提交
96
	});
97
});