How i can use absolute path in k6 load testing framework

I want to use absolute path in k6 js script file. Can someone please help in how to do this?

Instead of this

import {getAddCookieInfoPayLoad} from "../../../scripts/oAuth/addCookieInfoScript.js";
import {getQueryCookieInfoPayLoad} from "../../../scripts/oAuth/queryCookieInfoScript.js";

I want this:

import {getAddCookieInfoPayLoad} from "scripts/oAuth/addCookieInfoScript.js";

import {getQueryCookieInfoPayLoad} from "scripts/oAuth/queryCookieInfoScript.js";

You can use absolute paths:

import {getAddCookieInfoPayLoad} from "/absolute/path/to/scripts/oAuth/addCookieInfoScript.js";

and you can also import them with the file:// schema:

import {getAddCookieInfoPayLoad} from "file:///absolute/path/to/scripts/oAuth/addCookieInfoScript.js";

Though in general I find relative paths to be more usable and be more reliable when multiple people are working on the scripts, possibly across different OSes.

If I understand you correctly, what you’d like is for absolute access using / to be relative to the project root rather than the file system root?

If so, there is an issue tracking that.

I would not expect this anytime soon, however, as changing the default behaviour would break backwards compatibility. The actual value other than cleaner-looking code is also, at least in my opinion, questionable.