Skip to content

Commit

Permalink
feat(git): add options.refDate to commitEntry (#1512)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed Nov 7, 2022
1 parent 1bed403 commit 7c661c6
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/modules/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export class GitModule {
* 'LF' = '\n',
* 'CRLF' = '\r\n'
*
* @param options.refDate The date to use as reference point for the commit. Defaults to now.
*
* @example
* faker.git.commitEntry()
* // commit fe8c38a965d13d9794eb36918cb24cebe49a45c2
Expand All @@ -51,11 +53,13 @@ export class GitModule {
options: {
merge?: boolean;
eol?: 'LF' | 'CRLF';
refDate?: string | Date | number;
} = {}
): string {
const {
merge = this.faker.datatype.number({ min: 0, max: 4 }) === 0,
eol = 'CRLF',
refDate,
} = options;

const lines = [`commit ${this.faker.git.commitSha()}`];
Expand All @@ -66,7 +70,7 @@ export class GitModule {

lines.push(
`Author: ${this.faker.person.firstName()} ${this.faker.person.lastName()} <${this.faker.internet.email()}>`,
`Date: ${this.faker.date.recent().toString()}`,
`Date: ${this.faker.date.recent(1, refDate).toString()}`,
'',
`\xa0\xa0\xa0\xa0${this.commitMessage()}`,
// to end with a eol char
Expand Down
24 changes: 24 additions & 0 deletions test/__snapshots__/date.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ exports[`date > 42 > birthdate > with year range and refDate 1`] = `0057-12-20T1

exports[`date > 42 > future > with only Date refDate 1`] = `2021-07-08T10:07:33.381Z`;

exports[`date > 42 > future > with only number refDate 1`] = `2021-07-08T10:07:33.381Z`;

exports[`date > 42 > future > with only string refDate 1`] = `2021-07-08T10:07:33.381Z`;

exports[`date > 42 > future > with value 1`] = `2024-11-19T18:52:06.785Z`;
Expand All @@ -70,18 +72,24 @@ exports[`date > 42 > month > with context = true 1`] = `"May"`;

exports[`date > 42 > past > with only Date refDate 1`] = `2020-10-08T00:10:58.041Z`;

exports[`date > 42 > past > with only number refDate 1`] = `2020-10-08T00:10:58.041Z`;

exports[`date > 42 > past > with only string refDate 1`] = `2020-10-08T00:10:58.041Z`;

exports[`date > 42 > past > with value 1`] = `2017-05-26T15:26:24.637Z`;

exports[`date > 42 > recent > with only Date refDate 1`] = `2021-02-21T08:09:54.820Z`;

exports[`date > 42 > recent > with only number refDate 1`] = `2021-02-21T08:09:54.820Z`;

exports[`date > 42 > recent > with only string refDate 1`] = `2021-02-21T08:09:54.820Z`;

exports[`date > 42 > recent > with value 1`] = `2021-02-17T23:15:52.427Z`;

exports[`date > 42 > soon > with only Date refDate 1`] = `2021-02-22T02:08:36.602Z`;

exports[`date > 42 > soon > with only number refDate 1`] = `2021-02-22T02:08:36.602Z`;

exports[`date > 42 > soon > with only string refDate 1`] = `2021-02-22T02:08:36.602Z`;

exports[`date > 42 > soon > with value 1`] = `2021-02-25T11:02:38.995Z`;
Expand Down Expand Up @@ -150,6 +158,8 @@ exports[`date > 1211 > birthdate > with year range and refDate 1`] = `0113-12-03

exports[`date > 1211 > future > with only Date refDate 1`] = `2022-01-26T14:59:27.351Z`;

exports[`date > 1211 > future > with only number refDate 1`] = `2022-01-26T14:59:27.351Z`;

exports[`date > 1211 > future > with only string refDate 1`] = `2022-01-26T14:59:27.351Z`;

exports[`date > 1211 > future > with value 1`] = `2030-06-03T19:31:11.467Z`;
Expand All @@ -164,18 +174,24 @@ exports[`date > 1211 > month > with context = true 1`] = `"December"`;

exports[`date > 1211 > past > with only Date refDate 1`] = `2020-03-19T19:19:04.071Z`;

exports[`date > 1211 > past > with only number refDate 1`] = `2020-03-19T19:19:04.071Z`;

exports[`date > 1211 > past > with only string refDate 1`] = `2020-03-19T19:19:04.071Z`;

exports[`date > 1211 > past > with value 1`] = `2011-11-12T14:47:19.955Z`;

exports[`date > 1211 > recent > with only Date refDate 1`] = `2021-02-20T18:52:11.498Z`;

exports[`date > 1211 > recent > with only number refDate 1`] = `2021-02-20T18:52:11.498Z`;

exports[`date > 1211 > recent > with only string refDate 1`] = `2021-02-20T18:52:11.498Z`;

exports[`date > 1211 > recent > with value 1`] = `2021-02-12T10:18:34.226Z`;

exports[`date > 1211 > soon > with only Date refDate 1`] = `2021-02-22T15:26:19.924Z`;

exports[`date > 1211 > soon > with only number refDate 1`] = `2021-02-22T15:26:19.924Z`;

exports[`date > 1211 > soon > with only string refDate 1`] = `2021-02-22T15:26:19.924Z`;

exports[`date > 1211 > soon > with value 1`] = `2021-03-02T23:59:57.196Z`;
Expand Down Expand Up @@ -244,6 +260,8 @@ exports[`date > 1337 > birthdate > with year range and refDate 1`] = `0046-08-09

exports[`date > 1337 > future > with only Date refDate 1`] = `2021-05-28T08:29:26.637Z`;

exports[`date > 1337 > future > with only number refDate 1`] = `2021-05-28T08:29:26.637Z`;

exports[`date > 1337 > future > with only string refDate 1`] = `2021-05-28T08:29:26.637Z`;

exports[`date > 1337 > future > with value 1`] = `2023-10-06T02:30:58.333Z`;
Expand All @@ -258,18 +276,24 @@ exports[`date > 1337 > month > with context = true 1`] = `"April"`;

exports[`date > 1337 > past > with only Date refDate 1`] = `2020-11-18T01:49:04.785Z`;

exports[`date > 1337 > past > with only number refDate 1`] = `2020-11-18T01:49:04.785Z`;

exports[`date > 1337 > past > with only string refDate 1`] = `2020-11-18T01:49:04.785Z`;

exports[`date > 1337 > past > with value 1`] = `2018-07-11T07:47:33.089Z`;

exports[`date > 1337 > recent > with only Date refDate 1`] = `2021-02-21T10:51:56.041Z`;

exports[`date > 1337 > recent > with only number refDate 1`] = `2021-02-21T10:51:56.041Z`;

exports[`date > 1337 > recent > with only string refDate 1`] = `2021-02-21T10:51:56.041Z`;

exports[`date > 1337 > recent > with value 1`] = `2021-02-19T02:16:05.653Z`;

exports[`date > 1337 > soon > with only Date refDate 1`] = `2021-02-21T23:26:35.381Z`;

exports[`date > 1337 > soon > with only number refDate 1`] = `2021-02-21T23:26:35.381Z`;

exports[`date > 1337 > soon > with only string refDate 1`] = `2021-02-21T23:26:35.381Z`;

exports[`date > 1337 > soon > with value 1`] = `2021-02-24T08:02:25.769Z`;
Expand Down
81 changes: 81 additions & 0 deletions test/__snapshots__/git.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@

exports[`git > 42 > branch 1`] = `"array-transmit"`;

exports[`git > 42 > commitEntry > with only Date refDate 1`] = `
"commit be4abdd39321ad7d3fe01ffce404f4d6db0906bd
Author: Gregg Conn <Eladio.Wiza@gmail.com>
Date: Tue Dec 31 2019 13:03:15 GMT+0000 (Coordinated Universal Time)
    bypass neural pixel
"
`;

exports[`git > 42 > commitEntry > with only number refDate 1`] = `
"commit be4abdd39321ad7d3fe01ffce404f4d6db0906bd
Author: Gregg Conn <Eladio.Wiza@gmail.com>
Date: Tue Dec 31 2019 13:03:15 GMT+0000 (Coordinated Universal Time)
    bypass neural pixel
"
`;

exports[`git > 42 > commitEntry > with only string refDate 1`] = `
"commit be4abdd39321ad7d3fe01ffce404f4d6db0906bd
Author: Gregg Conn <Eladio.Wiza@gmail.com>
Date: Tue Dec 31 2019 13:03:15 GMT+0000 (Coordinated Universal Time)
    bypass neural pixel
"
`;

exports[`git > 42 > commitMessage 1`] = `"navigate neural capacitor"`;

exports[`git > 42 > commitSha 1`] = `"8be4abdd39321ad7d3fe01ffce404f4d6db0906b"`;
Expand All @@ -10,6 +37,33 @@ exports[`git > 42 > shortSha 1`] = `"8be4abd"`;

exports[`git > 1211 > branch 1`] = `"capacitor-connect"`;

exports[`git > 1211 > commitEntry > with only Date refDate 1`] = `
"commit adb42f0e3f4a973fab0aeefce96dfcf49cd438df
Author: Imani Runolfsson <Gracie.Gutmann53@gmail.com>
Date: Tue Dec 31 2019 13:53:17 GMT+0000 (Coordinated Universal Time)
    parse back-end program
"
`;

exports[`git > 1211 > commitEntry > with only number refDate 1`] = `
"commit adb42f0e3f4a973fab0aeefce96dfcf49cd438df
Author: Imani Runolfsson <Gracie.Gutmann53@gmail.com>
Date: Tue Dec 31 2019 13:53:17 GMT+0000 (Coordinated Universal Time)
    parse back-end program
"
`;

exports[`git > 1211 > commitEntry > with only string refDate 1`] = `
"commit adb42f0e3f4a973fab0aeefce96dfcf49cd438df
Author: Imani Runolfsson <Gracie.Gutmann53@gmail.com>
Date: Tue Dec 31 2019 13:53:17 GMT+0000 (Coordinated Universal Time)
    parse back-end program
"
`;

exports[`git > 1211 > commitMessage 1`] = `"reboot online circuit"`;

exports[`git > 1211 > commitSha 1`] = `"eadb42f0e3f4a973fab0aeefce96dfcf49cd438d"`;
Expand All @@ -18,6 +72,33 @@ exports[`git > 1211 > shortSha 1`] = `"eadb42f"`;

exports[`git > 1337 > branch 1`] = `"port-quantify"`;

exports[`git > 1337 > commitEntry > with only Date refDate 1`] = `
"commit c346ba075bd57f5a62b82d72af39cbbb07a98cba
Author: Friedrich Dibbert <Edward.Stracke49@yahoo.com>
Date: Tue Dec 31 2019 13:25:40 GMT+0000 (Coordinated Universal Time)
    override back-end interface
"
`;

exports[`git > 1337 > commitEntry > with only number refDate 1`] = `
"commit c346ba075bd57f5a62b82d72af39cbbb07a98cba
Author: Friedrich Dibbert <Edward.Stracke49@yahoo.com>
Date: Tue Dec 31 2019 13:25:40 GMT+0000 (Coordinated Universal Time)
    override back-end interface
"
`;

exports[`git > 1337 > commitEntry > with only string refDate 1`] = `
"commit c346ba075bd57f5a62b82d72af39cbbb07a98cba
Author: Friedrich Dibbert <Edward.Stracke49@yahoo.com>
Date: Tue Dec 31 2019 13:25:40 GMT+0000 (Coordinated Universal Time)
    override back-end interface
"
`;

exports[`git > 1337 > commitMessage 1`] = `"compress multi-byte panel"`;

exports[`git > 1337 > commitSha 1`] = `"5c346ba075bd57f5a62b82d72af39cbbb07a98cb"`;
Expand Down
3 changes: 2 additions & 1 deletion test/date.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ describe('date', () => {
)((t) => {
t.it('with only string refDate', undefined, refDate)
.it('with only Date refDate', undefined, new Date(refDate))
.it('with value', 10, refDate);
.it('with value', 10, refDate)
.it('with only number refDate', undefined, new Date(refDate).getTime());
});

t.describeEach(
Expand Down
11 changes: 9 additions & 2 deletions test/git.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { seededTests } from './support/seededRuns';

const NON_SEEDED_BASED_RUN = 5;

const refDate = '2020-01-01T00:00:00.000Z';

describe('git', () => {
afterEach(() => {
faker.locale = 'en';
Expand All @@ -13,8 +15,13 @@ describe('git', () => {
seededTests(faker, 'git', (t) => {
t.itEach('branch', 'commitMessage', 'commitSha', 'shortSha');

// The timestamp is not fixed, so we can't compare it
t.todo('commitEntry');
t.describe('commitEntry', (t) => {
t.it('with only string refDate', { refDate })
.it('with only Date refDate', { refDate: new Date(refDate) })
.it('with only number refDate', {
refDate: new Date(refDate).getTime(),
});
});
});

describe(`random seeded tests for seed ${faker.seed()}`, () => {
Expand Down

0 comments on commit 7c661c6

Please sign in to comment.