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

refactor(fakerjs): use the new fakerjs community package #107

Merged
merged 3 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions .changeset/modern-bulldogs-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@commercetools-test-data/core': patch
'@commercetools-test-data/category': patch
'@commercetools-test-data/commons': patch
'@commercetools-test-data/utils': patch
---

Replace deleted fakerjs library with the new community package (fakerjs.dev)
2 changes: 1 addition & 1 deletion core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ For example:
```ts
// presets/author-with-one-book.ts
import type { TAuthorBuilder } from './types';
import * as faker from 'faker';
import faker from '@faker-js/faker';
import * as Book from '../../book';
import Author from './builder';

Expand Down
3 changes: 1 addition & 2 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
"dependencies": {
"@babel/runtime": "^7.13.10",
"@babel/runtime-corejs3": "^7.13.10",
"@types/faker": "^5.5.1",
"@faker-js/faker": "^6.0.0-alpha.5",
"@types/lodash": "^4.14.168",
"faker": "^5.5.3",
"lodash": "^4.17.21"
}
}
7 changes: 4 additions & 3 deletions core/src/@jackfranklin/test-data-bot/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as faker from 'faker';
import type { Faker } from '@faker-js/faker';
import faker from '@faker-js/faker';
import { mapValues } from 'lodash';

export type SequenceFunction = (counter: number) => unknown;
Expand All @@ -12,7 +13,7 @@ export interface SequenceGenerator {

export interface FakerGenerator {
generatorType: 'faker';
call: (fake: Faker.FakerStatic) => any;
call: (fake: Faker) => any;
}

export interface PerBuildGenerator {
Expand Down Expand Up @@ -239,7 +240,7 @@ export const perBuild = <T>(func: () => T): PerBuildGenerator => {
};
};

export type FakerUserArgs = (fake: Faker.FakerStatic) => any;
export type FakerUserArgs = (fake: Faker) => any;

export const fake = (userDefinedUsage: FakerUserArgs): FakerGenerator => {
return {
Expand Down
3 changes: 1 addition & 2 deletions models/category/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
"@babel/runtime-corejs3": "^7.13.10",
"@commercetools-test-data/core": "2.4.1",
"@commercetools-test-data/utils": "2.4.0",
"@types/faker": "^5.5.1",
"faker": "^5.5.3",
"@faker-js/faker": "^6.0.0-alpha.5",
"lodash": "^4.17.21"
}
}
3 changes: 1 addition & 2 deletions models/commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"@babel/runtime": "^7.13.10",
"@babel/runtime-corejs3": "^7.13.10",
"@commercetools-test-data/core": "2.4.1",
"@types/faker": "^5.5.1",
"faker": "^5.5.3",
"@faker-js/faker": "^6.0.0-alpha.5",
"lodash": "^4.17.21"
}
}
2 changes: 1 addition & 1 deletion models/commons/src/localized-string/presets/of-slugs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TLocalizedStringBuilder } from '../types';

import * as faker from 'faker';
import faker from '@faker-js/faker';
import LocalizedString from '../builder';

const ofSlugs = (): TLocalizedStringBuilder =>
Expand Down
3 changes: 1 addition & 2 deletions utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"dependencies": {
"@babel/runtime": "^7.13.10",
"@babel/runtime-corejs3": "^7.13.10",
"@types/faker": "^5.5.1",
"faker": "^5.5.3"
"@faker-js/faker": "^6.0.0-alpha.5"
}
}
8 changes: 5 additions & 3 deletions utils/src/create-related-dates.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Faker } from '@faker-js/faker';

/**
* Create two related dates (one comes before the other) by using a reference
* in the past. The reference will be the result of invoking `Date.now()` when this
Expand Down Expand Up @@ -32,15 +34,15 @@
*/
const createRelatedDates = (recentDaysFromPastReference: number = 10) => {
const pastReference = new Date();
const getOlderDate = (f: Faker.FakerStatic) =>
const getOlderDate = (f: Faker) =>
f.date.recent(recentDaysFromPastReference, pastReference.toISOString());

const getNewerDate = (f: Faker.FakerStatic) =>
const getNewerDate = (f: Faker) =>
f.date.between(
new Date(pastReference).toISOString(),
new Date().toISOString()
);
const getFutureDate = (f: Faker.FakerStatic) => f.date.future();
const getFutureDate = (f: Faker) => f.date.future();
return [getOlderDate, getNewerDate, getFutureDate];
};

Expand Down
33 changes: 11 additions & 22 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1883,8 +1883,7 @@ __metadata:
"@babel/runtime-corejs3": ^7.13.10
"@commercetools-test-data/core": 2.4.1
"@commercetools-test-data/utils": 2.4.0
"@types/faker": ^5.5.1
faker: ^5.5.3
"@faker-js/faker": ^6.0.0-alpha.5
lodash: ^4.17.21
languageName: unknown
linkType: soft
Expand All @@ -1896,8 +1895,7 @@ __metadata:
"@babel/runtime": ^7.13.10
"@babel/runtime-corejs3": ^7.13.10
"@commercetools-test-data/core": 2.4.1
"@types/faker": ^5.5.1
faker: ^5.5.3
"@faker-js/faker": ^6.0.0-alpha.5
lodash: ^4.17.21
languageName: unknown
linkType: soft
Expand All @@ -1908,9 +1906,8 @@ __metadata:
dependencies:
"@babel/runtime": ^7.13.10
"@babel/runtime-corejs3": ^7.13.10
"@types/faker": ^5.5.1
"@faker-js/faker": ^6.0.0-alpha.5
"@types/lodash": ^4.14.168
faker: ^5.5.3
lodash: ^4.17.21
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -1953,8 +1950,7 @@ __metadata:
dependencies:
"@babel/runtime": ^7.13.10
"@babel/runtime-corejs3": ^7.13.10
"@types/faker": ^5.5.1
faker: ^5.5.3
"@faker-js/faker": ^6.0.0-alpha.5
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -2251,6 +2247,13 @@ __metadata:
languageName: node
linkType: hard

"@faker-js/faker@npm:^6.0.0-alpha.5":
version: 6.0.0-alpha.5
resolution: "@faker-js/faker@npm:6.0.0-alpha.5"
checksum: aa145eaeba624a65fe3237f2abfe4fa4a87fb7283cda983cafad95fd8b88b9e58eae403a36bdc4108f9625b0c64b81e901e68d11b33c04c8f24dae07c31e314f
languageName: node
linkType: hard

"@gar/promisify@npm:^1.0.1":
version: 1.1.2
resolution: "@gar/promisify@npm:1.1.2"
Expand Down Expand Up @@ -2893,13 +2896,6 @@ __metadata:
languageName: node
linkType: hard

"@types/faker@npm:^5.5.1":
version: 5.5.9
resolution: "@types/faker@npm:5.5.9"
checksum: c2cbd082abe29047c89cf29b86257e582d2a177a9d1ed3abf99aa1cc025d5e8a3d201dfaddf8441bfcc57ed43e4da80e666951e1c23a5b759ac441a5855b5c36
languageName: node
linkType: hard

"@types/glob@npm:^7.1.1":
version: 7.2.0
resolution: "@types/glob@npm:7.2.0"
Expand Down Expand Up @@ -5669,13 +5665,6 @@ __metadata:
languageName: node
linkType: hard

"faker@npm:^5.5.3":
version: 5.5.3
resolution: "faker@npm:5.5.3"
checksum: 684fd64c8d3897e54248f95b4f6319f75d97691b8500cd13adf4af2c28f9204f766c1d1aaa6b41338f0beaaa87256c3132f8708a1a8f189d122b92f6b98081c3
languageName: node
linkType: hard

"fast-deep-equal@npm:^2.0.1":
version: 2.0.1
resolution: "fast-deep-equal@npm:2.0.1"
Expand Down