Skip to content

Commit aee077f

Browse files
authored
test(core-utils): add test coverage for spawnPackageManager (#3868)
1 parent 632117e commit aee077f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packages/utils/core-utils/spec/package-manager.spec.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { spawn } from '@malept/cross-spawn-promise';
12
import findUp from 'find-up';
23
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
34

4-
import { resolvePackageManager } from '../src/package-manager';
5+
import { resolvePackageManager, spawnPackageManager } from '../src/package-manager';
56

7+
vi.mock('@malept/cross-spawn-promise');
68
vi.mock('find-up', async (importOriginal) => {
79
const mod = await importOriginal<object>();
810
return {
@@ -83,6 +85,19 @@ describe('package-manager', () => {
8385
});
8486
});
8587

88+
describe('spawnPackageManager', () => {
89+
it('should trim the output', async () => {
90+
vi.mocked(spawn).mockResolvedValue(' foo \n');
91+
const result = await spawnPackageManager({
92+
executable: 'npm',
93+
install: 'install',
94+
dev: '--save-dev',
95+
exact: '--save-exact',
96+
});
97+
expect(result).toBe('foo');
98+
});
99+
});
100+
86101
it('should use the package manager for the nearest ancestor lockfile if detected', async () => {
87102
vi.mocked(findUp).mockResolvedValue('yarn.lock');
88103
await expect(resolvePackageManager()).resolves.toHaveProperty('executable', 'yarn');

0 commit comments

Comments
 (0)