Archived
Merge from master
This commit is contained in:
@@ -3,8 +3,6 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
@@ -30,53 +28,57 @@ class SettingsTestEnvironmentService extends EnvironmentService {
|
||||
|
||||
suite('ConfigurationService - Node', () => {
|
||||
|
||||
test('simple', () => {
|
||||
return testFile('config', 'config.json').then(res => {
|
||||
fs.writeFileSync(res.testFile, '{ "foo": "bar" }');
|
||||
test('simple', async () => {
|
||||
const res = await testFile('config', 'config.json');
|
||||
fs.writeFileSync(res.testFile, '{ "foo": "bar" }');
|
||||
|
||||
const service = new ConfigurationService(new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, res.testFile));
|
||||
const service = new ConfigurationService(new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, res.testFile));
|
||||
const config = service.getValue<{
|
||||
foo: string;
|
||||
}>();
|
||||
|
||||
const config = service.getValue<{ foo: string }>();
|
||||
assert.ok(config);
|
||||
assert.equal(config.foo, 'bar');
|
||||
assert.ok(config);
|
||||
assert.equal(config.foo, 'bar');
|
||||
service.dispose();
|
||||
|
||||
service.dispose();
|
||||
|
||||
return res.cleanUp();
|
||||
});
|
||||
return res.cleanUp();
|
||||
});
|
||||
|
||||
test('config gets flattened', () => {
|
||||
return testFile('config', 'config.json').then(res => {
|
||||
fs.writeFileSync(res.testFile, '{ "testworkbench.editor.tabs": true }');
|
||||
test('config gets flattened', async () => {
|
||||
const res = await testFile('config', 'config.json');
|
||||
|
||||
const service = new ConfigurationService(new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, res.testFile));
|
||||
fs.writeFileSync(res.testFile, '{ "testworkbench.editor.tabs": true }');
|
||||
|
||||
const config = service.getValue<{ testworkbench: { editor: { tabs: boolean } } }>();
|
||||
assert.ok(config);
|
||||
assert.ok(config.testworkbench);
|
||||
assert.ok(config.testworkbench.editor);
|
||||
assert.equal(config.testworkbench.editor.tabs, true);
|
||||
const service = new ConfigurationService(new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, res.testFile));
|
||||
const config = service.getValue<{
|
||||
testworkbench: {
|
||||
editor: {
|
||||
tabs: boolean;
|
||||
};
|
||||
};
|
||||
}>();
|
||||
assert.ok(config);
|
||||
assert.ok(config.testworkbench);
|
||||
assert.ok(config.testworkbench.editor);
|
||||
assert.equal(config.testworkbench.editor.tabs, true);
|
||||
|
||||
service.dispose();
|
||||
|
||||
return res.cleanUp();
|
||||
});
|
||||
service.dispose();
|
||||
return res.cleanUp();
|
||||
});
|
||||
|
||||
test('error case does not explode', () => {
|
||||
return testFile('config', 'config.json').then(res => {
|
||||
fs.writeFileSync(res.testFile, ',,,,');
|
||||
test('error case does not explode', async () => {
|
||||
const res = await testFile('config', 'config.json');
|
||||
|
||||
const service = new ConfigurationService(new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, res.testFile));
|
||||
fs.writeFileSync(res.testFile, ',,,,');
|
||||
|
||||
const config = service.getValue<{ foo: string }>();
|
||||
assert.ok(config);
|
||||
const service = new ConfigurationService(new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, res.testFile));
|
||||
const config = service.getValue<{
|
||||
foo: string;
|
||||
}>();
|
||||
assert.ok(config);
|
||||
|
||||
service.dispose();
|
||||
|
||||
return res.cleanUp();
|
||||
});
|
||||
service.dispose();
|
||||
return res.cleanUp();
|
||||
});
|
||||
|
||||
test('missing file does not explode', () => {
|
||||
@@ -93,34 +95,51 @@ suite('ConfigurationService - Node', () => {
|
||||
service.dispose();
|
||||
});
|
||||
|
||||
test('reloadConfiguration', () => {
|
||||
return testFile('config', 'config.json').then(res => {
|
||||
fs.writeFileSync(res.testFile, '{ "foo": "bar" }');
|
||||
|
||||
const service = new ConfigurationService(new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, res.testFile));
|
||||
|
||||
let config = service.getValue<{ foo: string }>();
|
||||
assert.ok(config);
|
||||
assert.equal(config.foo, 'bar');
|
||||
|
||||
fs.writeFileSync(res.testFile, '{ "foo": "changed" }');
|
||||
|
||||
// still outdated
|
||||
config = service.getValue<{ foo: string }>();
|
||||
assert.ok(config);
|
||||
assert.equal(config.foo, 'bar');
|
||||
|
||||
// force a reload to get latest
|
||||
return service.reloadConfiguration().then(() => {
|
||||
config = service.getValue<{ foo: string }>();
|
||||
assert.ok(config);
|
||||
assert.equal(config.foo, 'changed');
|
||||
test('trigger configuration change event', async () => {
|
||||
const res = await testFile('config', 'config.json');
|
||||
|
||||
const service = new ConfigurationService(new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, res.testFile));
|
||||
return new Promise((c, e) => {
|
||||
service.onDidChangeConfiguration(() => {
|
||||
assert.equal(service.getValue('foo'), 'bar');
|
||||
service.dispose();
|
||||
|
||||
return res.cleanUp();
|
||||
c();
|
||||
});
|
||||
fs.writeFileSync(res.testFile, '{ "foo": "bar" }');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test('reloadConfiguration', async () => {
|
||||
const res = await testFile('config', 'config.json');
|
||||
|
||||
fs.writeFileSync(res.testFile, '{ "foo": "bar" }');
|
||||
|
||||
const service = new ConfigurationService(new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, res.testFile));
|
||||
let config = service.getValue<{
|
||||
foo: string;
|
||||
}>();
|
||||
assert.ok(config);
|
||||
assert.equal(config.foo, 'bar');
|
||||
fs.writeFileSync(res.testFile, '{ "foo": "changed" }');
|
||||
|
||||
// still outdated
|
||||
config = service.getValue<{
|
||||
foo: string;
|
||||
}>();
|
||||
assert.ok(config);
|
||||
assert.equal(config.foo, 'bar');
|
||||
|
||||
// force a reload to get latest
|
||||
await service.reloadConfiguration();
|
||||
config = service.getValue<{
|
||||
foo: string;
|
||||
}>();
|
||||
assert.ok(config);
|
||||
assert.equal(config.foo, 'changed');
|
||||
|
||||
service.dispose();
|
||||
return res.cleanUp();
|
||||
});
|
||||
|
||||
test('model defaults', () => {
|
||||
@@ -150,7 +169,7 @@ suite('ConfigurationService - Node', () => {
|
||||
assert.ok(setting);
|
||||
assert.equal(setting.configuration.service.testSetting, 'isSet');
|
||||
|
||||
return testFile('config', 'config.json').then(res => {
|
||||
return testFile('config', 'config.json').then(async res => {
|
||||
fs.writeFileSync(res.testFile, '{ "testworkbench.editor.tabs": true }');
|
||||
|
||||
const service = new ConfigurationService(new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, res.testFile));
|
||||
@@ -162,21 +181,17 @@ suite('ConfigurationService - Node', () => {
|
||||
|
||||
fs.writeFileSync(res.testFile, '{ "configuration.service.testSetting": "isChanged" }');
|
||||
|
||||
return service.reloadConfiguration().then(() => {
|
||||
let setting = service.getValue<ITestSetting>();
|
||||
|
||||
assert.ok(setting);
|
||||
assert.equal(setting.configuration.service.testSetting, 'isChanged');
|
||||
|
||||
service.dispose();
|
||||
serviceWithoutFile.dispose();
|
||||
|
||||
return res.cleanUp();
|
||||
});
|
||||
await service.reloadConfiguration();
|
||||
let setting_1 = service.getValue<ITestSetting>();
|
||||
assert.ok(setting_1);
|
||||
assert.equal(setting_1.configuration.service.testSetting, 'isChanged');
|
||||
service.dispose();
|
||||
serviceWithoutFile.dispose();
|
||||
return res.cleanUp();
|
||||
});
|
||||
});
|
||||
|
||||
test('lookup', () => {
|
||||
test('lookup', async () => {
|
||||
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
|
||||
configurationRegistry.registerConfiguration({
|
||||
'id': '_test',
|
||||
@@ -189,35 +204,31 @@ suite('ConfigurationService - Node', () => {
|
||||
}
|
||||
});
|
||||
|
||||
return testFile('config', 'config.json').then(r => {
|
||||
const service = new ConfigurationService(new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, r.testFile));
|
||||
const r = await testFile('config', 'config.json');
|
||||
const service = new ConfigurationService(new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, r.testFile));
|
||||
let res = service.inspect('something.missing');
|
||||
assert.strictEqual(res.value, void 0);
|
||||
assert.strictEqual(res.default, void 0);
|
||||
assert.strictEqual(res.user, void 0);
|
||||
|
||||
let res = service.inspect('something.missing');
|
||||
assert.strictEqual(res.value, void 0);
|
||||
assert.strictEqual(res.default, void 0);
|
||||
assert.strictEqual(res.user, void 0);
|
||||
res = service.inspect('lookup.service.testSetting');
|
||||
assert.strictEqual(res.default, 'isSet');
|
||||
assert.strictEqual(res.value, 'isSet');
|
||||
assert.strictEqual(res.user, void 0);
|
||||
|
||||
res = service.inspect('lookup.service.testSetting');
|
||||
assert.strictEqual(res.default, 'isSet');
|
||||
assert.strictEqual(res.value, 'isSet');
|
||||
assert.strictEqual(res.user, void 0);
|
||||
fs.writeFileSync(r.testFile, '{ "lookup.service.testSetting": "bar" }');
|
||||
|
||||
fs.writeFileSync(r.testFile, '{ "lookup.service.testSetting": "bar" }');
|
||||
await service.reloadConfiguration();
|
||||
res = service.inspect('lookup.service.testSetting');
|
||||
assert.strictEqual(res.default, 'isSet');
|
||||
assert.strictEqual(res.user, 'bar');
|
||||
assert.strictEqual(res.value, 'bar');
|
||||
|
||||
return service.reloadConfiguration().then(() => {
|
||||
res = service.inspect('lookup.service.testSetting');
|
||||
assert.strictEqual(res.default, 'isSet');
|
||||
assert.strictEqual(res.user, 'bar');
|
||||
assert.strictEqual(res.value, 'bar');
|
||||
|
||||
service.dispose();
|
||||
|
||||
return r.cleanUp();
|
||||
});
|
||||
});
|
||||
service.dispose();
|
||||
return r.cleanUp();
|
||||
});
|
||||
|
||||
test('lookup with null', () => {
|
||||
test('lookup with null', async () => {
|
||||
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
|
||||
configurationRegistry.registerConfiguration({
|
||||
'id': '_testNull',
|
||||
@@ -229,26 +240,23 @@ suite('ConfigurationService - Node', () => {
|
||||
}
|
||||
});
|
||||
|
||||
return testFile('config', 'config.json').then(r => {
|
||||
const service = new ConfigurationService(new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, r.testFile));
|
||||
const r = await testFile('config', 'config.json');
|
||||
const service = new ConfigurationService(new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, r.testFile));
|
||||
let res = service.inspect('lookup.service.testNullSetting');
|
||||
assert.strictEqual(res.default, null);
|
||||
assert.strictEqual(res.value, null);
|
||||
assert.strictEqual(res.user, void 0);
|
||||
|
||||
let res = service.inspect('lookup.service.testNullSetting');
|
||||
assert.strictEqual(res.default, null);
|
||||
assert.strictEqual(res.value, null);
|
||||
assert.strictEqual(res.user, void 0);
|
||||
fs.writeFileSync(r.testFile, '{ "lookup.service.testNullSetting": null }');
|
||||
|
||||
fs.writeFileSync(r.testFile, '{ "lookup.service.testNullSetting": null }');
|
||||
await service.reloadConfiguration();
|
||||
|
||||
return service.reloadConfiguration().then(() => {
|
||||
res = service.inspect('lookup.service.testNullSetting');
|
||||
assert.strictEqual(res.default, null);
|
||||
assert.strictEqual(res.value, null);
|
||||
assert.strictEqual(res.user, null);
|
||||
res = service.inspect('lookup.service.testNullSetting');
|
||||
assert.strictEqual(res.default, null);
|
||||
assert.strictEqual(res.value, null);
|
||||
assert.strictEqual(res.user, null);
|
||||
|
||||
service.dispose();
|
||||
|
||||
return r.cleanUp();
|
||||
});
|
||||
});
|
||||
service.dispose();
|
||||
return r.cleanUp();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user