mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
parent
192efe14c3
commit
06d3f37ce5
File diff suppressed because it is too large
Load diff
|
@ -5,6 +5,7 @@
|
|||
|
||||
import * as assert from 'assert';
|
||||
import { VSBuffer } from 'vs/base/common/buffer';
|
||||
import { runWithFakedTimers } from 'vs/base/test/common/timeTravelScheduler';
|
||||
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
|
||||
import { IFileService } from 'vs/platform/files/common/files';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
|
@ -33,514 +34,544 @@ suite('TasksSync', () => {
|
|||
});
|
||||
|
||||
test('when tasks file does not exist', async () => {
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
|
||||
assert.deepStrictEqual(await testObject.getLastSyncUserData(), null);
|
||||
let manifest = await client.getResourceManifest();
|
||||
server.reset();
|
||||
await testObject.sync(manifest);
|
||||
assert.deepStrictEqual(await testObject.getLastSyncUserData(), null);
|
||||
let manifest = await client.getResourceManifest();
|
||||
server.reset();
|
||||
await testObject.sync(manifest);
|
||||
|
||||
assert.deepStrictEqual(server.requests, [
|
||||
{ type: 'GET', url: `${server.url}/v1/resource/${testObject.resource}/latest`, headers: {} },
|
||||
]);
|
||||
assert.ok(!await fileService.exists(tasksResource));
|
||||
assert.deepStrictEqual(server.requests, [
|
||||
{ type: 'GET', url: `${server.url}/v1/resource/${testObject.resource}/latest`, headers: {} },
|
||||
]);
|
||||
assert.ok(!await fileService.exists(tasksResource));
|
||||
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.deepStrictEqual(lastSyncUserData!.ref, remoteUserData.ref);
|
||||
assert.deepStrictEqual(lastSyncUserData!.syncData, remoteUserData.syncData);
|
||||
assert.strictEqual(lastSyncUserData!.syncData, null);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.deepStrictEqual(lastSyncUserData!.ref, remoteUserData.ref);
|
||||
assert.deepStrictEqual(lastSyncUserData!.syncData, remoteUserData.syncData);
|
||||
assert.strictEqual(lastSyncUserData!.syncData, null);
|
||||
|
||||
manifest = await client.getResourceManifest();
|
||||
server.reset();
|
||||
await testObject.sync(manifest);
|
||||
assert.deepStrictEqual(server.requests, []);
|
||||
manifest = await client.getResourceManifest();
|
||||
server.reset();
|
||||
await testObject.sync(manifest);
|
||||
assert.deepStrictEqual(server.requests, []);
|
||||
|
||||
manifest = await client.getResourceManifest();
|
||||
server.reset();
|
||||
await testObject.sync(manifest);
|
||||
assert.deepStrictEqual(server.requests, []);
|
||||
manifest = await client.getResourceManifest();
|
||||
server.reset();
|
||||
await testObject.sync(manifest);
|
||||
assert.deepStrictEqual(server.requests, []);
|
||||
});
|
||||
});
|
||||
|
||||
test('when tasks file does not exist and remote has changes', async () => {
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
});
|
||||
const tasksResource2 = client2.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
await client2.instantiationService.get(IFileService).writeFile(tasksResource2, VSBuffer.fromString(content));
|
||||
await client2.sync();
|
||||
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual((await fileService.readFile(tasksResource)).value.toString(), content);
|
||||
});
|
||||
const tasksResource2 = client2.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
await client2.instantiationService.get(IFileService).writeFile(tasksResource2, VSBuffer.fromString(content));
|
||||
await client2.sync();
|
||||
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual((await fileService.readFile(tasksResource)).value.toString(), content);
|
||||
});
|
||||
|
||||
test('when tasks file exists locally and remote has no tasks', async () => {
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
});
|
||||
fileService.writeFile(tasksResource, VSBuffer.fromString(content));
|
||||
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
});
|
||||
fileService.writeFile(tasksResource, VSBuffer.fromString(content));
|
||||
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
});
|
||||
|
||||
test('first time sync: when tasks file exists locally with same content as remote', async () => {
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
});
|
||||
const tasksResource2 = client2.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
await client2.instantiationService.get(IFileService).writeFile(tasksResource2, VSBuffer.fromString(content));
|
||||
await client2.sync();
|
||||
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
await fileService.writeFile(tasksResource, VSBuffer.fromString(content));
|
||||
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual((await fileService.readFile(tasksResource)).value.toString(), content);
|
||||
});
|
||||
const tasksResource2 = client2.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
await client2.instantiationService.get(IFileService).writeFile(tasksResource2, VSBuffer.fromString(content));
|
||||
await client2.sync();
|
||||
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
await fileService.writeFile(tasksResource, VSBuffer.fromString(content));
|
||||
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual((await fileService.readFile(tasksResource)).value.toString(), content);
|
||||
});
|
||||
|
||||
test('when tasks file locally has moved forward', async () => {
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
fileService.writeFile(tasksResource, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': []
|
||||
})));
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
fileService.writeFile(tasksResource, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': []
|
||||
})));
|
||||
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
});
|
||||
fileService.writeFile(tasksResource, VSBuffer.fromString(content));
|
||||
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
});
|
||||
fileService.writeFile(tasksResource, VSBuffer.fromString(content));
|
||||
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
});
|
||||
|
||||
test('when tasks file remotely has moved forward', async () => {
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
const tasksResource2 = client2.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService2 = client2.instantiationService.get(IFileService);
|
||||
await fileService2.writeFile(tasksResource2, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': []
|
||||
})));
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
const tasksResource2 = client2.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService2 = client2.instantiationService.get(IFileService);
|
||||
await fileService2.writeFile(tasksResource2, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': []
|
||||
})));
|
||||
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
|
||||
await client2.sync();
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
await client2.sync();
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
});
|
||||
fileService2.writeFile(tasksResource2, VSBuffer.fromString(content));
|
||||
|
||||
await client2.sync();
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual((await fileService.readFile(tasksResource)).value.toString(), content);
|
||||
});
|
||||
fileService2.writeFile(tasksResource2, VSBuffer.fromString(content));
|
||||
|
||||
await client2.sync();
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual((await fileService.readFile(tasksResource)).value.toString(), content);
|
||||
});
|
||||
|
||||
test('when tasks file has moved forward locally and remotely with same changes', async () => {
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
const tasksResource2 = client2.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService2 = client2.instantiationService.get(IFileService);
|
||||
await fileService2.writeFile(tasksResource2, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': []
|
||||
})));
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
const tasksResource2 = client2.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService2 = client2.instantiationService.get(IFileService);
|
||||
await fileService2.writeFile(tasksResource2, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': []
|
||||
})));
|
||||
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
|
||||
await client2.sync();
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
await client2.sync();
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
});
|
||||
fileService2.writeFile(tasksResource2, VSBuffer.fromString(content));
|
||||
await client2.sync();
|
||||
|
||||
fileService.writeFile(tasksResource, VSBuffer.fromString(content));
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual((await fileService.readFile(tasksResource)).value.toString(), content);
|
||||
});
|
||||
fileService2.writeFile(tasksResource2, VSBuffer.fromString(content));
|
||||
await client2.sync();
|
||||
|
||||
fileService.writeFile(tasksResource, VSBuffer.fromString(content));
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual((await fileService.readFile(tasksResource)).value.toString(), content);
|
||||
});
|
||||
|
||||
test('when tasks file has moved forward locally and remotely - accept preview', async () => {
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
const tasksResource2 = client2.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService2 = client2.instantiationService.get(IFileService);
|
||||
await fileService2.writeFile(tasksResource2, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': []
|
||||
})));
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
const tasksResource2 = client2.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService2 = client2.instantiationService.get(IFileService);
|
||||
await fileService2.writeFile(tasksResource2, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': []
|
||||
})));
|
||||
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
|
||||
await client2.sync();
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
await client2.sync();
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
fileService2.writeFile(tasksResource2, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
}]
|
||||
})));
|
||||
await client2.sync();
|
||||
fileService2.writeFile(tasksResource2, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
}]
|
||||
})));
|
||||
await client2.sync();
|
||||
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
});
|
||||
fileService.writeFile(tasksResource, VSBuffer.fromString(content));
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
const previewContent = (await fileService.readFile(testObject.conflicts.conflicts[0].previewResource)).value.toString();
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.HasConflicts);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts.length, 1);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts[0].mergeState, MergeState.Conflict);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts[0].localChange, Change.Modified);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts[0].remoteChange, Change.Modified);
|
||||
|
||||
await testObject.accept(testObject.conflicts.conflicts[0].previewResource);
|
||||
await testObject.apply(false);
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), previewContent);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), previewContent);
|
||||
assert.strictEqual((await fileService.readFile(tasksResource)).value.toString(), previewContent);
|
||||
});
|
||||
fileService.writeFile(tasksResource, VSBuffer.fromString(content));
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
const previewContent = (await fileService.readFile(testObject.conflicts.conflicts[0].previewResource)).value.toString();
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.HasConflicts);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts.length, 1);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts[0].mergeState, MergeState.Conflict);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts[0].localChange, Change.Modified);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts[0].remoteChange, Change.Modified);
|
||||
|
||||
await testObject.accept(testObject.conflicts.conflicts[0].previewResource);
|
||||
await testObject.apply(false);
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), previewContent);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), previewContent);
|
||||
assert.strictEqual((await fileService.readFile(tasksResource)).value.toString(), previewContent);
|
||||
});
|
||||
|
||||
test('when tasks file has moved forward locally and remotely - accept modified preview', async () => {
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
const tasksResource2 = client2.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService2 = client2.instantiationService.get(IFileService);
|
||||
await fileService2.writeFile(tasksResource2, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': []
|
||||
})));
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
const tasksResource2 = client2.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService2 = client2.instantiationService.get(IFileService);
|
||||
await fileService2.writeFile(tasksResource2, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': []
|
||||
})));
|
||||
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
|
||||
await client2.sync();
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
await client2.sync();
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
fileService2.writeFile(tasksResource2, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
}]
|
||||
})));
|
||||
await client2.sync();
|
||||
fileService2.writeFile(tasksResource2, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
}]
|
||||
})));
|
||||
await client2.sync();
|
||||
|
||||
fileService.writeFile(tasksResource, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
})));
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
fileService.writeFile(tasksResource, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
})));
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch 2'
|
||||
}]
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch 2'
|
||||
}]
|
||||
});
|
||||
await testObject.accept(testObject.conflicts.conflicts[0].previewResource, content);
|
||||
await testObject.apply(false);
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual((await fileService.readFile(tasksResource)).value.toString(), content);
|
||||
});
|
||||
await testObject.accept(testObject.conflicts.conflicts[0].previewResource, content);
|
||||
await testObject.apply(false);
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual((await fileService.readFile(tasksResource)).value.toString(), content);
|
||||
});
|
||||
|
||||
test('when tasks file has moved forward locally and remotely - accept remote', async () => {
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
const tasksResource2 = client2.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService2 = client2.instantiationService.get(IFileService);
|
||||
await fileService2.writeFile(tasksResource2, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': []
|
||||
})));
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
const tasksResource2 = client2.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService2 = client2.instantiationService.get(IFileService);
|
||||
await fileService2.writeFile(tasksResource2, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': []
|
||||
})));
|
||||
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
|
||||
await client2.sync();
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
await client2.sync();
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
}]
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
}]
|
||||
});
|
||||
fileService2.writeFile(tasksResource2, VSBuffer.fromString(content));
|
||||
await client2.sync();
|
||||
|
||||
fileService.writeFile(tasksResource, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
})));
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.HasConflicts);
|
||||
|
||||
await testObject.accept(testObject.conflicts.conflicts[0].remoteResource);
|
||||
await testObject.apply(false);
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual((await fileService.readFile(tasksResource)).value.toString(), content);
|
||||
});
|
||||
fileService2.writeFile(tasksResource2, VSBuffer.fromString(content));
|
||||
await client2.sync();
|
||||
|
||||
fileService.writeFile(tasksResource, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
})));
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.HasConflicts);
|
||||
|
||||
await testObject.accept(testObject.conflicts.conflicts[0].remoteResource);
|
||||
await testObject.apply(false);
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual((await fileService.readFile(tasksResource)).value.toString(), content);
|
||||
});
|
||||
|
||||
test('when tasks file has moved forward locally and remotely - accept local', async () => {
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
const tasksResource2 = client2.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService2 = client2.instantiationService.get(IFileService);
|
||||
await fileService2.writeFile(tasksResource2, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': []
|
||||
})));
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
const tasksResource2 = client2.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService2 = client2.instantiationService.get(IFileService);
|
||||
await fileService2.writeFile(tasksResource2, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': []
|
||||
})));
|
||||
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
|
||||
await client2.sync();
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
await client2.sync();
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
fileService2.writeFile(tasksResource2, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
}]
|
||||
})));
|
||||
await client2.sync();
|
||||
fileService2.writeFile(tasksResource2, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
}]
|
||||
})));
|
||||
await client2.sync();
|
||||
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
});
|
||||
fileService.writeFile(tasksResource, VSBuffer.fromString(content));
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.HasConflicts);
|
||||
|
||||
await testObject.accept(testObject.conflicts.conflicts[0].localResource);
|
||||
await testObject.apply(false);
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual((await fileService.readFile(tasksResource)).value.toString(), content);
|
||||
});
|
||||
fileService.writeFile(tasksResource, VSBuffer.fromString(content));
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.HasConflicts);
|
||||
|
||||
await testObject.accept(testObject.conflicts.conflicts[0].localResource);
|
||||
await testObject.apply(false);
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
assert.strictEqual((await fileService.readFile(tasksResource)).value.toString(), content);
|
||||
});
|
||||
|
||||
test('when tasks file was removed in one client', async () => {
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
await fileService.writeFile(tasksResource, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': []
|
||||
})));
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
await fileService.writeFile(tasksResource, VSBuffer.fromString(JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': []
|
||||
})));
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
await client2.sync();
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
await client2.sync();
|
||||
|
||||
const tasksResource2 = client2.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService2 = client2.instantiationService.get(IFileService);
|
||||
fileService2.del(tasksResource2);
|
||||
await client2.sync();
|
||||
const tasksResource2 = client2.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
const fileService2 = client2.instantiationService.get(IFileService);
|
||||
fileService2.del(tasksResource2);
|
||||
await client2.sync();
|
||||
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), null);
|
||||
assert.strictEqual(await fileService.exists(tasksResource), false);
|
||||
assert.deepStrictEqual(testObject.status, SyncStatus.Idle);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), null);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(remoteUserData.syncData!.content, client.instantiationService.get(ILogService)), null);
|
||||
assert.strictEqual(await fileService.exists(tasksResource), false);
|
||||
});
|
||||
});
|
||||
|
||||
test('when tasks file is created after first sync', async () => {
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
await testObject.sync(await client.getResourceManifest());
|
||||
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
const content = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
});
|
||||
await fileService.createFile(tasksResource, VSBuffer.fromString(content));
|
||||
|
||||
let lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const manifest = await client.getResourceManifest();
|
||||
server.reset();
|
||||
await testObject.sync(manifest);
|
||||
|
||||
assert.deepStrictEqual(server.requests, [
|
||||
{ type: 'POST', url: `${server.url}/v1/resource/${testObject.resource}`, headers: { 'If-Match': lastSyncUserData?.ref } },
|
||||
]);
|
||||
|
||||
lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.deepStrictEqual(lastSyncUserData!.ref, remoteUserData.ref);
|
||||
assert.deepStrictEqual(lastSyncUserData!.syncData, remoteUserData.syncData);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
});
|
||||
await fileService.createFile(tasksResource, VSBuffer.fromString(content));
|
||||
|
||||
let lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const manifest = await client.getResourceManifest();
|
||||
server.reset();
|
||||
await testObject.sync(manifest);
|
||||
|
||||
assert.deepStrictEqual(server.requests, [
|
||||
{ type: 'POST', url: `${server.url}/v1/resource/${testObject.resource}`, headers: { 'If-Match': lastSyncUserData?.ref } },
|
||||
]);
|
||||
|
||||
lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.deepStrictEqual(lastSyncUserData!.ref, remoteUserData.ref);
|
||||
assert.deepStrictEqual(lastSyncUserData!.syncData, remoteUserData.syncData);
|
||||
assert.strictEqual(getTasksContentFromSyncContent(lastSyncUserData!.syncData!.content, client.instantiationService.get(ILogService)), content);
|
||||
});
|
||||
|
||||
test('apply remote when tasks file does not exist', async () => {
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
if (await fileService.exists(tasksResource)) {
|
||||
await fileService.del(tasksResource);
|
||||
}
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
const fileService = client.instantiationService.get(IFileService);
|
||||
const tasksResource = client.instantiationService.get(IUserDataProfilesService).defaultProfile.tasksResource;
|
||||
if (await fileService.exists(tasksResource)) {
|
||||
await fileService.del(tasksResource);
|
||||
}
|
||||
|
||||
const preview = (await testObject.preview(await client.getResourceManifest(), {}))!;
|
||||
const preview = (await testObject.preview(await client.getResourceManifest(), {}))!;
|
||||
|
||||
server.reset();
|
||||
const content = await testObject.resolveContent(preview.resourcePreviews[0].remoteResource);
|
||||
await testObject.accept(preview.resourcePreviews[0].remoteResource, content);
|
||||
await testObject.apply(false);
|
||||
assert.deepStrictEqual(server.requests, []);
|
||||
server.reset();
|
||||
const content = await testObject.resolveContent(preview.resourcePreviews[0].remoteResource);
|
||||
await testObject.accept(preview.resourcePreviews[0].remoteResource, content);
|
||||
await testObject.apply(false);
|
||||
assert.deepStrictEqual(server.requests, []);
|
||||
});
|
||||
});
|
||||
|
||||
test('sync profile tasks', async () => {
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
const profile = await client2.instantiationService.get(IUserDataProfilesService).createNamedProfile('profile1');
|
||||
const expected = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
const client2 = disposableStore.add(new UserDataSyncClient(server));
|
||||
await client2.setUp(true);
|
||||
const profile = await client2.instantiationService.get(IUserDataProfilesService).createNamedProfile('profile1');
|
||||
const expected = JSON.stringify({
|
||||
'version': '2.0.0',
|
||||
'tasks': [{
|
||||
'type': 'npm',
|
||||
'script': 'watch',
|
||||
'label': 'Watch'
|
||||
}]
|
||||
});
|
||||
await client2.instantiationService.get(IFileService).createFile(profile.tasksResource, VSBuffer.fromString(expected));
|
||||
await client2.sync();
|
||||
|
||||
await client.sync();
|
||||
|
||||
const syncedProfile = client.instantiationService.get(IUserDataProfilesService).profiles.find(p => p.id === profile.id)!;
|
||||
const actual = (await client.instantiationService.get(IFileService).readFile(syncedProfile.tasksResource)).value.toString();
|
||||
assert.strictEqual(actual, expected);
|
||||
});
|
||||
await client2.instantiationService.get(IFileService).createFile(profile.tasksResource, VSBuffer.fromString(expected));
|
||||
await client2.sync();
|
||||
|
||||
await client.sync();
|
||||
|
||||
const syncedProfile = client.instantiationService.get(IUserDataProfilesService).profiles.find(p => p.id === profile.id)!;
|
||||
const actual = (await client.instantiationService.get(IFileService).readFile(syncedProfile.tasksResource)).value.toString();
|
||||
assert.strictEqual(actual, expected);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { runWithFakedTimers } from 'vs/base/test/common/timeTravelScheduler';
|
||||
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
|
||||
import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
|
||||
import { UserDataProfilesManifestSynchroniser } from 'vs/platform/userDataSync/common/userDataProfilesManifestSync';
|
||||
|
@ -34,230 +35,254 @@ suite('UserDataProfilesManifestSync', () => {
|
|||
});
|
||||
|
||||
test('when profiles does not exist', async () => {
|
||||
assert.deepStrictEqual(await testObject.getLastSyncUserData(), null);
|
||||
let manifest = await testClient.getResourceManifest();
|
||||
server.reset();
|
||||
await testObject.sync(manifest);
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
assert.deepStrictEqual(await testObject.getLastSyncUserData(), null);
|
||||
let manifest = await testClient.getResourceManifest();
|
||||
server.reset();
|
||||
await testObject.sync(manifest);
|
||||
|
||||
assert.deepStrictEqual(server.requests, [
|
||||
{ type: 'GET', url: `${server.url}/v1/resource/${testObject.resource}/latest`, headers: {} },
|
||||
]);
|
||||
assert.deepStrictEqual(server.requests, [
|
||||
{ type: 'GET', url: `${server.url}/v1/resource/${testObject.resource}/latest`, headers: {} },
|
||||
]);
|
||||
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.deepStrictEqual(lastSyncUserData!.ref, remoteUserData.ref);
|
||||
assert.deepStrictEqual(lastSyncUserData!.syncData, remoteUserData.syncData);
|
||||
assert.strictEqual(lastSyncUserData!.syncData, null);
|
||||
const lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.deepStrictEqual(lastSyncUserData!.ref, remoteUserData.ref);
|
||||
assert.deepStrictEqual(lastSyncUserData!.syncData, remoteUserData.syncData);
|
||||
assert.strictEqual(lastSyncUserData!.syncData, null);
|
||||
|
||||
manifest = await testClient.getResourceManifest();
|
||||
server.reset();
|
||||
await testObject.sync(manifest);
|
||||
assert.deepStrictEqual(server.requests, []);
|
||||
manifest = await testClient.getResourceManifest();
|
||||
server.reset();
|
||||
await testObject.sync(manifest);
|
||||
assert.deepStrictEqual(server.requests, []);
|
||||
|
||||
manifest = await testClient.getResourceManifest();
|
||||
server.reset();
|
||||
await testObject.sync(manifest);
|
||||
assert.deepStrictEqual(server.requests, []);
|
||||
manifest = await testClient.getResourceManifest();
|
||||
server.reset();
|
||||
await testObject.sync(manifest);
|
||||
assert.deepStrictEqual(server.requests, []);
|
||||
});
|
||||
});
|
||||
|
||||
test('when profile is created after first sync', async () => {
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
await testClient.instantiationService.get(IUserDataProfilesService).createProfile('1', '1');
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
await testClient.instantiationService.get(IUserDataProfilesService).createProfile('1', '1');
|
||||
|
||||
let lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const manifest = await testClient.getResourceManifest();
|
||||
server.reset();
|
||||
await testObject.sync(manifest);
|
||||
let lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const manifest = await testClient.getResourceManifest();
|
||||
server.reset();
|
||||
await testObject.sync(manifest);
|
||||
|
||||
assert.deepStrictEqual(server.requests, [
|
||||
{ type: 'POST', url: `${server.url}/v1/collection`, headers: {} },
|
||||
{ type: 'POST', url: `${server.url}/v1/resource/${testObject.resource}`, headers: { 'If-Match': lastSyncUserData?.ref } },
|
||||
]);
|
||||
assert.deepStrictEqual(server.requests, [
|
||||
{ type: 'POST', url: `${server.url}/v1/collection`, headers: {} },
|
||||
{ type: 'POST', url: `${server.url}/v1/resource/${testObject.resource}`, headers: { 'If-Match': lastSyncUserData?.ref } },
|
||||
]);
|
||||
|
||||
lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.deepStrictEqual(lastSyncUserData!.ref, remoteUserData.ref);
|
||||
assert.deepStrictEqual(lastSyncUserData!.syncData, remoteUserData.syncData);
|
||||
assert.deepStrictEqual(JSON.parse(lastSyncUserData!.syncData!.content), [{ 'name': '1', 'id': '1', 'collection': '1' }]);
|
||||
lastSyncUserData = await testObject.getLastSyncUserData();
|
||||
const remoteUserData = await testObject.getRemoteUserData(null);
|
||||
assert.deepStrictEqual(lastSyncUserData!.ref, remoteUserData.ref);
|
||||
assert.deepStrictEqual(lastSyncUserData!.syncData, remoteUserData.syncData);
|
||||
assert.deepStrictEqual(JSON.parse(lastSyncUserData!.syncData!.content), [{ 'name': '1', 'id': '1', 'collection': '1' }]);
|
||||
});
|
||||
});
|
||||
|
||||
test('first time sync - outgoing to server (no state)', async () => {
|
||||
await testClient.instantiationService.get(IUserDataProfilesService).createProfile('1', '1');
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
await testClient.instantiationService.get(IUserDataProfilesService).createProfile('1', '1');
|
||||
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
|
||||
const { content } = await testClient.read(testObject.resource);
|
||||
assert.ok(content !== null);
|
||||
assert.deepStrictEqual(JSON.parse(JSON.parse(content).content), [{ 'name': '1', 'id': '1', 'collection': '1' }]);
|
||||
const { content } = await testClient.read(testObject.resource);
|
||||
assert.ok(content !== null);
|
||||
assert.deepStrictEqual(JSON.parse(JSON.parse(content).content), [{ 'name': '1', 'id': '1', 'collection': '1' }]);
|
||||
});
|
||||
});
|
||||
|
||||
test('first time sync - incoming from server (no state)', async () => {
|
||||
await client2.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1');
|
||||
await client2.sync();
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
await client2.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1');
|
||||
await client2.sync();
|
||||
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
|
||||
const profiles = getLocalProfiles(testClient);
|
||||
assert.deepStrictEqual(profiles, [{ id: '1', name: 'name 1', shortName: undefined, useDefaultFlags: undefined }]);
|
||||
const profiles = getLocalProfiles(testClient);
|
||||
assert.deepStrictEqual(profiles, [{ id: '1', name: 'name 1', shortName: undefined, useDefaultFlags: undefined }]);
|
||||
});
|
||||
});
|
||||
|
||||
test('first time sync when profiles exists', async () => {
|
||||
await client2.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1');
|
||||
await client2.sync();
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
await client2.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1');
|
||||
await client2.sync();
|
||||
|
||||
await testClient.instantiationService.get(IUserDataProfilesService).createProfile('2', 'name 2');
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
await testClient.instantiationService.get(IUserDataProfilesService).createProfile('2', 'name 2');
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
|
||||
const profiles = getLocalProfiles(testClient);
|
||||
assert.deepStrictEqual(profiles, [{ id: '1', name: 'name 1', shortName: undefined, useDefaultFlags: undefined }, { id: '2', name: 'name 2', shortName: undefined, useDefaultFlags: undefined }]);
|
||||
const profiles = getLocalProfiles(testClient);
|
||||
assert.deepStrictEqual(profiles, [{ id: '1', name: 'name 1', shortName: undefined, useDefaultFlags: undefined }, { id: '2', name: 'name 2', shortName: undefined, useDefaultFlags: undefined }]);
|
||||
|
||||
const { content } = await testClient.read(testObject.resource);
|
||||
assert.ok(content !== null);
|
||||
const actual = parseRemoteProfiles(content);
|
||||
assert.deepStrictEqual(actual, [{ id: '1', name: 'name 1', collection: '1' }, { id: '2', name: 'name 2', collection: '2' }]);
|
||||
const { content } = await testClient.read(testObject.resource);
|
||||
assert.ok(content !== null);
|
||||
const actual = parseRemoteProfiles(content);
|
||||
assert.deepStrictEqual(actual, [{ id: '1', name: 'name 1', collection: '1' }, { id: '2', name: 'name 2', collection: '2' }]);
|
||||
});
|
||||
});
|
||||
|
||||
test('first time sync when storage exists - has conflicts', async () => {
|
||||
await client2.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1');
|
||||
await client2.sync();
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
await client2.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1');
|
||||
await client2.sync();
|
||||
|
||||
await testClient.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 2');
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
await testClient.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 2');
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
|
||||
const profiles = getLocalProfiles(testClient);
|
||||
assert.deepStrictEqual(profiles, [{ id: '1', name: 'name 1', shortName: undefined, useDefaultFlags: undefined }]);
|
||||
const profiles = getLocalProfiles(testClient);
|
||||
assert.deepStrictEqual(profiles, [{ id: '1', name: 'name 1', shortName: undefined, useDefaultFlags: undefined }]);
|
||||
|
||||
const { content } = await testClient.read(testObject.resource);
|
||||
assert.ok(content !== null);
|
||||
const actual = parseRemoteProfiles(content);
|
||||
assert.deepStrictEqual(actual, [{ id: '1', name: 'name 1', collection: '1' }]);
|
||||
const { content } = await testClient.read(testObject.resource);
|
||||
assert.ok(content !== null);
|
||||
const actual = parseRemoteProfiles(content);
|
||||
assert.deepStrictEqual(actual, [{ id: '1', name: 'name 1', collection: '1' }]);
|
||||
});
|
||||
});
|
||||
|
||||
test('sync adding a profile', async () => {
|
||||
await testClient.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1', { shortName: 'short 1' });
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
await client2.sync();
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
await testClient.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1', { shortName: 'short 1' });
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
await client2.sync();
|
||||
|
||||
await testClient.instantiationService.get(IUserDataProfilesService).createProfile('2', 'name 2');
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '1', name: 'name 1', shortName: 'short 1', useDefaultFlags: undefined }, { id: '2', name: 'name 2', shortName: undefined, useDefaultFlags: undefined }]);
|
||||
await testClient.instantiationService.get(IUserDataProfilesService).createProfile('2', 'name 2');
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '1', name: 'name 1', shortName: 'short 1', useDefaultFlags: undefined }, { id: '2', name: 'name 2', shortName: undefined, useDefaultFlags: undefined }]);
|
||||
|
||||
await client2.sync();
|
||||
assert.deepStrictEqual(getLocalProfiles(client2), [{ id: '1', name: 'name 1', shortName: 'short 1', useDefaultFlags: undefined }, { id: '2', name: 'name 2', shortName: undefined, useDefaultFlags: undefined }]);
|
||||
await client2.sync();
|
||||
assert.deepStrictEqual(getLocalProfiles(client2), [{ id: '1', name: 'name 1', shortName: 'short 1', useDefaultFlags: undefined }, { id: '2', name: 'name 2', shortName: undefined, useDefaultFlags: undefined }]);
|
||||
|
||||
const { content } = await testClient.read(testObject.resource);
|
||||
assert.ok(content !== null);
|
||||
const actual = parseRemoteProfiles(content);
|
||||
assert.deepStrictEqual(actual, [{ id: '1', name: 'name 1', collection: '1', shortName: 'short 1' }, { id: '2', name: 'name 2', collection: '2' }]);
|
||||
const { content } = await testClient.read(testObject.resource);
|
||||
assert.ok(content !== null);
|
||||
const actual = parseRemoteProfiles(content);
|
||||
assert.deepStrictEqual(actual, [{ id: '1', name: 'name 1', collection: '1', shortName: 'short 1' }, { id: '2', name: 'name 2', collection: '2' }]);
|
||||
});
|
||||
});
|
||||
|
||||
test('sync updating a profile', async () => {
|
||||
const profile = await testClient.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1');
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
await client2.sync();
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
const profile = await testClient.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1');
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
await client2.sync();
|
||||
|
||||
await testClient.instantiationService.get(IUserDataProfilesService).updateProfile(profile, { name: 'name 2', shortName: '2' });
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '1', name: 'name 2', shortName: '2', useDefaultFlags: undefined }]);
|
||||
await testClient.instantiationService.get(IUserDataProfilesService).updateProfile(profile, { name: 'name 2', shortName: '2' });
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '1', name: 'name 2', shortName: '2', useDefaultFlags: undefined }]);
|
||||
|
||||
await client2.sync();
|
||||
assert.deepStrictEqual(getLocalProfiles(client2), [{ id: '1', name: 'name 2', shortName: '2', useDefaultFlags: undefined }]);
|
||||
await client2.sync();
|
||||
assert.deepStrictEqual(getLocalProfiles(client2), [{ id: '1', name: 'name 2', shortName: '2', useDefaultFlags: undefined }]);
|
||||
|
||||
const { content } = await testClient.read(testObject.resource);
|
||||
assert.ok(content !== null);
|
||||
const actual = parseRemoteProfiles(content);
|
||||
assert.deepStrictEqual(actual, [{ id: '1', name: 'name 2', collection: '1', shortName: '2' }]);
|
||||
const { content } = await testClient.read(testObject.resource);
|
||||
assert.ok(content !== null);
|
||||
const actual = parseRemoteProfiles(content);
|
||||
assert.deepStrictEqual(actual, [{ id: '1', name: 'name 2', collection: '1', shortName: '2' }]);
|
||||
});
|
||||
});
|
||||
|
||||
test('sync removing a profile', async () => {
|
||||
const profile = await testClient.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1');
|
||||
await testClient.instantiationService.get(IUserDataProfilesService).createProfile('2', 'name 2');
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
await client2.sync();
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
const profile = await testClient.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1');
|
||||
await testClient.instantiationService.get(IUserDataProfilesService).createProfile('2', 'name 2');
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
await client2.sync();
|
||||
|
||||
testClient.instantiationService.get(IUserDataProfilesService).removeProfile(profile);
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '2', name: 'name 2', shortName: undefined, useDefaultFlags: undefined }]);
|
||||
testClient.instantiationService.get(IUserDataProfilesService).removeProfile(profile);
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '2', name: 'name 2', shortName: undefined, useDefaultFlags: undefined }]);
|
||||
|
||||
await client2.sync();
|
||||
assert.deepStrictEqual(getLocalProfiles(client2), [{ id: '2', name: 'name 2', shortName: undefined, useDefaultFlags: undefined }]);
|
||||
await client2.sync();
|
||||
assert.deepStrictEqual(getLocalProfiles(client2), [{ id: '2', name: 'name 2', shortName: undefined, useDefaultFlags: undefined }]);
|
||||
|
||||
const { content } = await testClient.read(testObject.resource);
|
||||
assert.ok(content !== null);
|
||||
const actual = parseRemoteProfiles(content);
|
||||
assert.deepStrictEqual(actual, [{ id: '2', name: 'name 2', collection: '2' }]);
|
||||
const { content } = await testClient.read(testObject.resource);
|
||||
assert.ok(content !== null);
|
||||
const actual = parseRemoteProfiles(content);
|
||||
assert.deepStrictEqual(actual, [{ id: '2', name: 'name 2', collection: '2' }]);
|
||||
});
|
||||
});
|
||||
|
||||
test('sync profile that uses default profile', async () => {
|
||||
await client2.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1', { useDefaultFlags: { keybindings: true } });
|
||||
await client2.sync();
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
await client2.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1', { useDefaultFlags: { keybindings: true } });
|
||||
await client2.sync();
|
||||
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
|
||||
const { content } = await testClient.read(testObject.resource);
|
||||
assert.ok(content !== null);
|
||||
const actual = parseRemoteProfiles(content);
|
||||
assert.deepStrictEqual(actual, [{ id: '1', name: 'name 1', collection: '1', useDefaultFlags: { keybindings: true } }]);
|
||||
const { content } = await testClient.read(testObject.resource);
|
||||
assert.ok(content !== null);
|
||||
const actual = parseRemoteProfiles(content);
|
||||
assert.deepStrictEqual(actual, [{ id: '1', name: 'name 1', collection: '1', useDefaultFlags: { keybindings: true } }]);
|
||||
|
||||
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '1', name: 'name 1', shortName: undefined, useDefaultFlags: { keybindings: true } }]);
|
||||
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '1', name: 'name 1', shortName: undefined, useDefaultFlags: { keybindings: true } }]);
|
||||
});
|
||||
});
|
||||
|
||||
test('sync profile when the profile is updated to use default profile locally', async () => {
|
||||
await client2.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1');
|
||||
await client2.sync();
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
await client2.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1');
|
||||
await client2.sync();
|
||||
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
|
||||
const profile = testClient.instantiationService.get(IUserDataProfilesService).profiles.find(p => p.id === '1')!;
|
||||
testClient.instantiationService.get(IUserDataProfilesService).updateProfile(profile, { useDefaultFlags: { keybindings: true } });
|
||||
const profile = testClient.instantiationService.get(IUserDataProfilesService).profiles.find(p => p.id === '1')!;
|
||||
testClient.instantiationService.get(IUserDataProfilesService).updateProfile(profile, { useDefaultFlags: { keybindings: true } });
|
||||
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
|
||||
const { content } = await testClient.read(testObject.resource);
|
||||
assert.ok(content !== null);
|
||||
const actual = parseRemoteProfiles(content);
|
||||
assert.deepStrictEqual(actual, [{ id: '1', name: 'name 1', collection: '1', useDefaultFlags: { keybindings: true } }]);
|
||||
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '1', name: 'name 1', shortName: undefined, useDefaultFlags: { keybindings: true } }]);
|
||||
const { content } = await testClient.read(testObject.resource);
|
||||
assert.ok(content !== null);
|
||||
const actual = parseRemoteProfiles(content);
|
||||
assert.deepStrictEqual(actual, [{ id: '1', name: 'name 1', collection: '1', useDefaultFlags: { keybindings: true } }]);
|
||||
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '1', name: 'name 1', shortName: undefined, useDefaultFlags: { keybindings: true } }]);
|
||||
});
|
||||
});
|
||||
|
||||
test('sync profile when the profile is updated to use default profile remotely', async () => {
|
||||
const profile = await client2.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1');
|
||||
await client2.sync();
|
||||
await runWithFakedTimers<void>({}, async () => {
|
||||
const profile = await client2.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1');
|
||||
await client2.sync();
|
||||
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
|
||||
client2.instantiationService.get(IUserDataProfilesService).updateProfile(profile, { useDefaultFlags: { keybindings: true } });
|
||||
await client2.sync();
|
||||
client2.instantiationService.get(IUserDataProfilesService).updateProfile(profile, { useDefaultFlags: { keybindings: true } });
|
||||
await client2.sync();
|
||||
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
await testObject.sync(await testClient.getResourceManifest());
|
||||
assert.strictEqual(testObject.status, SyncStatus.Idle);
|
||||
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
|
||||
|
||||
const { content } = await testClient.read(testObject.resource);
|
||||
assert.ok(content !== null);
|
||||
const actual = parseRemoteProfiles(content);
|
||||
assert.deepStrictEqual(actual, [{ id: '1', name: 'name 1', collection: '1', useDefaultFlags: { keybindings: true } }]);
|
||||
const { content } = await testClient.read(testObject.resource);
|
||||
assert.ok(content !== null);
|
||||
const actual = parseRemoteProfiles(content);
|
||||
assert.deepStrictEqual(actual, [{ id: '1', name: 'name 1', collection: '1', useDefaultFlags: { keybindings: true } }]);
|
||||
|
||||
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '1', name: 'name 1', shortName: undefined, useDefaultFlags: { keybindings: true } }]);
|
||||
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '1', name: 'name 1', shortName: undefined, useDefaultFlags: { keybindings: true } }]);
|
||||
});
|
||||
});
|
||||
|
||||
function parseRemoteProfiles(content: string): ISyncUserDataProfile[] {
|
||||
|
|
Loading…
Reference in a new issue