Skip to content

feat: upgrade to @faker-js/faker v9 #187

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

Merged
merged 1 commit into from
Jun 26, 2025
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ Feel free to open issues and pull requests. We always welcome support from the c

To run this project locally:

- Use Node >= 16
- Use Node >= 18
- Make sure that you have the latest Yarn version (https://yarnpkg.com/lang/en/docs/install/)
- Clone this repo using `git clone`
- Run `yarn`
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"fakes"
],
"dependencies": {
"@faker-js/faker": "^8.4.1",
"@faker-js/faker": "^9.8.0",
"@graphql-codegen/plugin-helpers": "^5.0.4",
"@graphql-tools/utils": "^10.7.2",
"casual": "^1.6.2",
Expand All @@ -34,7 +34,11 @@
"upper-case": "^2.0.1"
},
"peerDependencies": {
"graphql": "^14.6.0 || ^15.0.0 || ^16.0.0"
"graphql": "^14.6.0 || ^15.0.0 || ^16.0.0",
"typescript": ">=5.0.0"
},
"engines": {
"node": ">=18.0.0"
},
"devDependencies": {
"@auto-it/conventional-commits": "^11.1.6",
Expand Down
482 changes: 241 additions & 241 deletions tests/__snapshots__/typescript-mock-data.spec.ts.snap

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions tests/generateLibrary/faker/__snapshots__/spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

exports[`should generate dynamic values when dynamicValues is true 1`] = `
Object {
"id": "89bd9d8d-69a6-474e-80f4-67cc8796ed15",
"id": "8b986a7e-f6c8-49e1-910d-cdfc7c1a2f86",
"obj": Object {
"bool": false,
"flt": 3.7,
"int": 202,
"bool": true,
"flt": 5.7,
"int": 4561,
},
"str": "socius",
"str": "teres",
}
`;

exports[`should generate dynamic values when dynamicValues is true 2`] = `
Object {
"id": "fc2ddf7c-c78c-4a1b-8a92-8fc816742cb7",
"id": "999fa56b-0aa3-4255-997f-132a47321a23",
"obj": Object {
"bool": true,
"flt": 0.1,
"int": 1352,
"flt": 8.4,
"int": 971,
},
"str": "minus",
"str": "trado",
}
`;
10 changes: 5 additions & 5 deletions tests/scalars/__snapshots__/spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ exports[`custom scalar generation using faker should generate custom scalars for
export const anA = (overrides?: Partial<A>): A => {
return {
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 83,
str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'Depereo nulla calco blanditiis cornu defetiscor.',
str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'Nulla blanditiis defetiscor usque adduco eveniet.',
obj: overrides && overrides.hasOwnProperty('obj') ? overrides.obj! : aB(),
anyObject: overrides && overrides.hasOwnProperty('anyObject') ? overrides.anyObject! : 'Orlando_Cremin@gmail.com',
anyObject: overrides && overrides.hasOwnProperty('anyObject') ? overrides.anyObject! : 'Kelly60@gmail.com',
};
};

Expand All @@ -139,7 +139,7 @@ export const aB = (overrides?: Partial<B>): B => {

export const aC = (overrides?: Partial<C>): C => {
return {
anyObject: overrides && overrides.hasOwnProperty('anyObject') ? overrides.anyObject! : 'Maia49@hotmail.com',
anyObject: overrides && overrides.hasOwnProperty('anyObject') ? overrides.anyObject! : 'Gianni_Kulas29@yahoo.com',
};
};
"
Expand Down Expand Up @@ -182,9 +182,9 @@ exports[`custom scalar generation using faker with different input/output config
export const anA = (overrides?: Partial<A>): A => {
return {
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 83,
str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'Depereo nulla calco blanditiis cornu defetiscor.',
str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'Nulla blanditiis defetiscor usque adduco eveniet.',
obj: overrides && overrides.hasOwnProperty('obj') ? overrides.obj! : aB(),
anyObject: overrides && overrides.hasOwnProperty('anyObject') ? overrides.anyObject! : 'Orlando_Cremin@gmail.com',
anyObject: overrides && overrides.hasOwnProperty('anyObject') ? overrides.anyObject! : 'Kelly60@gmail.com',
};
};

Expand Down
42 changes: 21 additions & 21 deletions tests/scalars/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@ describe('Custom scalar generation using casual', () => {
expect(result).toBeDefined();

// String
expect(result).toContain(
"str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'ea corrupti qui incidunt eius consequatur blanditiis',",
);
expect(result).toMatch(/str: overrides && overrides\.hasOwnProperty\('str'\) \? overrides\.str! : '[^']+',/);

// Float
expect(result).toContain(
"flt: overrides && overrides.hasOwnProperty('flt') ? overrides.flt! : -24.509902694262564,",
expect(result).toMatch(
/flt: overrides && overrides\.hasOwnProperty\('flt'\) \? overrides\.flt! : -?\d+\.?\d*,/,
);

// ID
expect(result).toContain("id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 82,");
expect(result).toMatch(/id: overrides && overrides\.hasOwnProperty\('id'\) \? overrides\.id! : \d+,/);

// Boolean
expect(result).toContain("bool: overrides && overrides.hasOwnProperty('bool') ? overrides.bool! : false");
Expand Down Expand Up @@ -251,15 +249,15 @@ describe('custom scalar generation using faker', () => {
expect(result).toBeDefined();

// String
expect(result).toContain(
"str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'Depereo nulla calco blanditiis cornu defetiscor.',",
);
expect(result).toMatch(/str: overrides && overrides\.hasOwnProperty\('str'\) \? overrides\.str! : '[^']+',/);

// Float
expect(result).toContain("flt: overrides && overrides.hasOwnProperty('flt') ? overrides.flt! : -24.51,");
expect(result).toMatch(
/flt: overrides && overrides\.hasOwnProperty\('flt'\) \? overrides\.flt! : -?\d+\.?\d*,/,
);

// ID
expect(result).toContain("id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 83,");
expect(result).toMatch(/id: overrides && overrides\.hasOwnProperty\('id'\) \? overrides\.id! : \d+,/);

// Boolean
expect(result).toContain("bool: overrides && overrides.hasOwnProperty('bool') ? overrides.bool! : false");
Expand Down Expand Up @@ -350,30 +348,32 @@ describe('custom scalar generation using faker', () => {
expect(result).toBeDefined();

// String
expect(result).toContain(
"str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'Depereo nulla calco blanditiis cornu defetiscor.',",
expect(result).toMatch(
/str: overrides && overrides\.hasOwnProperty\('str'\) \? overrides\.str! : '[^']+',/,
);

// Float
expect(result).toContain("flt: overrides && overrides.hasOwnProperty('flt') ? overrides.flt! : -24.51,");
expect(result).toMatch(
/flt: overrides && overrides\.hasOwnProperty\('flt'\) \? overrides\.flt! : -?\d+\.?\d*,/,
);

// ID
expect(result).toContain("id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 83,");
expect(result).toMatch(/id: overrides && overrides\.hasOwnProperty\('id'\) \? overrides\.id! : \d+,/);

// Boolean
expect(result).toContain("bool: overrides && overrides.hasOwnProperty('bool') ? overrides.bool! : false");

// Int
expect(result).toContain("int: overrides && overrides.hasOwnProperty('int') ? overrides.int! : -93,");

// AnyObject in type A (an email)
expect(result).toContain(
"anyObject: overrides && overrides.hasOwnProperty('anyObject') ? overrides.anyObject! : '[email protected]',",
// AnyObject in type A (an email) - use regex pattern instead of hardcoded email
expect(result).toMatch(
/anyObject: overrides && overrides\.hasOwnProperty\('anyObject'\) \? overrides\.anyObject! : '[^@]+@[^.]+\.[^']+',/,
);

// AnyObject in input C (a string)
expect(result).toContain(
"anyObject: overrides && overrides.hasOwnProperty('anyObject') ? overrides.anyObject! : 'vilicus',",
// AnyObject in input C (a string) - use regex pattern instead of hardcoded word
expect(result).toMatch(
/anyObject: overrides && overrides\.hasOwnProperty\('anyObject'\) \? overrides\.anyObject! : '[^']+',/,
);

expect(result).toMatchSnapshot();
Expand Down
8 changes: 4 additions & 4 deletions tests/typescript-mock-data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ it('should correctly generate the `faker` data for a scalar mapping of type stri
const result = await plugin(testSchema, [], { scalars: { AnyObject: 'internet.email' } });

expect(result).toBeDefined();
expect(result).toContain('Geovany63@gmail.com');
expect(result).toMatch(/@[a-zA-Z0-9]+\.(com|org|net)/);
expect(result).toMatchSnapshot();
});

Expand All @@ -309,7 +309,7 @@ it('should correctly generate the `faker` data for a non-string scalar mapping',
});

expect(result).toBeDefined();
expect(result).toContain(JSON.stringify([41, 98, 185]));
expect(result).toMatch(/\[\d+,\d+,\d+\]/);
expect(result).toMatchSnapshot();
});

Expand All @@ -324,7 +324,7 @@ it('should correctly generate the `faker` data for a function with arguments sca
});

expect(result).toBeDefined();
expect(result).toContain('"2024-10-29T22:31:35.873Z"');
expect(result).toMatch(/"20\d{2}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z"/);
expect(result).toMatchSnapshot();
});

Expand All @@ -339,7 +339,7 @@ it('should correctly generate the `faker` data for a function with one argument
});

expect(result).toBeDefined();
expect(result).toContain('"2024-10-29T22:31:35.873Z"');
expect(result).toMatch(/"20\d{2}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z"/);
expect(result).toMatchSnapshot();
});

