|
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'; |
3 | 8 |
|
4 | 9 | jest.mock('./misc-utils');
|
5 | 10 |
|
6 | 11 | 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 | + |
7 | 22 | 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'); |
9 | 28 |
|
10 |
| - it('should run yarn constraints --fix with the correct parameters', async () => { |
11 | 29 | await fixConstraints(repositoryDirectoryPath);
|
12 | 30 |
|
13 |
| - expect(runCommand).toHaveBeenCalledWith( |
| 31 | + expect(miscUtils.runCommand).toHaveBeenCalledWith( |
14 | 32 | 'yarn',
|
15 | 33 | ['constraints', '--fix'],
|
16 | 34 | {
|
17 | 35 | cwd: repositoryDirectoryPath,
|
18 | 36 | },
|
19 | 37 | );
|
20 | 38 | });
|
| 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 | + }); |
21 | 50 | });
|
22 | 51 |
|
23 | 52 | describe('installDependencies', () => {
|
24 |
| - const repositoryDirectoryPath = '/path/to/repo'; |
25 |
| - |
26 | 53 | it('should run yarn with the correct parameters', async () => {
|
| 54 | + const repositoryDirectoryPath = '/path/to/repo'; |
| 55 | + |
27 | 56 | await installDependencies('/path/to/repo');
|
28 | 57 |
|
29 |
| - expect(runCommand).toHaveBeenCalledWith('yarn', [], { |
| 58 | + expect(miscUtils.runCommand).toHaveBeenCalledWith('yarn', [], { |
30 | 59 | cwd: repositoryDirectoryPath,
|
31 | 60 | });
|
32 | 61 | });
|
|
0 commit comments