https://github.com/grafana/xk6-faker
Random fake data generator for k6.
https://github.com/grafana/xk6-faker
xk6
Last synced: about 2 months ago
JSON representation
Random fake data generator for k6.
- Host: GitHub
- URL: https://github.com/grafana/xk6-faker
- Owner: grafana
- License: agpl-3.0
- Created: 2021-05-31T15:06:54.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2025-04-06T16:50:12.000Z (about 2 months ago)
- Last Synced: 2025-04-06T20:47:16.818Z (about 2 months ago)
- Topics: xk6
- Language: JavaScript
- Homepage: https://faker.x.k6.io
- Size: 477 KB
- Stars: 82
- Watchers: 3
- Forks: 21
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
[](https://faker.x.k6.io)
[](https://github.com/grafana/xk6-faker/releases/)
[](https://goreportcard.com/report/github.com/grafana/xk6-faker)
[](https://github.com/grafana/xk6-faker/actions/workflows/validate.yml)
[](https://codecov.io/gh/grafana/xk6-faker)
# xk6-faker
**Random fake data generator for k6.**
Although there are several good JavaScript fake data generators, using these in [k6](https://k6.io) tests has several disadvantages (download size, memory usage, startup time, etc). The xk6-faker implemented as a golang extension, so tests start faster and use less memory. The price is a little bit smaller feature set compared with popular JavaScript fake data generators.
For convenience, the xk6-faker API resembles the popular [Faker.js](https://fakerjs.dev/). The category names and the generator function names are often different (due to the [underlying go faker library](https://github.com/brianvoe/gofakeit)), but the usage pattern is similar.
Check out the API documentation [here](https://faker.x.k6.io). The TypeScript declaration file can be downloaded from [here](https://faker.x.k6.io/index.d.ts).
> [!NOTE]
> To use the TypeScript declaration file in your IDE (e.g. Visual Studio Code), you need to create a `jsconfig.json` (or `tsconfig.json`) file with the following content:
>
> ```json file=examples/jsconfig.json
> {
> "compilerOptions": {
> "target": "ES6",
> "module": "ES6",
> "paths": {
> "k6/x/faker": ["./typings/xk6-faker/index.d.ts"]
> }
> }
>}
>```
> You will need to update the TypeScript declaration file location in the example above to where you downloaded it.## Usage
For convenient use, the default export of the module is a Faker instance, it just needs to be imported and it is ready for use.
```ts file=examples/default-faker.js
import faker from "k6/x/faker";export default function () {
console.log(faker.person.firstName());
}// prints a random first name
```For a reproducible test run, a random seed value can be passed to the constructor of the Faker class.
```ts file=examples/custom-faker.js
import { Faker } from "k6/x/faker";const faker = new Faker(11);
export default function () {
console.log(faker.person.firstName());
}// output: Josiah
```Test reproducibility can also be achieved using the default Faker instance, if the seed value is set in the `XK6_FAKER_SEED` environment variable.
```bash
k6 run --env XK6_FAKER_SEED=11 script.js
```then
```ts file=examples/default-faker-env.js
import faker from "k6/x/faker";export default function () {
console.log(faker.person.firstName());
}// as long as XK6_FAKER_SEED is 11
// output: Josiah
```The [examples](https://github.com/grafana/xk6-faker/blob/master/examples) directory contains examples of how to use the xk6-faker extension. A k6 binary containing the xk6-faker extension is required to run the examples.
> [!IMPORTANT]
> If the search path also contains the k6 command, don't forget to specify which k6 you want to run (for example `./k6`).## Download
You can download pre-built k6 binaries from the [Releases](https://github.com/grafana/xk6-faker/releases/) page.
**Build**
The [xk6](https://github.com/grafana/xk6) build tool can be used to build a k6 that will include xk6-faker extension:
```bash
$ xk6 build --with github.com/grafana/xk6-faker@latest
```For more build options and how to use xk6, check out the [xk6 documentation](https://github.com/grafana/xk6).
## Contribute
If you want to contribute or help with the development of **xk6-faker**, start by reading [CONTRIBUTING.md](CONTRIBUTING.md).
## Feedback
If you find the xk6-faker extension useful, please star the repo. The number of stars will determine the time allocated for maintenance.
[](https://starchart.cc/grafana/xk6-faker)