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 1 commit
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
15 changes: 15 additions & 0 deletions @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 @@ -28,47 +29,61 @@ test('scope-enum is function', () => {
});

test('scope-enum does not throw for missing context', async () => {
const semverLt = jest.spyOn(semver, 'lt');
const {'scope-enum': fn} = config.rules;
await expect(fn()).resolves.toBeTruthy();
expect(semverLt).toHaveBeenLastCalledWith('3.20.2', '3.0.0');
});

test('scope-enum has expected severity', async () => {
const semverLt = jest.spyOn(semver, 'lt');
const {'scope-enum': fn} = config.rules;
const [severity] = await fn();
expect(severity).toBe(2);
expect(semverLt).toHaveBeenLastCalledWith('3.20.2', '3.0.0');
});

test('scope-enum has expected modifier', async () => {
const semverLt = jest.spyOn(semver, 'lt');
const {'scope-enum': fn} = config.rules;
const [, modifier] = await fn();
expect(modifier).toBe('always');
expect(semverLt).toHaveBeenLastCalledWith('3.20.2', '3.0.0');
});

test('returns empty value for empty lerna repository', async () => {
const semverLt = jest.spyOn(semver, 'lt');
const {'scope-enum': fn} = config.rules;
const cwd = await lerna.bootstrap('empty', __dirname);
const [, , value] = await fn({cwd});
expect(value).toEqual([]);
expect(semverLt).toHaveBeenLastCalledWith('3.20.2', '3.0.0');
});

test('returns expected value for basic lerna repository', async () => {
const semverLt = jest.spyOn(semver, 'lt');
const {'scope-enum': fn} = config.rules;
const cwd = await lerna.bootstrap('basic', __dirname);

const [, , value] = await fn({cwd});
expect(value).toEqual(['a', 'b']);
expect(semverLt).toHaveBeenLastCalledWith('3.20.2', '3.0.0');
});

test('returns expected value for scoped lerna repository', async () => {
const semverLt = jest.spyOn(semver, 'lt');
const {'scope-enum': fn} = config.rules;
const cwd = await lerna.bootstrap('scoped', __dirname);

const [, , value] = await fn({cwd});
expect(value).toEqual(['a', 'b']);
expect(semverLt).toHaveBeenLastCalledWith('3.20.2', '3.0.0');
});

test('works with lerna version < 3', async () => {
const semverLt = jest.spyOn(semver, 'lt');
const {'scope-enum': fn} = config.rules;
const cwd = await lerna.bootstrap('lerna-two', __dirname);
await expect(fn({cwd})).resolves.toBeTruthy();
expect(semverLt).toHaveBeenLastCalledWith('2.11.0', '3.0.0');
});
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"
}
}