Expand Down
8 changes: 4 additions & 4 deletions tests/useImplementingTypes/__snapshots__/spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const mockAction = (overrides?: Partial<Action>): Action => {

export const mockA = (overrides?: Partial<A>): A => {
return {
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'dae147b0-0c04-459e-912d-b724dd87433b',
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'de4b005e-2b2d-4843-94d1-d356d75d933b',
str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'cuius',
obj: overrides && overrides.hasOwnProperty('obj') ? overrides.obj! : mockB(),
config: overrides && overrides.hasOwnProperty('config') ? overrides.config! : mockTestAConfig() || mockTestTwoAConfig(),
Expand Down Expand Up @@ -85,7 +85,7 @@ export const mockAction = (overrides?: Partial<Action>): Action => {

export const mockA = (overrides?: Partial<A>): A => {
return {
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'dae147b0-0c04-459e-912d-b724dd87433b',
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'de4b005e-2b2d-4843-94d1-d356d75d933b',
str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'cuius',
obj: overrides && overrides.hasOwnProperty('obj') ? overrides.obj! : mockB(),
config: overrides && overrides.hasOwnProperty('config') ? overrides.config! : mockAConfig(),
Expand Down Expand Up @@ -148,10 +148,10 @@ export const mockAction = (overrides?: Partial<Action>): Action => {

export const mockA = (overrides?: Partial<A>): A => {
return {
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'dae147b0-0c04-459e-912d-b724dd87433b',
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'de4b005e-2b2d-4843-94d1-d356d75d933b',
str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'cuius',
obj: overrides && overrides.hasOwnProperty('obj') ? overrides.obj! : mockB(),
config: overrides && overrides.hasOwnProperty('config') ? overrides.config! : 'Kian.Keeling70@gmail.com',
config: overrides && overrides.hasOwnProperty('config') ? overrides.config! : 'Karen.Prosacco@gmail.com',
configArray: overrides && overrides.hasOwnProperty('configArray') ? overrides.configArray! : [mockTestAConfig() || mockTestTwoAConfig()],
field: overrides && overrides.hasOwnProperty('field') ? overrides.field! : mockTestTwoAConfig(),
action: overrides && overrides.hasOwnProperty('action') ? overrides.action! : mockTestAction(),
Expand Down
8 changes: 4 additions & 4 deletions tests/useImplementingTypes/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ it(`support useImplementingTypes with fieldGeneration prop`, async () => {
});
expect(result).toBeDefined();

expect(result).toContain(
"str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : '[email protected]'",
expect(result).toMatch(
/str: overrides && overrides\.hasOwnProperty\('str'\) \? overrides\.str! : '[^@]+@[^.]+\.[^']+'/,
);

expect(result).toContain(
Expand All @@ -65,8 +65,8 @@ it(`support useImplementingTypes with fieldGeneration prop`, async () => {

expect(result).toContain("str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'cuius'");

expect(result).toContain(
"config: overrides && overrides.hasOwnProperty('config') ? overrides.config! : '[email protected]',",
expect(result).toMatch(
/config: overrides && overrides\.hasOwnProperty\('config'\) \? overrides\.config! : '[^@]+@[^.]+\.[^']+',/,
);

expect(result).toMatchSnapshot();
Expand Down
14 changes: 7 additions & 7 deletions tests/useTypeImports/__snapshots__/spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ exports[`should support useTypeImports 1`] = `

export const anAvatar = (overrides?: Partial<Avatar>): Avatar => {
return {
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '1550ff93-cd31-49b4-a3c3-8ef1cb68bdc3',
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '15f9c394-c8fc-46bc-a882-b3b853f28c03',
url: overrides && overrides.hasOwnProperty('url') ? overrides.url! : 'consectetur',
};
};

export const aUser = (overrides?: Partial<User>): User => {
return {
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'b5756f00-51a6-422a-81a7-dc13ee6a6375',
creationDate: overrides && overrides.hasOwnProperty('creationDate') ? overrides.creationDate! : '2021-06-27T14:29:24.774Z',
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'b7605a2a-ad1e-4667-801e-5e47e5de933b',
creationDate: overrides && overrides.hasOwnProperty('creationDate') ? overrides.creationDate! : '2021-07-07T09:30:34.236Z',
login: overrides && overrides.hasOwnProperty('login') ? overrides.login! : 'sordeo',
avatar: overrides && overrides.hasOwnProperty('avatar') ? overrides.avatar! : anAvatar(),
status: overrides && overrides.hasOwnProperty('status') ? overrides.status! : Status.Online,
Expand All @@ -27,20 +27,20 @@ export const aUser = (overrides?: Partial<User>): User => {

export const aPartial = (overrides?: Partial<Partial>): Partial => {
return {
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '262c8866-bf76-4ccf-b606-2a0b4742f81f',
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '2286b7cf-0204-44f1-bc80-c295b5723a4b',
};
};

export const aWithAvatar = (overrides?: Partial<WithAvatar>): WithAvatar => {
return {
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '99f515e7-21e0-461d-b823-0d4c7f4dafc5',
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '9f1e2e6d-2047-44ac-ac43-58f18eff5255',
avatar: overrides && overrides.hasOwnProperty('avatar') ? overrides.avatar! : anAvatar(),
};
};

export const aCamelCaseThing = (overrides?: Partial<CamelCaseThing>): CamelCaseThing => {
return {
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '245b9cf9-10fa-4974-8100-fbeee5ee7fd4',
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '259f1f94-0fee-4e7d-8280-96dd5d8d9177',
};
};

Expand All @@ -65,7 +65,7 @@ export const aListType = (overrides?: Partial<ListType>): ListType => {

export const anUpdateUserInput = (overrides?: Partial<UpdateUserInput>): UpdateUserInput => {
return {
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '0d6a9360-d92b-4660-b1e5-f14155047bdd',
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '0696d260-ef45-407d-ac64-e375cbd7e441',
login: overrides && overrides.hasOwnProperty('login') ? overrides.login! : 'apud',
avatar: overrides && overrides.hasOwnProperty('avatar') ? overrides.avatar! : anAvatar(),
};
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -941,10 +941,10 @@
minimatch "^3.0.4"
strip-json-comments "^3.1.1"

"@faker-js/faker@^8.4.1":
version "8.4.1"
resolved "https://registry.yarnpkg.com/@faker-js/faker/-/faker-8.4.1.tgz#5d5e8aee8fce48f5e189bf730ebd1f758f491451"
integrity sha512-XQ3cU+Q8Uqmrbf2e0cIC/QN43sTBSC8KF12u29Mb47tWrt2hAgBXSgpZMj4Ao8Uk0iJcU99QsOCaIL8934obCg==
"@faker-js/faker@^9.8.0":
version "9.8.0"
resolved "https://registry.yarnpkg.com/@faker-js/faker/-/faker-9.8.0.tgz#3344284028d1c9dc98dee2479f82939310370d88"
integrity sha512-U9wpuSrJC93jZBxx/Qq2wPjCuYISBueyVUGK7qqdmj7r/nxaxwW8AQDCLeRO7wZnjj94sh3p246cAYjUKuqgfg==

"@graphql-codegen/plugin-helpers@^5.0.3", "@graphql-codegen/plugin-helpers@^5.0.4":
version "5.0.4"
Expand Down
Loading