release notes/v0.43.0.md
k6 v0.43.0 is here! :tada:
Notable changes in this release include:
async/await.Keep reading for the details.
#2807 Use non-zero exit codes for tests aborted by Ctrl+C or the REST API.
Aborting a test run with Ctrl+C will now exit with code 105, and stopping via the REST API will exit with code 103.
This release includes xk6-browser as an experimental module. This means you can now also use the main k6 binary for browser automation and end-to-end testing, without needing to build a custom binary with xk6.
All xk6-browser scripts that work with v0.8.0 will continue to work with the built-in module in k6 v0.43.0. To use them, change the import path from k6/x/browser to k6/experimental/browser, and set the environment variable K6_BROWSER_ENABLED to true. The requirement to specify the environment variable is temporary and may be removed in a future k6 release. It was added to minimize the risks with k6 unexpectedly launching a browser (or another process) from k6 scripts. It's also a mechanism we use in the k6 Cloud, where browser tests are currently disabled.
For details, review the script example, or the updated browser module documentation.
The module is currently under the experimental namespace, which means we reserve the decision to introduce breaking changes in the future. However, our mid-term goal is to drop the experimental label and make browser support a stable part of the k6 feature set, eventually enabling it in k6 Cloud as well.
async/await #2830In v0.35.0 we added support for asynchronous functionality in k6 scripts with the addition of Promise.
While useful, the experience wasn't very friendly. Scripts had to use the .then() API to chain Promises, instead of the await syntax available in most other JavaScript runtimes, and the async keyword wasn't supported. Some workarounds were possible, but it required a separate build pipeline to transpile the syntax into the older ES5.1+ standard supported by k6.
That is, until now! :tada: With invaluable help from @dop251, who maintains goja, the JS VM k6 uses, v0.43.0 brings native async/await to your k6 scripts. This functionality works just as you'd expect in other JS runtimes, and makes working with async APIs much more convenient. For details, review the following http.asyncRequest() example.
One caveat to note: async functions can't be passed to group() or check(). These functions are incompatible with asynchronous behavior, so you will get an error if trying to do so.
This release brings a new experimental JavaScript module that adds distributed tracing support to k6. With one call in init context, you can instrument your test script's HTTP requests. If the system you're testing is instrumented in the same way, this module brings visibility to SUT behavior for the lifetime of each request.
An example:
import tracing from 'k6/experimental/tracing';
import http from 'k6/http';
tracing.instrumentHTTP({
propagator: 'w3c',
});
export default () => {
http.get('https://httpbin.test.k6.io/get', {
headers: {
'X-Example-Header': 'instrumented/get',
},
});
};
For details and examples, refer to the tracing module documentation.
http.asyncRequest #2877The k6/http module has a new asyncRequest function that takes the same arguments as http.request(), but returns a Promise that, when used with await, will be resolved with a Response object. This gives you more control over script execution, as potentially the most time-consuming calls—making HTTP requests—will no longer block the thread of execution.
An example issuing a POST request:
import http from 'k6/http';
export default async function () {
const resPromise = http.asyncRequest(
'POST', 'https://httpbin.test.k6.io/post', { name: 'Bert' });
// Do something else here, make other requests, etc.
// Then when you're ready to use the response:
const resp = await resPromise;
console.log(resp.json().form.name); // Bert
}
This is one of the first steps towards migrating our APIs to be asynchronous, and similar changes can be expected in the future.
You can read more about asyncRequest in the documentation.
k6 version command has been enhanced to also show the version of all extensions built into the k6 binary produced by xk6. Thanks, @HarrisChu!os package.csv output now correctly shows vu and iter system tags. This fixes a regression introduced in v0.40.0. Thanks, @leonyork!k6/execution.test.abort() within a group() now correctly exits the k6 process with code 108. Thanks for reporting this, @pomeh!k6/ws when using Socket.setInterval() with values between 0 and 1.run_status value when the cloud output aborts a test.Engine, was removed, and the behavior heavily refactored. This change simplifies the code base and unblocks further improvements.k6/http module.js.Bundle was simplified.Full Changelog: https://github.com/grafana/k6/compare/v0.42.0...v0.43.0