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

feat: 🔥 First punt at priority option #223

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6160c3c
feat: 🔥 First punt at priority option
Mar 16, 2022
485782e
Merge remote-tracking branch 'origin/main' into feat/220-unique-values
theryansmee Mar 22, 2022
6b57aa0
feat: 🔥 Clean up fakFromArray logic
theryansmee Mar 22, 2022
713c77d
feat: 🔥 Replace use of random index logic with getRandomInRange
theryansmee Mar 22, 2022
bbe7b0b
feat: 🔥 Revert rand element logic for now
theryansmee Mar 22, 2022
7f69bad
feat: 🔥 Allow devs to pass in comparison functions
theryansmee Mar 23, 2022
77831a5
feat: 🔥 Add custom comparison functions non-conforming function
theryansmee Mar 23, 2022
96acb7e
Merge remote-tracking branch 'origin/main' into feat/220-unique-values
theryansmee Mar 24, 2022
af09284
feat: 🔥 Add json check unique function. Clean up code
theryansmee Mar 24, 2022
6833592
feat: 🔥 Add generic comparison function
Apr 1, 2022
13998f6
feat: 🔥 Replace duplicate checkUnique logic with objectIsUnique
Apr 4, 2022
717bb7d
feat: 🔥 Fix function name. Update file name
Apr 4, 2022
660f53a
test: 🥳 Move error to snapshot
Apr 4, 2022
b18c227
Merge remote-tracking branch 'origin/main' into feat/220-unique-values
Apr 5, 2022
42a54d4
feat: 🔥 Fix snapshot
Apr 5, 2022
0ec65be
feat: 🔥 Move snapshots folder to tests/ route
Apr 5, 2022
ff6980a
feat: 🔥 Clean up core file
Apr 5, 2022
d57bd25
feat: 🔥 Add missing priority doc comment
Apr 5, 2022
fc5f8fc
test: 🥳 Replace flakey regex
Apr 5, 2022
67c4f5f
Merge remote-tracking branch 'origin/main' into feat/220-unique-values
Apr 19, 2022
2b84b1a
feat: 🔥 return empty array if length is 0
Apr 19, 2022
d4d1fa3
Merge remote-tracking branch 'origin/main' into feat/220-unique-values
May 3, 2022
32b84de
feat: 🔥 clean up unique validators
May 3, 2022
6f7dcc6
Merge remote-tracking branch 'origin/main' into feat/220-unique-values
May 6, 2022
2d0aecc
feat: 🔥 Add tests for unique validators
May 6, 2022
dbddca3
feat: 🔥 Fix reversed logic and corresponding tests
May 6, 2022
2331772
feat: 🔥 Combine uniqueComparer and comparisonKeys into config
May 10, 2022
b54d6b2
Merge remote-tracking branch 'origin/main' into feat/220-unique-values
May 10, 2022
39e7fa5
Merge remote-tracking branch 'origin/main' into feat/220-unique-values
May 12, 2022
e29cc7f
feat: 🔥 Simplify priority documentation comment
May 12, 2022
641a875
feat: 🔥 Tweak documentation comment to be priority specific
May 12, 2022
c48790a
feat: 🔥 Revert package.lock
May 12, 2022
f29cca6
Merge remote-tracking branch 'origin/main' into feat/220-unique-values
May 23, 2022
e7dac07
Merge remote-tracking branch 'origin/main' into feat/220-unique-values
Jun 13, 2022
77edc54
feat: 🔥 Fix merge conflicts in core
Jun 13, 2022
fee5cf6
Merge remote-tracking branch 'origin/main' into feat/220-unique-values
Sep 12, 2022
23f628e
fix: 🐞 Fix outdated tests
Sep 12, 2022
e2fb265
refactor: 💡 Remove commented out code
Sep 12, 2022
086ec7b
test: 🥳 Add basic tests for core fake function
Sep 12, 2022
2e5b650
refactor: 💡 Code review changes
Sep 18, 2022
10cd7d0
refactor: 💡 Code review changes
Sep 18, 2022
274fdc9
refactor: 💡 Change request changes
Sep 18, 2022
1143091
refactor: 💡 Code review changes
Sep 18, 2022
2a037d0
Update packages/falso/src/lib/core/core.ts
theryansmee Sep 19, 2022
8869b35
refactor: 💡 Code review changes
Sep 19, 2022
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
1 change: 1 addition & 0 deletions packages/falso/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ module.exports = {
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/packages/falso',
preset: '../../jest.preset.ts',
snapshotResolver: './snapshot-resolver.js',
};
11 changes: 11 additions & 0 deletions packages/falso/snapshot-resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
testPathForConsistencyCheck: 'some/tests/example.spec.ts',
resolveSnapshotPath: (testPath, snapshotExtension) => {
return testPath.replace('tests/', 'tests/__snapshots__/') + snapshotExtension
},
resolveTestPath: (snapshotFilePath, snapshotExtension) => {
return snapshotFilePath
.replace('tests/__snapshots__/', 'tests/')
.slice(0, -snapshotExtension.length)
},
}
4 changes: 4 additions & 0 deletions packages/falso/src/lib/abbreviation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { data } from './abbreviation.json';
*
* randAbbreviation({ length: 10 })
*
* @example
*
* randAbbreviation({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randAbbreviation<O extends FakeOptions = never>(options?: O) {
return fake(data, options);
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { data } from './accessory.json';
*
* randAccessory({ length: 10 })
*
* @example
*
* randAccessory({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randAccessory<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export interface AccountOptions extends FakeOptions {
*
* randAccount({ length: 10 })
*
* @example
*
* randAccount({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randAccount<Options extends AccountOptions = never>(
options?: Options
Expand Down
11 changes: 10 additions & 1 deletion packages/falso/src/lib/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { randStreetAddress } from './street-address';
import { randZipCode } from './zip-code';
import { randCounty } from './county';
import { randCountry } from './country';
import { objectIsUnique } from './core/unique-validators';

export interface AddressOptions extends FakeOptions {
includeCounty?: boolean;
Expand Down Expand Up @@ -39,6 +40,10 @@ export interface Address {
*
* randAddress({ length: 10 })
*
* @example
*
* randAddress({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randAddress<Options extends AddressOptions = never>(
options?: Options
Expand All @@ -64,5 +69,9 @@ export function randAddress<Options extends AddressOptions = never>(
return address;
};

return fake(factory, options);
return fake(factory, options, { uniqueComparer: checkUnique });
}

function checkUnique(address: Address, addresses: Address[]): boolean {
return objectIsUnique(address, addresses, ['street', 'zipCode']);
}
4 changes: 4 additions & 0 deletions packages/falso/src/lib/airline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { data } from './airline.json';
*
* randAirline({ length: 10 })
*
* @example
*
* randAirline({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randAirline<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/airport-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import { rand } from './rand';
*
* randAirportCode({ length: 10 })
*
* @example
*
* randAirportCode({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randAirportCode<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/airport-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import { rand } from './rand';
*
* randAirportName({ length: 10 })
*
* @example
*
* randAirportName({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randAirportName<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/airport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export interface Airport {
*
* randAirport({ length: 10 })
*
* @example
*
* randAirport({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randAirport<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/alpha-numeric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import { randNumber } from './number';
*
* randAlphaNumeric({ length: 3 })
*
* @example
*
* randAlphaNumeric({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randAlphaNumeric<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/alpha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { alphaChars } from './sequence';
*
* randAlpha({ length: 3 })
*
* @example
*
* randAlpha({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randAlpha<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/american-football-team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { data } from './american-football-team.json';
*
* randAmericanFootballTeam({ length: 10 })
*
* @example
*
* randAmericanFootballTeam({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randAmericanFootballTeam<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/animal-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { data } from './animal-type.json';
*
* randAnimalType({ length: 10 })
*
* @example
*
* randAnimalType({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randAnimalType<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/arn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const serviceArn: Record<string, () => string> = {
*
* randArn({ length: 10 })
*
* @example
*
* randArn({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randArn<Options extends FakeOptions = never>(
options?: Options
Expand Down
6 changes: 5 additions & 1 deletion packages/falso/src/lib/avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ interface AvatarOptions extends FakeOptions {
*
* @example
*
* randAvatar({ size: 200 }) // default is 100
*
* @example
*
* randAvatar({ length: 10 })
*
* @example
*
* randAvatar({ size: 200 }) // default is 100
* randAvatar({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randAvatar<Options extends AvatarOptions = never>(
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/aws-region.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { data } from './aws-region.json';
*
* randAwsRegion({ length: 10 })
*
* @example
*
* randAwsRegion({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randAwsRegion<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/aws-request-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { fake, FakeOptions } from './core/core';
*
* randAwsRequestId({ length: 10 })
*
* @example
*
* randAwsRequestId({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randAwsRequestId<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/aws-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { data } from './aws-service.json';
*
* randAwsService({ length: 10 })
*
* @example
*
* randAwsService({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randAwsService<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/baseball-team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { data } from './baseball-team.json';
*
* randBaseballTeam({ length: 10 })
*
* @example
*
* randBaseballTeam({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randBaseballTeam<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/basketball-team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { data } from './basketball-team.json';
*
* randBasketballTeam({ length: 10 })
*
* @example
*
* randBasketballTeam({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randBasketballTeam<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/bear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { data } from './bear.json';
*
* randBear({ length: 10 })
*
* @example
*
* randBear({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randBear<Options extends FakeOptions = never>(
options?: Options
Expand Down
7 changes: 6 additions & 1 deletion packages/falso/src/lib/between-date.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fake, FakeOptions } from './core/core';
import { randNumber } from './number';
import { dateIsUnique } from './core/unique-validators';

interface BetweenOptions extends FakeOptions {
from: Date | string;
Expand All @@ -19,6 +20,10 @@ interface BetweenOptions extends FakeOptions {
*
* randBetweenDate({ from: new Date('10/07/2020'), to: new Date(), length: 10 })
*
* @example
*
* randBetweenDate({ from: new Date('10/07/2020'), to: new Date(), length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randBetweenDate<Options extends BetweenOptions = never>(
options: Options
Expand All @@ -39,5 +44,5 @@ export function randBetweenDate<Options extends BetweenOptions = never>(
);
};

return fake(generator, options);
return fake(generator, options, { uniqueComparer: dateIsUnique });
}
4 changes: 4 additions & 0 deletions packages/falso/src/lib/binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { FakeOptions, fake, getRandomInRange } from './core/core';
*
* randBinary({ length: 10 })
*
* @example
*
* randBinary({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randBinary<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/bird.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { data } from './bird.i18n.json';
*
* randBird({ length: 10 })
*
* @example
*
* randBird({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randBird<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/bitcoin-address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { randSequence } from './sequence';
*
* randBitcoinAddress({ length: 10 })
*
* @example
*
* randBitcoinAddress({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randBitcoinAddress<Options extends FakeOptions = never>(
options?: Options
Expand Down
6 changes: 5 additions & 1 deletion packages/falso/src/lib/book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ export interface Book {
*
* @example
*
* randBook({ category: 'Comedy' })
*
* @example
*
* randBook({ length: 10 })
*
* @example
*
* randBook({ category: 'Comedy' })
* randBook({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randBook<Options extends BookOptions = never>(
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { fake, FakeOptions, randElement } from './core/core';
*
* randBoolean({ length: 10 })
*
* @example
*
* randBoolean({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randBoolean<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/brand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { data } from './brand.json';
*
* randBrand({ length: 10 })
*
* @example
*
* randBrand({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randBrand<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { data } from './browser.json';
*
* randBrowser({ length: 10 })
*
* @example
*
* randBrowser({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randBrowser<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/cardinal-direction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { data } from './cardinal-direction.json';
*
* randCardinalDirection({ length: 10 })
*
* @example
*
* randCardinalDirection({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randCardinalDirection<Options extends FakeOptions = never>(
options?: Options
Expand Down
4 changes: 4 additions & 0 deletions packages/falso/src/lib/cat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { data } from './cat.json';
*
* randCat({ length: 10 })
*
* @example
*
* randCat({ length: 10, priority: 'unique' }) // default priority is 'length'
*
*/
export function randCat<Options extends FakeOptions = never>(
options?: Options
Expand Down
Loading