Skip to content

Commit 3085f53

Browse files
authored
Merge branch 'next' into chore/better-british-addresses
2 parents f61bf47 + 23c2d3d commit 3085f53

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+713
-906
lines changed

.github/workflows/pr.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ jobs:
3535
CYPRESS_INSTALL_BINARY: 0
3636

3737
- name: Generate code
38+
id: generate
3839
run: |
3940
pnpm run generate:locales
4041
pnpm run generate:api-docs
4142
pnpm run build
4243
pnpm run test -u
44+
continue-on-error: true
4345

4446
- name: Check diff
4547
id: diff
@@ -56,8 +58,8 @@ jobs:
5658
with:
5759
script: |
5860
const script = require('${{ github.workspace }}/.github/workflows/commentCodeGeneration.js')
59-
await script(github, context, ${{ steps.diff.outcome == 'success' }})
61+
await script(github, context, ${{ steps.generate.outcome == 'success' && steps.diff.outcome == 'success' }})
6062
6163
- name: Status
62-
if: ${{ steps.diff.outcome == 'failure' }}
64+
if: ${{ steps.generate.outcome == 'failure' || steps.diff.outcome == 'failure' }}
6365
run: exit 1

docs/.vitepress/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ const config = defineConfig({
193193
text: 'Localization',
194194
link: '/guide/localization',
195195
},
196+
{
197+
text: 'Frameworks',
198+
link: '/guide/frameworks',
199+
},
196200
{
197201
text: 'Upgrading to v8',
198202
link: '/guide/upgrading',

docs/guide/frameworks.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Frameworks
2+
3+
Faker can easily be used with a variety of testing frameworks. Here are a few examples with popular frameworks.
4+
5+
Note that these examples use only the `en` locale for better performance. For more information visit [localization](./localization.md).
6+
7+
## Vitest and Jest
8+
9+
Since [Vitest](https://vitest.dev/) and [Jest](https://jestjs.io/) use an extremely similar notation, this section will cover both at once.
10+
The main difference is that testing methods need to be imported in Vitest.
11+
Simply crop that line out for a Jest integration.
12+
13+
These frameworks work about exactly as you would expect with Faker. Here's a minimal example:
14+
15+
```ts
16+
import { describe, it, expect } from 'vitest';
17+
import { faker } from '@faker-js/faker/locale/en';
18+
19+
describe('reverse array', () => {
20+
it('should reverse the array', () => {
21+
const title = faker.name.jobTitle();
22+
const name = faker.name.fullName();
23+
const animal = faker.animal.bear();
24+
25+
const array = [title, name, animal];
26+
27+
expect(array.reverse()).toStrictEqual([animal, name, title]);
28+
});
29+
});
30+
```
31+
32+
It can sometimes be useful to do seeded tests, where we seed our faker instance with a static value so that it will generate the same random value each time.
33+
These are especially useful in tests that are meant to be deterministic, such as snapshot tests.
34+
35+
- [Snapshots in Vitest](https://vitest.dev/guide/snapshot.html)
36+
- [Snapshots in Jest](https://jestjs.io/docs/snapshot-testing)
37+
38+
```ts
39+
import { describe, it, expect } from 'vitest';
40+
import { faker } from '@faker-js/faker/locale/en';
41+
42+
// We might want other tests to *not* be seeded. This will re-seed our faker instance after each test.
43+
afterEach(() => {
44+
faker.seed();
45+
});
46+
47+
describe('reverse array', () => {
48+
it('should reverse the array', () => {
49+
// Seed our faker instance with some static number.
50+
faker.seed(1234);
51+
const title = faker.name.jobTitle();
52+
const name = faker.name.fullName();
53+
const animal = faker.animal.bear();
54+
55+
const array = [title, name, animal];
56+
57+
expect(array.reverse()).toStrictEqual([animal, name, title]);
58+
59+
// Expect our value to always match a generated snapshot.
60+
expect(array.reverse()).toMatchSnapshot();
61+
});
62+
});
63+
```
64+
65+
## Cypress
66+
67+
[Cypress](https://www.cypress.io/) integration is fairly straighforward as well:
68+
69+
```ts
70+
import { faker } from '@faker-js/faker/locale/en';
71+
72+
describe('Testing the application', () => {
73+
it('should create an account with username and password', () => {
74+
let username = faker.internet.userName();
75+
let password = faker.internet.password();
76+
let email = faker.internet.exampleEmail();
77+
78+
// Visit the a webpage and create an account.
79+
cy.visit('https://www.example.com/register');
80+
81+
cy.get('#email-input').type(email);
82+
cy.get('#username-input').type(username);
83+
cy.get('#password-input').type(password);
84+
cy.get('#password-confirm-input').type(password);
85+
86+
cy.get('#register-submit-input').click();
87+
88+
// Now, we try to login with these credentials.
89+
cy.visit('https://www.example.com/login');
90+
91+
cy.get('#email-input').type(email);
92+
cy.get('#password-input').type(password);
93+
94+
cy.get('#login-submit-input').click();
95+
96+
// We should have logged in successfully to the dashboard page.
97+
cy.url().should('include', '/dashboard');
98+
});
99+
});
100+
```

docs/guide/upgrading.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Not the version you are looking for?
3434
| `faker.address.citySuffix` | _Removed_ |
3535
| `faker.address.streetPrefix` | _Removed_ |
3636
| `faker.address.streetSuffix` | _Removed_ |
37+
| `faker.image.lorempixel` | _Removed, as the LoremPixel service is no longer available_ |
3738

3839
### Locale renamed
3940

package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,21 @@
9797
"@algolia/client-search": "~4.14.2",
9898
"@types/glob": "~8.0.0",
9999
"@types/markdown-it": "~12.2.3",
100-
"@types/node": "~18.11.10",
100+
"@types/node": "~18.11.13",
101101
"@types/prettier": "~2.7.1",
102102
"@types/react": "~18.0.26",
103103
"@types/sanitize-html": "~2.6.2",
104104
"@types/semver": "~7.3.13",
105105
"@types/validator": "~13.7.10",
106-
"@typescript-eslint/eslint-plugin": "~5.45.0",
107-
"@typescript-eslint/parser": "~5.45.0",
108-
"@vitest/coverage-c8": "~0.25.3",
109-
"@vitest/ui": "~0.25.3",
106+
"@typescript-eslint/eslint-plugin": "~5.46.0",
107+
"@typescript-eslint/parser": "~5.46.0",
108+
"@vitest/coverage-c8": "~0.25.7",
109+
"@vitest/ui": "~0.25.7",
110110
"@vueuse/core": "~9.6.0",
111111
"c8": "~7.12.0",
112112
"conventional-changelog-cli": "~2.2.2",
113-
"cypress": "~11.2.0",
114-
"esbuild": "~0.15.18",
113+
"cypress": "~12.0.2",
114+
"esbuild": "~0.16.4",
115115
"eslint": "~8.29.0",
116116
"eslint-config-prettier": "~8.5.0",
117117
"eslint-define-config": "~1.12.0",
@@ -123,7 +123,7 @@
123123
"mime-db": "~1.52.0",
124124
"npm-run-all": "~4.1.5",
125125
"picocolors": "~1.0.0",
126-
"prettier": "2.8.0",
126+
"prettier": "2.8.1",
127127
"prettier-plugin-organize-imports": "~3.2.1",
128128
"react": "~18.2.0",
129129
"react-dom": "~18.2.0",
@@ -133,16 +133,16 @@
133133
"simple-git-hooks": "~2.8.1",
134134
"standard-version": "~9.5.0",
135135
"tsx": "~3.12.1",
136-
"typedoc": "~0.23.21",
136+
"typedoc": "~0.23.22",
137137
"typedoc-plugin-missing-exports": "~1.0.0",
138-
"typescript": "~4.9.3",
138+
"typescript": "~4.9.4",
139139
"validator": "~13.7.0",
140-
"vite": "~3.2.5",
141-
"vitepress": "1.0.0-alpha.30",
142-
"vitest": "~0.25.3",
140+
"vite": "~4.0.0",
141+
"vitepress": "1.0.0-alpha.31",
142+
"vitest": "~0.25.7",
143143
"vue": "~3.2.45"
144144
},
145-
"packageManager": "[email protected].0",
145+
"packageManager": "[email protected].1",
146146
"engines": {
147147
"node": "^14.17.0 || ^16.13.0 || >=18.0.0",
148148
"npm": ">=6.14.13"

0 commit comments

Comments
 (0)