Skip to content

Commit 52d5904

Browse files
authored
Merge pull request #1889 from grafana/document_local_templates
Document custom templates support in `k6 new`
2 parents ee9a9da + 722b745 commit 52d5904

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

docs/sources/k6/next/using-k6/test-authoring/create-test-script-using-the-cli.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Writing a k6 test script from scratch can seem challenging if you're just gettin
1313
To use the k6 `new` command, you'll need:
1414

1515
- [k6 v0.57 or higher](https://grafana.com/docs/k6/<K6_VERSION>/set-up/install-k6/) installed on your machine.
16+
- Custom templates require k6 v1.0.0-rc1 or higher.
1617

1718
## Use the k6 new command
1819

@@ -43,16 +44,23 @@ The options are:
4344
- `minimal`: Creates a minimal test script with a short options configuration, and a single request and check example. This is the default option.
4445
- `protocol`: Creates a script that includes environment variables, stages with different durations and VUs, thresholds, and a setup function. This is ideal for learning, and as a good starting point for real-world scenarios.
4546
- `browser`: Creates a browser script that checks if a websites successfully loaded, looks for elements on the screen, and takes a screenshot. Similar to the `protocol` option, this is ideal for learning, and a good starting point for creating browser tests.
47+
- An absolute or a relative path to a local file, such as `./my-template.js` or `/path/to/my-template.js` to use a custom template. `k6` uses [Go templating syntax](https://pkg.go.dev/text/template#section-documentation) to render the script.
4648

47-
To use the template flag, run:
49+
To generate a script using a template, run:
4850

4951
```bash
5052
k6 new --template protocol
5153
```
5254

5355
### --project-id
5456

55-
The `--project-id` allows you to specify a Grafana Cloud k6 project ID. The generated script is then configured to run in that project.
57+
The `--project-id` flag allows you to specify a Grafana Cloud k6 project ID. The generated script is then configured to run in that project. To include the project ID in your custom template, use `{{ .ProjectID }}` as a placeholder, for example:
58+
59+
```javascript
60+
export default function () {
61+
console.log('Hello from project {{ .ProjectID }}!');
62+
}
63+
```
5664

5765
To use the project ID flag, run:
5866

0 commit comments

Comments
 (0)