Use dotenv-cli for k6 environment variables, easily import JS util libs like lodash, faker, moment

Поделиться
HTML-код
  • Опубликовано: 29 сен 2024

Комментарии • 13

  • @amyohare395
    @amyohare395 2 месяца назад

    This is great, thank you! I also struggled getting the xk6 binary working with the extension and then came across your suggestion. Thank you!

  • @kanew1
    @kanew1 3 месяца назад

    Thank you! Awesome solution!

  • @tomaszaszkiewicz1534
    @tomaszaszkiewicz1534 5 месяцев назад

    Hi! I have trouble running it as you showed. If i try to run it as you did I get an error saying .env is not a valid boolean. If i try to use -f flag to specify .env file dotenv is giving me an error that "k6" is not a valid command even though it's installed globally and added to path. I tried doing it on windows 10 and on ubuntu subsystem through WSL with same results.

    • @MuratKeremOzcan
      @MuratKeremOzcan  5 месяцев назад

      you have other problems there
      need to isolate dotenv CLI and make it work just by itself, do the same for k6, and try to combine them later

  • @AdnanErlansyah-nx7xp
    @AdnanErlansyah-nx7xp 4 месяца назад

    Sir but I think it wouldn't be working if we use k6 web dashboard, so I've already tried the command like this:
    ``dotenv -e .env k6 run --out 'web-dashboard' main.js``
    it's to run the test and the output of the test is from web dashboard k6.

    • @MuratKeremOzcan
      @MuratKeremOzcan  4 месяца назад

      never used dashboard, can't say

    • @AdnanErlansyah-nx7xp
      @AdnanErlansyah-nx7xp 4 месяца назад

      @@MuratKeremOzcan is there another way to pass the env but we can still use the other arguments of k6 sir?

    • @MuratKeremOzcan
      @MuratKeremOzcan  4 месяца назад

      @@AdnanErlansyah-nx7xp I haven't needed to do this, maybe there is something in the docs. The dotenv vars are separate from k6 command, so if k6 has a way of passing the args, then yes

    • @amyohare395
      @amyohare395 2 месяца назад

      I had a similar issue but it worked when I set up the arguments in the .env file.
      My command is `dotenv -e .env.test k6 run ./k6-tests/test_name.js`
      I then added the dashboard arguments to my .env file like so:
      K6_WEB_DASHBOARD=true
      K6_WEB_DASHBOARD_EXPORT=test-report.html
      K6_WEB_DASHBOARD_OPEN=true
      And now it works great! Hope this helps :)

  • @OliverDungey
    @OliverDungey 10 месяцев назад

    Love your style and feel the same. I have adopted a pattern of having an 'env' object in each test file to encapsulate the config and keep it nice and simple for the tests that I thought you might like:
    const env = {
    endpoint: __ENV.SOMEOLDSYSTEM_ENDPOINT || fail('Missing SOMEOLDSYSTEM_ENDPOINT environment variable'),
    pathA: 'home'
    get endPointWithPath() {
    `${this.endpoint}/${this.pathA}`
    }
    };
    Gives nice fast feedback to testers when they miss out environment variables and allows me to compose complex config whilst keeping it DRY. Environment config does get very complex!

  • @ganeshkamble9078
    @ganeshkamble9078 Год назад +1

    Thanks Murat, It works for me !!

  • @Kpizzle1289
    @Kpizzle1289 Год назад

    There is a typescript template you can use for k6 which uses webpack to compile to vanilla js.

  • @quocthinhluu4098
    @quocthinhluu4098 Год назад

    Thank you. You saved my day!