k6-template-typescript
k6-template-typescript copied to clipboard
Add support for k6 remote modules
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));
};
@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.
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.