Skip to content

Commit 01c451c

Browse files
authored
test(config-lerna-scopes): add regression tests (#979)
* test(config-lerna-scopes): add regression tests * test(config-lerna-scopes): do not break tests in case of lerna update * test(config-lerna-scopes): improve tests for lerna 2 and split tests
1 parent 21a91e7 commit 01c451c

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "a2",
3+
"version": "1.0.0"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "b2",
3+
"version": "1.0.0"
4+
}

@commitlint/config-lerna-scopes/index.test.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {lerna} from '@commitlint/test';
22
import config from '.';
3+
import semver from 'semver';
34

45
test('exports rules key', () => {
56
expect(config).toHaveProperty('rules');
@@ -70,5 +71,27 @@ test('returns expected value for scoped lerna repository', async () => {
7071
test('works with lerna version < 3', async () => {
7172
const {'scope-enum': fn} = config.rules;
7273
const cwd = await lerna.bootstrap('lerna-two', __dirname);
73-
await expect(fn({cwd})).resolves.toBeTruthy();
74+
const [, , value] = await fn({cwd});
75+
expect(value).toEqual(['a2', 'b2']);
76+
});
77+
78+
test('uses lerna version < 3 if installed', async () => {
79+
const semverLt = jest.spyOn(semver, 'lt');
80+
const cwd = await lerna.bootstrap('lerna-two', __dirname);
81+
const packages = await config.utils.getPackages({cwd});
82+
83+
expect(packages).toEqual(['a2', 'b2']);
84+
expect(semverLt).toHaveBeenLastCalledWith('2.11.0', '3.0.0');
85+
expect(semverLt).toHaveLastReturnedWith(true);
86+
});
87+
88+
test('uses lerna version >= 3 if installed', async () => {
89+
const semverLt = jest.spyOn(semver, 'lt');
90+
const cwd = await lerna.bootstrap('basic', __dirname);
91+
92+
const packages = await config.utils.getPackages({cwd});
93+
94+
expect(packages).toEqual(['a', 'b']);
95+
expect(semverLt).toHaveBeenLastCalledWith('3.20.2', '3.0.0');
96+
expect(semverLt).toHaveLastReturnedWith(false);
7497
});

@packages/test/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"execa": "0.11.0",
3636
"fs-extra": "^8.1.0",
3737
"pkg-dir": "4.2.0",
38+
"resolve-pkg": "2.0.0",
3839
"tmp": "0.1.0"
3940
}
4041
}

0 commit comments

Comments
 (0)