Simplify getTagParts.test.ts now that there's module specific tests in place

Signed-off-by: Erik Engervall <erik.engervall@gmail.com>
This commit is contained in:
Erik Engervall
2021-04-21 18:00:15 +02:00
parent 99cabc5865
commit 278dcdd92b
@@ -18,104 +18,34 @@ import {
mockCalverProject,
mockSemverProject,
} from '../../test-helpers/test-helpers';
jest.mock('./getCalverTagParts', () => ({
getCalverTagParts: jest.fn(),
}));
jest.mock('./getSemverTagParts', () => ({
getSemverTagParts: jest.fn(),
}));
import { getCalverTagParts } from './getCalverTagParts';
import { getSemverTagParts } from './getSemverTagParts';
import { getTagParts } from './getTagParts';
describe('getTagParts', () => {
beforeEach(jest.resetAllMocks);
describe('calver', () => {
it('should return tagParts for RC tag', () =>
expect(
getTagParts({ project: mockCalverProject, tag: 'rc-2020.01.01_1' }),
).toMatchInlineSnapshot(`
Object {
"calver": "2020.01.01",
"patch": 1,
"prefix": "rc",
}
`));
it('should call getCalverTagParts for calver projects', () => {
getTagParts({ project: mockCalverProject, tag: 'banana' });
it('should return tagParts for Version tag', () =>
expect(
getTagParts({
project: mockCalverProject,
tag: 'version-2020.01.01_1',
}),
).toMatchInlineSnapshot(`
Object {
"calver": "2020.01.01",
"patch": 1,
"prefix": "version",
}
`));
it('should return null for invalid prefix', () => {
expect(() =>
getTagParts({
project: mockCalverProject,
tag: 'invalid-2020.01.01_1',
}),
).toThrowErrorMatchingInlineSnapshot(`"Invalid calver tag"`);
});
it('should return null for invalid calver (missing padded zero)', () => {
expect(() =>
getTagParts({ project: mockCalverProject, tag: 'rc-2020.1.01_1' }),
).toThrowErrorMatchingInlineSnapshot(`"Invalid calver tag"`);
});
it('should return null for invalid calver (missing day)', () => {
expect(() =>
getTagParts({ project: mockCalverProject, tag: 'rc-2020.01_1' }),
).toThrowErrorMatchingInlineSnapshot(`"Invalid calver tag"`);
});
it('should return null for invalid patch (letter instead of number)', () => {
expect(() =>
getTagParts({ project: mockCalverProject, tag: 'rc-2020.01.01_a' }),
).toThrowErrorMatchingInlineSnapshot(`"Invalid calver tag"`);
expect(getCalverTagParts).toHaveBeenCalledTimes(1);
});
});
describe('semver', () => {
it('should return tagParts for RC tag', () =>
expect(getTagParts({ project: mockSemverProject, tag: 'rc-1.2.3' }))
.toMatchInlineSnapshot(`
Object {
"major": 1,
"minor": 2,
"patch": 3,
"prefix": "rc",
}
`));
it('should call getSemverTagParts for calver projects', () => {
getTagParts({ project: mockSemverProject, tag: 'banana' });
it('should return tagParts for Version tag', () =>
expect(getTagParts({ project: mockSemverProject, tag: 'version-1.2.3' }))
.toMatchInlineSnapshot(`
Object {
"major": 1,
"minor": 2,
"patch": 3,
"prefix": "version",
}
`));
it('should throw for invalid prefix', () => {
expect(() =>
getTagParts({ project: mockSemverProject, tag: 'invalid-1.2.3' }),
).toThrowErrorMatchingInlineSnapshot(`"Invalid semver tag"`);
});
it('should throw for invalid semver (missing patch)', () => {
expect(() =>
getTagParts({ project: mockSemverProject, tag: 'rc-1.2' }),
).toThrowErrorMatchingInlineSnapshot(`"Invalid semver tag"`);
});
it('should throw for invalid semver (founds calver)', () => {
expect(() =>
getTagParts({ project: mockSemverProject, tag: 'rc-1337.01.01_1' }),
).toThrowErrorMatchingInlineSnapshot(
`"Invalid semver tag, found calver"`,
);
expect(getSemverTagParts).toHaveBeenCalledTimes(1);
});
});
});