Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with built standalone.js #111

Open
amommersteeg-d2l opened this issue Nov 17, 2022 · 1 comment
Open

Error with built standalone.js #111

amommersteeg-d2l opened this issue Nov 17, 2022 · 1 comment
Assignees

Comments

@amommersteeg-d2l
Copy link

amommersteeg-d2l commented Nov 17, 2022

The following error is seen in the browser console when trying to use the standalone.js in website.

standalone.js:11 Uncaught (in promise) ReferenceError: regeneratorRuntime is not defined
    at Object.d (standalone.js:11:356755)
    at e.exports [as liHARToK6Script] (standalone.js:11:357262)
    at run ((index):48:36)
    at (index):52:3

This is the code used to create the website

<!DOCTYPE html>
<html lang="en">
<head>
  <title>k6 test</title>
</head>
<body>
    Check the console.
</body>

<script src="standalone.js"></script>
<script>
  async function run () {

    const config = {
      log: {
        entries: [
          {
            request: {
              method: "POST",
              url: "http://test.loadimpact.com/login",
              headers: [
                {
                  "name": "Content-Type",
                  "value": "application/json"
                }
              ],
              postData: {
                "mimeType": "application/json",
                "text": "{\"user\":\"admin\",\"password\":\"123\"}"
              },
            },
          }
        ],
      }
    };

    const { main } = await harToK6.liHARToK6Script(config);
    console.log(main);
  }

  run()
</script>

</html>

I tried both the pre-built standalone.js in the repo and building one myself with the webpack config in the repo.

@amommersteeg-d2l
Copy link
Author

Found a work around for the error. Add the following script along with the standalone.js <script src="https://unpkg.com/regenerator-runtime@0.13.1/runtime.js"></script> . It was mentioned in this thread, babel/babel#9849

Example:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>k6 test</title>
</head>
<body>
    Check the console.
</body>

<script src="https://unpkg.com/regenerator-runtime@0.13.1/runtime.js"></script>
<script src="standalone.js"></script>

<script>
  async function run () {

    const config = {
      log: {
        entries: [
          {
            request: {
              method: "POST",
              url: "http://test.loadimpact.com/login",
              headers: [
                {
                  "name": "Content-Type",
                  "value": "application/json"
                }
              ],
              postData: {
                "mimeType": "application/json",
                "text": "{\"user\":\"admin\",\"password\":\"123\"}"
              },
            },
          }
        ],
      }
    };

    const { main } = await harToK6.liHARToK6Script(config);
    console.log(main);
  }

  run()
</script>

</html>

Returns the following to the console:

import { sleep } from 'k6'
import http from 'k6/http'

export const options = {}

export default function main() {
  let response

  response = http.post('http://test.loadimpact.com/login', '{"user":"admin","password":"123"}', {
    headers: {
      'Content-Type': 'application/json',
    },
  })

  // Automatically added sleep
  sleep(1)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants