K6.io The moduleSpecifier “./path/to/file” couldn’t be found on local disk

  Kiến thức lập trình

I’m writing a performance test with k6.io and I need to generate a new user for each request, the application checks for existing emails and will assume all request need to be linked to that existing user. This isn’t the scenario I’m testing.

I’ve got a function that builds me a user and then I import that function into my k6 script, but when I run the script, I get the following error:

GoError: The moduleSpecifier “./utils/generateConsumer” couldn’t be found on local disk. Make sure that you’ve specified the right path to the file. If you’re running k6 using the Docker image make sure you have mounted the local directory (-v /local/path/:/inside/docker/path) containing your script and modules so that they’re accessible by k6 from inside of the container

I’m not running the code in a docker container, I’m running locally on my 2019 Macbook Pro running Sonoma 14.4.1. Once I’ve got the script running locally, I’ll be using my Grafana Account to actually run the tests for testing our service.

My file structure looks like this:

.
├── utils/
│   └── generateConsumer.js
├── script.js
└── package.json

Here is the generateConsumer.js file

import { faker } from '@faker-js/faker';

export function generateConsumer() {
  return {
    firstName: faker.person.firstName(),
    lastName: faker.person.lastName(),
    email: faker.person.email(),
  };
}

And here is my script.js file

import http from 'k6/http';
import { sleep } from 'k6';
import { generateConsumer } from './utils/generateConsumer';

export const options = {
  vus: 1,
};

function createConsumer() {
  const consumer = generateConsumer();
  return JSON.stringify(consumer);
}

export default function () {
  const url = process.env.URL;
  const payload = createConsumer();

  const params = {
    headers: {
      'Content-Type': 'application/json',
    },
  };

  http.post(url, payload, params);
}

LEAVE A COMMENT