Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esm - remove getPathFromAmdModule, replace its usages with FileAccess.asFileUri and AppResourcePath #171250

Merged
merged 1 commit into from Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/vs/base/parts/ipc/test/node/ipc.cp.integrationTest.ts
Expand Up @@ -7,11 +7,11 @@ import * as assert from 'assert';
import { Event } from 'vs/base/common/event';
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
import { Client } from 'vs/base/parts/ipc/node/ipc.cp';
import { getPathFromAmdModule } from 'vs/base/test/node/testUtils';
import { ITestService, TestServiceClient } from './testService';
import { FileAccess } from 'vs/base/common/network';

function createClient(): Client {
return new Client(getPathFromAmdModule(require, 'bootstrap-fork'), {
return new Client(FileAccess.asFileUri('bootstrap-fork').fsPath, {
serverName: 'TestServer',
env: { VSCODE_AMD_ENTRYPOINT: 'vs/base/parts/ipc/test/node/testApp', verbose: true }
});
Expand Down
5 changes: 3 additions & 2 deletions src/vs/base/test/node/pfs/pfs.test.ts
Expand Up @@ -9,10 +9,11 @@ import { tmpdir } from 'os';
import { timeout } from 'vs/base/common/async';
import { VSBuffer } from 'vs/base/common/buffer';
import { randomPath } from 'vs/base/common/extpath';
import { FileAccess } from 'vs/base/common/network';
import { join, sep } from 'vs/base/common/path';
import { isWindows } from 'vs/base/common/platform';
import { configureFlushOnWrite, Promises, RimRafMode, rimrafSync, SymlinkSupport, writeFileSync } from 'vs/base/node/pfs';
import { flakySuite, getPathFromAmdModule, getRandomTestPath } from 'vs/base/test/node/testUtils';
import { flakySuite, getRandomTestPath } from 'vs/base/test/node/testUtils';

configureFlushOnWrite(false); // speed up all unit tests by disabling flush on write

Expand Down Expand Up @@ -165,7 +166,7 @@ flakySuite('PFS', function () {
});

test('copy, move and delete', async () => {
const sourceDir = getPathFromAmdModule(require, './fixtures');
const sourceDir = FileAccess.asFileUri('vs/base/test/node/pfs/fixtures').fsPath;
const parentDir = join(tmpdir(), 'vsctests', 'pfs');
const targetDir = randomPath(parentDir);
const targetDir2 = randomPath(parentDir);
Expand Down
4 changes: 2 additions & 2 deletions src/vs/base/test/node/processes/processes.integrationTest.ts
Expand Up @@ -5,10 +5,10 @@

import * as assert from 'assert';
import * as cp from 'child_process';
import { FileAccess } from 'vs/base/common/network';
import * as objects from 'vs/base/common/objects';
import * as platform from 'vs/base/common/platform';
import * as processes from 'vs/base/node/processes';
import { getPathFromAmdModule } from 'vs/base/test/node/testUtils';

function fork(id: string): cp.ChildProcess {
const opts: any = {
Expand All @@ -19,7 +19,7 @@ function fork(id: string): cp.ChildProcess {
})
};

return cp.fork(getPathFromAmdModule(require, 'bootstrap-fork'), ['--type=processTests'], opts);
return cp.fork(FileAccess.asFileUri('bootstrap-fork').fsPath, ['--type=processTests'], opts);
}

suite('Processes', () => {
Expand Down
5 changes: 0 additions & 5 deletions src/vs/base/test/node/testUtils.ts
Expand Up @@ -5,15 +5,10 @@

import { randomPath } from 'vs/base/common/extpath';
import { join } from 'vs/base/common/path';
import { URI } from 'vs/base/common/uri';
import * as testUtils from 'vs/base/test/common/testUtils';

export function getRandomTestPath(tmpdir: string, ...segments: string[]): string {
return randomPath(join(tmpdir, ...segments));
}

export function getPathFromAmdModule(requirefn: typeof require, relativePath: string): string {
return URI.parse(requirefn.toUrl(relativePath)).fsPath;
}

export import flakySuite = testUtils.flakySuite;
4 changes: 2 additions & 2 deletions src/vs/base/test/node/uri.test.perf.ts
Expand Up @@ -5,15 +5,15 @@

import * as assert from 'assert';
import { readFileSync } from 'fs';
import { FileAccess } from 'vs/base/common/network';
import { URI } from 'vs/base/common/uri';
import { getPathFromAmdModule } from 'vs/base/test/node/testUtils';

suite('URI - perf', function () {

let manyFileUris: URI[];
setup(function () {
manyFileUris = [];
const data = readFileSync(getPathFromAmdModule(require, './uri.test.data.txt')).toString();
const data = readFileSync(FileAccess.asFileUri('vs/base/test/node/uri.test.data.txt').fsPath).toString();
const lines = data.split('\n');
for (const line of lines) {
manyFileUris.push(URI.file(line));
Expand Down
5 changes: 3 additions & 2 deletions src/vs/base/test/node/zip/zip.test.ts
Expand Up @@ -6,10 +6,11 @@
import * as assert from 'assert';
import { tmpdir } from 'os';
import { createCancelablePromise } from 'vs/base/common/async';
import { FileAccess } from 'vs/base/common/network';
import * as path from 'vs/base/common/path';
import { Promises } from 'vs/base/node/pfs';
import { extract } from 'vs/base/node/zip';
import { getPathFromAmdModule, getRandomTestPath } from 'vs/base/test/node/testUtils';
import { getRandomTestPath } from 'vs/base/test/node/testUtils';

suite('Zip', () => {

Expand All @@ -26,7 +27,7 @@ suite('Zip', () => {
});

test('extract should handle directories', async () => {
const fixtures = getPathFromAmdModule(require, './fixtures');
const fixtures = FileAccess.asFileUri('vs/base/test/node/zip/fixtures').fsPath;
const fixture = path.join(fixtures, 'extract.zip');

await createCancelablePromise(token => extract(fixture, testDir, {}, token));
Expand Down
5 changes: 2 additions & 3 deletions src/vs/platform/checksum/test/node/checksumService.test.ts
Expand Up @@ -4,9 +4,8 @@
*--------------------------------------------------------------------------------------------*/

import * as assert from 'assert';
import { Schemas } from 'vs/base/common/network';
import { FileAccess, Schemas } from 'vs/base/common/network';
import { URI } from 'vs/base/common/uri';
import { getPathFromAmdModule } from 'vs/base/test/node/testUtils';
import { ChecksumService } from 'vs/platform/checksum/node/checksumService';
import { IFileService } from 'vs/platform/files/common/files';
import { FileService } from 'vs/platform/files/common/fileService';
Expand Down Expand Up @@ -34,7 +33,7 @@ suite('Checksum Service', () => {
test('checksum', async () => {
const checksumService = new ChecksumService(fileService);

const checksum = await checksumService.checksum(URI.file(getPathFromAmdModule(require, './fixtures/lorem.txt')));
const checksum = await checksumService.checksum(URI.file(FileAccess.asFileUri('vs/platform/checksum/test/node/fixtures/lorem.txt').fsPath));
assert.ok(checksum === '8mi5KF8kcb817zmlal1kZA' || checksum === 'DnUKbJ1bHPPNZoHgHV25sg'); // depends on line endings git config
});
});
22 changes: 11 additions & 11 deletions src/vs/platform/files/test/node/diskFileService.test.ts
Expand Up @@ -9,13 +9,13 @@ import { tmpdir } from 'os';
import { timeout } from 'vs/base/common/async';
import { bufferToReadable, bufferToStream, streamToBuffer, streamToBufferReadableStream, VSBuffer, VSBufferReadable, VSBufferReadableStream } from 'vs/base/common/buffer';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { Schemas } from 'vs/base/common/network';
import { FileAccess, Schemas } from 'vs/base/common/network';
import { basename, dirname, join, posix } from 'vs/base/common/path';
import { isLinux, isWindows } from 'vs/base/common/platform';
import { joinPath } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { Promises } from 'vs/base/node/pfs';
import { flakySuite, getPathFromAmdModule, getRandomTestPath } from 'vs/base/test/node/testUtils';
import { flakySuite, getRandomTestPath } from 'vs/base/test/node/testUtils';
import { etag, IFileAtomicReadOptions, FileOperation, FileOperationError, FileOperationEvent, FileOperationResult, FilePermission, FileSystemProviderCapabilities, hasFileAtomicReadCapability, hasOpenReadWriteCloseCapability, IFileStat, IFileStatWithMetadata, IReadFileOptions, IStat, NotModifiedSinceFileOperationError, TooLargeFileOperationError } from 'vs/platform/files/common/files';
import { FileService } from 'vs/platform/files/common/fileService';
import { DiskFileSystemProvider } from 'vs/platform/files/node/diskFileSystemProvider';
Expand Down Expand Up @@ -157,7 +157,7 @@ flakySuite('Disk File Service', function () {

testDir = getRandomTestPath(tmpdir(), 'vsctests', 'diskfileservice');

const sourceDir = getPathFromAmdModule(require, './fixtures/service');
const sourceDir = FileAccess.asFileUri('vs/platform/files/test/node/fixtures/service').fsPath;

await Promises.copy(sourceDir, testDir, { preserveSymlinks: false });
});
Expand Down Expand Up @@ -219,7 +219,7 @@ flakySuite('Disk File Service', function () {
});

test('resolve - file', async () => {
const resource = URI.file(getPathFromAmdModule(require, './fixtures/resolver/index.html'));
const resource = FileAccess.asFileUri('vs/platform/files/test/node/fixtures/resolver/index.html');
const resolved = await service.resolve(resource);

assert.strictEqual(resolved.name, 'index.html');
Expand All @@ -237,7 +237,7 @@ flakySuite('Disk File Service', function () {
test('resolve - directory', async () => {
const testsElements = ['examples', 'other', 'index.html', 'site.css'];

const resource = URI.file(getPathFromAmdModule(require, './fixtures/resolver'));
const resource = FileAccess.asFileUri('vs/platform/files/test/node/fixtures/resolver');
const result = await service.resolve(resource);

assert.ok(result);
Expand Down Expand Up @@ -282,7 +282,7 @@ flakySuite('Disk File Service', function () {
test('resolve - directory - with metadata', async () => {
const testsElements = ['examples', 'other', 'index.html', 'site.css'];

const result = await service.resolve(URI.file(getPathFromAmdModule(require, './fixtures/resolver')), { resolveMetadata: true });
const result = await service.resolve(FileAccess.asFileUri('vs/platform/files/test/node/fixtures/resolver'), { resolveMetadata: true });

assert.ok(result);
assert.strictEqual(result.name, 'resolver');
Expand Down Expand Up @@ -332,7 +332,7 @@ flakySuite('Disk File Service', function () {
});

test('resolve - directory - resolveTo single directory', async () => {
const resolverFixturesPath = getPathFromAmdModule(require, './fixtures/resolver');
const resolverFixturesPath = FileAccess.asFileUri('vs/platform/files/test/node/fixtures/resolver').fsPath;
const result = await service.resolve(URI.file(resolverFixturesPath), { resolveTo: [URI.file(join(resolverFixturesPath, 'other/deep'))] });

assert.ok(result);
Expand Down Expand Up @@ -362,7 +362,7 @@ flakySuite('Disk File Service', function () {
});

async function testResolveDirectoryWithTarget(withQueryParam: boolean): Promise<void> {
const resolverFixturesPath = getPathFromAmdModule(require, './fixtures/resolver');
const resolverFixturesPath = FileAccess.asFileUri('vs/platform/files/test/node/fixtures/resolver').fsPath;
const result = await service.resolve(URI.file(resolverFixturesPath).with({ query: withQueryParam ? 'test' : undefined }), {
resolveTo: [
URI.file(join(resolverFixturesPath, 'other/deep')).with({ query: withQueryParam ? 'test' : undefined }),
Expand Down Expand Up @@ -394,7 +394,7 @@ flakySuite('Disk File Service', function () {
}

test('resolve directory - resolveSingleChildFolders', async () => {
const resolverFixturesPath = getPathFromAmdModule(require, './fixtures/resolver/other');
const resolverFixturesPath = FileAccess.asFileUri('vs/platform/files/test/node/fixtures/resolver/other').fsPath;
const result = await service.resolve(URI.file(resolverFixturesPath), { resolveSingleChildDescendants: true });

assert.ok(result);
Expand Down Expand Up @@ -462,7 +462,7 @@ flakySuite('Disk File Service', function () {
});

test('stat - file', async () => {
const resource = URI.file(getPathFromAmdModule(require, './fixtures/resolver/index.html'));
const resource = FileAccess.asFileUri('vs/platform/files/test/node/fixtures/resolver/index.html');
const resolved = await service.stat(resource);

assert.strictEqual(resolved.name, 'index.html');
Expand All @@ -477,7 +477,7 @@ flakySuite('Disk File Service', function () {
});

test('stat - directory', async () => {
const resource = URI.file(getPathFromAmdModule(require, './fixtures/resolver'));
const resource = FileAccess.asFileUri('vs/platform/files/test/node/fixtures/resolver');
const result = await service.stat(resource);

assert.ok(result);
Expand Down
Expand Up @@ -6,7 +6,7 @@
import { tmpdir } from 'os';
import { basename, dirname, join } from 'vs/base/common/path';
import { Promises, RimRafMode } from 'vs/base/node/pfs';
import { flakySuite, getPathFromAmdModule, getRandomTestPath } from 'vs/base/test/node/testUtils';
import { flakySuite, getRandomTestPath } from 'vs/base/test/node/testUtils';
import { FileChangeType } from 'vs/platform/files/common/files';
import { INonRecursiveWatchRequest } from 'vs/platform/files/common/watcher';
import { NodeJSFileWatcherLibrary, watchFileContents } from 'vs/platform/files/node/watcher/nodejs/nodejsWatcherLib';
Expand All @@ -16,6 +16,7 @@ import { ltrim } from 'vs/base/common/strings';
import { DeferredPromise } from 'vs/base/common/async';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { NodeJSWatcher } from 'vs/platform/files/node/watcher/nodejs/nodejsWatcher';
import { FileAccess } from 'vs/base/common/network';

// this suite has shown flaky runs in Azure pipelines where
// tasks would just hang and timeout after a while (not in
Expand Down Expand Up @@ -80,7 +81,7 @@ import { NodeJSWatcher } from 'vs/platform/files/node/watcher/nodejs/nodejsWatch

testDir = getRandomTestPath(tmpdir(), 'vsctests', 'filewatcher');

const sourceDir = getPathFromAmdModule(require, './fixtures/service');
const sourceDir = FileAccess.asFileUri('vs/platform/files/test/node/fixtures/service').fsPath;

await Promises.copy(sourceDir, testDir, { preserveSymlinks: false });
});
Expand Down
Expand Up @@ -10,12 +10,13 @@ import { timeout } from 'vs/base/common/async';
import { join } from 'vs/base/common/path';
import { isLinux, isMacintosh, isWindows } from 'vs/base/common/platform';
import { Promises, RimRafMode } from 'vs/base/node/pfs';
import { flakySuite, getPathFromAmdModule, getRandomTestPath } from 'vs/base/test/node/testUtils';
import { flakySuite, getRandomTestPath } from 'vs/base/test/node/testUtils';
import { FileChangeType } from 'vs/platform/files/common/files';
import { ParcelWatcher } from 'vs/platform/files/node/watcher/parcel/parcelWatcher';
import { IDiskFileChange, IRecursiveWatchRequest } from 'vs/platform/files/common/watcher';
import { getDriveLetter } from 'vs/base/common/extpath';
import { ltrim } from 'vs/base/common/strings';
import { FileAccess } from 'vs/base/common/network';

// this suite has shown flaky runs in Azure pipelines where
// tasks would just hang and timeout after a while (not in
Expand Down Expand Up @@ -78,7 +79,7 @@ import { ltrim } from 'vs/base/common/strings';

testDir = getRandomTestPath(tmpdir(), 'vsctests', 'filewatcher');

const sourceDir = getPathFromAmdModule(require, './fixtures/service');
const sourceDir = FileAccess.asFileUri('vs/platform/files/test/node/fixtures/service').fsPath;

await Promises.copy(sourceDir, testDir, { preserveSymlinks: false });
});
Expand Down
Expand Up @@ -9,18 +9,18 @@ import { Event } from 'vs/base/common/event';
import { join } from 'vs/base/common/path';
import { extUriBiasedIgnorePathCase } from 'vs/base/common/resources';
import { URI, UriDto } from 'vs/base/common/uri';
import { getPathFromAmdModule } from 'vs/base/test/node/testUtils';
import { ICommandAction } from 'vs/platform/action/common/action';
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
import { INativeWindowConfiguration } from 'vs/platform/window/common/window';
import { ICodeWindow, ILoadEvent, IWindowState } from 'vs/platform/window/electron-main/window';
import { findWindowOnFile } from 'vs/platform/windows/electron-main/windowsFinder';
import { toWorkspaceFolders } from 'vs/platform/workspaces/common/workspaces';
import { IWorkspaceIdentifier } from 'vs/platform/workspace/common/workspace';
import { FileAccess } from 'vs/base/common/network';

suite('WindowsFinder', () => {

const fixturesFolder = getPathFromAmdModule(require, './fixtures');
const fixturesFolder = FileAccess.asFileUri('vs/platform/windows/test/electron-main/fixtures').fsPath;

const testWorkspace: IWorkspaceIdentifier = {
id: Date.now().toString(),
Expand Down
Expand Up @@ -9,7 +9,6 @@ import { asTextOrError } from 'vs/platform/request/common/request';
import * as pfs from 'vs/base/node/pfs';
import * as path from 'vs/base/common/path';
import * as assert from 'assert';
import { getPathFromAmdModule } from 'vs/base/test/node/testUtils';
import { CancellationToken } from 'vs/base/common/cancellation';
import { RequestService } from 'vs/platform/request/node/requestService';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
Expand All @@ -18,6 +17,7 @@ import 'vs/workbench/workbench.desktop.main';
import { NullLogService } from 'vs/platform/log/common/log';
import { mock } from 'vs/base/test/common/mock';
import { INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { FileAccess } from 'vs/base/common/network';

interface ColorInfo {
description: string;
Expand Down Expand Up @@ -115,7 +115,7 @@ function getDescription(color: ColorContribution) {
}

async function getColorsFromExtension(): Promise<{ [id: string]: string }> {
const extPath = getPathFromAmdModule(require, '../../../../../../../extensions');
const extPath = FileAccess.asFileUri('vs/../../extensions').fsPath;
const extFolders = await pfs.Promises.readDirsInDir(extPath);
const result: { [id: string]: string } = Object.create(null);
for (const folder of extFolders) {
Expand Down
Expand Up @@ -5,11 +5,11 @@

import * as assert from 'assert';
import * as path from 'vs/base/common/path';
import { getPathFromAmdModule } from 'vs/base/test/node/testUtils';
import { SingleModifierChord, ResolvedKeybinding, Keybinding } from 'vs/base/common/keybindings';
import { Promises } from 'vs/base/node/pfs';
import { IKeyboardEvent } from 'vs/platform/keybinding/common/keybinding';
import { IKeyboardMapper } from 'vs/platform/keyboardLayout/common/keyboardMapper';
import { FileAccess } from 'vs/base/common/network';

export interface IResolvedKeybinding {
label: string | null;
Expand Down Expand Up @@ -46,7 +46,7 @@ export function assertResolveKeybinding(mapper: IKeyboardMapper, keybinding: Key
}

export function readRawMapping<T>(file: string): Promise<T> {
return Promises.readFile(getPathFromAmdModule(require, `vs/workbench/services/keybinding/test/node/${file}.js`)).then((buff) => {
return Promises.readFile(FileAccess.asFileUri(`vs/workbench/services/keybinding/test/node/${file}.js`).fsPath).then((buff) => {
const contents = buff.toString();
const func = new Function('define', contents);
let rawMappings: T | null = null;
Expand All @@ -58,7 +58,7 @@ export function readRawMapping<T>(file: string): Promise<T> {
}

export function assertMapping(writeFileIfDifferent: boolean, mapper: IKeyboardMapper, file: string): Promise<void> {
const filePath = path.normalize(getPathFromAmdModule(require, `vs/workbench/services/keybinding/test/node/${file}`));
const filePath = path.normalize(FileAccess.asFileUri(`vs/workbench/services/keybinding/test/node/${file}`).fsPath);

return Promises.readFile(filePath).then((buff) => {
const expected = buff.toString().replace(/\r\n/g, '\n');
Expand Down
Expand Up @@ -7,17 +7,18 @@ import * as assert from 'assert';
import { CancelablePromise, createCancelablePromise } from 'vs/base/common/async';
import { Emitter, Event } from 'vs/base/common/event';
import { IDisposable } from 'vs/base/common/lifecycle';
import { FileAccess } from 'vs/base/common/network';
import * as path from 'vs/base/common/path';
import { URI } from 'vs/base/common/uri';
import { flakySuite, getPathFromAmdModule } from 'vs/base/test/node/testUtils';
import { flakySuite } from 'vs/base/test/node/testUtils';
import { IFileQuery, IFileSearchStats, IFolderQuery, IProgressMessage, IRawFileMatch, ISearchEngine, ISearchEngineStats, ISearchEngineSuccess, ISerializedFileMatch, ISerializedSearchComplete, ISerializedSearchProgressItem, ISerializedSearchSuccess, isSerializedSearchComplete, isSerializedSearchSuccess, QueryType } from 'vs/workbench/services/search/common/search';
import { IProgressCallback, SearchService as RawSearchService } from 'vs/workbench/services/search/node/rawSearchService';

const TEST_FOLDER_QUERIES = [
{ folder: URI.file(path.normalize('/some/where')) }
];

const TEST_FIXTURES = path.normalize(getPathFromAmdModule(require, '../node/fixtures'));
const TEST_FIXTURES = path.normalize(FileAccess.asFileUri('vs/workbench/services/search/test/node/fixtures').fsPath);
const MULTIROOT_QUERIES: IFolderQuery[] = [
{ folder: URI.file(path.join(TEST_FIXTURES, 'examples')) },
{ folder: URI.file(path.join(TEST_FIXTURES, 'more')) }
Expand Down