Importing functions and using in scenarios

Hi Team,
I’m facing this issue:

Contents of home/vivekchamoli/K6/requests/GET_ListTodos.js file

import http from ‘k6/http’;

export function GET_ListTodos() {
let base_url= ‘https://gorest.co.in’;

let resp_GET_ListTodos = http.get(base_url + '/public/v1/todos', {
    tags: {name: 'GET_ListTodos'}
});

check(
    resp_GET_ListTodos, {
        'is status 200': (r) => r.status === 200
    }
);

}

Contents of scenarios/gorest_test.js:

import { GET_ListTodos } from ‘/home/vivekchamoli/K6/requests/GET_ListTodos.js’;

export let options = {
scenarios: {
scenario_GET_ListTodos: {
executor: ‘ramping-vus’,
exec: ‘GET_ListTodos’ ,
stages: [
{ duration: ‘5s’, target: 50 },
{ duration: ‘5s’, target: 0}
]
}
}
}

When I’m running:
k6 run scenarios/gorest_test.js

Getting this error:

ERRO[0000] no exported functions in script

Please help…

1 Like

Hi there, welcome to the forum :slight_smile:

This happens because the function you specify in exec should be exported from the main script as well.

Try this instead:

export { GET_ListTodos } from '/home/vivekchamoli/K6/requests/GET_ListTodos.js';

Hi imiric,

Thank you very much…

On changing in scenarios/gorest_test.js

import { GET_ListTodos } from ‘…/…/requests/gorest/GET_ListTodos.js’;

to

export { GET_ListTodos } from ‘…/…/requests/gorest/GET_ListTodos.js’;

Now it works FINE.