Skip to content

Commit 7eaaf36

Browse files
committed
feat: upgrade to @faker-js/faker v9
1 parent ef575fd commit 7eaaf36

File tree

13 files changed

+328
-302
lines changed

13 files changed

+328
-302
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/*.snap linguist-generated=true
2+

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
# v5.0.0 (Thu Jan 02 2025)
2+
3+
#### 💥 Breaking Change
4+
5+
- feat: upgrade to @faker-js/faker v9
6+
7+
This release upgrades to Faker v9, which introduces several breaking changes:
8+
9+
- **Node.js v18+ required**: Faker v9 requires Node.js v18 or higher
10+
- **TypeScript v5+ required**: Faker v9 requires TypeScript v5 or higher
11+
- **Different mock values**: Due to Faker v9's improved RNG (53-bit vs 32-bit), generated mock values will be different even with the same seed
12+
- **Removed deprecated code**: Faker v8 had deprecated many methods, [which have now been removed](https://fakerjs.dev/guide/upgrading.html#removals-of-deprecated-code)
13+
14+
For more details, see the [Faker v9 migration guide](https://fakerjs.dev/guide/upgrading.html).
15+
16+
#### Authors: 1
17+
18+
- Brendan Mulholland ([@bmulholland](https://github.com/bmulholland))
19+
20+
---
21+
122
# v4.4.0 (Thu Apr 03 2025)
223

324
#### 🚀 Enhancement

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ Feel free to open issues and pull requests. We always welcome support from the c
530530

531531
To run this project locally:
532532

533-
- Use Node >= 16
533+
- Use Node >= 18
534534
- Make sure that you have the latest Yarn version (https://yarnpkg.com/lang/en/docs/install/)
535535
- Clone this repo using `git clone`
536536
- Run `yarn`

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-codegen-typescript-mock-data",
3-
"version": "4.4.0",
3+
"version": "5.0.0",
44
"description": "GraphQL Codegen plugin for building mock data",
55
"main": "dist/commonjs/index.js",
66
"module": "dist/esnext/index.js",
@@ -22,7 +22,7 @@
2222
"fakes"
2323
],
2424
"dependencies": {
25-
"@faker-js/faker": "^8.4.1",
25+
"@faker-js/faker": "^9.8.0",
2626
"@graphql-codegen/plugin-helpers": "^5.0.4",
2727
"@graphql-tools/utils": "^10.7.2",
2828
"casual": "^1.6.2",
@@ -36,6 +36,9 @@
3636
"peerDependencies": {
3737
"graphql": "^14.6.0 || ^15.0.0 || ^16.0.0"
3838
},
39+
"engines": {
40+
"node": ">=18.0.0"
41+
},
3942
"devDependencies": {
4043
"@auto-it/conventional-commits": "^11.1.6",
4144
"@graphql-codegen/testing": "^3.0.3",

tests/__snapshots__/typescript-mock-data.spec.ts.snap

Lines changed: 241 additions & 241 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generateLibrary/faker/__snapshots__/spec.ts.snap

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/scalars/__snapshots__/spec.ts.snap

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/scalars/spec.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,15 @@ describe('Custom scalar generation using casual', () => {
2727
expect(result).toBeDefined();
2828

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

3432
// Float
35-
expect(result).toContain(
36-
"flt: overrides && overrides.hasOwnProperty('flt') ? overrides.flt! : -24.509902694262564,",
33+
expect(result).toMatch(
34+
/flt: overrides && overrides\.hasOwnProperty\('flt'\) \? overrides\.flt! : -?\d+\.?\d*,/,
3735
);
3836

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

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

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

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

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

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

352350
// String
353-
expect(result).toContain(
354-
"str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'Depereo nulla calco blanditiis cornu defetiscor.',",
351+
expect(result).toMatch(
352+
/str: overrides && overrides\.hasOwnProperty\('str'\) \? overrides\.str! : '[^']+',/,
355353
);
356354

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

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

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

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

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

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

379379
expect(result).toMatchSnapshot();

tests/typescript-mock-data.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ it('should correctly generate the `faker` data for a scalar mapping of type stri
299299
const result = await plugin(testSchema, [], { scalars: { AnyObject: 'internet.email' } });
300300

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

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

311311
expect(result).toBeDefined();
312-
expect(result).toContain(JSON.stringify([41, 98, 185]));
312+
expect(result).toMatch(/\[\d+,\d+,\d+\]/);
313313
expect(result).toMatchSnapshot();
314314
});
315315

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

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

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

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

tests/useImplementingTypes/__snapshots__/spec.ts.snap

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)