k6
k6 copied to clipboard
output format for errors changes to structured log when running k6 as a subprocess
Brief summary
When running k6 as a subprocess (from a go program) and capturing the stdout and stderr in a buffer, the format of error messages changes to a structured log format.
k6 version
v0.50.0
OS
windows
Docker version and image (if applicable)
No response
Steps to reproduce the problem
-
Create an empty file named
script.js
-
Run the following go program:
package main
import (
"bytes"
"fmt"
"os/exec"
)
func main() {
cmd := exec.Command("k6", "run", "script.js")
outBuff := bytes.NewBuffer(nil)
cmd.Stdout = outBuff
cmd.Stderr = outBuff
cmd.Run()
fmt.Println(outBuff.String())
}
Expected behaviour
The same output that is generated when running the script.js
file with k6
in the console:
> k6 run script.js
/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ \/ \ | ( / ‾‾\
/ \ | |\ \ | (‾) |
/ __________ \ |__| \__\ \_____/ .io
ERRO[0000] could not initialize 'script.js': could not load JS test 'file:///home/pablo/go/src/github.com/grafana/grafana-api-tests/script.js': no exported functions in script
Actual behaviour
The output has a structured log format:
> go run main.go
/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ \/ \ | ( / ‾‾\
/ \ | |\ \ | (‾) |
/ __________ \ |__| \__\ \_____/ .io
time="2024-05-16T11:43:43+02:00" level=error msg="could not initialize 'script.js': could not load JS test 'file:///home/pablo/go/src/github.com/grafana/grafana-api-tests/script.js': no exported functions in script"