Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions tests/classes/ManagerLocal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '../data/Project';
import { CONFIG_LOCAL_TEST } from '../data/Config';
import { ManagerLocal } from '../../src/classes/ManagerLocal';
import { Package } from '../../src/classes/Package';
import {
dirCreate,
dirDelete,
Expand Down Expand Up @@ -235,6 +236,37 @@ test('Install installer-only package still elevates when unprivileged', async ()
runCliAsAdminSpy.mockRestore();
});

test('Install all installs every listed package', async () => {
const manager = new ManagerLocal(RegistryType.Plugins, CONFIG);
// Seed a single known package directly rather than sync()'ing the live registry - installAll()
// only cares about whatever's already in listPackages(), and this keeps the test's network
// footprint fixed regardless of how many packages the real registry happens to have.
const pkg = new Package(PLUGIN_PACKAGE.slug);
pkg.addVersion(PLUGIN_PACKAGE.version, PLUGIN);
manager.addPackage(pkg);

const packages = await manager.installAll();
expect(packages).toHaveLength(1);
expect(packages[0].getVersion(PLUGIN_PACKAGE.version)?.installed).toEqual(true);

await manager.uninstall(PLUGIN_PACKAGE.slug, PLUGIN_PACKAGE.version);
});

test('Install all elevates when unprivileged', async () => {
const isAdminSpy = vi.spyOn(fileHelpers, 'isAdmin').mockReturnValue(false);
const isTestsSpy = vi.spyOn(utilsLocalHelpers, 'isTests').mockReturnValue(false);
const runCliAsAdminSpy = vi.spyOn(fileHelpers, 'runCliAsAdmin').mockResolvedValue(undefined);

const manager = new ManagerLocal(RegistryType.Plugins, CONFIG);
await manager.installAll();
expect(runCliAsAdminSpy).toHaveBeenCalledTimes(1);
expect(runCliAsAdminSpy).toHaveBeenCalledWith(expect.objectContaining({ operation: 'installAll' }));

isAdminSpy.mockRestore();
isTestsSpy.mockRestore();
runCliAsAdminSpy.mockRestore();
});

test('Project sync, install project, install dependencies, uninstall dependencies', async () => {
const manager = new ManagerLocal(RegistryType.Projects, CONFIG);
await manager.sync();
Expand Down
Loading