Skip to content

Commit e01e3a4

Browse files
committed
Fix add getYarnVersion missing tests
1 parent 165ebe4 commit e01e3a4

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

src/yarn-commands.test.ts

+37-8
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,61 @@
1-
import { fixConstraints, installDependencies } from './yarn-commands.js';
2-
import { runCommand } from './misc-utils.js';
1+
import { when } from 'jest-when';
2+
import {
3+
fixConstraints,
4+
getYarnVersion,
5+
installDependencies,
6+
} from './yarn-commands.js';
7+
import * as miscUtils from './misc-utils.js';
38

49
jest.mock('./misc-utils');
510

611
describe('yarn-commands', () => {
12+
describe('getYarnVersion', () => {
13+
it('should run yarn --version with the correct parameters', async () => {
14+
await getYarnVersion();
15+
16+
expect(miscUtils.getStdoutFromCommand).toHaveBeenCalledWith('yarn', [
17+
'--version',
18+
]);
19+
});
20+
});
21+
722
describe('fixConstraints', () => {
8-
const repositoryDirectoryPath = '/path/to/repo';
23+
it('should run yarn constraints --fix when yarn version is compatible with constraints', async () => {
24+
const repositoryDirectoryPath = '/path/to/repo';
25+
when(jest.spyOn(miscUtils, 'getStdoutFromCommand'))
26+
.calledWith('yarn', ['--version'])
27+
.mockResolvedValue('2.0.0');
928

10-
it('should run yarn constraints --fix with the correct parameters', async () => {
1129
await fixConstraints(repositoryDirectoryPath);
1230

13-
expect(runCommand).toHaveBeenCalledWith(
31+
expect(miscUtils.runCommand).toHaveBeenCalledWith(
1432
'yarn',
1533
['constraints', '--fix'],
1634
{
1735
cwd: repositoryDirectoryPath,
1836
},
1937
);
2038
});
39+
40+
it('should not run yarn constraints --fix when yarn version is not compatible with constraints', async () => {
41+
const repositoryDirectoryPath = '/path/to/repo';
42+
when(jest.spyOn(miscUtils, 'getStdoutFromCommand'))
43+
.calledWith('yarn', ['--version'])
44+
.mockResolvedValue('1.0.0');
45+
46+
await fixConstraints(repositoryDirectoryPath);
47+
48+
expect(miscUtils.runCommand).toHaveBeenCalledTimes(0);
49+
});
2150
});
2251

2352
describe('installDependencies', () => {
24-
const repositoryDirectoryPath = '/path/to/repo';
25-
2653
it('should run yarn with the correct parameters', async () => {
54+
const repositoryDirectoryPath = '/path/to/repo';
55+
2756
await installDependencies('/path/to/repo');
2857

29-
expect(runCommand).toHaveBeenCalledWith('yarn', [], {
58+
expect(miscUtils.runCommand).toHaveBeenCalledWith('yarn', [], {
3059
cwd: repositoryDirectoryPath,
3160
});
3261
});

0 commit comments

Comments
 (0)