How to run node command in setup function?

I want to run a function before k6 script. I thought that using node command in setup function (E.g. node test.js) This is possible? If it is not possible how can I run a function before k6 script ? And how I use that outside function ‘s returning value in setup? I m searching this because my function takes 5 minute to giving response for server. It is not meaningful using in k6 script so calling from response data outside is more effective

If there is any alternative idea could u give me a sample code or etc?

Hi @Yusuf !
Look at this example, maybe it can help you.
Example:

import { addToCart } from "./addToCart.js"; // import js file with function

export default function main() {
  
  addToCart(); //function call

}

Hi @PaulM thanks for reply , I know this method but the main case is like below;

I should run a function outside of k6 script . And I have to call returning value in k6. Because I must run that function one time . If I call in export default function it will work more than one time . It should work one time . When running in setup it passes the default 60 sn so giving timeout error. Because of this I should find a solution like this;
1.Running function outside
2. Pushing the json value to an array (I will set the returning value in outside function)
3. I will call the array in setup function

When I use this methods , function run one time outside of k6 script. I will only take returning array in k6 script. I m searching a code like this :slightly_smiling_face:

@Yusuf One of the options is to output data to a file with one script. Another script unloads the required values ​​from the file.
Example:

  1. To write to the file, you will need to display the required values ​​in log cosole.log(response) and run the script with parameters k6 run test.js 2>resp.txt and then use the resp.txt file. And example this and this
  2. Try to use the setup function. @ned wrote about the possibility of overriding the timeout..
import http from 'k6/http';

export function setup() {
  let params = {
    timeout: "120s"
  };

  const res = http.get('https://httpbin.org/get', params);
  return { data: res.json() };
}

export default function (data) {
  console.log(JSON.stringify(data));
}
  1. Change the timeout in the default function as described above and place the data acquisition in 1 iteration.
if(__ITER == 0){

// Get values ​​here
}

Thanks for help @PaulM

@PaulM When I use the timeout like below the setup time does not takes 4m=240000ms.Takes again 60s.Tried also timeout:“240000ms”;

export function setup() {
  let createPickingStartedSalesOrdersRes = http.post(
    Load.api + endpoints.SalesOrderLoadSeed.CreatePickingCompletedSalesOrders,
    JSON.stringify({
      salesOrderConfigurations: [
        {
          amount: 500,
        },
      ],
      tenant: "test",
     
    }),
    {
      headers: {
        apikey: "*",
        "Content-Type": "application/json",
      },
      timeout:240000
    }
  );
  let operatorAuth = Load.auth(Roles.Operator);
  let supportAuth = Load.auth(Roles.Support);
  return [
    operatorAuth.json(),
    supportAuth.json(),
    createPickingStartedSalesOrdersRes.json(),
    
  ];
}

@Yusuf Is it possible that a timeout of 60s is set on the server under test?
Please check this code:

export function setup() {

let url =  Load.api + endpoints.SalesOrderLoadSeed.CreatePickingCompletedSalesOrders;

let data = JSON.stringify({
  salesOrderConfigurations: [
    {
      amount: 500,
    },
  ],
  tenant: "test",
 
});

let params = {
  headers: { apikey: "*", "Content-Type": "application/json"},
    timeout: "120s",

};

  let createPickingStartedSalesOrdersRes = http.post(url, data, params);
  let operatorAuth = Load.auth(Roles.Operator);
  let supportAuth = Load.auth(Roles.Support);
  return [
    operatorAuth.json(),
    supportAuth.json(),
    createPickingStartedSalesOrdersRes.json(),
    
  ];
}

@ned @inanc Can you please tell me if we are redefining the timeout for the request correctly?

The request timeout looks correct, but consider that setup() itself might also time out. That behavior is determined by the setupTimeout global option, see https://k6.io/docs/using-k6/options/#setup-timeout