提交 1bf1bc2c 编写于 作者: M Matt Bierner

Use async/await in tests

上级 3ad13abc
......@@ -46,38 +46,34 @@ suite('Suggest', function () {
model.dispose();
});
test('sort - snippet inline', function () {
return provideSuggestionItems(model, new Position(1, 1), 'inline').then(items => {
assert.equal(items.length, 3);
assert.equal(items[0].suggestion.label, 'aaa');
assert.equal(items[1].suggestion.label, 'fff');
assert.equal(items[2].suggestion.label, 'zzz');
});
test('sort - snippet inline', async function () {
const items = await provideSuggestionItems(model, new Position(1, 1), 'inline');
assert.equal(items.length, 3);
assert.equal(items[0].suggestion.label, 'aaa');
assert.equal(items[1].suggestion.label, 'fff');
assert.equal(items[2].suggestion.label, 'zzz');
});
test('sort - snippet top', function () {
return provideSuggestionItems(model, new Position(1, 1), 'top').then(items => {
assert.equal(items.length, 3);
assert.equal(items[0].suggestion.label, 'aaa');
assert.equal(items[1].suggestion.label, 'zzz');
assert.equal(items[2].suggestion.label, 'fff');
});
test('sort - snippet top', async function () {
const items = await provideSuggestionItems(model, new Position(1, 1), 'top');
assert.equal(items.length, 3);
assert.equal(items[0].suggestion.label, 'aaa');
assert.equal(items[1].suggestion.label, 'zzz');
assert.equal(items[2].suggestion.label, 'fff');
});
test('sort - snippet bottom', function () {
return provideSuggestionItems(model, new Position(1, 1), 'bottom').then(items => {
assert.equal(items.length, 3);
assert.equal(items[0].suggestion.label, 'fff');
assert.equal(items[1].suggestion.label, 'aaa');
assert.equal(items[2].suggestion.label, 'zzz');
});
test('sort - snippet bottom', async function () {
const items = await provideSuggestionItems(model, new Position(1, 1), 'bottom');
assert.equal(items.length, 3);
assert.equal(items[0].suggestion.label, 'fff');
assert.equal(items[1].suggestion.label, 'aaa');
assert.equal(items[2].suggestion.label, 'zzz');
});
test('sort - snippet none', function () {
return provideSuggestionItems(model, new Position(1, 1), 'none').then(items => {
assert.equal(items.length, 1);
assert.equal(items[0].suggestion.label, 'fff');
});
test('sort - snippet none', async function () {
const items = await provideSuggestionItems(model, new Position(1, 1), 'none');
assert.equal(items.length, 1);
assert.equal(items[0].suggestion.label, 'fff');
});
test('only from', function () {
......
......@@ -28,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 config = service.getValue<{ foo: string }>();
assert.ok(config);
assert.equal(config.foo, 'bar');
const service = new ConfigurationService(new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, res.testFile));
const config = service.getValue<{
foo: string;
}>();
service.dispose();
assert.ok(config);
assert.equal(config.foo, 'bar');
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);
service.dispose();
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);
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);
service.dispose();
const service = new ConfigurationService(new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, res.testFile));
const config = service.getValue<{
foo: string;
}>();
assert.ok(config);
return res.cleanUp();
});
service.dispose();
return res.cleanUp();
});
test('missing file does not explode', () => {
......@@ -91,34 +95,36 @@ 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');
test('reloadConfiguration', async () => {
const res = await testFile('config', 'config.json');
fs.writeFileSync(res.testFile, '{ "foo": "changed" }');
fs.writeFileSync(res.testFile, '{ "foo": "bar" }');
// still outdated
config = service.getValue<{ foo: string }>();
assert.ok(config);
assert.equal(config.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" }');
// force a reload to get latest
return service.reloadConfiguration().then(() => {
config = service.getValue<{ foo: string }>();
assert.ok(config);
assert.equal(config.foo, 'changed');
// still outdated
config = service.getValue<{
foo: string;
}>();
assert.ok(config);
assert.equal(config.foo, 'bar');
service.dispose();
// force a reload to get latest
await service.reloadConfiguration();
config = service.getValue<{
foo: string;
}>();
assert.ok(config);
assert.equal(config.foo, 'changed');
return res.cleanUp();
});
});
service.dispose();
return res.cleanUp();
});
test('model defaults', () => {
......@@ -148,7 +154,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));
......@@ -160,21 +166,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',
......@@ -187,35 +189,31 @@ suite('ConfigurationService - Node', () => {
}
});
return testFile('config', 'config.json').then(r => {
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);
res = service.inspect('lookup.service.testSetting');
assert.strictEqual(res.default, 'isSet');
assert.strictEqual(res.value, 'isSet');
assert.strictEqual(res.user, void 0);
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);
fs.writeFileSync(r.testFile, '{ "lookup.service.testSetting": "bar" }');
res = service.inspect('lookup.service.testSetting');
assert.strictEqual(res.default, 'isSet');
assert.strictEqual(res.value, 'isSet');
assert.strictEqual(res.user, void 0);
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');
fs.writeFileSync(r.testFile, '{ "lookup.service.testSetting": "bar" }');
service.dispose();
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 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',
......@@ -227,26 +225,23 @@ suite('ConfigurationService - Node', () => {
}
});
return testFile('config', 'config.json').then(r => {
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);
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);
fs.writeFileSync(r.testFile, '{ "lookup.service.testNullSetting": null }');
fs.writeFileSync(r.testFile, '{ "lookup.service.testNullSetting": null }');
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);
await service.reloadConfiguration();
service.dispose();
res = service.inspect('lookup.service.testNullSetting');
assert.strictEqual(res.default, null);
assert.strictEqual(res.value, null);
assert.strictEqual(res.user, null);
return r.cleanUp();
});
});
service.dispose();
return r.cleanUp();
});
});
......@@ -12,10 +12,9 @@ import { ScanCodeBinding, ScanCode } from 'vs/base/common/scanCode';
const WRITE_FILE_IF_DIFFERENT = false;
function createKeyboardMapper(isUSStandard: boolean, file: string): TPromise<WindowsKeyboardMapper> {
return readRawMapping<IWindowsKeyboardMapping>(file).then((rawMappings) => {
return new WindowsKeyboardMapper(isUSStandard, rawMappings);
});
async function createKeyboardMapper(isUSStandard: boolean, file: string): TPromise<WindowsKeyboardMapper> {
const rawMappings = await readRawMapping<IWindowsKeyboardMapping>(file);
return new WindowsKeyboardMapper(isUSStandard, rawMappings);
}
function _assertResolveKeybinding(mapper: WindowsKeyboardMapper, k: number, expected: IResolvedKeybinding[]): void {
......@@ -26,10 +25,8 @@ suite('keyboardMapper - WINDOWS de_ch', () => {
let mapper: WindowsKeyboardMapper;
suiteSetup(() => {
return createKeyboardMapper(false, 'win_de_ch').then((_mapper) => {
mapper = _mapper;
});
suiteSetup(async () => {
mapper = await createKeyboardMapper(false, 'win_de_ch');
});
test('mapping', () => {
......@@ -318,10 +315,8 @@ suite('keyboardMapper - WINDOWS en_us', () => {
let mapper: WindowsKeyboardMapper;
suiteSetup(() => {
return createKeyboardMapper(true, 'win_en_us').then((_mapper) => {
mapper = _mapper;
});
suiteSetup(async () => {
mapper = await createKeyboardMapper(true, 'win_en_us');
});
test('mapping', () => {
......@@ -406,10 +401,8 @@ suite('keyboardMapper - WINDOWS por_ptb', () => {
let mapper: WindowsKeyboardMapper;
suiteSetup(() => {
return createKeyboardMapper(false, 'win_por_ptb').then((_mapper) => {
mapper = _mapper;
});
suiteSetup(async () => {
mapper = await createKeyboardMapper(false, 'win_por_ptb');
});
test('mapping', () => {
......@@ -467,10 +460,8 @@ suite('keyboardMapper - WINDOWS ru', () => {
let mapper: WindowsKeyboardMapper;
suiteSetup(() => {
return createKeyboardMapper(false, 'win_ru').then((_mapper) => {
mapper = _mapper;
});
suiteSetup(async () => {
mapper = await createKeyboardMapper(false, 'win_ru');
});
test('mapping', () => {
......
......@@ -91,7 +91,7 @@ suite('SearchService', () => {
path: path.normalize('/some/where')
};
test('Individual results', function () {
test('Individual results', async function () {
this.timeout(testTimeout);
let i = 5;
const Engine = TestSearchEngine.bind(null, () => i-- && rawMatch);
......@@ -107,11 +107,11 @@ suite('SearchService', () => {
}
};
return service.doFileSearch(Engine, rawSearch, cb)
.then(() => assert.strictEqual(results, 5));
await service.doFileSearch(Engine, rawSearch, cb);
return assert.strictEqual(results, 5);
});
test('Batch results', function () {
test('Batch results', async function () {
this.timeout(testTimeout);
let i = 25;
const Engine = TestSearchEngine.bind(null, () => i-- && rawMatch);
......@@ -129,12 +129,11 @@ suite('SearchService', () => {
}
};
return service.doFileSearch(Engine, rawSearch, cb, undefined, 10).then(() => {
assert.deepStrictEqual(results, [10, 10, 5]);
});
await service.doFileSearch(Engine, rawSearch, cb, undefined, 10);
assert.deepStrictEqual(results, [10, 10, 5]);
});
test('Collect batched results', function () {
test('Collect batched results', async function () {
this.timeout(testTimeout);
const uriPath = '/some/where';
let i = 25;
......@@ -163,14 +162,12 @@ suite('SearchService', () => {
progressResults.push(match);
};
return DiskSearch.collectResultsFromEvent(fileSearch(rawSearch, 10), onProgress)
.then(result => {
assert.strictEqual(result.results.length, 25, 'Result');
assert.strictEqual(progressResults.length, 25, 'Progress');
});
const result_2 = await DiskSearch.collectResultsFromEvent(fileSearch(rawSearch, 10), onProgress);
assert.strictEqual(result_2.results.length, 25, 'Result');
assert.strictEqual(progressResults.length, 25, 'Progress');
});
test('Multi-root with include pattern and maxResults', function () {
test('Multi-root with include pattern and maxResults', async function () {
this.timeout(testTimeout);
const service = new RawSearchService();
......@@ -183,13 +180,11 @@ suite('SearchService', () => {
},
};
return DiskSearch.collectResultsFromEvent(service.fileSearch(query))
.then(result => {
assert.strictEqual(result.results.length, 1, 'Result');
});
const result = await DiskSearch.collectResultsFromEvent(service.fileSearch(query));
assert.strictEqual(result.results.length, 1, 'Result');
});
test('Multi-root with include pattern and exists', function () {
test('Multi-root with include pattern and exists', async function () {
this.timeout(testTimeout);
const service = new RawSearchService();
......@@ -202,14 +197,12 @@ suite('SearchService', () => {
},
};
return DiskSearch.collectResultsFromEvent(service.fileSearch(query))
.then(result => {
assert.strictEqual(result.results.length, 0, 'Result');
assert.ok(result.limitHit);
});
const result = await DiskSearch.collectResultsFromEvent(service.fileSearch(query));
assert.strictEqual(result.results.length, 0, 'Result');
assert.ok(result.limitHit);
});
test('Sorted results', function () {
test('Sorted results', async function () {
this.timeout(testTimeout);
const paths = ['bab', 'bbc', 'abb'];
const matches: IRawFileMatch[] = paths.map(relativePath => ({
......@@ -230,18 +223,17 @@ suite('SearchService', () => {
}
};
return service.doFileSearch(Engine, {
await service.doFileSearch(Engine, {
folderQueries: TEST_FOLDER_QUERIES,
filePattern: 'bb',
sortByScore: true,
maxResults: 2
}, cb, undefined, 1).then(() => {
assert.notStrictEqual(typeof TestSearchEngine.last.config.maxResults, 'number');
assert.deepStrictEqual(results, [path.normalize('/some/where/bbc'), path.normalize('/some/where/bab')]);
});
}, cb, undefined, 1);
assert.notStrictEqual(typeof TestSearchEngine.last.config.maxResults, 'number');
assert.deepStrictEqual(results, [path.normalize('/some/where/bbc'), path.normalize('/some/where/bab')]);
});
test('Sorted result batches', function () {
test('Sorted result batches', async function () {
this.timeout(testTimeout);
let i = 25;
const Engine = TestSearchEngine.bind(null, () => i-- && rawMatch);
......@@ -258,15 +250,13 @@ suite('SearchService', () => {
assert.fail(JSON.stringify(value));
}
};
return service.doFileSearch(Engine, {
await service.doFileSearch(Engine, {
folderQueries: TEST_FOLDER_QUERIES,
filePattern: 'a',
sortByScore: true,
maxResults: 23
}, cb, undefined, 10)
.then(() => {
assert.deepStrictEqual(results, [10, 10, 3]);
});
}, cb, undefined, 10);
assert.deepStrictEqual(results, [10, 10, 3]);
});
test('Cached results', function () {
......@@ -297,7 +287,7 @@ suite('SearchService', () => {
}, cb, undefined, -1).then(complete => {
assert.strictEqual((<IFileSearchStats>complete.stats).fromCache, false);
assert.deepStrictEqual(results, [path.normalize('/some/where/bcb'), path.normalize('/some/where/bbc'), path.normalize('/some/where/aab')]);
}).then(() => {
}).then(async () => {
const results = [];
const cb = value => {
if (Array.isArray(value)) {
......@@ -306,18 +296,20 @@ suite('SearchService', () => {
assert.fail(JSON.stringify(value));
}
};
return service.doFileSearch(Engine, {
folderQueries: TEST_FOLDER_QUERIES,
filePattern: 'bc',
sortByScore: true,
cacheKey: 'x'
}, cb, undefined, -1).then(complete => {
try {
const complete = await service.doFileSearch(Engine, {
folderQueries: TEST_FOLDER_QUERIES,
filePattern: 'bc',
sortByScore: true,
cacheKey: 'x'
}, cb, undefined, -1);
assert.ok((<IFileSearchStats>complete.stats).fromCache);
assert.deepStrictEqual(results, [path.normalize('/some/where/bcb'), path.normalize('/some/where/bbc')]);
}, null);
}
catch (e) { }
}).then(() => {
return service.clearCache('x');
}).then(() => {
}).then(async () => {
matches.push({
base: path.normalize('/some/where'),
relativePath: 'bc',
......@@ -332,15 +324,14 @@ suite('SearchService', () => {
assert.fail(JSON.stringify(value));
}
};
return service.doFileSearch(Engine, {
const complete = await service.doFileSearch(Engine, {
folderQueries: TEST_FOLDER_QUERIES,
filePattern: 'bc',
sortByScore: true,
cacheKey: 'x'
}, cb, undefined, -1).then(complete => {
assert.strictEqual((<IFileSearchStats>complete.stats).fromCache, false);
assert.deepStrictEqual(results, [path.normalize('/some/where/bc')]);
});
}, cb, undefined, -1);
assert.strictEqual((<IFileSearchStats>complete.stats).fromCache, false);
assert.deepStrictEqual(results, [path.normalize('/some/where/bc')]);
});
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册