Skip to content

Commit 216c3ec

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

File tree

11 files changed

+306
-302
lines changed

11 files changed

+306
-302
lines changed

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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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",
@@ -34,7 +34,11 @@
3434
"upper-case": "^2.0.1"
3535
},
3636
"peerDependencies": {
37-
"graphql": "^14.6.0 || ^15.0.0 || ^16.0.0"
37+
"graphql": "^14.6.0 || ^15.0.0 || ^16.0.0",
38+
"typescript": ">=5.0.0"
39+
},
40+
"engines": {
41+
"node": ">=18.0.0"
3842
},
3943
"devDependencies": {
4044
"@auto-it/conventional-commits": "^11.1.6",

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

Lines changed: 241 additions & 241 deletions
Large diffs are not rendered by default.

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22

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

1515
exports[`should generate dynamic values when dynamicValues is true 2`] = `
1616
Object {
17-
"id": "fc2ddf7c-c78c-4a1b-8a92-8fc816742cb7",
17+
"id": "999fa56b-0aa3-4255-997f-132a47321a23",
1818
"obj": Object {
1919
"bool": true,
20-
"flt": 0.1,
21-
"int": 1352,
20+
"flt": 8.4,
21+
"int": 971,
2222
},
23-
"str": "minus",
23+
"str": "trado",
2424
}
2525
`;

tests/scalars/__snapshots__/spec.ts.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ exports[`custom scalar generation using faker should generate custom scalars for
123123
export const anA = (overrides?: Partial<A>): A => {
124124
return {
125125
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 83,
126-
str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'Depereo nulla calco blanditiis cornu defetiscor.',
126+
str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'Nulla blanditiis defetiscor usque adduco eveniet.',
127127
obj: overrides && overrides.hasOwnProperty('obj') ? overrides.obj! : aB(),
128-
anyObject: overrides && overrides.hasOwnProperty('anyObject') ? overrides.anyObject! : 'Orlando_Cremin@gmail.com',
128+
anyObject: overrides && overrides.hasOwnProperty('anyObject') ? overrides.anyObject! : 'Kelly60@gmail.com',
129129
};
130130
};
131131
@@ -139,7 +139,7 @@ export const aB = (overrides?: Partial<B>): B => {
139139
140140
export const aC = (overrides?: Partial<C>): C => {
141141
return {
142-
anyObject: overrides && overrides.hasOwnProperty('anyObject') ? overrides.anyObject! : 'Maia49@hotmail.com',
142+
anyObject: overrides && overrides.hasOwnProperty('anyObject') ? overrides.anyObject! : 'Gianni_Kulas29@yahoo.com',
143143
};
144144
};
145145
"
@@ -182,9 +182,9 @@ exports[`custom scalar generation using faker with different input/output config
182182
export const anA = (overrides?: Partial<A>): A => {
183183
return {
184184
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 83,
185-
str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'Depereo nulla calco blanditiis cornu defetiscor.',
185+
str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'Nulla blanditiis defetiscor usque adduco eveniet.',
186186
obj: overrides && overrides.hasOwnProperty('obj') ? overrides.obj! : aB(),
187-
anyObject: overrides && overrides.hasOwnProperty('anyObject') ? overrides.anyObject! : 'Orlando_Cremin@gmail.com',
187+
anyObject: overrides && overrides.hasOwnProperty('anyObject') ? overrides.anyObject! : 'Kelly60@gmail.com',
188188
};
189189
};
190190

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
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const mockAction = (overrides?: Partial<Action>): Action => {
2222
2323
export const mockA = (overrides?: Partial<A>): A => {
2424
return {
25-
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'dae147b0-0c04-459e-912d-b724dd87433b',
25+
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'de4b005e-2b2d-4843-94d1-d356d75d933b',
2626
str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'cuius',
2727
obj: overrides && overrides.hasOwnProperty('obj') ? overrides.obj! : mockB(),
2828
config: overrides && overrides.hasOwnProperty('config') ? overrides.config! : mockTestAConfig() || mockTestTwoAConfig(),
@@ -85,7 +85,7 @@ export const mockAction = (overrides?: Partial<Action>): Action => {
8585
8686
export const mockA = (overrides?: Partial<A>): A => {
8787
return {
88-
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'dae147b0-0c04-459e-912d-b724dd87433b',
88+
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'de4b005e-2b2d-4843-94d1-d356d75d933b',
8989
str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'cuius',
9090
obj: overrides && overrides.hasOwnProperty('obj') ? overrides.obj! : mockB(),
9191
config: overrides && overrides.hasOwnProperty('config') ? overrides.config! : mockAConfig(),
@@ -148,10 +148,10 @@ export const mockAction = (overrides?: Partial<Action>): Action => {
148148
149149
export const mockA = (overrides?: Partial<A>): A => {
150150
return {
151-
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'dae147b0-0c04-459e-912d-b724dd87433b',
151+
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'de4b005e-2b2d-4843-94d1-d356d75d933b',
152152
str: overrides && overrides.hasOwnProperty('str') ? overrides.str! : 'cuius',
153153
obj: overrides && overrides.hasOwnProperty('obj') ? overrides.obj! : mockB(),
154-
config: overrides && overrides.hasOwnProperty('config') ? overrides.config! : 'Kian.Keeling70@gmail.com',
154+
config: overrides && overrides.hasOwnProperty('config') ? overrides.config! : 'Karen.Prosacco@gmail.com',
155155
configArray: overrides && overrides.hasOwnProperty('configArray') ? overrides.configArray! : [mockTestAConfig() || mockTestTwoAConfig()],
156156
field: overrides && overrides.hasOwnProperty('field') ? overrides.field! : mockTestTwoAConfig(),
157157
action: overrides && overrides.hasOwnProperty('action') ? overrides.action! : mockTestAction(),

tests/useImplementingTypes/spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ it(`support useImplementingTypes with fieldGeneration prop`, async () => {
4646
});
4747
expect(result).toBeDefined();
4848

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

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

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

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

7272
expect(result).toMatchSnapshot();

tests/useTypeImports/__snapshots__/spec.ts.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ exports[`should support useTypeImports 1`] = `
55
66
export const anAvatar = (overrides?: Partial<Avatar>): Avatar => {
77
return {
8-
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '1550ff93-cd31-49b4-a3c3-8ef1cb68bdc3',
8+
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '15f9c394-c8fc-46bc-a882-b3b853f28c03',
99
url: overrides && overrides.hasOwnProperty('url') ? overrides.url! : 'consectetur',
1010
};
1111
};
1212
1313
export const aUser = (overrides?: Partial<User>): User => {
1414
return {
15-
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'b5756f00-51a6-422a-81a7-dc13ee6a6375',
16-
creationDate: overrides && overrides.hasOwnProperty('creationDate') ? overrides.creationDate! : '2021-06-27T14:29:24.774Z',
15+
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'b7605a2a-ad1e-4667-801e-5e47e5de933b',
16+
creationDate: overrides && overrides.hasOwnProperty('creationDate') ? overrides.creationDate! : '2021-07-07T09:30:34.236Z',
1717
login: overrides && overrides.hasOwnProperty('login') ? overrides.login! : 'sordeo',
1818
avatar: overrides && overrides.hasOwnProperty('avatar') ? overrides.avatar! : anAvatar(),
1919
status: overrides && overrides.hasOwnProperty('status') ? overrides.status! : Status.Online,
@@ -27,20 +27,20 @@ export const aUser = (overrides?: Partial<User>): User => {
2727
2828
export const aPartial = (overrides?: Partial<Partial>): Partial => {
2929
return {
30-
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '262c8866-bf76-4ccf-b606-2a0b4742f81f',
30+
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '2286b7cf-0204-44f1-bc80-c295b5723a4b',
3131
};
3232
};
3333
3434
export const aWithAvatar = (overrides?: Partial<WithAvatar>): WithAvatar => {
3535
return {
36-
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '99f515e7-21e0-461d-b823-0d4c7f4dafc5',
36+
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '9f1e2e6d-2047-44ac-ac43-58f18eff5255',
3737
avatar: overrides && overrides.hasOwnProperty('avatar') ? overrides.avatar! : anAvatar(),
3838
};
3939
};
4040
4141
export const aCamelCaseThing = (overrides?: Partial<CamelCaseThing>): CamelCaseThing => {
4242
return {
43-
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '245b9cf9-10fa-4974-8100-fbeee5ee7fd4',
43+
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '259f1f94-0fee-4e7d-8280-96dd5d8d9177',
4444
};
4545
};
4646
@@ -65,7 +65,7 @@ export const aListType = (overrides?: Partial<ListType>): ListType => {
6565
6666
export const anUpdateUserInput = (overrides?: Partial<UpdateUserInput>): UpdateUserInput => {
6767
return {
68-
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '0d6a9360-d92b-4660-b1e5-f14155047bdd',
68+
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '0696d260-ef45-407d-ac64-e375cbd7e441',
6969
login: overrides && overrides.hasOwnProperty('login') ? overrides.login! : 'apud',
7070
avatar: overrides && overrides.hasOwnProperty('avatar') ? overrides.avatar! : anAvatar(),
7171
};

0 commit comments

Comments
 (0)