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

Add support for k6 remote modules #16

Open
ppcano opened this issue Jun 7, 2021 · 2 comments
Open

Add support for k6 remote modules #16

ppcano opened this issue Jun 7, 2021 · 2 comments

Comments

@ppcano
Copy link
Collaborator

ppcano commented Jun 7, 2021

It is not supported in TypeScript yet - Add support for URI style import.

You need to use ts-ignore to skip the compiler error.

import { sleep, check } from 'k6';
import { Options } from 'k6/options';

/* @ts-ignore */
import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.1.0/index.js';
import http from 'k6/http';

export let options:Options = {
  vus: 50,
  duration: '10s'
};

export default () => {
  const res = http.post('https://httpbin.org/status/400');
  check(res, {
    'status is 400': () => res.status === 400,
  });
  sleep(randomIntBetween(1,5));
};
@mrjocab
Copy link

mrjocab commented Feb 6, 2023

@ppcano, would you consider declaring a module and defining custom types, instead of relying on @ts-ignore? Since TypeScript doesn't currently support these imports, I believe it would be beneficial to explicitly provide relevant types in order to fully leverage the benefits of a TypeScript-based implementation.

@ppcano
Copy link
Collaborator Author

ppcano commented Feb 6, 2023

Do you mean declaring a module and defining custom types for jslib libraries?

https://github.com/grafana/jslib.k6.io/ is a set of pure Javascript utils for k6. They are built non-natively within the k6 version, so they are available from a remote url.

Note that k6 modules such k6/http, k6/crypto are built-in/native k6 modules. You can read more about the different types of k6 modules.

If you want to avoid the @ts-ignore. You can download the jslib library to your local project and import like:

import { randomIntBetween } from './k6-utils/1.1.0/index.js';

If you want to request TypeScript definitions for jslib modules, I suggest opening feature request to https://github.com/grafana/jslib.k6.io/ or the specific project.

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