mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
Cleanup some file related unit tests (#114895)
* wip * clean up * more test cleanup * cleanup more * more cleanup
This commit is contained in:
parent
a38cc82a15
commit
e60e0eab35
|
@ -509,15 +509,15 @@ export async function move(source: string, target: string): Promise<void> {
|
|||
}
|
||||
}
|
||||
|
||||
export async function copy(source: string, target: string, copiedSourcesIn?: { [path: string]: boolean }): Promise<void> {
|
||||
export async function copy(source: string, target: string, handledSourcesIn?: { [path: string]: boolean }): Promise<void> {
|
||||
|
||||
// Keep track of paths already copied to prevent
|
||||
// cycles from symbolic links to cause issues
|
||||
const copiedSources = copiedSourcesIn ?? Object.create(null);
|
||||
if (copiedSources[source]) {
|
||||
const handledSources = handledSourcesIn ?? Object.create(null);
|
||||
if (handledSources[source]) {
|
||||
return;
|
||||
} else {
|
||||
copiedSources[source] = true;
|
||||
handledSources[source] = true;
|
||||
}
|
||||
|
||||
const { stat, symbolicLink } = await statLink(source);
|
||||
|
@ -536,7 +536,7 @@ export async function copy(source: string, target: string, copiedSourcesIn?: { [
|
|||
const files = await readdir(source);
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const file = files[i];
|
||||
await copy(join(source, file), join(target, file), copiedSources);
|
||||
await copy(join(source, file), join(target, file), handledSources);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,20 +17,20 @@ import { generateUuid } from 'vs/base/common/uuid';
|
|||
|
||||
flakySuite('Storage Library', function () {
|
||||
|
||||
let storageDir: string;
|
||||
let testDir: string;
|
||||
|
||||
setup(function () {
|
||||
storageDir = getRandomTestPath(tmpdir(), 'vsctests', 'storagelibrary');
|
||||
testDir = getRandomTestPath(tmpdir(), 'vsctests', 'storagelibrary');
|
||||
|
||||
return mkdirp(storageDir);
|
||||
return mkdirp(testDir);
|
||||
});
|
||||
|
||||
teardown(function () {
|
||||
return rimraf(storageDir);
|
||||
return rimraf(testDir);
|
||||
});
|
||||
|
||||
test('basics', async () => {
|
||||
const storage = new Storage(new SQLiteStorageDatabase(join(storageDir, 'storage.db')));
|
||||
const storage = new Storage(new SQLiteStorageDatabase(join(testDir, 'storage.db')));
|
||||
|
||||
await storage.init();
|
||||
|
||||
|
@ -116,7 +116,7 @@ flakySuite('Storage Library', function () {
|
|||
}
|
||||
}
|
||||
|
||||
const database = new TestSQLiteStorageDatabase(join(storageDir, 'storage.db'));
|
||||
const database = new TestSQLiteStorageDatabase(join(testDir, 'storage.db'));
|
||||
const storage = new Storage(database);
|
||||
|
||||
let changes = new Set<string>();
|
||||
|
@ -158,7 +158,7 @@ flakySuite('Storage Library', function () {
|
|||
});
|
||||
|
||||
test('close flushes data', async () => {
|
||||
let storage = new Storage(new SQLiteStorageDatabase(join(storageDir, 'storage.db')));
|
||||
let storage = new Storage(new SQLiteStorageDatabase(join(testDir, 'storage.db')));
|
||||
await storage.init();
|
||||
|
||||
const set1Promise = storage.set('foo', 'bar');
|
||||
|
@ -178,7 +178,7 @@ flakySuite('Storage Library', function () {
|
|||
strictEqual(setPromiseResolved, true);
|
||||
strictEqual(flushPromiseResolved, true);
|
||||
|
||||
storage = new Storage(new SQLiteStorageDatabase(join(storageDir, 'storage.db')));
|
||||
storage = new Storage(new SQLiteStorageDatabase(join(testDir, 'storage.db')));
|
||||
await storage.init();
|
||||
|
||||
strictEqual(storage.get('foo'), 'bar');
|
||||
|
@ -186,7 +186,7 @@ flakySuite('Storage Library', function () {
|
|||
|
||||
await storage.close();
|
||||
|
||||
storage = new Storage(new SQLiteStorageDatabase(join(storageDir, 'storage.db')));
|
||||
storage = new Storage(new SQLiteStorageDatabase(join(testDir, 'storage.db')));
|
||||
await storage.init();
|
||||
|
||||
const delete1Promise = storage.delete('foo');
|
||||
|
@ -202,7 +202,7 @@ flakySuite('Storage Library', function () {
|
|||
|
||||
strictEqual(deletePromiseResolved, true);
|
||||
|
||||
storage = new Storage(new SQLiteStorageDatabase(join(storageDir, 'storage.db')));
|
||||
storage = new Storage(new SQLiteStorageDatabase(join(testDir, 'storage.db')));
|
||||
await storage.init();
|
||||
|
||||
ok(!storage.get('foo'));
|
||||
|
@ -212,7 +212,7 @@ flakySuite('Storage Library', function () {
|
|||
});
|
||||
|
||||
test('conflicting updates', async () => {
|
||||
let storage = new Storage(new SQLiteStorageDatabase(join(storageDir, 'storage.db')));
|
||||
let storage = new Storage(new SQLiteStorageDatabase(join(testDir, 'storage.db')));
|
||||
await storage.init();
|
||||
|
||||
let changes = new Set<string>();
|
||||
|
@ -254,7 +254,7 @@ flakySuite('Storage Library', function () {
|
|||
});
|
||||
|
||||
test('corrupt DB recovers', async () => {
|
||||
const storageFile = join(storageDir, 'storage.db');
|
||||
const storageFile = join(testDir, 'storage.db');
|
||||
|
||||
let storage = new Storage(new SQLiteStorageDatabase(storageFile));
|
||||
await storage.init();
|
||||
|
|
|
@ -48,12 +48,8 @@ flakySuite('Extpath', () => {
|
|||
assert.ok(realpathVal);
|
||||
});
|
||||
|
||||
test('realpathSync', async () => {
|
||||
try {
|
||||
const realpath = realpathSync(testDir);
|
||||
assert.ok(realpath);
|
||||
} catch (error) {
|
||||
assert.fail(error);
|
||||
}
|
||||
test('realpathSync', () => {
|
||||
const realpath = realpathSync(testDir);
|
||||
assert.ok(realpath);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -13,11 +13,11 @@ suite('Keytar', () => {
|
|||
const name = `VSCode Test ${Math.floor(Math.random() * 1e9)}`;
|
||||
try {
|
||||
await keytar.setPassword(name, 'foo', 'bar');
|
||||
assert.equal(await keytar.findPassword(name), 'bar');
|
||||
assert.equal((await keytar.findCredentials(name)).length, 1);
|
||||
assert.equal(await keytar.getPassword(name, 'foo'), 'bar');
|
||||
assert.strictEqual(await keytar.findPassword(name), 'bar');
|
||||
assert.strictEqual((await keytar.findCredentials(name)).length, 1);
|
||||
assert.strictEqual(await keytar.getPassword(name, 'foo'), 'bar');
|
||||
await keytar.deletePassword(name, 'foo');
|
||||
assert.equal(await keytar.getPassword(name, 'foo'), undefined);
|
||||
assert.strictEqual(await keytar.getPassword(name, 'foo'), null);
|
||||
} catch (err) {
|
||||
// try to clean up
|
||||
try {
|
||||
|
|
|
@ -8,7 +8,7 @@ import * as fs from 'fs';
|
|||
import { tmpdir } from 'os';
|
||||
import { join, sep } from 'vs/base/common/path';
|
||||
import { generateUuid } from 'vs/base/common/uuid';
|
||||
import { copy, mkdirp, move, readdir, readDirsInDir, readdirWithFileTypes, renameIgnoreError, rimraf, RimRafMode, rimrafSync, statLink, writeFile, writeFileSync } from 'vs/base/node/pfs';
|
||||
import { copy, exists, mkdirp, move, readdir, readDirsInDir, readdirWithFileTypes, readFile, renameIgnoreError, rimraf, RimRafMode, rimrafSync, statLink, writeFile, writeFileSync } from 'vs/base/node/pfs';
|
||||
import { timeout } from 'vs/base/common/async';
|
||||
import { getPathFromAmdModule } from 'vs/base/common/amd';
|
||||
import { isWindows } from 'vs/base/common/platform';
|
||||
|
@ -18,33 +18,34 @@ import { flakySuite, getRandomTestPath } from 'vs/base/test/node/testUtils';
|
|||
|
||||
flakySuite('PFS', function () {
|
||||
|
||||
test('writeFile', async () => {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = generateUuid();
|
||||
const newDir = join(parentDir, 'pfs', id);
|
||||
const testFile = join(newDir, 'writefile.txt');
|
||||
let testDir: string;
|
||||
|
||||
await mkdirp(newDir, 493);
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
setup(() => {
|
||||
testDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
|
||||
return mkdirp(testDir, 493);
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
return rimraf(testDir);
|
||||
});
|
||||
|
||||
test('writeFile', async () => {
|
||||
const testFile = join(testDir, 'writefile.txt');
|
||||
|
||||
assert.ok(!(await exists(testFile)));
|
||||
|
||||
await writeFile(testFile, 'Hello World', (null!));
|
||||
assert.equal(fs.readFileSync(testFile), 'Hello World');
|
||||
|
||||
return rimraf(parentDir);
|
||||
assert.strictEqual((await readFile(testFile)).toString(), 'Hello World');
|
||||
});
|
||||
|
||||
test('writeFile - parallel write on different files works', async () => {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = generateUuid();
|
||||
const newDir = join(parentDir, 'pfs', id);
|
||||
const testFile1 = join(newDir, 'writefile1.txt');
|
||||
const testFile2 = join(newDir, 'writefile2.txt');
|
||||
const testFile3 = join(newDir, 'writefile3.txt');
|
||||
const testFile4 = join(newDir, 'writefile4.txt');
|
||||
const testFile5 = join(newDir, 'writefile5.txt');
|
||||
|
||||
await mkdirp(newDir, 493);
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
const testFile1 = join(testDir, 'writefile1.txt');
|
||||
const testFile2 = join(testDir, 'writefile2.txt');
|
||||
const testFile3 = join(testDir, 'writefile3.txt');
|
||||
const testFile4 = join(testDir, 'writefile4.txt');
|
||||
const testFile5 = join(testDir, 'writefile5.txt');
|
||||
|
||||
await Promise.all([
|
||||
writeFile(testFile1, 'Hello World 1', (null!)),
|
||||
|
@ -53,23 +54,15 @@ flakySuite('PFS', function () {
|
|||
writeFile(testFile4, 'Hello World 4', (null!)),
|
||||
writeFile(testFile5, 'Hello World 5', (null!))
|
||||
]);
|
||||
assert.equal(fs.readFileSync(testFile1), 'Hello World 1');
|
||||
assert.equal(fs.readFileSync(testFile2), 'Hello World 2');
|
||||
assert.equal(fs.readFileSync(testFile3), 'Hello World 3');
|
||||
assert.equal(fs.readFileSync(testFile4), 'Hello World 4');
|
||||
assert.equal(fs.readFileSync(testFile5), 'Hello World 5');
|
||||
|
||||
return rimraf(parentDir);
|
||||
assert.strictEqual(fs.readFileSync(testFile1).toString(), 'Hello World 1');
|
||||
assert.strictEqual(fs.readFileSync(testFile2).toString(), 'Hello World 2');
|
||||
assert.strictEqual(fs.readFileSync(testFile3).toString(), 'Hello World 3');
|
||||
assert.strictEqual(fs.readFileSync(testFile4).toString(), 'Hello World 4');
|
||||
assert.strictEqual(fs.readFileSync(testFile5).toString(), 'Hello World 5');
|
||||
});
|
||||
|
||||
test('writeFile - parallel write on same files works and is sequentalized', async () => {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = generateUuid();
|
||||
const newDir = join(parentDir, 'pfs', id);
|
||||
const testFile = join(newDir, 'writefile.txt');
|
||||
|
||||
await mkdirp(newDir, 493);
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
const testFile = join(testDir, 'writefile.txt');
|
||||
|
||||
await Promise.all([
|
||||
writeFile(testFile, 'Hello World 1', undefined),
|
||||
|
@ -78,166 +71,91 @@ flakySuite('PFS', function () {
|
|||
writeFile(testFile, 'Hello World 4', undefined),
|
||||
timeout(10).then(() => writeFile(testFile, 'Hello World 5', undefined))
|
||||
]);
|
||||
assert.equal(fs.readFileSync(testFile), 'Hello World 5');
|
||||
|
||||
return rimraf(parentDir);
|
||||
assert.strictEqual(fs.readFileSync(testFile).toString(), 'Hello World 5');
|
||||
});
|
||||
|
||||
test('rimraf - simple - unlink', async () => {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = generateUuid();
|
||||
const newDir = join(parentDir, 'pfs', id);
|
||||
fs.writeFileSync(join(testDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(join(testDir, 'someOtherFile.txt'), 'Contents');
|
||||
|
||||
await mkdirp(newDir, 493);
|
||||
fs.writeFileSync(join(newDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(join(newDir, 'someOtherFile.txt'), 'Contents');
|
||||
|
||||
await rimraf(newDir);
|
||||
assert.ok(!fs.existsSync(newDir));
|
||||
|
||||
return rimraf(parentDir);
|
||||
await rimraf(testDir);
|
||||
assert.ok(!fs.existsSync(testDir));
|
||||
});
|
||||
|
||||
test('rimraf - simple - move', async () => {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = generateUuid();
|
||||
const newDir = join(parentDir, 'pfs', id);
|
||||
fs.writeFileSync(join(testDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(join(testDir, 'someOtherFile.txt'), 'Contents');
|
||||
|
||||
await mkdirp(newDir, 493);
|
||||
fs.writeFileSync(join(newDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(join(newDir, 'someOtherFile.txt'), 'Contents');
|
||||
|
||||
await rimraf(newDir, RimRafMode.MOVE);
|
||||
assert.ok(!fs.existsSync(newDir));
|
||||
|
||||
return rimraf(parentDir);
|
||||
await rimraf(testDir, RimRafMode.MOVE);
|
||||
assert.ok(!fs.existsSync(testDir));
|
||||
});
|
||||
|
||||
test('rimraf - recursive folder structure - unlink', async () => {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = generateUuid();
|
||||
const newDir = join(parentDir, 'pfs', id);
|
||||
fs.writeFileSync(join(testDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(join(testDir, 'someOtherFile.txt'), 'Contents');
|
||||
fs.mkdirSync(join(testDir, 'somefolder'));
|
||||
fs.writeFileSync(join(testDir, 'somefolder', 'somefile.txt'), 'Contents');
|
||||
|
||||
await mkdirp(newDir, 493);
|
||||
fs.writeFileSync(join(newDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(join(newDir, 'someOtherFile.txt'), 'Contents');
|
||||
fs.mkdirSync(join(newDir, 'somefolder'));
|
||||
fs.writeFileSync(join(newDir, 'somefolder', 'somefile.txt'), 'Contents');
|
||||
|
||||
await rimraf(newDir);
|
||||
assert.ok(!fs.existsSync(newDir));
|
||||
|
||||
return rimraf(parentDir);
|
||||
await rimraf(testDir);
|
||||
assert.ok(!fs.existsSync(testDir));
|
||||
});
|
||||
|
||||
test('rimraf - recursive folder structure - move', async () => {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = generateUuid();
|
||||
const newDir = join(parentDir, 'pfs', id);
|
||||
fs.writeFileSync(join(testDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(join(testDir, 'someOtherFile.txt'), 'Contents');
|
||||
fs.mkdirSync(join(testDir, 'somefolder'));
|
||||
fs.writeFileSync(join(testDir, 'somefolder', 'somefile.txt'), 'Contents');
|
||||
|
||||
await mkdirp(newDir, 493);
|
||||
fs.writeFileSync(join(newDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(join(newDir, 'someOtherFile.txt'), 'Contents');
|
||||
fs.mkdirSync(join(newDir, 'somefolder'));
|
||||
fs.writeFileSync(join(newDir, 'somefolder', 'somefile.txt'), 'Contents');
|
||||
|
||||
await rimraf(newDir, RimRafMode.MOVE);
|
||||
assert.ok(!fs.existsSync(newDir));
|
||||
|
||||
return rimraf(parentDir);
|
||||
await rimraf(testDir, RimRafMode.MOVE);
|
||||
assert.ok(!fs.existsSync(testDir));
|
||||
});
|
||||
|
||||
test('rimraf - simple ends with dot - move', async () => {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = `${generateUuid()}.`;
|
||||
const newDir = join(parentDir, 'pfs', id);
|
||||
fs.writeFileSync(join(testDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(join(testDir, 'someOtherFile.txt'), 'Contents');
|
||||
|
||||
await mkdirp(newDir, 493);
|
||||
fs.writeFileSync(join(newDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(join(newDir, 'someOtherFile.txt'), 'Contents');
|
||||
|
||||
await rimraf(newDir, RimRafMode.MOVE);
|
||||
assert.ok(!fs.existsSync(newDir));
|
||||
|
||||
return rimraf(parentDir);
|
||||
await rimraf(testDir, RimRafMode.MOVE);
|
||||
assert.ok(!fs.existsSync(testDir));
|
||||
});
|
||||
|
||||
test('rimraf - simple ends with dot slash/backslash - move', async () => {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = `${generateUuid()}.`;
|
||||
const newDir = join(parentDir, 'pfs', id);
|
||||
fs.writeFileSync(join(testDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(join(testDir, 'someOtherFile.txt'), 'Contents');
|
||||
|
||||
await mkdirp(newDir, 493);
|
||||
fs.writeFileSync(join(newDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(join(newDir, 'someOtherFile.txt'), 'Contents');
|
||||
|
||||
await rimraf(`${newDir}${sep}`, RimRafMode.MOVE);
|
||||
assert.ok(!fs.existsSync(newDir));
|
||||
|
||||
return rimraf(parentDir);
|
||||
await rimraf(`${testDir}${sep}`, RimRafMode.MOVE);
|
||||
assert.ok(!fs.existsSync(testDir));
|
||||
});
|
||||
|
||||
test('rimrafSync - swallows file not found error', function () {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = generateUuid();
|
||||
const newDir = join(parentDir, 'pfs', id);
|
||||
const nonExistingDir = join(testDir, 'not-existing');
|
||||
rimrafSync(nonExistingDir);
|
||||
|
||||
rimrafSync(newDir);
|
||||
|
||||
assert.ok(!fs.existsSync(newDir));
|
||||
|
||||
return rimraf(parentDir);
|
||||
assert.ok(!fs.existsSync(nonExistingDir));
|
||||
});
|
||||
|
||||
test('rimrafSync - simple', async () => {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = generateUuid();
|
||||
const newDir = join(parentDir, 'pfs', id);
|
||||
fs.writeFileSync(join(testDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(join(testDir, 'someOtherFile.txt'), 'Contents');
|
||||
|
||||
await mkdirp(newDir, 493);
|
||||
rimrafSync(testDir);
|
||||
|
||||
fs.writeFileSync(join(newDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(join(newDir, 'someOtherFile.txt'), 'Contents');
|
||||
|
||||
rimrafSync(newDir);
|
||||
|
||||
assert.ok(!fs.existsSync(newDir));
|
||||
|
||||
return rimraf(parentDir);
|
||||
assert.ok(!fs.existsSync(testDir));
|
||||
});
|
||||
|
||||
test('rimrafSync - recursive folder structure', async () => {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = generateUuid();
|
||||
const newDir = join(parentDir, 'pfs', id);
|
||||
fs.writeFileSync(join(testDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(join(testDir, 'someOtherFile.txt'), 'Contents');
|
||||
|
||||
await mkdirp(newDir, 493);
|
||||
fs.writeFileSync(join(newDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(join(newDir, 'someOtherFile.txt'), 'Contents');
|
||||
fs.mkdirSync(join(testDir, 'somefolder'));
|
||||
fs.writeFileSync(join(testDir, 'somefolder', 'somefile.txt'), 'Contents');
|
||||
|
||||
fs.mkdirSync(join(newDir, 'somefolder'));
|
||||
fs.writeFileSync(join(newDir, 'somefolder', 'somefile.txt'), 'Contents');
|
||||
rimrafSync(testDir);
|
||||
|
||||
rimrafSync(newDir);
|
||||
|
||||
assert.ok(!fs.existsSync(newDir));
|
||||
|
||||
return rimraf(parentDir);
|
||||
assert.ok(!fs.existsSync(testDir));
|
||||
});
|
||||
|
||||
test('moveIgnoreError', async () => {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = generateUuid();
|
||||
const newDir = join(parentDir, 'pfs', id);
|
||||
|
||||
await mkdirp(newDir, 493);
|
||||
try {
|
||||
await renameIgnoreError(join(newDir, 'foo'), join(newDir, 'bar'));
|
||||
return rimraf(parentDir, RimRafMode.MOVE);
|
||||
}
|
||||
catch (error) {
|
||||
assert.fail(error);
|
||||
}
|
||||
test('moveIgnoreError', () => {
|
||||
return renameIgnoreError(join(testDir, 'foo'), join(testDir, 'bar'));
|
||||
});
|
||||
|
||||
test('copy, move and delete', async () => {
|
||||
|
@ -279,15 +197,13 @@ flakySuite('PFS', function () {
|
|||
|
||||
(isWindows ? test.skip : test)('copy skips over dangling symbolic links', async () => { // Symlinks are not the same on win, and we can not create them programmatically without admin privileges
|
||||
const id1 = generateUuid();
|
||||
const parentDir = join(tmpdir(), 'vsctests', id1);
|
||||
|
||||
const symbolicLinkTarget = join(parentDir, 'pfs', id1);
|
||||
const symbolicLinkTarget = join(testDir, id1);
|
||||
|
||||
const id2 = generateUuid();
|
||||
const symbolicLink = join(parentDir, 'pfs', id2);
|
||||
const symbolicLink = join(testDir, id2);
|
||||
|
||||
const id3 = generateUuid();
|
||||
const copyTarget = join(parentDir, 'pfs', id3);
|
||||
const copyTarget = join(testDir, id3);
|
||||
|
||||
await mkdirp(symbolicLinkTarget, 493);
|
||||
|
||||
|
@ -298,51 +214,36 @@ flakySuite('PFS', function () {
|
|||
await copy(symbolicLink, copyTarget); // this should not throw
|
||||
|
||||
assert.ok(!fs.existsSync(copyTarget));
|
||||
|
||||
return rimraf(parentDir);
|
||||
});
|
||||
|
||||
test('mkdirp', async () => {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = generateUuid();
|
||||
const newDir = join(parentDir, 'pfs', id);
|
||||
const newDir = join(testDir, generateUuid());
|
||||
|
||||
await mkdirp(newDir, 493);
|
||||
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
|
||||
return rimraf(parentDir);
|
||||
});
|
||||
|
||||
test('readDirsInDir', async () => {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = generateUuid();
|
||||
const newDir = join(parentDir, 'pfs', id);
|
||||
fs.mkdirSync(join(testDir, 'somefolder1'));
|
||||
fs.mkdirSync(join(testDir, 'somefolder2'));
|
||||
fs.mkdirSync(join(testDir, 'somefolder3'));
|
||||
fs.writeFileSync(join(testDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(join(testDir, 'someOtherFile.txt'), 'Contents');
|
||||
|
||||
await mkdirp(newDir, 493);
|
||||
|
||||
fs.mkdirSync(join(newDir, 'somefolder1'));
|
||||
fs.mkdirSync(join(newDir, 'somefolder2'));
|
||||
fs.mkdirSync(join(newDir, 'somefolder3'));
|
||||
fs.writeFileSync(join(newDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(join(newDir, 'someOtherFile.txt'), 'Contents');
|
||||
|
||||
const result = await readDirsInDir(newDir);
|
||||
assert.equal(result.length, 3);
|
||||
const result = await readDirsInDir(testDir);
|
||||
assert.strictEqual(result.length, 3);
|
||||
assert.ok(result.indexOf('somefolder1') !== -1);
|
||||
assert.ok(result.indexOf('somefolder2') !== -1);
|
||||
assert.ok(result.indexOf('somefolder3') !== -1);
|
||||
|
||||
return rimraf(parentDir);
|
||||
});
|
||||
|
||||
(isWindows ? test.skip : test)('stat link', async () => { // Symlinks are not the same on win, and we can not create them programmatically without admin privileges
|
||||
const id1 = generateUuid();
|
||||
const parentDir = join(tmpdir(), 'vsctests', id1);
|
||||
const directory = join(parentDir, 'pfs', id1);
|
||||
const directory = join(testDir, id1);
|
||||
|
||||
const id2 = generateUuid();
|
||||
const symbolicLink = join(parentDir, 'pfs', id2);
|
||||
const symbolicLink = join(testDir, id2);
|
||||
|
||||
await mkdirp(directory, 493);
|
||||
|
||||
|
@ -354,17 +255,14 @@ flakySuite('PFS', function () {
|
|||
statAndIsLink = await statLink(symbolicLink);
|
||||
assert.ok(statAndIsLink?.symbolicLink);
|
||||
assert.ok(!statAndIsLink?.symbolicLink?.dangling);
|
||||
|
||||
return rimraf(parentDir);
|
||||
});
|
||||
|
||||
(isWindows ? test.skip : test)('stat link (non existing target)', async () => { // Symlinks are not the same on win, and we can not create them programmatically without admin privileges
|
||||
const id1 = generateUuid();
|
||||
const parentDir = join(tmpdir(), 'vsctests', id1);
|
||||
const directory = join(parentDir, 'pfs', id1);
|
||||
const directory = join(testDir, id1);
|
||||
|
||||
const id2 = generateUuid();
|
||||
const symbolicLink = join(parentDir, 'pfs', id2);
|
||||
const symbolicLink = join(testDir, id2);
|
||||
|
||||
await mkdirp(directory, 493);
|
||||
|
||||
|
@ -375,33 +273,24 @@ flakySuite('PFS', function () {
|
|||
const statAndIsLink = await statLink(symbolicLink);
|
||||
assert.ok(statAndIsLink?.symbolicLink);
|
||||
assert.ok(statAndIsLink?.symbolicLink?.dangling);
|
||||
|
||||
return rimraf(parentDir);
|
||||
});
|
||||
|
||||
test('readdir', async () => {
|
||||
if (canNormalize && typeof process.versions['electron'] !== 'undefined' /* needs electron */) {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = generateUuid();
|
||||
const newDir = join(parentDir, 'pfs', id, 'öäü');
|
||||
const newDir = join(testDir, 'pfs', id, 'öäü');
|
||||
|
||||
await mkdirp(newDir, 493);
|
||||
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
|
||||
const children = await readdir(join(parentDir, 'pfs', id));
|
||||
assert.equal(children.some(n => n === 'öäü'), true); // Mac always converts to NFD, so
|
||||
|
||||
return rimraf(parentDir);
|
||||
const children = await readdir(join(testDir, 'pfs', id));
|
||||
assert.strictEqual(children.some(n => n === 'öäü'), true); // Mac always converts to NFD, so
|
||||
}
|
||||
});
|
||||
|
||||
test('readdirWithFileTypes', async () => {
|
||||
if (canNormalize && typeof process.versions['electron'] !== 'undefined' /* needs electron */) {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = generateUuid();
|
||||
const testDir = join(parentDir, 'pfs', id);
|
||||
|
||||
const newDir = join(testDir, 'öäü');
|
||||
await mkdirp(newDir, 493);
|
||||
|
||||
|
@ -411,13 +300,11 @@ flakySuite('PFS', function () {
|
|||
|
||||
const children = await readdirWithFileTypes(testDir);
|
||||
|
||||
assert.equal(children.some(n => n.name === 'öäü'), true); // Mac always converts to NFD, so
|
||||
assert.equal(children.some(n => n.isDirectory()), true);
|
||||
assert.strictEqual(children.some(n => n.name === 'öäü'), true); // Mac always converts to NFD, so
|
||||
assert.strictEqual(children.some(n => n.isDirectory()), true);
|
||||
|
||||
assert.equal(children.some(n => n.name === 'somefile.txt'), true);
|
||||
assert.equal(children.some(n => n.isFile()), true);
|
||||
|
||||
return rimraf(parentDir);
|
||||
assert.strictEqual(children.some(n => n.name === 'somefile.txt'), true);
|
||||
assert.strictEqual(children.some(n => n.isFile()), true);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -448,34 +335,21 @@ flakySuite('PFS', function () {
|
|||
bigData: string | Buffer | Uint8Array,
|
||||
bigDataValue: string
|
||||
): Promise<void> {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = generateUuid();
|
||||
const newDir = join(parentDir, 'pfs', id);
|
||||
const testFile = join(newDir, 'flushed.txt');
|
||||
const testFile = join(testDir, 'flushed.txt');
|
||||
|
||||
await mkdirp(newDir, 493);
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
assert.ok(fs.existsSync(testDir));
|
||||
|
||||
await writeFile(testFile, smallData);
|
||||
assert.equal(fs.readFileSync(testFile), smallDataValue);
|
||||
assert.strictEqual(fs.readFileSync(testFile).toString(), smallDataValue);
|
||||
|
||||
await writeFile(testFile, bigData);
|
||||
assert.equal(fs.readFileSync(testFile), bigDataValue);
|
||||
|
||||
return rimraf(parentDir);
|
||||
assert.strictEqual(fs.readFileSync(testFile).toString(), bigDataValue);
|
||||
}
|
||||
|
||||
test('writeFile (string, error handling)', async () => {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = generateUuid();
|
||||
const newDir = join(parentDir, 'pfs', id);
|
||||
const testFile = join(newDir, 'flushed.txt');
|
||||
const testFile = join(testDir, 'flushed.txt');
|
||||
|
||||
await mkdirp(newDir, 493);
|
||||
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
|
||||
fs.mkdirSync(testFile); // this will trigger an error because testFile is now a directory!
|
||||
fs.mkdirSync(testFile); // this will trigger an error later because testFile is now a directory!
|
||||
|
||||
let expectedError: Error | undefined;
|
||||
try {
|
||||
|
@ -485,28 +359,17 @@ flakySuite('PFS', function () {
|
|||
}
|
||||
|
||||
assert.ok(expectedError);
|
||||
|
||||
return rimraf(parentDir);
|
||||
});
|
||||
|
||||
test('writeFileSync', async () => {
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs');
|
||||
const id = generateUuid();
|
||||
const newDir = join(parentDir, 'pfs', id);
|
||||
const testFile = join(newDir, 'flushed.txt');
|
||||
|
||||
await mkdirp(newDir, 493);
|
||||
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
const testFile = join(testDir, 'flushed.txt');
|
||||
|
||||
writeFileSync(testFile, 'Hello World');
|
||||
assert.equal(fs.readFileSync(testFile), 'Hello World');
|
||||
assert.strictEqual(fs.readFileSync(testFile).toString(), 'Hello World');
|
||||
|
||||
const largeString = (new Array(100 * 1024)).join('Large String\n');
|
||||
|
||||
writeFileSync(testFile, largeString);
|
||||
assert.equal(fs.readFileSync(testFile), largeString);
|
||||
|
||||
return rimraf(parentDir);
|
||||
assert.strictEqual(fs.readFileSync(testFile).toString(), largeString);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -27,32 +27,7 @@ import { isEqual } from 'vs/base/common/resources';
|
|||
flakySuite('BackupMainService', () => {
|
||||
|
||||
function assertEqualUris(actual: URI[], expected: URI[]) {
|
||||
assert.deepEqual(actual.map(a => a.toString()), expected.map(a => a.toString()));
|
||||
}
|
||||
|
||||
const parentDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'backupservice');
|
||||
const backupHome = path.join(parentDir, 'Backups');
|
||||
const backupWorkspacesPath = path.join(backupHome, 'workspaces.json');
|
||||
|
||||
const environmentService = new EnvironmentMainService(parseArgs(process.argv, OPTIONS));
|
||||
|
||||
class TestBackupMainService extends BackupMainService {
|
||||
|
||||
constructor(backupHome: string, backupWorkspacesPath: string, configService: TestConfigurationService) {
|
||||
super(environmentService, configService, new ConsoleLogMainService());
|
||||
|
||||
this.backupHome = backupHome;
|
||||
this.workspacesJsonPath = backupWorkspacesPath;
|
||||
}
|
||||
|
||||
toBackupPath(arg: URI | string): string {
|
||||
const id = arg instanceof URI ? super.getFolderHash(arg) : arg;
|
||||
return path.join(this.backupHome, id);
|
||||
}
|
||||
|
||||
getFolderHash(folderUri: URI): string {
|
||||
return super.getFolderHash(folderUri);
|
||||
}
|
||||
assert.deepStrictEqual(actual.map(a => a.toString()), expected.map(a => a.toString()));
|
||||
}
|
||||
|
||||
function toWorkspace(path: string): IWorkspaceIdentifier {
|
||||
|
@ -79,20 +54,23 @@ flakySuite('BackupMainService', () => {
|
|||
};
|
||||
}
|
||||
|
||||
async function ensureFolderExists(uri: URI): Promise<void> {
|
||||
function ensureFolderExists(uri: URI): Promise<void> {
|
||||
if (!fs.existsSync(uri.fsPath)) {
|
||||
fs.mkdirSync(uri.fsPath);
|
||||
}
|
||||
|
||||
const backupFolder = service.toBackupPath(uri);
|
||||
await createBackupFolder(backupFolder);
|
||||
return createBackupFolder(backupFolder);
|
||||
}
|
||||
|
||||
async function ensureWorkspaceExists(workspace: IWorkspaceIdentifier): Promise<IWorkspaceIdentifier> {
|
||||
if (!fs.existsSync(workspace.configPath.fsPath)) {
|
||||
await pfs.writeFile(workspace.configPath.fsPath, 'Hello');
|
||||
}
|
||||
|
||||
const backupFolder = service.toBackupPath(workspace.id);
|
||||
await createBackupFolder(backupFolder);
|
||||
|
||||
return workspace;
|
||||
}
|
||||
|
||||
|
@ -111,25 +89,49 @@ flakySuite('BackupMainService', () => {
|
|||
const fooFile = URI.file(platform.isWindows ? 'C:\\foo' : '/foo');
|
||||
const barFile = URI.file(platform.isWindows ? 'C:\\bar' : '/bar');
|
||||
|
||||
const existingTestFolder1 = URI.file(path.join(parentDir, 'folder1'));
|
||||
|
||||
let service: TestBackupMainService;
|
||||
let service: BackupMainService & { toBackupPath(arg: URI | string): string, getFolderHash(folderUri: URI): string };
|
||||
let configService: TestConfigurationService;
|
||||
|
||||
setup(async () => {
|
||||
let environmentService: EnvironmentMainService;
|
||||
let testDir: string;
|
||||
let backupHome: string;
|
||||
let backupWorkspacesPath: string;
|
||||
let existingTestFolder1: URI;
|
||||
|
||||
setup(async () => {
|
||||
testDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'backupmainservice');
|
||||
backupHome = path.join(testDir, 'Backups');
|
||||
backupWorkspacesPath = path.join(backupHome, 'workspaces.json');
|
||||
existingTestFolder1 = URI.file(path.join(testDir, 'folder1'));
|
||||
|
||||
environmentService = new EnvironmentMainService(parseArgs(process.argv, OPTIONS));
|
||||
|
||||
// Delete any existing backups completely and then re-create it.
|
||||
await pfs.rimraf(backupHome);
|
||||
await pfs.mkdirp(backupHome);
|
||||
|
||||
configService = new TestConfigurationService();
|
||||
service = new TestBackupMainService(backupHome, backupWorkspacesPath, configService);
|
||||
service = new class TestBackupMainService extends BackupMainService {
|
||||
constructor() {
|
||||
super(environmentService, configService, new ConsoleLogMainService());
|
||||
|
||||
this.backupHome = backupHome;
|
||||
this.workspacesJsonPath = backupWorkspacesPath;
|
||||
}
|
||||
|
||||
toBackupPath(arg: URI | string): string {
|
||||
const id = arg instanceof URI ? super.getFolderHash(arg) : arg;
|
||||
return path.join(this.backupHome, id);
|
||||
}
|
||||
|
||||
getFolderHash(folderUri: URI): string {
|
||||
return super.getFolderHash(folderUri);
|
||||
}
|
||||
};
|
||||
|
||||
return service.initialize();
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
return pfs.rimraf(backupHome);
|
||||
return pfs.rimraf(testDir);
|
||||
});
|
||||
|
||||
test('service validates backup workspaces on startup and cleans up (folder workspaces)', async function () {
|
||||
|
@ -169,12 +171,12 @@ flakySuite('BackupMainService', () => {
|
|||
fs.mkdirSync(service.toBackupPath(barFile));
|
||||
fs.mkdirSync(fileBackups);
|
||||
service.registerFolderBackupSync(fooFile);
|
||||
assert.equal(service.getFolderBackupPaths().length, 1);
|
||||
assert.equal(service.getEmptyWindowBackupPaths().length, 0);
|
||||
assert.strictEqual(service.getFolderBackupPaths().length, 1);
|
||||
assert.strictEqual(service.getEmptyWindowBackupPaths().length, 0);
|
||||
fs.writeFileSync(path.join(fileBackups, 'backup.txt'), '');
|
||||
await service.initialize();
|
||||
assert.equal(service.getFolderBackupPaths().length, 0);
|
||||
assert.equal(service.getEmptyWindowBackupPaths().length, 1);
|
||||
assert.strictEqual(service.getFolderBackupPaths().length, 0);
|
||||
assert.strictEqual(service.getEmptyWindowBackupPaths().length, 1);
|
||||
});
|
||||
|
||||
test('service validates backup workspaces on startup and cleans up (root workspaces)', async function () {
|
||||
|
@ -183,7 +185,7 @@ flakySuite('BackupMainService', () => {
|
|||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(fooFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(barFile.fsPath));
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
|
||||
// 2) backup workspace path exists with empty contents within
|
||||
fs.mkdirSync(service.toBackupPath(fooFile));
|
||||
|
@ -191,7 +193,7 @@ flakySuite('BackupMainService', () => {
|
|||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(fooFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(barFile.fsPath));
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
assert.ok(!fs.existsSync(service.toBackupPath(fooFile)));
|
||||
assert.ok(!fs.existsSync(service.toBackupPath(barFile)));
|
||||
|
||||
|
@ -203,7 +205,7 @@ flakySuite('BackupMainService', () => {
|
|||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(fooFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(barFile.fsPath));
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
assert.ok(!fs.existsSync(service.toBackupPath(fooFile)));
|
||||
assert.ok(!fs.existsSync(service.toBackupPath(barFile)));
|
||||
|
||||
|
@ -214,12 +216,12 @@ flakySuite('BackupMainService', () => {
|
|||
fs.mkdirSync(service.toBackupPath(barFile));
|
||||
fs.mkdirSync(fileBackups);
|
||||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(fooFile.fsPath));
|
||||
assert.equal(service.getWorkspaceBackups().length, 1);
|
||||
assert.equal(service.getEmptyWindowBackupPaths().length, 0);
|
||||
assert.strictEqual(service.getWorkspaceBackups().length, 1);
|
||||
assert.strictEqual(service.getEmptyWindowBackupPaths().length, 0);
|
||||
fs.writeFileSync(path.join(fileBackups, 'backup.txt'), '');
|
||||
await service.initialize();
|
||||
assert.equal(service.getWorkspaceBackups().length, 0);
|
||||
assert.equal(service.getEmptyWindowBackupPaths().length, 1);
|
||||
assert.strictEqual(service.getWorkspaceBackups().length, 0);
|
||||
assert.strictEqual(service.getEmptyWindowBackupPaths().length, 1);
|
||||
});
|
||||
|
||||
test('service supports to migrate backup data from another location', () => {
|
||||
|
@ -235,7 +237,7 @@ flakySuite('BackupMainService', () => {
|
|||
assert.ok(!fs.existsSync(backupPathToMigrate));
|
||||
|
||||
const emptyBackups = service.getEmptyWindowBackupPaths();
|
||||
assert.equal(0, emptyBackups.length);
|
||||
assert.strictEqual(0, emptyBackups.length);
|
||||
});
|
||||
|
||||
test('service backup migration makes sure to preserve existing backups', () => {
|
||||
|
@ -256,8 +258,8 @@ flakySuite('BackupMainService', () => {
|
|||
assert.ok(!fs.existsSync(backupPathToMigrate));
|
||||
|
||||
const emptyBackups = service.getEmptyWindowBackupPaths();
|
||||
assert.equal(1, emptyBackups.length);
|
||||
assert.equal(1, fs.readdirSync(path.join(backupHome, emptyBackups[0].backupFolder!)).length);
|
||||
assert.strictEqual(1, emptyBackups.length);
|
||||
assert.strictEqual(1, fs.readdirSync(path.join(backupHome, emptyBackups[0].backupFolder!)).length);
|
||||
});
|
||||
|
||||
suite('loadSync', () => {
|
||||
|
@ -313,120 +315,120 @@ flakySuite('BackupMainService', () => {
|
|||
});
|
||||
|
||||
test('getWorkspaceBackups() should return [] when workspaces.json doesn\'t exist', () => {
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
});
|
||||
|
||||
test('getWorkspaceBackups() should return [] when workspaces.json is not properly formed JSON', async () => {
|
||||
fs.writeFileSync(backupWorkspacesPath, '');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{]');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, 'foo');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
});
|
||||
|
||||
test('getWorkspaceBackups() should return [] when folderWorkspaces in workspaces.json is absent', async () => {
|
||||
fs.writeFileSync(backupWorkspacesPath, '{}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
});
|
||||
|
||||
test('getWorkspaceBackups() should return [] when rootWorkspaces in workspaces.json is not a object array', async () => {
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootWorkspaces":{}}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootWorkspaces":{"foo": ["bar"]}}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootWorkspaces":{"foo": []}}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootWorkspaces":{"foo": "bar"}}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootWorkspaces":"foo"}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootWorkspaces":1}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
});
|
||||
|
||||
test('getWorkspaceBackups() should return [] when rootURIWorkspaces in workspaces.json is not a object array', async () => {
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootURIWorkspaces":{}}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootURIWorkspaces":{"foo": ["bar"]}}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootURIWorkspaces":{"foo": []}}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootURIWorkspaces":{"foo": "bar"}}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootURIWorkspaces":"foo"}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootURIWorkspaces":1}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
});
|
||||
|
||||
test('getWorkspaceBackups() should return [] when files.hotExit = "onExitAndWindowClose"', async () => {
|
||||
const upperFooPath = fooFile.fsPath.toUpperCase();
|
||||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(upperFooPath));
|
||||
assert.equal(service.getWorkspaceBackups().length, 1);
|
||||
assert.strictEqual(service.getWorkspaceBackups().length, 1);
|
||||
assertEqualUris(service.getWorkspaceBackups().map(r => r.workspace.configPath), [URI.file(upperFooPath)]);
|
||||
configService.setUserConfiguration('files.hotExit', HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE);
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.deepStrictEqual(service.getWorkspaceBackups(), []);
|
||||
});
|
||||
|
||||
test('getEmptyWorkspaceBackupPaths() should return [] when workspaces.json doesn\'t exist', () => {
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
assert.deepStrictEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
});
|
||||
|
||||
test('getEmptyWorkspaceBackupPaths() should return [] when workspaces.json is not properly formed JSON', async () => {
|
||||
fs.writeFileSync(backupWorkspacesPath, '');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
assert.deepStrictEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{]');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
assert.deepStrictEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, 'foo');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
assert.deepStrictEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
});
|
||||
|
||||
test('getEmptyWorkspaceBackupPaths() should return [] when folderWorkspaces in workspaces.json is absent', async () => {
|
||||
fs.writeFileSync(backupWorkspacesPath, '{}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
assert.deepStrictEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
});
|
||||
|
||||
test('getEmptyWorkspaceBackupPaths() should return [] when folderWorkspaces in workspaces.json is not a string array', async function () {
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"emptyWorkspaces":{}}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
assert.deepStrictEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"emptyWorkspaces":{"foo": ["bar"]}}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
assert.deepStrictEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"emptyWorkspaces":{"foo": []}}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
assert.deepStrictEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"emptyWorkspaces":{"foo": "bar"}}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
assert.deepStrictEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"emptyWorkspaces":"foo"}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
assert.deepStrictEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"emptyWorkspaces":1}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
assert.deepStrictEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -445,7 +447,7 @@ flakySuite('BackupMainService', () => {
|
|||
|
||||
const buffer = await pfs.readFile(backupWorkspacesPath, 'utf-8');
|
||||
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
|
||||
assert.deepEqual(json.folderURIWorkspaces, [existingTestFolder1.toString()]);
|
||||
assert.deepStrictEqual(json.folderURIWorkspaces, [existingTestFolder1.toString()]);
|
||||
});
|
||||
|
||||
test('should ignore duplicates on Windows and Mac (folder workspace)', async () => {
|
||||
|
@ -461,14 +463,13 @@ flakySuite('BackupMainService', () => {
|
|||
await service.initialize();
|
||||
const buffer = await pfs.readFile(backupWorkspacesPath, 'utf-8');
|
||||
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
|
||||
assert.deepEqual(json.folderURIWorkspaces, [existingTestFolder1.toString()]);
|
||||
assert.deepStrictEqual(json.folderURIWorkspaces, [existingTestFolder1.toString()]);
|
||||
});
|
||||
|
||||
test('should ignore duplicates on Windows and Mac (root workspace)', async () => {
|
||||
|
||||
const workspacePath = path.join(parentDir, 'Foo.code-workspace');
|
||||
const workspacePath1 = path.join(parentDir, 'FOO.code-workspace');
|
||||
const workspacePath2 = path.join(parentDir, 'foo.code-workspace');
|
||||
const workspacePath = path.join(testDir, 'Foo.code-workspace');
|
||||
const workspacePath1 = path.join(testDir, 'FOO.code-workspace');
|
||||
const workspacePath2 = path.join(testDir, 'foo.code-workspace');
|
||||
|
||||
const workspace1 = await ensureWorkspaceExists(toWorkspace(workspacePath));
|
||||
const workspace2 = await ensureWorkspaceExists(toWorkspace(workspacePath1));
|
||||
|
@ -484,11 +485,11 @@ flakySuite('BackupMainService', () => {
|
|||
|
||||
const buffer = await pfs.readFile(backupWorkspacesPath, 'utf-8');
|
||||
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
|
||||
assert.equal(json.rootURIWorkspaces.length, platform.isLinux ? 3 : 1);
|
||||
assert.strictEqual(json.rootURIWorkspaces.length, platform.isLinux ? 3 : 1);
|
||||
if (platform.isLinux) {
|
||||
assert.deepEqual(json.rootURIWorkspaces.map(r => r.configURIPath), [URI.file(workspacePath).toString(), URI.file(workspacePath1).toString(), URI.file(workspacePath2).toString()]);
|
||||
assert.deepStrictEqual(json.rootURIWorkspaces.map(r => r.configURIPath), [URI.file(workspacePath).toString(), URI.file(workspacePath1).toString(), URI.file(workspacePath2).toString()]);
|
||||
} else {
|
||||
assert.deepEqual(json.rootURIWorkspaces.map(r => r.configURIPath), [URI.file(workspacePath).toString()], 'should return the first duplicated entry');
|
||||
assert.deepStrictEqual(json.rootURIWorkspaces.map(r => r.configURIPath), [URI.file(workspacePath).toString()], 'should return the first duplicated entry');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -500,7 +501,7 @@ flakySuite('BackupMainService', () => {
|
|||
assertEqualUris(service.getFolderBackupPaths(), [fooFile, barFile]);
|
||||
const buffer = await pfs.readFile(backupWorkspacesPath, 'utf-8');
|
||||
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
|
||||
assert.deepEqual(json.folderURIWorkspaces, [fooFile.toString(), barFile.toString()]);
|
||||
assert.deepStrictEqual(json.folderURIWorkspaces, [fooFile.toString(), barFile.toString()]);
|
||||
});
|
||||
|
||||
test('should persist paths to workspaces.json (root workspace)', async () => {
|
||||
|
@ -510,15 +511,15 @@ flakySuite('BackupMainService', () => {
|
|||
service.registerWorkspaceBackupSync(ws2);
|
||||
|
||||
assertEqualUris(service.getWorkspaceBackups().map(b => b.workspace.configPath), [fooFile, barFile]);
|
||||
assert.equal(ws1.workspace.id, service.getWorkspaceBackups()[0].workspace.id);
|
||||
assert.equal(ws2.workspace.id, service.getWorkspaceBackups()[1].workspace.id);
|
||||
assert.strictEqual(ws1.workspace.id, service.getWorkspaceBackups()[0].workspace.id);
|
||||
assert.strictEqual(ws2.workspace.id, service.getWorkspaceBackups()[1].workspace.id);
|
||||
|
||||
const buffer = await pfs.readFile(backupWorkspacesPath, 'utf-8');
|
||||
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
|
||||
|
||||
assert.deepEqual(json.rootURIWorkspaces.map(b => b.configURIPath), [fooFile.toString(), barFile.toString()]);
|
||||
assert.equal(ws1.workspace.id, json.rootURIWorkspaces[0].id);
|
||||
assert.equal(ws2.workspace.id, json.rootURIWorkspaces[1].id);
|
||||
assert.deepStrictEqual(json.rootURIWorkspaces.map(b => b.configURIPath), [fooFile.toString(), barFile.toString()]);
|
||||
assert.strictEqual(ws1.workspace.id, json.rootURIWorkspaces[0].id);
|
||||
assert.strictEqual(ws2.workspace.id, json.rootURIWorkspaces[1].id);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -528,7 +529,7 @@ flakySuite('BackupMainService', () => {
|
|||
|
||||
const buffer = await pfs.readFile(backupWorkspacesPath, 'utf-8');
|
||||
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
|
||||
assert.deepEqual(json.folderURIWorkspaces, [URI.file(fooFile.fsPath.toUpperCase()).toString()]);
|
||||
assert.deepStrictEqual(json.folderURIWorkspaces, [URI.file(fooFile.fsPath.toUpperCase()).toString()]);
|
||||
});
|
||||
|
||||
test('should always store the workspace path in workspaces.json using the case given, regardless of whether the file system is case-sensitive (root workspace)', async () => {
|
||||
|
@ -538,7 +539,7 @@ flakySuite('BackupMainService', () => {
|
|||
|
||||
const buffer = await pfs.readFile(backupWorkspacesPath, 'utf-8');
|
||||
const json = (<IBackupWorkspacesFormat>JSON.parse(buffer));
|
||||
assert.deepEqual(json.rootURIWorkspaces.map(b => b.configURIPath), [URI.file(upperFooPath).toString()]);
|
||||
assert.deepStrictEqual(json.rootURIWorkspaces.map(b => b.configURIPath), [URI.file(upperFooPath).toString()]);
|
||||
});
|
||||
|
||||
suite('removeBackupPathSync', () => {
|
||||
|
@ -549,12 +550,12 @@ flakySuite('BackupMainService', () => {
|
|||
|
||||
const buffer = await pfs.readFile(backupWorkspacesPath, 'utf-8');
|
||||
const json = (<IBackupWorkspacesFormat>JSON.parse(buffer));
|
||||
assert.deepEqual(json.folderURIWorkspaces, [barFile.toString()]);
|
||||
assert.deepStrictEqual(json.folderURIWorkspaces, [barFile.toString()]);
|
||||
service.unregisterFolderBackupSync(barFile);
|
||||
|
||||
const content = await pfs.readFile(backupWorkspacesPath, 'utf-8');
|
||||
const json2 = (<IBackupWorkspacesFormat>JSON.parse(content));
|
||||
assert.deepEqual(json2.folderURIWorkspaces, []);
|
||||
assert.deepStrictEqual(json2.folderURIWorkspaces, []);
|
||||
});
|
||||
|
||||
test('should remove folder workspaces from workspaces.json (root workspace)', async () => {
|
||||
|
@ -566,12 +567,12 @@ flakySuite('BackupMainService', () => {
|
|||
|
||||
const buffer = await pfs.readFile(backupWorkspacesPath, 'utf-8');
|
||||
const json = (<IBackupWorkspacesFormat>JSON.parse(buffer));
|
||||
assert.deepEqual(json.rootURIWorkspaces.map(r => r.configURIPath), [barFile.toString()]);
|
||||
assert.deepStrictEqual(json.rootURIWorkspaces.map(r => r.configURIPath), [barFile.toString()]);
|
||||
service.unregisterWorkspaceBackupSync(ws2.workspace);
|
||||
|
||||
const content = await pfs.readFile(backupWorkspacesPath, 'utf-8');
|
||||
const json2 = (<IBackupWorkspacesFormat>JSON.parse(content));
|
||||
assert.deepEqual(json2.rootURIWorkspaces, []);
|
||||
assert.deepStrictEqual(json2.rootURIWorkspaces, []);
|
||||
});
|
||||
|
||||
test('should remove empty workspaces from workspaces.json', async () => {
|
||||
|
@ -581,12 +582,12 @@ flakySuite('BackupMainService', () => {
|
|||
|
||||
const buffer = await pfs.readFile(backupWorkspacesPath, 'utf-8');
|
||||
const json = (<IBackupWorkspacesFormat>JSON.parse(buffer));
|
||||
assert.deepEqual(json.emptyWorkspaceInfos, [{ backupFolder: 'bar' }]);
|
||||
assert.deepStrictEqual(json.emptyWorkspaceInfos, [{ backupFolder: 'bar' }]);
|
||||
service.unregisterEmptyWindowBackupSync('bar');
|
||||
|
||||
const content = await pfs.readFile(backupWorkspacesPath, 'utf-8');
|
||||
const json2 = (<IBackupWorkspacesFormat>JSON.parse(content));
|
||||
assert.deepEqual(json2.emptyWorkspaceInfos, []);
|
||||
assert.deepStrictEqual(json2.emptyWorkspaceInfos, []);
|
||||
});
|
||||
|
||||
test('should fail gracefully when removing a path that doesn\'t exist', async () => {
|
||||
|
@ -600,18 +601,18 @@ flakySuite('BackupMainService', () => {
|
|||
service.unregisterEmptyWindowBackupSync('test');
|
||||
const content = await pfs.readFile(backupWorkspacesPath, 'utf-8');
|
||||
const json = (<IBackupWorkspacesFormat>JSON.parse(content));
|
||||
assert.deepEqual(json.folderURIWorkspaces, [existingTestFolder1.toString()]);
|
||||
assert.deepStrictEqual(json.folderURIWorkspaces, [existingTestFolder1.toString()]);
|
||||
});
|
||||
});
|
||||
|
||||
suite('getWorkspaceHash', () => {
|
||||
(platform.isLinux ? test.skip : test)('should ignore case on Windows and Mac', () => {
|
||||
if (platform.isMacintosh) {
|
||||
assert.equal(service.getFolderHash(URI.file('/foo')), service.getFolderHash(URI.file('/FOO')));
|
||||
assert.strictEqual(service.getFolderHash(URI.file('/foo')), service.getFolderHash(URI.file('/FOO')));
|
||||
}
|
||||
|
||||
if (platform.isWindows) {
|
||||
assert.equal(service.getFolderHash(URI.file('c:\\foo')), service.getFolderHash(URI.file('C:\\FOO')));
|
||||
assert.strictEqual(service.getFolderHash(URI.file('c:\\foo')), service.getFolderHash(URI.file('C:\\FOO')));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -622,9 +623,9 @@ flakySuite('BackupMainService', () => {
|
|||
service.registerFolderBackupSync(URI.file(fooFile.fsPath.toUpperCase()));
|
||||
|
||||
if (platform.isLinux) {
|
||||
assert.equal(service.getFolderBackupPaths().length, 2);
|
||||
assert.strictEqual(service.getFolderBackupPaths().length, 2);
|
||||
} else {
|
||||
assert.equal(service.getFolderBackupPaths().length, 1);
|
||||
assert.strictEqual(service.getFolderBackupPaths().length, 1);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -633,9 +634,9 @@ flakySuite('BackupMainService', () => {
|
|||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(fooFile.fsPath.toUpperCase()));
|
||||
|
||||
if (platform.isLinux) {
|
||||
assert.equal(service.getWorkspaceBackups().length, 2);
|
||||
assert.strictEqual(service.getWorkspaceBackups().length, 2);
|
||||
} else {
|
||||
assert.equal(service.getWorkspaceBackups().length, 1);
|
||||
assert.strictEqual(service.getWorkspaceBackups().length, 1);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -644,16 +645,16 @@ flakySuite('BackupMainService', () => {
|
|||
// same case
|
||||
service.registerFolderBackupSync(fooFile);
|
||||
service.unregisterFolderBackupSync(fooFile);
|
||||
assert.equal(service.getFolderBackupPaths().length, 0);
|
||||
assert.strictEqual(service.getFolderBackupPaths().length, 0);
|
||||
|
||||
// mixed case
|
||||
service.registerFolderBackupSync(fooFile);
|
||||
service.unregisterFolderBackupSync(URI.file(fooFile.fsPath.toUpperCase()));
|
||||
|
||||
if (platform.isLinux) {
|
||||
assert.equal(service.getFolderBackupPaths().length, 1);
|
||||
assert.strictEqual(service.getFolderBackupPaths().length, 1);
|
||||
} else {
|
||||
assert.equal(service.getFolderBackupPaths().length, 0);
|
||||
assert.strictEqual(service.getFolderBackupPaths().length, 0);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -665,7 +666,7 @@ flakySuite('BackupMainService', () => {
|
|||
const backupWorkspaceInfo = toWorkspaceBackupInfo(fooFile.fsPath);
|
||||
const workspaceBackupPath = service.registerWorkspaceBackupSync(backupWorkspaceInfo);
|
||||
|
||||
assert.equal(((await service.getDirtyWorkspaces()).length), 0);
|
||||
assert.strictEqual(((await service.getDirtyWorkspaces()).length), 0);
|
||||
|
||||
try {
|
||||
await pfs.mkdirp(path.join(folderBackupPath, Schemas.file));
|
||||
|
@ -674,13 +675,13 @@ flakySuite('BackupMainService', () => {
|
|||
// ignore - folder might exist already
|
||||
}
|
||||
|
||||
assert.equal(((await service.getDirtyWorkspaces()).length), 0);
|
||||
assert.strictEqual(((await service.getDirtyWorkspaces()).length), 0);
|
||||
|
||||
fs.writeFileSync(path.join(folderBackupPath, Schemas.file, '594a4a9d82a277a899d4713a5b08f504'), '');
|
||||
fs.writeFileSync(path.join(workspaceBackupPath, Schemas.untitled, '594a4a9d82a277a899d4713a5b08f504'), '');
|
||||
|
||||
const dirtyWorkspaces = await service.getDirtyWorkspaces();
|
||||
assert.equal(dirtyWorkspaces.length, 2);
|
||||
assert.strictEqual(dirtyWorkspaces.length, 2);
|
||||
|
||||
let found = 0;
|
||||
for (const dirtyWorkpspace of dirtyWorkspaces) {
|
||||
|
@ -695,7 +696,7 @@ flakySuite('BackupMainService', () => {
|
|||
}
|
||||
}
|
||||
|
||||
assert.equal(found, 2);
|
||||
assert.strictEqual(found, 2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -83,8 +83,8 @@ const windows: ICodeWindow[] = [
|
|||
suite('WindowsFinder', () => {
|
||||
|
||||
test('New window without folder when no windows exist', () => {
|
||||
assert.equal(findWindowOnFile([], URI.file('nonexisting'), localWorkspaceResolver), null);
|
||||
assert.equal(findWindowOnFile([], URI.file(path.join(fixturesFolder, 'no_vscode_folder', 'file.txt')), localWorkspaceResolver), null);
|
||||
assert.strictEqual(findWindowOnFile([], URI.file('nonexisting'), localWorkspaceResolver), undefined);
|
||||
assert.strictEqual(findWindowOnFile([], URI.file(path.join(fixturesFolder, 'no_vscode_folder', 'file.txt')), localWorkspaceResolver), undefined);
|
||||
});
|
||||
|
||||
test('Existing window with folder', () => {
|
||||
|
|
|
@ -129,8 +129,5 @@ suite('History Storage', () => {
|
|||
};
|
||||
|
||||
assertEqualRecentlyOpened(windowsState, expected, 'v1_33');
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
|
|
@ -105,14 +105,6 @@ export class TestBackupMainService implements IBackupMainService {
|
|||
}
|
||||
|
||||
suite('WorkspacesManagementMainService', () => {
|
||||
const parentDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'workspacesmanagementmainservice');
|
||||
const untitledWorkspacesHomePath = path.join(parentDir, 'Workspaces');
|
||||
|
||||
class TestEnvironmentService extends EnvironmentMainService {
|
||||
get untitledWorkspacesHome(): URI {
|
||||
return URI.file(untitledWorkspacesHomePath);
|
||||
}
|
||||
}
|
||||
|
||||
function createUntitledWorkspace(folders: string[], names?: string[]) {
|
||||
return service.createUntitledWorkspace(folders.map((folder, index) => ({ uri: URI.file(folder), name: names ? names[index] : undefined } as IWorkspaceFolderCreationData)));
|
||||
|
@ -138,22 +130,31 @@ suite('WorkspacesManagementMainService', () => {
|
|||
return service.createUntitledWorkspaceSync(folders.map((folder, index) => ({ uri: URI.file(folder), name: names ? names[index] : undefined } as IWorkspaceFolderCreationData)));
|
||||
}
|
||||
|
||||
const environmentService = new TestEnvironmentService(parseArgs(process.argv, OPTIONS));
|
||||
const logService = new NullLogService();
|
||||
|
||||
let testDir: string;
|
||||
let untitledWorkspacesHomePath: string;
|
||||
let environmentService: EnvironmentMainService;
|
||||
let service: WorkspacesManagementMainService;
|
||||
|
||||
setup(async () => {
|
||||
service = new WorkspacesManagementMainService(environmentService, logService, new TestBackupMainService(), new TestDialogMainService());
|
||||
testDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'workspacesmanagementmainservice');
|
||||
untitledWorkspacesHomePath = path.join(testDir, 'Workspaces');
|
||||
|
||||
// Delete any existing backups completely and then re-create it.
|
||||
await pfs.rimraf(parentDir);
|
||||
environmentService = new class TestEnvironmentService extends EnvironmentMainService {
|
||||
constructor() {
|
||||
super(parseArgs(process.argv, OPTIONS));
|
||||
}
|
||||
get untitledWorkspacesHome(): URI {
|
||||
return URI.file(untitledWorkspacesHomePath);
|
||||
}
|
||||
};
|
||||
|
||||
service = new WorkspacesManagementMainService(environmentService, new NullLogService(), new TestBackupMainService(), new TestDialogMainService());
|
||||
|
||||
return pfs.mkdirp(untitledWorkspacesHomePath);
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
return pfs.rimraf(parentDir);
|
||||
return pfs.rimraf(testDir);
|
||||
});
|
||||
|
||||
function assertPathEquals(p1: string, p2: string): void {
|
||||
|
@ -454,13 +455,13 @@ suite('WorkspacesManagementMainService', () => {
|
|||
const nonLocalUriId = getSingleFolderWorkspaceIdentifier(nonLocalUri);
|
||||
assert.ok(nonLocalUriId?.id);
|
||||
|
||||
const localNonExistingUri = URI.file(path.join(parentDir, 'f1'));
|
||||
const localNonExistingUri = URI.file(path.join(testDir, 'f1'));
|
||||
const localNonExistingUriId = getSingleFolderWorkspaceIdentifier(localNonExistingUri);
|
||||
assert.ok(!localNonExistingUriId);
|
||||
|
||||
fs.mkdirSync(path.join(parentDir, 'f1'));
|
||||
fs.mkdirSync(path.join(testDir, 'f1'));
|
||||
|
||||
const localExistingUri = URI.file(path.join(parentDir, 'f1'));
|
||||
const localExistingUri = URI.file(path.join(testDir, 'f1'));
|
||||
const localExistingUriId = getSingleFolderWorkspaceIdentifier(localExistingUri);
|
||||
assert.ok(localExistingUriId?.id);
|
||||
});
|
||||
|
|
|
@ -89,6 +89,7 @@ class BeforeShutdownEventImpl implements BeforeShutdownEvent {
|
|||
}
|
||||
|
||||
flakySuite('BackupTracker (native)', function () {
|
||||
let testDir: string;
|
||||
let backupHome: string;
|
||||
let workspaceBackupPath: string;
|
||||
|
||||
|
@ -96,8 +97,8 @@ flakySuite('BackupTracker (native)', function () {
|
|||
let disposables: IDisposable[] = [];
|
||||
|
||||
setup(async () => {
|
||||
const userdataDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'backuprestorer');
|
||||
backupHome = path.join(userdataDir, 'Backups');
|
||||
testDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'backuprestorer');
|
||||
backupHome = path.join(testDir, 'Backups');
|
||||
const workspacesJsonPath = path.join(backupHome, 'workspaces.json');
|
||||
|
||||
const workspaceResource = URI.file(platform.isWindows ? 'c:\\workspace' : '/workspace');
|
||||
|
@ -127,11 +128,11 @@ flakySuite('BackupTracker (native)', function () {
|
|||
|
||||
(<TextFileEditorModelManager>accessor.textFileService.files).dispose();
|
||||
|
||||
return pfs.rimraf(backupHome);
|
||||
return pfs.rimraf(testDir);
|
||||
});
|
||||
|
||||
async function createTracker(autoSaveEnabled = false): Promise<{ accessor: TestServiceAccessor, part: EditorPart, tracker: BackupTracker, instantiationService: IInstantiationService, cleanup: () => Promise<void> }> {
|
||||
const backupFileService = new NodeTestBackupFileService(workspaceBackupPath);
|
||||
const backupFileService = new NodeTestBackupFileService(testDir, workspaceBackupPath);
|
||||
const instantiationService = workbenchInstantiationService();
|
||||
instantiationService.stub(IBackupFileService, backupFileService);
|
||||
|
||||
|
|
|
@ -31,26 +31,10 @@ import { TestProductService } from 'vs/workbench/test/browser/workbenchTestServi
|
|||
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
|
||||
import { insert } from 'vs/base/common/arrays';
|
||||
|
||||
const userdataDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'backupfileservice');
|
||||
const backupHome = path.join(userdataDir, 'Backups');
|
||||
const workspacesJsonPath = path.join(backupHome, 'workspaces.json');
|
||||
|
||||
const workspaceResource = URI.file(platform.isWindows ? 'c:\\workspace' : '/workspace');
|
||||
const workspaceBackupPath = path.join(backupHome, hashPath(workspaceResource));
|
||||
const fooFile = URI.file(platform.isWindows ? 'c:\\Foo' : '/Foo');
|
||||
const customFile = URI.parse('customScheme://some/path');
|
||||
const customFileWithFragment = URI.parse('customScheme2://some/path#fragment');
|
||||
const barFile = URI.file(platform.isWindows ? 'c:\\Bar' : '/Bar');
|
||||
const fooBarFile = URI.file(platform.isWindows ? 'c:\\Foo Bar' : '/Foo Bar');
|
||||
const untitledFile = URI.from({ scheme: Schemas.untitled, path: 'Untitled-1' });
|
||||
const fooBackupPath = path.join(workspaceBackupPath, 'file', hashPath(fooFile));
|
||||
const barBackupPath = path.join(workspaceBackupPath, 'file', hashPath(barFile));
|
||||
const untitledBackupPath = path.join(workspaceBackupPath, 'untitled', hashPath(untitledFile));
|
||||
|
||||
class TestWorkbenchEnvironmentService extends NativeWorkbenchEnvironmentService {
|
||||
|
||||
constructor(backupPath: string) {
|
||||
super({ ...TestWorkbenchConfiguration, backupPath, 'user-data-dir': userdataDir }, TestProductService);
|
||||
constructor(testDir: string, backupPath: string) {
|
||||
super({ ...TestWorkbenchConfiguration, backupPath, 'user-data-dir': testDir }, TestProductService);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,8 +47,8 @@ export class NodeTestBackupFileService extends NativeBackupFileService {
|
|||
discardedBackups: URI[];
|
||||
private pendingBackupsArr: Promise<void>[];
|
||||
|
||||
constructor(workspaceBackupPath: string) {
|
||||
const environmentService = new TestWorkbenchEnvironmentService(workspaceBackupPath);
|
||||
constructor(testDir: string, workspaceBackupPath: string) {
|
||||
const environmentService = new TestWorkbenchEnvironmentService(testDir, workspaceBackupPath);
|
||||
const logService = new NullLogService();
|
||||
const fileService = new FileService(logService);
|
||||
const diskFileSystemProvider = new DiskFileSystemProvider(logService);
|
||||
|
@ -126,20 +110,43 @@ export class NodeTestBackupFileService extends NativeBackupFileService {
|
|||
}
|
||||
|
||||
suite('BackupFileService', () => {
|
||||
|
||||
let testDir: string;
|
||||
let backupHome: string;
|
||||
let workspacesJsonPath: string;
|
||||
let workspaceBackupPath: string;
|
||||
let fooBackupPath: string;
|
||||
let barBackupPath: string;
|
||||
let untitledBackupPath: string;
|
||||
|
||||
let service: NodeTestBackupFileService;
|
||||
|
||||
setup(async () => {
|
||||
service = new NodeTestBackupFileService(workspaceBackupPath);
|
||||
let workspaceResource = URI.file(platform.isWindows ? 'c:\\workspace' : '/workspace');
|
||||
let fooFile = URI.file(platform.isWindows ? 'c:\\Foo' : '/Foo');
|
||||
let customFile = URI.parse('customScheme://some/path');
|
||||
let customFileWithFragment = URI.parse('customScheme2://some/path#fragment');
|
||||
let barFile = URI.file(platform.isWindows ? 'c:\\Bar' : '/Bar');
|
||||
let fooBarFile = URI.file(platform.isWindows ? 'c:\\Foo Bar' : '/Foo Bar');
|
||||
let untitledFile = URI.from({ scheme: Schemas.untitled, path: 'Untitled-1' });
|
||||
|
||||
setup(async () => {
|
||||
testDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'backupfileservice');
|
||||
backupHome = path.join(testDir, 'Backups');
|
||||
workspacesJsonPath = path.join(backupHome, 'workspaces.json');
|
||||
workspaceBackupPath = path.join(backupHome, hashPath(workspaceResource));
|
||||
fooBackupPath = path.join(workspaceBackupPath, 'file', hashPath(fooFile));
|
||||
barBackupPath = path.join(workspaceBackupPath, 'file', hashPath(barFile));
|
||||
untitledBackupPath = path.join(workspaceBackupPath, 'untitled', hashPath(untitledFile));
|
||||
|
||||
service = new NodeTestBackupFileService(testDir, workspaceBackupPath);
|
||||
|
||||
// Delete any existing backups completely and then re-create it.
|
||||
await pfs.rimraf(backupHome);
|
||||
await pfs.mkdirp(backupHome);
|
||||
|
||||
return pfs.writeFile(workspacesJsonPath, '');
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
return pfs.rimraf(backupHome);
|
||||
return pfs.rimraf(testDir);
|
||||
});
|
||||
|
||||
suite('hashPath', () => {
|
||||
|
@ -150,8 +157,8 @@ suite('BackupFileService', () => {
|
|||
});
|
||||
const actual = hashPath(uri);
|
||||
// If these hashes change people will lose their backed up files!
|
||||
assert.equal(actual, '13264068d108c6901b3592ea654fcd57');
|
||||
assert.equal(actual, crypto.createHash('md5').update(uri.fsPath).digest('hex'));
|
||||
assert.strictEqual(actual, '13264068d108c6901b3592ea654fcd57');
|
||||
assert.strictEqual(actual, crypto.createHash('md5').update(uri.fsPath).digest('hex'));
|
||||
});
|
||||
|
||||
test('should correctly hash the path for file scheme URIs', () => {
|
||||
|
@ -159,11 +166,11 @@ suite('BackupFileService', () => {
|
|||
const actual = hashPath(uri);
|
||||
// If these hashes change people will lose their backed up files!
|
||||
if (platform.isWindows) {
|
||||
assert.equal(actual, 'dec1a583f52468a020bd120c3f01d812');
|
||||
assert.strictEqual(actual, 'dec1a583f52468a020bd120c3f01d812');
|
||||
} else {
|
||||
assert.equal(actual, '1effb2475fcfba4f9e8b8a1dbc8f3caf');
|
||||
assert.strictEqual(actual, '1effb2475fcfba4f9e8b8a1dbc8f3caf');
|
||||
}
|
||||
assert.equal(actual, crypto.createHash('md5').update(uri.fsPath).digest('hex'));
|
||||
assert.strictEqual(actual, crypto.createHash('md5').update(uri.fsPath).digest('hex'));
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -174,7 +181,7 @@ suite('BackupFileService', () => {
|
|||
const workspaceHash = hashPath(workspaceResource);
|
||||
const filePathHash = hashPath(backupResource);
|
||||
const expectedPath = URI.file(path.join(backupHome, workspaceHash, Schemas.file, filePathHash)).with({ scheme: Schemas.userData }).toString();
|
||||
assert.equal(service.toBackupResource(backupResource).toString(), expectedPath);
|
||||
assert.strictEqual(service.toBackupResource(backupResource).toString(), expectedPath);
|
||||
});
|
||||
|
||||
test('should get the correct backup path for untitled files', () => {
|
||||
|
@ -183,49 +190,49 @@ suite('BackupFileService', () => {
|
|||
const workspaceHash = hashPath(workspaceResource);
|
||||
const filePathHash = hashPath(backupResource);
|
||||
const expectedPath = URI.file(path.join(backupHome, workspaceHash, Schemas.untitled, filePathHash)).with({ scheme: Schemas.userData }).toString();
|
||||
assert.equal(service.toBackupResource(backupResource).toString(), expectedPath);
|
||||
assert.strictEqual(service.toBackupResource(backupResource).toString(), expectedPath);
|
||||
});
|
||||
});
|
||||
|
||||
suite('backup', () => {
|
||||
test('no text', async () => {
|
||||
await service.backup(fooFile);
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
assert.equal(fs.existsSync(fooBackupPath), true);
|
||||
assert.equal(fs.readFileSync(fooBackupPath), `${fooFile.toString()}\n`);
|
||||
assert.strictEqual(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
assert.strictEqual(fs.existsSync(fooBackupPath), true);
|
||||
assert.strictEqual(fs.readFileSync(fooBackupPath).toString(), `${fooFile.toString()}\n`);
|
||||
assert.ok(service.hasBackupSync(fooFile));
|
||||
});
|
||||
|
||||
test('text file', async () => {
|
||||
await service.backup(fooFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).textBuffer.createSnapshot(false));
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
assert.equal(fs.existsSync(fooBackupPath), true);
|
||||
assert.equal(fs.readFileSync(fooBackupPath), `${fooFile.toString()}\ntest`);
|
||||
assert.strictEqual(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
assert.strictEqual(fs.existsSync(fooBackupPath), true);
|
||||
assert.strictEqual(fs.readFileSync(fooBackupPath).toString(), `${fooFile.toString()}\ntest`);
|
||||
assert.ok(service.hasBackupSync(fooFile));
|
||||
});
|
||||
|
||||
test('text file (with version)', async () => {
|
||||
await service.backup(fooFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).textBuffer.createSnapshot(false), 666);
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
assert.equal(fs.existsSync(fooBackupPath), true);
|
||||
assert.equal(fs.readFileSync(fooBackupPath), `${fooFile.toString()}\ntest`);
|
||||
assert.strictEqual(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
assert.strictEqual(fs.existsSync(fooBackupPath), true);
|
||||
assert.strictEqual(fs.readFileSync(fooBackupPath).toString(), `${fooFile.toString()}\ntest`);
|
||||
assert.ok(!service.hasBackupSync(fooFile, 555));
|
||||
assert.ok(service.hasBackupSync(fooFile, 666));
|
||||
});
|
||||
|
||||
test('text file (with meta)', async () => {
|
||||
await service.backup(fooFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).textBuffer.createSnapshot(false), undefined, { etag: '678', orphaned: true });
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
assert.equal(fs.existsSync(fooBackupPath), true);
|
||||
assert.equal(fs.readFileSync(fooBackupPath).toString(), `${fooFile.toString()} {"etag":"678","orphaned":true}\ntest`);
|
||||
assert.strictEqual(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
assert.strictEqual(fs.existsSync(fooBackupPath), true);
|
||||
assert.strictEqual(fs.readFileSync(fooBackupPath).toString(), `${fooFile.toString()} {"etag":"678","orphaned":true}\ntest`);
|
||||
assert.ok(service.hasBackupSync(fooFile));
|
||||
});
|
||||
|
||||
test('untitled file', async () => {
|
||||
await service.backup(untitledFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).textBuffer.createSnapshot(false));
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'untitled')).length, 1);
|
||||
assert.equal(fs.existsSync(untitledBackupPath), true);
|
||||
assert.equal(fs.readFileSync(untitledBackupPath), `${untitledFile.toString()}\ntest`);
|
||||
assert.strictEqual(fs.readdirSync(path.join(workspaceBackupPath, 'untitled')).length, 1);
|
||||
assert.strictEqual(fs.existsSync(untitledBackupPath), true);
|
||||
assert.strictEqual(fs.readFileSync(untitledBackupPath).toString(), `${untitledFile.toString()}\ntest`);
|
||||
assert.ok(service.hasBackupSync(untitledFile));
|
||||
});
|
||||
|
||||
|
@ -233,9 +240,9 @@ suite('BackupFileService', () => {
|
|||
const model = createTextModel('test');
|
||||
|
||||
await service.backup(fooFile, model.createSnapshot());
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
assert.equal(fs.existsSync(fooBackupPath), true);
|
||||
assert.equal(fs.readFileSync(fooBackupPath), `${fooFile.toString()}\ntest`);
|
||||
assert.strictEqual(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
assert.strictEqual(fs.existsSync(fooBackupPath), true);
|
||||
assert.strictEqual(fs.readFileSync(fooBackupPath).toString(), `${fooFile.toString()}\ntest`);
|
||||
assert.ok(service.hasBackupSync(fooFile));
|
||||
|
||||
model.dispose();
|
||||
|
@ -245,9 +252,9 @@ suite('BackupFileService', () => {
|
|||
const model = createTextModel('test');
|
||||
|
||||
await service.backup(untitledFile, model.createSnapshot());
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'untitled')).length, 1);
|
||||
assert.equal(fs.existsSync(untitledBackupPath), true);
|
||||
assert.equal(fs.readFileSync(untitledBackupPath), `${untitledFile.toString()}\ntest`);
|
||||
assert.strictEqual(fs.readdirSync(path.join(workspaceBackupPath, 'untitled')).length, 1);
|
||||
assert.strictEqual(fs.existsSync(untitledBackupPath), true);
|
||||
assert.strictEqual(fs.readFileSync(untitledBackupPath).toString(), `${untitledFile.toString()}\ntest`);
|
||||
|
||||
model.dispose();
|
||||
});
|
||||
|
@ -257,9 +264,9 @@ suite('BackupFileService', () => {
|
|||
const model = createTextModel(largeString);
|
||||
|
||||
await service.backup(fooFile, model.createSnapshot());
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
assert.equal(fs.existsSync(fooBackupPath), true);
|
||||
assert.equal(fs.readFileSync(fooBackupPath), `${fooFile.toString()}\n${largeString}`);
|
||||
assert.strictEqual(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
assert.strictEqual(fs.existsSync(fooBackupPath), true);
|
||||
assert.strictEqual(fs.readFileSync(fooBackupPath).toString(), `${fooFile.toString()}\n${largeString}`);
|
||||
assert.ok(service.hasBackupSync(fooFile));
|
||||
|
||||
model.dispose();
|
||||
|
@ -270,9 +277,9 @@ suite('BackupFileService', () => {
|
|||
const model = createTextModel(largeString);
|
||||
|
||||
await service.backup(untitledFile, model.createSnapshot());
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'untitled')).length, 1);
|
||||
assert.equal(fs.existsSync(untitledBackupPath), true);
|
||||
assert.equal(fs.readFileSync(untitledBackupPath), `${untitledFile.toString()}\n${largeString}`);
|
||||
assert.strictEqual(fs.readdirSync(path.join(workspaceBackupPath, 'untitled')).length, 1);
|
||||
assert.strictEqual(fs.existsSync(untitledBackupPath), true);
|
||||
assert.strictEqual(fs.readFileSync(untitledBackupPath).toString(), `${untitledFile.toString()}\n${largeString}`);
|
||||
assert.ok(service.hasBackupSync(untitledFile));
|
||||
|
||||
model.dispose();
|
||||
|
@ -284,7 +291,7 @@ suite('BackupFileService', () => {
|
|||
cts.cancel();
|
||||
await promise;
|
||||
|
||||
assert.equal(fs.existsSync(fooBackupPath), false);
|
||||
assert.strictEqual(fs.existsSync(fooBackupPath), false);
|
||||
assert.ok(!service.hasBackupSync(fooFile));
|
||||
});
|
||||
});
|
||||
|
@ -292,48 +299,48 @@ suite('BackupFileService', () => {
|
|||
suite('discardBackup', () => {
|
||||
test('text file', async () => {
|
||||
await service.backup(fooFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).textBuffer.createSnapshot(false));
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
assert.strictEqual(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
assert.ok(service.hasBackupSync(fooFile));
|
||||
|
||||
await service.discardBackup(fooFile);
|
||||
assert.equal(fs.existsSync(fooBackupPath), false);
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 0);
|
||||
assert.strictEqual(fs.existsSync(fooBackupPath), false);
|
||||
assert.strictEqual(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 0);
|
||||
assert.ok(!service.hasBackupSync(fooFile));
|
||||
});
|
||||
|
||||
test('untitled file', async () => {
|
||||
await service.backup(untitledFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).textBuffer.createSnapshot(false));
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'untitled')).length, 1);
|
||||
assert.strictEqual(fs.readdirSync(path.join(workspaceBackupPath, 'untitled')).length, 1);
|
||||
await service.discardBackup(untitledFile);
|
||||
assert.equal(fs.existsSync(untitledBackupPath), false);
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'untitled')).length, 0);
|
||||
assert.strictEqual(fs.existsSync(untitledBackupPath), false);
|
||||
assert.strictEqual(fs.readdirSync(path.join(workspaceBackupPath, 'untitled')).length, 0);
|
||||
});
|
||||
});
|
||||
|
||||
suite('discardBackups', () => {
|
||||
test('text file', async () => {
|
||||
await service.backup(fooFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).textBuffer.createSnapshot(false));
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
assert.strictEqual(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 1);
|
||||
await service.backup(barFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).textBuffer.createSnapshot(false));
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 2);
|
||||
assert.strictEqual(fs.readdirSync(path.join(workspaceBackupPath, 'file')).length, 2);
|
||||
await service.discardBackups();
|
||||
assert.equal(fs.existsSync(fooBackupPath), false);
|
||||
assert.equal(fs.existsSync(barBackupPath), false);
|
||||
assert.equal(fs.existsSync(path.join(workspaceBackupPath, 'file')), false);
|
||||
assert.strictEqual(fs.existsSync(fooBackupPath), false);
|
||||
assert.strictEqual(fs.existsSync(barBackupPath), false);
|
||||
assert.strictEqual(fs.existsSync(path.join(workspaceBackupPath, 'file')), false);
|
||||
});
|
||||
|
||||
test('untitled file', async () => {
|
||||
await service.backup(untitledFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).textBuffer.createSnapshot(false));
|
||||
assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'untitled')).length, 1);
|
||||
assert.strictEqual(fs.readdirSync(path.join(workspaceBackupPath, 'untitled')).length, 1);
|
||||
await service.discardBackups();
|
||||
assert.equal(fs.existsSync(untitledBackupPath), false);
|
||||
assert.equal(fs.existsSync(path.join(workspaceBackupPath, 'untitled')), false);
|
||||
assert.strictEqual(fs.existsSync(untitledBackupPath), false);
|
||||
assert.strictEqual(fs.existsSync(path.join(workspaceBackupPath, 'untitled')), false);
|
||||
});
|
||||
|
||||
test('can backup after discarding all', async () => {
|
||||
await service.discardBackups();
|
||||
await service.backup(untitledFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).textBuffer.createSnapshot(false));
|
||||
assert.equal(fs.existsSync(workspaceBackupPath), true);
|
||||
assert.strictEqual(fs.existsSync(workspaceBackupPath), true);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -341,22 +348,22 @@ suite('BackupFileService', () => {
|
|||
test('("file") - text file', async () => {
|
||||
await service.backup(fooFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).textBuffer.createSnapshot(false));
|
||||
const textFiles = await service.getBackups();
|
||||
assert.deepEqual(textFiles.map(f => f.fsPath), [fooFile.fsPath]);
|
||||
assert.deepStrictEqual(textFiles.map(f => f.fsPath), [fooFile.fsPath]);
|
||||
await service.backup(barFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).textBuffer.createSnapshot(false));
|
||||
const textFiles_1 = await service.getBackups();
|
||||
assert.deepEqual(textFiles_1.map(f => f.fsPath), [fooFile.fsPath, barFile.fsPath]);
|
||||
assert.deepStrictEqual(textFiles_1.map(f => f.fsPath), [fooFile.fsPath, barFile.fsPath]);
|
||||
});
|
||||
|
||||
test('("file") - untitled file', async () => {
|
||||
await service.backup(untitledFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).textBuffer.createSnapshot(false));
|
||||
const textFiles = await service.getBackups();
|
||||
assert.deepEqual(textFiles.map(f => f.fsPath), [untitledFile.fsPath]);
|
||||
assert.deepStrictEqual(textFiles.map(f => f.fsPath), [untitledFile.fsPath]);
|
||||
});
|
||||
|
||||
test('("untitled") - untitled file', async () => {
|
||||
await service.backup(untitledFile, createTextBufferFactory('test').create(DefaultEndOfLine.LF).textBuffer.createSnapshot(false));
|
||||
const textFiles = await service.getBackups();
|
||||
assert.deepEqual(textFiles.map(f => f.fsPath), ['Untitled-1']);
|
||||
assert.deepStrictEqual(textFiles.map(f => f.fsPath), ['Untitled-1']);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -468,7 +475,7 @@ suite('BackupFileService', () => {
|
|||
await service.backup(fooFile, createTextBufferFactory(contents).create(DefaultEndOfLine.LF).textBuffer.createSnapshot(false), 1, meta);
|
||||
|
||||
const fileContents = fs.readFileSync(fooBackupPath).toString();
|
||||
assert.equal(fileContents.indexOf(fooFile.toString()), 0);
|
||||
assert.strictEqual(fileContents.indexOf(fooFile.toString()), 0);
|
||||
|
||||
const metaIndex = fileContents.indexOf('{');
|
||||
const newFileContents = fileContents.substring(0, metaIndex) + '{{' + fileContents.substr(metaIndex);
|
||||
|
@ -476,7 +483,7 @@ suite('BackupFileService', () => {
|
|||
|
||||
const backup = await service.resolve(fooFile);
|
||||
assert.ok(backup);
|
||||
assert.equal(contents, snapshotToString(backup!.value.create(platform.isWindows ? DefaultEndOfLine.CRLF : DefaultEndOfLine.LF).textBuffer.createSnapshot(true)));
|
||||
assert.strictEqual(contents, snapshotToString(backup!.value.create(platform.isWindows ? DefaultEndOfLine.CRLF : DefaultEndOfLine.LF).textBuffer.createSnapshot(true)));
|
||||
assert.ok(!backup!.meta);
|
||||
});
|
||||
|
||||
|
@ -565,111 +572,96 @@ suite('BackupFileService', () => {
|
|||
|
||||
const backup = await service.resolve<IBackupTestMetaData>(resource);
|
||||
assert.ok(backup);
|
||||
assert.equal(contents, snapshotToString(backup!.value.create(platform.isWindows ? DefaultEndOfLine.CRLF : DefaultEndOfLine.LF).textBuffer.createSnapshot(true)));
|
||||
assert.strictEqual(contents, snapshotToString(backup!.value.create(platform.isWindows ? DefaultEndOfLine.CRLF : DefaultEndOfLine.LF).textBuffer.createSnapshot(true)));
|
||||
|
||||
if (expectedMeta) {
|
||||
assert.equal(backup!.meta!.etag, expectedMeta.etag);
|
||||
assert.equal(backup!.meta!.size, expectedMeta.size);
|
||||
assert.equal(backup!.meta!.mtime, expectedMeta.mtime);
|
||||
assert.equal(backup!.meta!.orphaned, expectedMeta.orphaned);
|
||||
assert.strictEqual(backup!.meta!.etag, expectedMeta.etag);
|
||||
assert.strictEqual(backup!.meta!.size, expectedMeta.size);
|
||||
assert.strictEqual(backup!.meta!.mtime, expectedMeta.mtime);
|
||||
assert.strictEqual(backup!.meta!.orphaned, expectedMeta.orphaned);
|
||||
} else {
|
||||
assert.ok(!backup!.meta);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
suite('BackupFilesModel', () => {
|
||||
|
||||
let service: NodeTestBackupFileService;
|
||||
|
||||
setup(async () => {
|
||||
service = new NodeTestBackupFileService(workspaceBackupPath);
|
||||
|
||||
// Delete any existing backups completely and then re-create it.
|
||||
await pfs.rimraf(backupHome);
|
||||
await pfs.mkdirp(backupHome);
|
||||
|
||||
return pfs.writeFile(workspacesJsonPath, '');
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
return pfs.rimraf(backupHome);
|
||||
});
|
||||
|
||||
test('simple', () => {
|
||||
const model = new BackupFilesModel(service.fileService);
|
||||
|
||||
const resource1 = URI.file('test.html');
|
||||
|
||||
assert.equal(model.has(resource1), false);
|
||||
|
||||
model.add(resource1);
|
||||
|
||||
assert.equal(model.has(resource1), true);
|
||||
assert.equal(model.has(resource1, 0), true);
|
||||
assert.equal(model.has(resource1, 1), false);
|
||||
assert.equal(model.has(resource1, 1, { foo: 'bar' }), false);
|
||||
|
||||
model.remove(resource1);
|
||||
|
||||
assert.equal(model.has(resource1), false);
|
||||
|
||||
model.add(resource1);
|
||||
|
||||
assert.equal(model.has(resource1), true);
|
||||
assert.equal(model.has(resource1, 0), true);
|
||||
assert.equal(model.has(resource1, 1), false);
|
||||
|
||||
model.clear();
|
||||
|
||||
assert.equal(model.has(resource1), false);
|
||||
|
||||
model.add(resource1, 1);
|
||||
|
||||
assert.equal(model.has(resource1), true);
|
||||
assert.equal(model.has(resource1, 0), false);
|
||||
assert.equal(model.has(resource1, 1), true);
|
||||
|
||||
const resource2 = URI.file('test1.html');
|
||||
const resource3 = URI.file('test2.html');
|
||||
const resource4 = URI.file('test3.html');
|
||||
|
||||
model.add(resource2);
|
||||
model.add(resource3);
|
||||
model.add(resource4, undefined, { foo: 'bar' });
|
||||
|
||||
assert.equal(model.has(resource1), true);
|
||||
assert.equal(model.has(resource2), true);
|
||||
assert.equal(model.has(resource3), true);
|
||||
|
||||
assert.equal(model.has(resource4), true);
|
||||
assert.equal(model.has(resource4, undefined, { foo: 'bar' }), true);
|
||||
assert.equal(model.has(resource4, undefined, { bar: 'foo' }), false);
|
||||
});
|
||||
|
||||
test('resolve', async () => {
|
||||
await pfs.mkdirp(path.dirname(fooBackupPath));
|
||||
fs.writeFileSync(fooBackupPath, 'foo');
|
||||
const model = new BackupFilesModel(service.fileService);
|
||||
|
||||
const resolvedModel = await model.resolve(URI.file(workspaceBackupPath));
|
||||
assert.equal(resolvedModel.has(URI.file(fooBackupPath)), true);
|
||||
});
|
||||
|
||||
test('get', () => {
|
||||
const model = new BackupFilesModel(service.fileService);
|
||||
|
||||
assert.deepEqual(model.get(), []);
|
||||
|
||||
const file1 = URI.file('/root/file/foo.html');
|
||||
const file2 = URI.file('/root/file/bar.html');
|
||||
const untitled = URI.file('/root/untitled/bar.html');
|
||||
|
||||
model.add(file1);
|
||||
model.add(file2);
|
||||
model.add(untitled);
|
||||
|
||||
assert.deepEqual(model.get().map(f => f.fsPath), [file1.fsPath, file2.fsPath, untitled.fsPath]);
|
||||
});
|
||||
|
||||
suite('BackupFilesModel', () => {
|
||||
|
||||
test('simple', () => {
|
||||
const model = new BackupFilesModel(service.fileService);
|
||||
|
||||
const resource1 = URI.file('test.html');
|
||||
|
||||
assert.strictEqual(model.has(resource1), false);
|
||||
|
||||
model.add(resource1);
|
||||
|
||||
assert.strictEqual(model.has(resource1), true);
|
||||
assert.strictEqual(model.has(resource1, 0), true);
|
||||
assert.strictEqual(model.has(resource1, 1), false);
|
||||
assert.strictEqual(model.has(resource1, 1, { foo: 'bar' }), false);
|
||||
|
||||
model.remove(resource1);
|
||||
|
||||
assert.strictEqual(model.has(resource1), false);
|
||||
|
||||
model.add(resource1);
|
||||
|
||||
assert.strictEqual(model.has(resource1), true);
|
||||
assert.strictEqual(model.has(resource1, 0), true);
|
||||
assert.strictEqual(model.has(resource1, 1), false);
|
||||
|
||||
model.clear();
|
||||
|
||||
assert.strictEqual(model.has(resource1), false);
|
||||
|
||||
model.add(resource1, 1);
|
||||
|
||||
assert.strictEqual(model.has(resource1), true);
|
||||
assert.strictEqual(model.has(resource1, 0), false);
|
||||
assert.strictEqual(model.has(resource1, 1), true);
|
||||
|
||||
const resource2 = URI.file('test1.html');
|
||||
const resource3 = URI.file('test2.html');
|
||||
const resource4 = URI.file('test3.html');
|
||||
|
||||
model.add(resource2);
|
||||
model.add(resource3);
|
||||
model.add(resource4, undefined, { foo: 'bar' });
|
||||
|
||||
assert.strictEqual(model.has(resource1), true);
|
||||
assert.strictEqual(model.has(resource2), true);
|
||||
assert.strictEqual(model.has(resource3), true);
|
||||
|
||||
assert.strictEqual(model.has(resource4), true);
|
||||
assert.strictEqual(model.has(resource4, undefined, { foo: 'bar' }), true);
|
||||
assert.strictEqual(model.has(resource4, undefined, { bar: 'foo' }), false);
|
||||
});
|
||||
|
||||
test('resolve', async () => {
|
||||
await pfs.mkdirp(path.dirname(fooBackupPath));
|
||||
fs.writeFileSync(fooBackupPath, 'foo');
|
||||
const model = new BackupFilesModel(service.fileService);
|
||||
|
||||
const resolvedModel = await model.resolve(URI.file(workspaceBackupPath));
|
||||
assert.strictEqual(resolvedModel.has(URI.file(fooBackupPath)), true);
|
||||
});
|
||||
|
||||
test('get', () => {
|
||||
const model = new BackupFilesModel(service.fileService);
|
||||
|
||||
assert.deepStrictEqual(model.get(), []);
|
||||
|
||||
const file1 = URI.file('/root/file/foo.html');
|
||||
const file2 = URI.file('/root/file/bar.html');
|
||||
const untitled = URI.file('/root/untitled/bar.html');
|
||||
|
||||
model.add(file1);
|
||||
model.add(file2);
|
||||
model.add(untitled);
|
||||
|
||||
assert.deepStrictEqual(model.get().map(f => f.fsPath), [file1.fsPath, file2.fsPath, untitled.fsPath]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -32,12 +32,12 @@ suite('URI Label', () => {
|
|||
});
|
||||
|
||||
const uri1 = TestWorkspace.folders[0].uri.with({ path: TestWorkspace.folders[0].uri.path.concat('/a/b/c/d') });
|
||||
assert.equal(labelService.getUriLabel(uri1, { relative: true }), isWindows ? 'a\\b\\c\\d' : 'a/b/c/d');
|
||||
assert.equal(labelService.getUriLabel(uri1, { relative: false }), isWindows ? 'C:\\testWorkspace\\a\\b\\c\\d' : '/testWorkspace/a/b/c/d');
|
||||
assert.equal(labelService.getUriBasenameLabel(uri1), 'd');
|
||||
assert.strictEqual(labelService.getUriLabel(uri1, { relative: true }), isWindows ? 'a\\b\\c\\d' : 'a/b/c/d');
|
||||
assert.strictEqual(labelService.getUriLabel(uri1, { relative: false }), isWindows ? 'C:\\testWorkspace\\a\\b\\c\\d' : '/testWorkspace/a/b/c/d');
|
||||
assert.strictEqual(labelService.getUriBasenameLabel(uri1), 'd');
|
||||
|
||||
const uri2 = URI.file('c:\\1/2/3');
|
||||
assert.equal(labelService.getUriLabel(uri2, { relative: false }), isWindows ? 'C:\\1\\2\\3' : '/c:\\1/2/3');
|
||||
assert.equal(labelService.getUriBasenameLabel(uri2), '3');
|
||||
assert.strictEqual(labelService.getUriLabel(uri2, { relative: false }), isWindows ? 'C:\\1\\2\\3' : '/c:\\1/2/3');
|
||||
assert.strictEqual(labelService.getUriBasenameLabel(uri2), '3');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue