提交 ba700608 编写于 作者: B Benjamin Pasero

tests - more logging for #117032

上级 bbd39767
......@@ -101,6 +101,19 @@ export class WorkspacesManagementMainService extends Disposable implements IWork
return this.doResolveWorkspace(uri, contents);
}
/* TODO@bpasero remove me */ _test_resolveLocalWorkspaceSync(uri: URI): IResolvedWorkspace {
if (!this.isWorkspacePath(uri)) {
throw new Error('!this.isWorkspacePath(uri)'); // does not look like a valid workspace config file
}
if (uri.scheme !== Schemas.file) {
throw new Error('uri.scheme !== Schemas.file');
}
return this._test_doResolveWorkspace(uri, readFileSync(uri.fsPath, 'utf8'));
}
private isWorkspacePath(uri: URI): boolean {
return isUntitledWorkspace(uri, this.environmentMainService) || hasWorkspaceFileExtension(uri);
}
......@@ -122,6 +135,17 @@ export class WorkspacesManagementMainService extends Disposable implements IWork
return null;
}
/* TODO@bpasero remove me */ _test_doResolveWorkspace(path: URI, contents: string): IResolvedWorkspace {
const workspace = this.doParseStoredWorkspace(path, contents);
const workspaceIdentifier = getWorkspaceIdentifier(path);
return {
id: workspaceIdentifier.id,
configPath: workspaceIdentifier.configPath,
folders: toWorkspaceFolders(workspace.folders, workspaceIdentifier.configPath, extUriBiasedIgnorePathCase),
remoteAuthority: workspace.remoteAuthority
};
}
/* TODO@bpasero make private again */ doParseStoredWorkspace(path: URI, contents: string): IStoredWorkspace {
// Parse workspace file
......@@ -245,6 +269,21 @@ export class WorkspacesManagementMainService extends Disposable implements IWork
return untitledWorkspaces;
}
/* TODO@bpasero remove me */_test_getUntitledWorkspacesSync(expected: number): IUntitledWorkspaceInfo[] {
const untitledWorkspaces: IUntitledWorkspaceInfo[] = [];
const untitledWorkspacePaths = readdirSync(this.untitledWorkspacesHome.fsPath).map(folder => joinPath(this.untitledWorkspacesHome, folder, UNTITLED_WORKSPACE_NAME));
if (untitledWorkspacePaths.length !== expected) {
throw new Error(`Missing workspaces, expected ${expected} but found ${untitledWorkspacePaths.length}`);
}
for (const untitledWorkspacePath of untitledWorkspacePaths) {
const workspace = getWorkspaceIdentifier(untitledWorkspacePath);
const resolvedWorkspace = this._test_resolveLocalWorkspaceSync(untitledWorkspacePath);
untitledWorkspaces.push({ workspace, remoteAuthority: resolvedWorkspace.remoteAuthority });
}
return untitledWorkspaces;
}
async enterWorkspace(window: ICodeWindow, windows: ICodeWindow[], path: URI): Promise<IEnterWorkspaceResult | null> {
if (!window || !window.win || !window.isReady) {
return null; // return early if the window is not ready or disposed
......
......@@ -17,7 +17,7 @@ import { URI } from 'vs/base/common/uri';
import { getRandomTestPath } from 'vs/base/test/node/testUtils';
import { isWindows } from 'vs/base/common/platform';
import { normalizeDriveLetter } from 'vs/base/common/labels';
import { dirname, extUriBiasedIgnorePathCase, joinPath } from 'vs/base/common/resources';
import { extUriBiasedIgnorePathCase, joinPath } from 'vs/base/common/resources';
import { IDialogMainService } from 'vs/platform/dialogs/electron-main/dialogMainService';
import { INativeOpenDialogOptions } from 'vs/platform/dialogs/common/dialogs';
import { IBackupMainService, IWorkspaceBackupInfo } from 'vs/platform/backup/electron-main/backup';
......@@ -375,13 +375,13 @@ suite('WorkspacesManagementMainService', () => {
});
test('getUntitledWorkspaceSync', async function () {
let untitled = service.getUntitledWorkspacesSync();
let untitled = service._test_getUntitledWorkspacesSync(0);
assert.strictEqual(untitled.length, 0);
const untitledOne = await createUntitledWorkspace([cwd, tmpDir]);
assert.ok(fs.existsSync(untitledOne.configPath.fsPath));
untitled = service.getUntitledWorkspacesSync();
untitled = service._test_getUntitledWorkspacesSync(1);
assert.strictEqual(1, untitled.length);
assert.strictEqual(untitledOne.id, untitled[0].workspace.id);
assert.ok(fs.existsSync(untitledOne.configPath.fsPath), `Unexpected missing untitled workspace: ${untitledOne.configPath.fsPath} does not exist anymore?`);
......@@ -389,13 +389,10 @@ suite('WorkspacesManagementMainService', () => {
const untitledTwo = await createUntitledWorkspace([tmpDir, cwd]);
assert.ok(fs.existsSync(untitledTwo.configPath.fsPath));
const untitledHome = dirname(dirname(untitledTwo.configPath));
const beforeGettingUntitledWorkspaces = fs.readdirSync(untitledHome.fsPath).map(folder => fs.readFileSync(joinPath(untitledHome, folder, UNTITLED_WORKSPACE_NAME).fsPath, 'utf8'));
const beforeGettingUntitledWorkspaces = fs.readdirSync(environmentMainService.untitledWorkspacesHome.fsPath).map(folder => fs.readFileSync(joinPath(environmentMainService.untitledWorkspacesHome, folder, UNTITLED_WORKSPACE_NAME).fsPath, 'utf8'));
assert.strictEqual(untitledHome.fsPath, dirname(dirname(untitledOne.configPath)).fsPath, `Unexpected different untitled workspace homes: ${untitledHome} vs ${dirname(dirname(untitledTwo.configPath))}`);
for (const folder of fs.readdirSync(untitledHome.fsPath)) {
const untitledPath = joinPath(untitledHome, folder, UNTITLED_WORKSPACE_NAME);
for (const folder of fs.readdirSync(environmentMainService.untitledWorkspacesHome.fsPath)) {
const untitledPath = joinPath(environmentMainService.untitledWorkspacesHome, folder, UNTITLED_WORKSPACE_NAME);
assert.strictEqual(isUntitledWorkspace(untitledPath, environmentMainService), true);
assert.strictEqual(untitledPath.scheme, 'file');
......@@ -411,17 +408,17 @@ suite('WorkspacesManagementMainService', () => {
assert.notStrictEqual(resolvedWorkspace, null, `Untitled workspace unexpectedly did not resolve: ${untitledPath.fsPath}`);
}
untitled = service.getUntitledWorkspacesSync();
untitled = service._test_getUntitledWorkspacesSync(2);
assert.ok(fs.existsSync(untitledOne.configPath.fsPath), `Unexpected missing untitled workspace: ${untitledOne.configPath.fsPath} does not exist anymore?`);
assert.ok(fs.existsSync(untitledTwo.configPath.fsPath), `Unexpected missing untitled workspace: ${untitledTwo.configPath.fsPath} does not exist anymore?`);
assert.strictEqual(2, untitled.length, `Unexpected workspaces count (expected 2), all workspaces:\n ${fs.readdirSync(untitledHome.fsPath).map(folder => fs.readFileSync(joinPath(untitledHome, folder, UNTITLED_WORKSPACE_NAME).fsPath, 'utf8'))}, before getUntitledWorkspacesSync: ${beforeGettingUntitledWorkspaces}`);
assert.strictEqual(2, untitled.length, `Unexpected workspaces count (expected 2), all workspaces:\n ${fs.readdirSync(environmentMainService.untitledWorkspacesHome.fsPath).map(folder => fs.readFileSync(joinPath(environmentMainService.untitledWorkspacesHome, folder, UNTITLED_WORKSPACE_NAME).fsPath, 'utf8'))}, before _test_getUntitledWorkspacesSync: ${beforeGettingUntitledWorkspaces}`);
service.deleteUntitledWorkspaceSync(untitledOne);
untitled = service.getUntitledWorkspacesSync();
untitled = service._test_getUntitledWorkspacesSync(1);
assert.strictEqual(1, untitled.length);
service.deleteUntitledWorkspaceSync(untitledTwo);
untitled = service.getUntitledWorkspacesSync();
untitled = service._test_getUntitledWorkspacesSync(0);
assert.strictEqual(0, untitled.length);
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册