Skip to content

Commit

Permalink
Skip example in changed files
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Feb 7, 2025
1 parent 4f0ddcd commit 5a0a543
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
32 changes: 18 additions & 14 deletions docs/sources/k6/next/get-started/write-your-first-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,29 @@ Let’s walk through creating a simple test which performs 10 `GET` HTTP request

2. **Import k6 modules**: As the end goal here is to perform HTTP requests, import the k6 `http` module at the top of the file. To help simulate a real-world scenario, import the `sleep` function from the `k6` module as well.

```javascript
// Import the http module to make HTTP requests. From this point, you can use `http` methods to make HTTP requests.
import http from 'k6/http';
<!--md-k6:skip-->

// Import the sleep function to introduce delays. From this point, you can use the `sleep` function to introduce delays in your test script.
import { sleep } from 'k6';
```
```javascript
// Import the http module to make HTTP requests. From this point, you can use `http` methods to make HTTP requests.
import http from 'k6/http';

// Import the sleep function to introduce delays. From this point, you can use the `sleep` function to introduce delays in your test script.
import { sleep } from 'k6';
```

3. **Define options**: To perform 10 HTTP requests, define an options block to configure the test execution. In this case, set the number of iterations to 10 to instruct k6 to execute the default function 10 times. Right beneath the imports, add the following code:

```javascript
import http from 'k6/http';
import { sleep } from 'k6';
<!--md-k6:skip-->

export const options = {
// Define the number of iterations for the test
iterations: 10,
};
```
```javascript
import http from 'k6/http';
import { sleep } from 'k6';

export const options = {
// Define the number of iterations for the test
iterations: 10,
};
```

4. **Define a default function**: The default exported function is the entry point for the test script. It will be executed repeatedly the number of times you define with the `iterations` option. In this function, make a `GET` request to a URL and introduce a 1-second delay between requests. Add the following code to your script:

Expand Down
26 changes: 25 additions & 1 deletion docs/sources/k6/next/using-k6/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ For example, the `http` client make requests against the
system under test.
For the full list of built-in modules, refer to the [API documentation](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api).

<!--md-k6:skip-->

```javascript
import http from 'k6/http';
```
Expand All @@ -34,6 +36,8 @@ These modules are stored on the local filesystem, and accessed either through re

k6 adopts a **browser-like module resolution** and doesn't support [Node.js module resolution](https://nodejs.org/api/modules.html#modules_all_together). File names for `imports` must be fully specified, such as `./helpers.js`.

<!--md-k6:skip-->

```javascript
//my-test.js
import { someHelper } from './helpers.js';
Expand All @@ -43,6 +47,8 @@ export default function () {
}
```

<!--md-k6:skip-->

```javascript
//helpers.js
export function someHelper() {
Expand All @@ -63,7 +69,7 @@ For example, [jslib](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jsl
import { randomItem } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';

export default function () {
randomItem();
randomItem([1, 2, 3]);
}
```

Expand All @@ -75,6 +81,8 @@ Like the [k6 APIs](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api), you

Below is an example that imports the `k6/x/kubernetes` module from the [xk6-kubernetes](https://github.com/grafana/xk6-kubernetes) extension.

<!--md-k6:skip-->

```javascript
import { Kubernetes } from 'k6/x/kubernetes';

Expand Down Expand Up @@ -120,6 +128,8 @@ The following options for distributing and sharing JavaScript libraries are avai

You can host your modules in a public webserver like GitHub and any CDN and be imported remotely.

<!--md-k6:skip-->

```javascript
// As GitHub release assets
import {
Expand All @@ -142,6 +152,8 @@ Be aware that k6 automatically executes remote modules, making it crucial to tru

In this example, the previous remote modules have been downloaded to the `lib` folder of the testing project and imported as follows:

<!--md-k6:skip-->

```javascript
import { WorkloadConfig, sayHello } from './libs/test-commons.js';

Expand All @@ -162,6 +174,8 @@ k6 isn't Node.js or a browser. Packages that rely on APIs provided by Node.js, f

In a JavaScript project running Node.js, modules are imported using either `import` or `require()`, using the Node.js module resolution algorithm. This means that a user can import modules by name, without providing the full filesystem path to the module. For instance:

<!--md-k6:skip-->

```javascript
import { ClassInAModule } from 'cool-module';
```
Expand Down Expand Up @@ -230,6 +244,8 @@ $ npm install --save-dev \

Once these packages have been added, the next step will be to set up a `webpack.config.js` file:

<!--md-k6:skip-->

```javascript
const path = require('path');

Expand Down Expand Up @@ -263,6 +279,8 @@ The files Webpack will use as its entry points while performing the bundling. Fr
Webpack will automatically traverse all imports recursively until every possible dependency path has
been exhausted. For instance:

<!--md-k6:skip-->

```javascript
// login.test.js

Expand All @@ -273,6 +291,8 @@ const svc = new SomeService();

and:

<!--md-k6:skip-->

```javascript
// some.service.js

Expand Down Expand Up @@ -372,6 +392,8 @@ For example, say you have the following structure on your host machine:

{{< code >}}

<!--md-k6:skip-->

```javascript
import { hello_world } from './modules/module.js';

Expand All @@ -384,6 +406,8 @@ export default function () {

{{< code >}}

<!--md-k6:skip-->

```javascript
export function hello_world() {
console.log('Hello world');
Expand Down

0 comments on commit 5a0a543

Please sign in to comment.