Skip to content

Commit 7ccb49c

Browse files
authored
Merge pull request #1425 from grafana/document_k6_new_subcommand
Suggest using `k6 new` instead of copying sample script
2 parents 0627d0d + a283cdd commit 7ccb49c

File tree

2 files changed

+41
-27
lines changed

2 files changed

+41
-27
lines changed

docs/sources/next/get-started/running-k6.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,26 @@ But, if you have a k6 Cloud account, you can also use the `k6 cloud` command to
2020

2121
To run a simple local script:
2222

23-
1. Copy the following code, paste it into your favorite editor, and save it as `script.js`:
23+
1. Create and initialize a new script by running the following command:
2424

25-
```javascript
26-
import http from 'k6/http';
27-
import { sleep } from 'k6';
25+
{{< code >}}
2826

29-
export default function () {
30-
http.get('https://test.k6.io');
31-
sleep(1);
32-
}
33-
```
27+
```linux
28+
$ k6 new
29+
```
30+
31+
```docker
32+
$ docker run --rm -i -v $PWD:/app -w /app grafana/k6 new
33+
```
34+
35+
```windows
36+
PS C:\> docker run --rm -i -v ${PWD}:/app -w /app grafana/k6 init
37+
```
38+
39+
{{< /code >}}
40+
41+
This command creates a new script file named `script.js` in the current directory.
42+
You can also specify a different file name as an argument to the `k6 new` command, for example `k6 new my-test.js`.
3443

3544
1. Run k6 with the following command:
3645

src/data/markdown/translated-guides/en/01 Get started/03 Running k6.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,36 @@ excerpt: 'Follow along to learn how to run a test, add virtual users, increase t
66
Follow along to learn how to:
77
1. Run a test.
88
2. Add virtual users.
9-
3. Increase the test duration.
9+
3. Increase the test duration.
1010
4. Ramp the number of requests up and down as the test runs.
1111

1212
With these example snippets, you'll run the test with your machine's resources.
13-
But, if you have a k6 Cloud account, you can also use the `k6 cloud` command to outsource the test to k6 servers.
13+
But, if you have a k6 Cloud account, you can also use the `k6 cloud` command to outsource the test to k6 servers.
1414

1515
<!-- preserving old anchor --->
1616
## Run local tests {#running-local-tests}
1717

1818
To run a simple local script:
19-
1. Copy the following code, paste it into your favorite editor, and save it as `script.js`:
19+
1. Create and initialize a new script by running the following command:
2020

21-
<CodeGroup labels={["script.js"]} lineNumbers={[true]}>
21+
<CodeGroup labels={["CLI", "Docker", "Docker in Win PowerShell"]}>
2222

23-
```javascript
24-
import http from 'k6/http';
25-
import { sleep } from 'k6';
23+
```bash
24+
$ k6 new
25+
```
2626

27-
export default function () {
28-
http.get('https://test.k6.io');
29-
sleep(1);
30-
}
31-
```
27+
```bash
28+
$ docker run --rm -i -v $PWD:/app -w /app grafana/k6 new
29+
```
3230

33-
</CodeGroup>
31+
```bash
32+
PS C:\> docker run --rm -i -v ${PWD}:/app -w /app grafana/k6 init
33+
```
34+
35+
</CodeGroup>
36+
37+
This command creates a new script file named `script.js` in the current directory.
38+
You can also specify a different file name as an argument to the `k6 new` command, for example `k6 new my-test.js`.
3439

3540
1. Run k6 with the following command:
3641

@@ -196,17 +201,17 @@ You can run the same test in different modes with minimal changes.
196201
197202
</Blockquote>
198203
199-
k6 supports three execution modes to run a k6 test: local, distributed, and cloud.
204+
k6 supports three execution modes to run a k6 test: local, distributed, and cloud.
200205
201-
- **Local**: the test execution happens entirely on a single machine, container, or CI server.
206+
- **Local**: the test execution happens entirely on a single machine, container, or CI server.
202207
203208
```bash
204209
k6 run script.js
205210
```
206211
207-
- **Distributed**: the test execution is [distributed across a Kubernetes cluster](/testing-guides/running-distributed-tests/).
208-
209-
<CodeGroup labels={["Running", "k6-resource.yaml"]} lineNumbers={[true]}>
212+
- **Distributed**: the test execution is [distributed across a Kubernetes cluster](/testing-guides/running-distributed-tests/).
213+
214+
<CodeGroup labels={["Running", "k6-resource.yaml"]} lineNumbers={[true]}>
210215
211216
```bash
212217
kubectl apply -f /path/k6-resource.yaml

0 commit comments

Comments
 (0)