Skip to content

Commit

Permalink
test(config-lerna-scopes): add regression tests (#979)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
armano2 committed Feb 8, 2020
1 parent 21a91e7 commit 01c451c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
@@ -0,0 +1,4 @@
{
"name": "a2",
"version": "1.0.0"
}
@@ -0,0 +1,4 @@
{
"name": "b2",
"version": "1.0.0"
}
25 changes: 24 additions & 1 deletion @commitlint/config-lerna-scopes/index.test.js
@@ -1,5 +1,6 @@
import {lerna} from '@commitlint/test';
import config from '.';
import semver from 'semver';

test('exports rules key', () => {
expect(config).toHaveProperty('rules');
Expand Down Expand Up @@ -70,5 +71,27 @@ test('returns expected value for scoped lerna repository', async () => {
test('works with lerna version < 3', async () => {
const {'scope-enum': fn} = config.rules;
const cwd = await lerna.bootstrap('lerna-two', __dirname);
await expect(fn({cwd})).resolves.toBeTruthy();
const [, , value] = await fn({cwd});
expect(value).toEqual(['a2', 'b2']);
});

test('uses lerna version < 3 if installed', async () => {
const semverLt = jest.spyOn(semver, 'lt');
const cwd = await lerna.bootstrap('lerna-two', __dirname);
const packages = await config.utils.getPackages({cwd});

expect(packages).toEqual(['a2', 'b2']);
expect(semverLt).toHaveBeenLastCalledWith('2.11.0', '3.0.0');
expect(semverLt).toHaveLastReturnedWith(true);
});

test('uses lerna version >= 3 if installed', async () => {
const semverLt = jest.spyOn(semver, 'lt');
const cwd = await lerna.bootstrap('basic', __dirname);

const packages = await config.utils.getPackages({cwd});

expect(packages).toEqual(['a', 'b']);
expect(semverLt).toHaveBeenLastCalledWith('3.20.2', '3.0.0');
expect(semverLt).toHaveLastReturnedWith(false);
});
1 change: 1 addition & 0 deletions @packages/test/package.json
Expand Up @@ -35,6 +35,7 @@
"execa": "0.11.0",
"fs-extra": "^8.1.0",
"pkg-dir": "4.2.0",
"resolve-pkg": "2.0.0",
"tmp": "0.1.0"
}
}

0 comments on commit 01c451c

Please sign in to comment.