How to solve the error tv4 is not defined

I am trying to perform Load test using k6 by converting the postman collection json files into k6-script.js files through githib actions. But on execution I see the error in github actions as

time="2023-12-21T12:36:12Z" level=error msg="ReferenceError: tv4 is not defined\n\tat file:///github/workspace/k6-script.js:86:21(1)\n\tat test (file:///github/workspace/libs/shim/core.js:504:6(15))\n\tat post (file:///github/workspace/k6-script.js:85:14(61))\n\tat executePostrequest (file:///github/workspace/libs/shim/core.js:1253:11(22))\n\tat executeRequest (file:///github/workspace/libs/shim/core.js:1034:25(108))\n\tat file:///github/workspace/libs/shim/core.js:314:30(27)\n\tat file:///github/workspace/k6-script.js:38:19(39)\n" executor=constant-vus scenario=default source=stacktrace

for schema validation using tv4 .
Example:

pm.test("Schema validation", function(){
    var result = tv4.validateResult(pm.response.json(),schema);
    if(!result.valid){
        console.log(result)
    }
    pm.expect(result.valid).to.be.true;
})

How can i solve this issue?

Hi @priyankalawale

Welcome to the community forum :wave:

I’m not experienced with postman-to-k6, though I can try to help troubleshoot.

Is the test working locally and then failing via GitHub actions? I would start by troubleshooting locally to determine if the issue lies within postman-to-k6 or the GitHub configuration.

Let me know and we’ll take it from there.

Cheers!

Locally working fine and also working with github workflow without k6, but failing with k6

Hi @priyankalawale

Thanks for the additional info.

Locally, what version of k6 are you running?

Can you share how you configure GitHub actions? I can try to reproduce it.

here the the config i am adding in github actions

steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-node@v4
      with:
        node-version: 18
    - name: Checkout
      uses: actions/checkout@v2
      
    - name: install postman-to-k6
      run: |
        npm install -g @apideck/postman-to-k6
        
    - name: convert json to js   
      run: |
        # Generate k6 script and store it in a temporary file
        postman-to-k6 ${{ github.workspace }}/postman/collections/artists.json -o artists.js
      
    - uses: grafana/k6-action@v0.2.0
      with:
          filename: artists.js
          flags: --vus 50 --duration 10s
1 Like