files - allow more file operations to run in the extension host (#172345) (#185988)

* files - allow more file operations to run in the extension host (#172345)

* fix tests

* tests

* tests

* tests
This commit is contained in:
Benjamin Pasero
2023-06-23 17:18:44 +02:00
committed by GitHub
parent 6b5330586a
commit 052ac9ca4c
4 changed files with 123 additions and 17 deletions

View File

@@ -187,7 +187,6 @@ suite('vscode API - workspace-fs', () => {
test('vscode.workspace.fs error reporting is weird #132981', async function () {
const uri = await createRandomFile();
const source = vscode.Uri.joinPath(uri, `./${Math.random().toString(16).slice(2, 8)}`);
@@ -217,4 +216,48 @@ suite('vscode API - workspace-fs', () => {
assert.strictEqual(err.code, 'FileNotFound');
}
});
test('fs.createFolder creates recursively', async function () {
const folder = root.with({ path: posix.join(root.path, 'deeply', 'nested', 'folder') });
await vscode.workspace.fs.createDirectory(folder);
let stat = await vscode.workspace.fs.stat(folder);
assert.strictEqual(stat.type, vscode.FileType.Directory);
await vscode.workspace.fs.delete(folder, { recursive: true, useTrash: false });
await vscode.workspace.fs.createDirectory(folder); // calling on existing folder is also ok!
const file = root.with({ path: posix.join(folder.path, 'file.txt') });
await vscode.workspace.fs.writeFile(file, Buffer.from('Hello World'));
const folder2 = root.with({ path: posix.join(file.path, 'invalid') });
let e;
try {
await vscode.workspace.fs.createDirectory(folder2); // cannot create folder on file path
} catch (error) {
e = error;
}
assert.ok(e);
const folder3 = root.with({ path: posix.join(root.path, 'DEEPLY', 'NESTED', 'FOLDER') });
await vscode.workspace.fs.createDirectory(folder3); // calling on different cased folder is ok!
stat = await vscode.workspace.fs.stat(folder3);
assert.strictEqual(stat.type, vscode.FileType.Directory);
await vscode.workspace.fs.delete(folder, { recursive: true, useTrash: false });
});
test('fs.writeFile creates parents recursively', async function () {
const folder = root.with({ path: posix.join(root.path, 'other-deeply', 'nested', 'folder') });
const file = root.with({ path: posix.join(folder.path, 'file.txt') });
await vscode.workspace.fs.writeFile(file, Buffer.from('Hello World'));
const stat = await vscode.workspace.fs.stat(file);
assert.strictEqual(stat.type, vscode.FileType.File);
await vscode.workspace.fs.delete(folder, { recursive: true, useTrash: false });
});
});