mirror of
https://github.com/microsoft/vscode.git
synced 2026-03-05 00:08:14 +00:00
💄
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
import assert = require('assert');
|
||||
import path = require('path');
|
||||
import { findBestWindowOrFolder, ISimpleWindow, IBestWindowOrFolderOptions } from 'vs/code/node/windowsUtils';
|
||||
import { findBestWindowOrFolderForFile, ISimpleWindow, IBestWindowOrFolderOptions } from 'vs/code/node/windowsFinder';
|
||||
import { OpenContext } from 'vs/platform/windows/common/windows';
|
||||
|
||||
const fixturesFolder = require.toUrl('./fixtures');
|
||||
@@ -17,7 +17,7 @@ function options(custom?: Partial<IBestWindowOrFolderOptions<ISimpleWindow>>): I
|
||||
newWindow: false,
|
||||
reuseWindow: false,
|
||||
context: OpenContext.CLI,
|
||||
vscodeFolder: '_vscode',
|
||||
codeSettingsFolder: '_vscode',
|
||||
...custom
|
||||
};
|
||||
}
|
||||
@@ -31,38 +31,38 @@ const windows = [
|
||||
noVscodeFolderWindow,
|
||||
];
|
||||
|
||||
suite('WindowsUtils', () => {
|
||||
suite('WindowsFinder', () => {
|
||||
|
||||
test('New window without folder when no windows exist', () => {
|
||||
assert.equal(findBestWindowOrFolder(options()), null);
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options()), null);
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
filePath: path.join(fixturesFolder, 'no_vscode_folder', 'file.txt')
|
||||
})), null);
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
filePath: path.join(fixturesFolder, 'vscode_folder', 'file.txt'),
|
||||
newWindow: true // We assume this implies 'editor' work mode, might need separate CLI option later.
|
||||
})), null);
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
filePath: path.join(fixturesFolder, 'vscode_folder', 'file.txt'),
|
||||
reuseWindow: true // We assume this implies 'editor' work mode, might need separate CLI option later.
|
||||
})), null);
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
filePath: path.join(fixturesFolder, 'vscode_folder', 'file.txt'),
|
||||
context: OpenContext.API
|
||||
})), null);
|
||||
});
|
||||
|
||||
test('New window with folder when no windows exist', () => {
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
filePath: path.join(fixturesFolder, 'vscode_folder', 'file.txt')
|
||||
})), path.join(fixturesFolder, 'vscode_folder'));
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
filePath: path.join(fixturesFolder, 'vscode_folder', 'new_folder', 'new_file.txt')
|
||||
})), path.join(fixturesFolder, 'vscode_folder'));
|
||||
});
|
||||
|
||||
test('New window without folder when windows exist', () => {
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
windows,
|
||||
filePath: path.join(fixturesFolder, 'no_vscode_folder', 'file.txt'),
|
||||
newWindow: true
|
||||
@@ -70,19 +70,19 @@ suite('WindowsUtils', () => {
|
||||
});
|
||||
|
||||
test('Last active window', () => {
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
windows
|
||||
})), lastActiveWindow);
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
windows,
|
||||
filePath: path.join(fixturesFolder, 'no_vscode_folder2', 'file.txt')
|
||||
})), lastActiveWindow);
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
windows: [lastActiveWindow, noVscodeFolderWindow],
|
||||
filePath: path.join(fixturesFolder, 'vscode_folder', 'file.txt'),
|
||||
reuseWindow: true
|
||||
})), lastActiveWindow);
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
windows,
|
||||
filePath: path.join(fixturesFolder, 'no_vscode_folder', 'file.txt'),
|
||||
context: OpenContext.API
|
||||
@@ -90,11 +90,11 @@ suite('WindowsUtils', () => {
|
||||
});
|
||||
|
||||
test('Existing window with folder', () => {
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
windows,
|
||||
filePath: path.join(fixturesFolder, 'no_vscode_folder', 'file.txt')
|
||||
})), noVscodeFolderWindow);
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
windows,
|
||||
filePath: path.join(fixturesFolder, 'vscode_folder', 'file.txt')
|
||||
})), vscodeFolderWindow);
|
||||
@@ -102,12 +102,12 @@ suite('WindowsUtils', () => {
|
||||
|
||||
test('Existing window wins over vscode folder if more specific', () => {
|
||||
const window = { lastFocusTime: 1, openedWorkspacePath: path.join(fixturesFolder, 'vscode_folder', 'nested_folder') };
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
windows: [window],
|
||||
filePath: path.join(fixturesFolder, 'vscode_folder', 'nested_folder', 'subfolder', 'file.txt')
|
||||
})), window);
|
||||
// check
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
windows: [window],
|
||||
filePath: path.join(fixturesFolder, 'vscode_folder', 'nested_folder2', 'subfolder', 'file.txt')
|
||||
})), path.join(fixturesFolder, 'vscode_folder'));
|
||||
@@ -116,7 +116,7 @@ suite('WindowsUtils', () => {
|
||||
test('More specific existing window wins', () => {
|
||||
const window = { lastFocusTime: 2, openedWorkspacePath: path.join(fixturesFolder, 'no_vscode_folder') };
|
||||
const nestedFolderWindow = { lastFocusTime: 1, openedWorkspacePath: path.join(fixturesFolder, 'no_vscode_folder', 'nested_folder') };
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
windows: [window, nestedFolderWindow],
|
||||
filePath: path.join(fixturesFolder, 'no_vscode_folder', 'nested_folder', 'subfolder', 'file.txt')
|
||||
})), nestedFolderWindow);
|
||||
@@ -124,30 +124,30 @@ suite('WindowsUtils', () => {
|
||||
|
||||
test('VSCode folder wins over existing window if more specific', () => {
|
||||
const window = { lastFocusTime: 1, openedWorkspacePath: path.join(fixturesFolder, 'vscode_folder') };
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
windows: [window],
|
||||
filePath: path.join(fixturesFolder, 'vscode_folder', 'nested_vscode_folder', 'subfolder', 'file.txt')
|
||||
})), path.join(fixturesFolder, 'vscode_folder', 'nested_vscode_folder'));
|
||||
// check
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
windows: [window],
|
||||
filePath: path.join(fixturesFolder, 'vscode_folder', 'nested_folder', 'subfolder', 'file.txt')
|
||||
})), window);
|
||||
});
|
||||
|
||||
test('More specific VSCode folder wins', () => {
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
filePath: path.join(fixturesFolder, 'vscode_folder', 'nested_vscode_folder', 'subfolder', 'file.txt')
|
||||
})), path.join(fixturesFolder, 'vscode_folder', 'nested_vscode_folder'));
|
||||
});
|
||||
|
||||
test('VSCode folder in home folder needs settings.json', () => {
|
||||
// Because ~/.vscode/extensions is used for extensions, ~/.vscode is not enough as a hint.
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
filePath: path.join(fixturesFolder, 'vscode_folder', 'file.txt'),
|
||||
userHome: path.join(fixturesFolder, 'vscode_folder')
|
||||
})), null);
|
||||
assert.equal(findBestWindowOrFolder(options({
|
||||
assert.equal(findBestWindowOrFolderForFile(options({
|
||||
filePath: path.join(fixturesFolder, 'vscode_home_folder', 'file.txt'),
|
||||
userHome: path.join(fixturesFolder, 'vscode_home_folder')
|
||||
})), path.join(fixturesFolder, 'vscode_home_folder'));
|
||||
|
||||
Reference in New Issue
Block a user