提交 87de60cc 编写于 作者: S Sandeep Somavarapu

Fix tests

上级 b1f6b66d
...@@ -73,28 +73,28 @@ suite('BackupMainService', () => { ...@@ -73,28 +73,28 @@ suite('BackupMainService', () => {
}; };
} }
function ensureFolderExists(uri: Uri): void { async function ensureFolderExists(uri: Uri): Promise<void> {
if (!fs.existsSync(uri.fsPath)) { if (!fs.existsSync(uri.fsPath)) {
fs.mkdirSync(uri.fsPath); fs.mkdirSync(uri.fsPath);
} }
const backupFolder = service.toBackupPath(uri); const backupFolder = service.toBackupPath(uri);
createBackupFolder(backupFolder); await createBackupFolder(backupFolder);
} }
function ensureWorkspaceExists(workspace: IWorkspaceIdentifier): IWorkspaceIdentifier { async function ensureWorkspaceExists(workspace: IWorkspaceIdentifier): Promise<IWorkspaceIdentifier> {
if (!fs.existsSync(workspace.configPath)) { if (!fs.existsSync(workspace.configPath)) {
fs.writeFile(workspace.configPath, 'Hello'); await pfs.writeFile(workspace.configPath, 'Hello');
} }
const backupFolder = service.toBackupPath(workspace.id); const backupFolder = service.toBackupPath(workspace.id);
createBackupFolder(backupFolder); await createBackupFolder(backupFolder);
return workspace; return workspace;
} }
function createBackupFolder(backupFolder: string) { async function createBackupFolder(backupFolder: string): Promise<void> {
if (!fs.existsSync(backupFolder)) { if (!fs.existsSync(backupFolder)) {
fs.mkdirSync(backupFolder); fs.mkdirSync(backupFolder);
fs.mkdirSync(path.join(backupFolder, Schemas.file)); fs.mkdirSync(path.join(backupFolder, Schemas.file));
fs.writeFile(path.join(backupFolder, Schemas.file, 'foo.txt'), 'Hello'); await pfs.writeFile(path.join(backupFolder, Schemas.file, 'foo.txt'), 'Hello');
} }
} }
...@@ -256,7 +256,7 @@ suite('BackupMainService', () => { ...@@ -256,7 +256,7 @@ suite('BackupMainService', () => {
suite('migrate folderPath to folderURI', () => { suite('migrate folderPath to folderURI', () => {
test('migration makes sure to preserve existing backups', () => { test('migration makes sure to preserve existing backups', async () => {
let path1 = path.join(parentDir, 'folder1').toLowerCase(); let path1 = path.join(parentDir, 'folder1').toLowerCase();
let path2 = path.join(parentDir, 'folder2').toUpperCase(); let path2 = path.join(parentDir, 'folder2').toUpperCase();
let uri1 = Uri.file(path1); let uri1 = Uri.file(path1);
...@@ -272,17 +272,17 @@ suite('BackupMainService', () => { ...@@ -272,17 +272,17 @@ suite('BackupMainService', () => {
if (!fs.existsSync(backupFolder1)) { if (!fs.existsSync(backupFolder1)) {
fs.mkdirSync(backupFolder1); fs.mkdirSync(backupFolder1);
fs.mkdirSync(path.join(backupFolder1, Schemas.file)); fs.mkdirSync(path.join(backupFolder1, Schemas.file));
fs.writeFile(path.join(backupFolder1, Schemas.file, 'unsaved1.txt'), 'Legacy'); await pfs.writeFile(path.join(backupFolder1, Schemas.file, 'unsaved1.txt'), 'Legacy');
} }
const backupFolder2 = service.toLegacyBackupPath(path2); const backupFolder2 = service.toLegacyBackupPath(path2);
if (!fs.existsSync(backupFolder2)) { if (!fs.existsSync(backupFolder2)) {
fs.mkdirSync(backupFolder2); fs.mkdirSync(backupFolder2);
fs.mkdirSync(path.join(backupFolder2, Schemas.file)); fs.mkdirSync(path.join(backupFolder2, Schemas.file));
fs.writeFile(path.join(backupFolder2, Schemas.file, 'unsaved2.txt'), 'Legacy'); await pfs.writeFile(path.join(backupFolder2, Schemas.file, 'unsaved2.txt'), 'Legacy');
} }
const workspacesJson = { rootWorkspaces: [], folderWorkspaces: [path1, path2], emptyWorkspaces: [] }; const workspacesJson = { rootWorkspaces: [], folderWorkspaces: [path1, path2], emptyWorkspaces: [] };
return pfs.writeFile(backupWorkspacesPath, JSON.stringify(workspacesJson)).then(() => { await pfs.writeFile(backupWorkspacesPath, JSON.stringify(workspacesJson)).then(() => {
service.loadSync(); service.loadSync();
return pfs.readFile(backupWorkspacesPath, 'utf-8').then(content => { return pfs.readFile(backupWorkspacesPath, 'utf-8').then(content => {
const json = <IBackupWorkspacesFormat>JSON.parse(content); const json = <IBackupWorkspacesFormat>JSON.parse(content);
...@@ -446,9 +446,9 @@ suite('BackupMainService', () => { ...@@ -446,9 +446,9 @@ suite('BackupMainService', () => {
}); });
suite('dedupeFolderWorkspaces', () => { suite('dedupeFolderWorkspaces', () => {
test('should ignore duplicates (folder workspace)', () => { test('should ignore duplicates (folder workspace)', async () => {
ensureFolderExists(existingTestFolder1); await ensureFolderExists(existingTestFolder1);
const workspacesJson: IBackupWorkspacesFormat = { const workspacesJson: IBackupWorkspacesFormat = {
rootWorkspaces: [], rootWorkspaces: [],
...@@ -464,9 +464,9 @@ suite('BackupMainService', () => { ...@@ -464,9 +464,9 @@ suite('BackupMainService', () => {
}); });
}); });
test('should ignore duplicates on Windows and Mac (folder workspace)', () => { test('should ignore duplicates on Windows and Mac (folder workspace)', async () => {
ensureFolderExists(existingTestFolder1); await ensureFolderExists(existingTestFolder1);
const workspacesJson: IBackupWorkspacesFormat = { const workspacesJson: IBackupWorkspacesFormat = {
rootWorkspaces: [], rootWorkspaces: [],
...@@ -482,11 +482,15 @@ suite('BackupMainService', () => { ...@@ -482,11 +482,15 @@ suite('BackupMainService', () => {
}); });
}); });
test('should ignore duplicates on Windows and Mac (root workspace)', () => { test('should ignore duplicates on Windows and Mac (root workspace)', async () => {
const workspacePath = path.join(parentDir, 'Foo.code-workspace'); const workspacePath = path.join(parentDir, 'Foo.code-workspace');
const workspace1 = await ensureWorkspaceExists(toWorkspace(workspacePath));
const workspace2 = await ensureWorkspaceExists(toWorkspace(workspacePath.toUpperCase()));
const workspace3 = await ensureWorkspaceExists(toWorkspace(workspacePath.toLowerCase()));
const workspacesJson: IBackupWorkspacesFormat = { const workspacesJson: IBackupWorkspacesFormat = {
rootWorkspaces: [ensureWorkspaceExists(toWorkspace(workspacePath)), ensureWorkspaceExists(toWorkspace(workspacePath.toUpperCase())), ensureWorkspaceExists(toWorkspace(workspacePath.toLowerCase()))], rootWorkspaces: [workspace1, workspace2, workspace3],
folderURIWorkspaces: [], folderURIWorkspaces: [],
emptyWorkspaces: [] emptyWorkspaces: []
}; };
...@@ -603,9 +607,9 @@ suite('BackupMainService', () => { ...@@ -603,9 +607,9 @@ suite('BackupMainService', () => {
}); });
}); });
test('should fail gracefully when removing a path that doesn\'t exist', () => { test('should fail gracefully when removing a path that doesn\'t exist', async () => {
ensureFolderExists(existingTestFolder1); // make sure backup folder exists, so the folder is not removed on loadSync await ensureFolderExists(existingTestFolder1); // make sure backup folder exists, so the folder is not removed on loadSync
const workspacesJson: IBackupWorkspacesFormat = { rootWorkspaces: [], folderURIWorkspaces: [existingTestFolder1.toString()], emptyWorkspaces: [] }; const workspacesJson: IBackupWorkspacesFormat = { rootWorkspaces: [], folderURIWorkspaces: [existingTestFolder1.toString()], emptyWorkspaces: [] };
return pfs.writeFile(backupWorkspacesPath, JSON.stringify(workspacesJson)).then(() => { return pfs.writeFile(backupWorkspacesPath, JSON.stringify(workspacesJson)).then(() => {
......
...@@ -69,7 +69,7 @@ suite('KeybindingsEditing', () => { ...@@ -69,7 +69,7 @@ suite('KeybindingsEditing', () => {
instantiationService = new TestInstantiationService(); instantiationService = new TestInstantiationService();
instantiationService.stub(IEnvironmentService, { appKeybindingsPath: keybindingsFile }); instantiationService.stub(IEnvironmentService, <IEnvironmentService>{ appKeybindingsPath: keybindingsFile, appSettingsPath: path.join(testDir, 'settings.json') });
instantiationService.stub(IConfigurationService, ConfigurationService); instantiationService.stub(IConfigurationService, ConfigurationService);
instantiationService.stub(IConfigurationService, 'getValue', { 'eol': '\n' }); instantiationService.stub(IConfigurationService, 'getValue', { 'eol': '\n' });
instantiationService.stub(IConfigurationService, 'onDidUpdateConfiguration', () => { }); instantiationService.stub(IConfigurationService, 'onDidUpdateConfiguration', () => { });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册