Code Monkey home page Code Monkey logo

xk6-faker's Introduction

API Reference GitHub Release Go Report Card GitHub Actions codecov GitHub Downloads

xk6-faker

Random fake data generator for k6.

Although there are several good JavaScript fake data generators, using these in k6 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. The category names and the generator function names are often different (due to the underlying go faker library), but the usage pattern is similar.

Check out the API documentation here. The TypeScript declaration file can be downloaded from here.

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.

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.

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.

k6 run --env XK6_FAKER_SEED=11 script.js

then

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 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 page.

Build

The xk6 build tool can be used to build a k6 that will include xk6-faker extension:

$ xk6 build --with github.com/szkiba/xk6-faker@latest

For more build options and how to use xk6, check out the xk6 documentation.

Feedback

If you find the xk6-faker extension useful, please star the repo. The number of stars will determine the time allocated for maintenance.

Stargazers over time

xk6-faker's People

Contributors

mstoykov avatar olegbespalov avatar szkiba avatar sztheory avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

xk6-faker's Issues

refactor the API to be more JavaScript-like

The xk6-faker API (up to v0.2.2) is currently a simple mirror of the gofakeit go API. In the JavaScript world, Faker.js is a well-known and widely used faker library. It is more convenient for developers if they can use a familiar API to generate fake data in k6 tests as well.

It is therefore advisable to refactor the xk6-faker API to resemble the faker APIs used by JavaScript developers. It is not necessary to fully implement the API of an existing JavaScript faker library, it is enough if the API is similar in nature and, for example, the same type of fake data can be generated in the same way.

This will be a breaking change, affecting the entire xk6-faker API (and implementation).

faker to DBMS

Hello. Do you have experience inserting data into a Postgresql DBMS using xk6-faker?
Best regards, Sergei.

Error running script using xk6-faker

Hi!

I'm trying to execute a script using faker, but I'm receiving this message:

ERRO[0000] unknown module: k6/x/faker
at reflect.methodValueCall (native)
at file:///Users/gabrielzc/desktop/k6-script/node_modules/scenarios/usuarios.js:38:121(35) hint="script exception"

I've imported like the example:

import { Faker } from "k6/x/faker"

let f = new Faker();
console.log(f.name());

Can you help me?

Thanks!

Make xk6-faker compatible with latest k6 version (0.41.0)

Is there any plans to make xk6-faker compatible with the latest k6 release? The extensions API has changed and such, this extension is no longer compatible with the latest release.

I see there are 2 open PRs related to this. Any chance to get any traction with this?

error running test k6 in the cloud

I run the command ./k6 cloud usercollection.js

I run the command and output I get:

ERRO[0044] unknown module: k6/x/faker
Run [at go.k6.io/k6/js.(*InitContext).Require-fm (native)
at file:///Users/nobody/Documents/UserCollection/usercollection.js:2:0(20)

when i run madly it works fine

I wait answer. Thanks a lot

Simplify API

The xk6-faker API currently consists of quite a few functions. As a result, it is difficult to maintain.

It is advisable to simplify the API and treat the name of the fake data generator function as a parameter. This way, the API can consist of a single JavaScript function and the implementation is greatly simplified. In addition, the expansion with custom fake data generator functions will also be easier.

K6 build failing in Gitlab CI

Hi,

I am encountering an error while building a K6 container that includes the xk6-faker plugin in a GitLab pipeline. The build process is failing with the following error:

#8 ERROR: process "/bin/sh -c xk6 build v0.36.0 --with github.com/szkiba/xk6-faker" did not complete successfully: exit code: 1
------
 > [go 3/4] RUN xk6 build v0.36.0 --with github.com/szkiba/xk6-faker:
------
process "/bin/sh -c xk6 build v0.36.0 --with github.com/szkiba/xk6-faker" did not complete successfully: exit code: 1
Service 'k6' failed to build : Build failed
Cleaning up project directory and file based variables
00:02
ERROR: Job failed: exit code 1

It however just suddenly stopped working, and I can still build my containers locally without having any problems. Any idea where the issue could lie?

[Feature] Generate fake IPs

I would love to be able to generate fake IPv4 & IPv6.
Also I which to be able to set some part of the IP.
Eg:
A.B.C.D
Where A & B are constant but C & D are random

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.