diff options
| author | Kevin Meinhardt <[email protected]> | 2022-11-07 09:46:38 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-11-07 08:46:38 +0000 |
| commit | 7c661c63d4eb6345ef7aab1836dc7643d412dd0c (patch) | |
| tree | dc4260895d59cc171df12b9f4bef97e5c78f9a9c | |
| parent | 1bed40369974db6a15db3e6cb8e765717e640ad1 (diff) | |
| download | faker-7c661c63d4eb6345ef7aab1836dc7643d412dd0c.tar.xz faker-7c661c63d4eb6345ef7aab1836dc7643d412dd0c.zip | |
feat(git): add options.refDate to commitEntry (#1512)
| -rw-r--r-- | src/modules/git/index.ts | 6 | ||||
| -rw-r--r-- | test/__snapshots__/date.spec.ts.snap | 24 | ||||
| -rw-r--r-- | test/__snapshots__/git.spec.ts.snap | 81 | ||||
| -rw-r--r-- | test/date.spec.ts | 3 | ||||
| -rw-r--r-- | test/git.spec.ts | 11 |
5 files changed, 121 insertions, 4 deletions
diff --git a/src/modules/git/index.ts b/src/modules/git/index.ts index 78cf0c68..232e0e27 100644 --- a/src/modules/git/index.ts +++ b/src/modules/git/index.ts @@ -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 @@ -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()}`]; @@ -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 diff --git a/test/__snapshots__/date.spec.ts.snap b/test/__snapshots__/date.spec.ts.snap index 42bc81c9..9969cf73 100644 --- a/test/__snapshots__/date.spec.ts.snap +++ b/test/__snapshots__/date.spec.ts.snap @@ -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`; @@ -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`; @@ -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`; @@ -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`; @@ -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`; @@ -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`; diff --git a/test/__snapshots__/git.spec.ts.snap b/test/__snapshots__/git.spec.ts.snap index d8e43f6c..e61c0578 100644 --- a/test/__snapshots__/git.spec.ts.snap +++ b/test/__snapshots__/git.spec.ts.snap @@ -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 <[email protected]> +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 <[email protected]> +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 <[email protected]> +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"`; @@ -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 <[email protected]> +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 <[email protected]> +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 <[email protected]> +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"`; @@ -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 <[email protected]> +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 <[email protected]> +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 <[email protected]> +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"`; diff --git a/test/date.spec.ts b/test/date.spec.ts index de06f1f3..d5016e2d 100644 --- a/test/date.spec.ts +++ b/test/date.spec.ts @@ -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( diff --git a/test/git.spec.ts b/test/git.spec.ts index 5f3287da..18cb153a 100644 --- a/test/git.spec.ts +++ b/test/git.spec.ts @@ -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'; @@ -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()}`, () => { |
