Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(config-lerna-scopes): add regression tests #979

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "a2",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "b2",
"version": "1.0.0"
}
25 changes: 24 additions & 1 deletion @commitlint/config-lerna-scopes/index.test.js
Original file line number Diff line number Diff line change
@@ -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']);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small improvement to test, we should validate what is actually returned

});

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
Original file line number Diff line number Diff line change
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",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this package is used within test but was present only in config-lerna-scopes

"tmp": "0.1.0"
}
}