Import using dynamic path

Is there any way i can use a dynamic path in my import like the below because i want this to be dynamic based on the active project

import {testCaseConfig} from `../config/${activeProject.testCaseFolder}/testcase_config.js}`
const testCases = testCaseConfig.testCases

Hi @AJSteenkamp :wave:

Welcome to the support forum :tada:

I’m afraid it is, to the best of my knowledge, not possible in k6, and the only way I believe would make this possible, with dynamic imports, is not yet supported by k6’s JavaScript runtime.

My understanding is that in ECMAScript JavaScript, unless using dynamic modules, imports are performed at the script parsing stage, not at runtime, so ${activeProject} wouldn’t be yet defined when the script is parsed for imports.

Let me know if that was useful :bowing_man:

Hi @oleiade

I was hoping this would be possible because I’m working on a generic api performance testing framework and I envision that you will be able to configure multiple ‘projects’ ie different APIs that you want to test and depending on which one is active, it will retrieve my test case config file for that project in the folder specified in the activeProject.testCaseFolder variable.

If this is not possible, I will just have an ‘active’ folder and then drop the test case config I want to use in the active folder and keep test case config for other projects in a different folder.

Was just hoping I could do this more dynamically.

Thanks for the assistance.

Hey @AJSteenkamp

Indeed, your specific use case might not be possible to achieve verbatim. Considering the optimal solution, I’m not necessarily the best person to offer it. Maybe someone in the wider community will have run into the same issue and have pointers to offer though :bowing_man:

Thanks @oleiade
I appreciate the assistance nonetheless.