How can I use Faker library on Artillery's Docker Image?

So my dilemma is I want to run my script, which has a processor function that uses Faker library, on Gitlab Pipeline. The problem is the Artillery does not have the Faker library. I tried installing Faker inside the docker container as an experiment, but my script is still not working. Here's the code of my processor.js file

const Faker = require("faker");

function generateLinkData(requestParams, ctx, ee, next) {

    let firstname = Faker.name.firstName();
    let lastname = Faker.name.lastName();
    ctx.vars["amount"] = Faker.finance.amount(5, 1000000, 2);
    ctx.vars["reference"] = Faker.commerce.price(100000, 200000, 0);
    ctx.vars["description"] = Faker.commerce.productDescription();
    ctx.vars["email_link"] = Faker.internet.email(firstname, lastname,'mailinator.com');
    ctx.vars["contact_first_name"] = firstname;
    ctx.vars["contact_last_name"] = lastname;

    

    return next();

}

module.exports = {
    generateLinkData,
  };

And here's the error:

  node:internal/modules/cjs/loader:933
  const err = new Error(message);
              ^
Error: Cannot find module 'faker'
Require stack:
- /builds/trial304/artillery-load-test/tests/performance/processor.js
- /home/node/artillery/core/lib/runner.js
- /home/node/artillery/lib/util.js
- /home/node/artillery/lib/console-reporter.js
- /home/node/artillery/lib/artillery-global.js
- /home/node/artillery/bin/run
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/builds/trial304/artillery-load-test/tests/performance/processor.js:2:15)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/builds/trial304/artillery-load-test/tests/performance/processor.js',
    '/home/node/artillery/core/lib/runner.js',
    '/home/node/artillery/lib/util.js',
    '/home/node/artillery/lib/console-reporter.js',
    '/home/node/artillery/lib/artillery-global.js',
    '/home/node/artillery/bin/run'
  ]
}

This is the command I run inside the docker container to install faker:

npm install @faker-js/faker --save-dev

The processor won't run and causes error since it needs the Faker library and it seems the Faker library is not being recognized (??). I hope anyone could help me with this. Thank you!



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation