Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #3

Merged
merged 2 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## install dependencies
install:
@echo "Installing dependencies"
@go install go.k6.io/xk6/cmd/xk6@latest
@go mod download

## build binary file
build:
@echo "Building binary file"
@xk6 build --with github.com/Juandavi1/xk6-prompt=. --output bin/

## run binary file example
run:
@echo "Running binary file"
@chmod +x ./bin/k6
./bin/k6 run ./examples/sample.js
108 changes: 83 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,114 @@
# xk6-prompt


![k6 version](https://img.shields.io/badge/K6-v0.41.0-7d64ff)
![xk6 version](https://img.shields.io/badge/Xk6-v0.8.1-7d64ff)
![k6 version](https://img.shields.io/badge/K6-v0.47.0-7d64ff)
![xk6 version](https://img.shields.io/badge/Xk6-v0.9.2-7d64ff)
![xk6 version](https://img.shields.io/badge/Go-v1.19-79d4fd)

![](https://cdn.jsdelivr.net/gh/egonelbre/gophers@master/vector/projects/surfing-js.svg)

![Alt text](prompt.svg)
![prompt_example](assets/prompt.svg)

k6 extension that adds support for input arguments via UI.
_k6 extension that adds support for input arguments via UI._


#### Install
#### Install

1. Install [xk6](https://github.com/grafana/xk6)
```shell
```console
go install go.k6.io/xk6/cmd/xk6@latest
```
2. Build the extension using:

```shell
xk6 build --with github.com/Juandavi1/xk6-prompt@0.0.1
```console
xk6 build --with github.com/Juandavi1/xk6-prompt
```

#### Import

```js
import prompt from 'k6/x/prompt';
import prompt from 'bin/k6/x/prompt';
```

> :warning: **If you are in a continuous testing environment, dont forget to add the conditional to read prompt inputs from [__ENV](https://k6.io/docs/using-k6/environment-variables/)**

> :warning: **Example: const myNumber = __ENV.value ? __ENV.value : prompt.readInt("enter number")**


#### Input select
```js
const options = ["smoke", "load"]
const selected = prompt.select("kind of test", ...options)
export default function () {
const options = ["smoke", "load"]
const selected = prompt.select("kind of test", ...options)
console.log(typeof selected === "string")
}
```

#### Read string
```js
const inputString = prompt.readString("type a string")
console.log(typeof inputString)
export default function () {
const inputString = prompt.readString("type a string")
console.log(typeof inputString === "string")
}
```

#### Read int
```js
const inputNumber = prompt.readInt("Type a number")
console.log(typeof inputNumber)
export default function () {
const inputNumber = prompt.readInt("Type a number")
console.log(typeof inputNumber === "number")
}
```

#### Read float
```js
export default function () {
const inputNumber = prompt.readFloat("Type a float")
console.log(typeof inputNumber === "number")
}
```

### Continuous Test

If you are in a **continuous testing environment** you can pass the input arguments via environment variables.

Example:

####
```js
export default function () {
const myNumber = __ENV.num ? __ENV.num : prompt.readInt("enter a number")
console.log(typeof myNumber === "number")
}
```

And run the test with the environment variable:

```console
k6 run -e num=10 script.js
```


### Manually building from source

Install Go tools [1.19](https://golang.org/doc/install)

Clone this repo
```console
git clone git@github.com:Juandavi1/xk6-prompt.git
```

Install dependencies
```console
make install
```

Build the extension binary
```console
make build
```

Execute the example using the extension binary
```console
make run
```

### [Options](https://k6.io/docs/es/usando-k6/opciones/) model
![options](carbon.png)
### Examples

You can find more examples in the [examples](examples) folder.

<br/>

*#HavingFunLearning* 🦾
File renamed without changes
File renamed without changes
Binary file renamed k6 → bin/k6
Binary file not shown.
File renamed without changes.
4 changes: 2 additions & 2 deletions extension.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package prompt

import (
"go.k6.io/k6/js/modules"
k6modules "go.k6.io/k6/js/modules"
)

func init() {
modules.Register("k6/x/prompt", new(Prompt))
k6modules.Register("k6/x/prompt", new(Prompt))
}
27 changes: 14 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,29 @@ go 1.19

require (
github.com/manifoldco/promptui v0.9.0
github.com/sirupsen/logrus v1.9.0
go.k6.io/k6 v0.41.0
go.k6.io/k6 v0.47.0
)

require (
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/dop251/goja v0.0.0-20221003171542-5ea1285e6c91 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/chzyer/readline v1.5.0 // indirect
github.com/dlclark/regexp2 v1.9.0 // indirect
github.com/dop251/goja v0.0.0-20230919151941-fc55792775de // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.4-0.20211119122758-180fcef48034+incompatible // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mstoykov/atlas v0.0.0-20220808085829-90340e9998bd // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mstoykov/atlas v0.0.0-20220811071828-388f114305dd // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.24.1 // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
github.com/onsi/gomega v1.20.2 // indirect
github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/afero v1.1.2 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/time v0.3.0 // indirect
gopkg.in/guregu/null.v3 v3.3.0 // indirect
)
Loading