diff --git a/README.md b/README.md index 9e414f1..1ee7795 100644 --- a/README.md +++ b/README.md @@ -126,4 +126,8 @@ Before the test run, transpilation and bundling are done on the fly. ## Compatibility warning -xk6-ts is currently integrated into k6 by modifying the execution of the `k6 run` command. This is a temporary solution, the final integration will be done in a different way. This temporary integration assumes that the last argument of the `k6 run` command line is the name of the script file. That is, contrary to the way the original `k6 run` command line works, xk6-ts does not accept flags after the script file name. By the way, this assumption is not uncommon, many other commands only accept flags before positional arguments. (the original `k6 run` command also accepts flags after the positional argument). \ No newline at end of file +xk6-ts is currently integrated into k6 by modifying the execution of the `k6 run` command. This is a temporary solution, the final integration will be done in a different way. This temporary integration assumes that the last argument of the `k6 run` command line is the name of the script file. That is, contrary to the way the original `k6 run` command line works, xk6-ts does not accept flags after the script file name. By the way, this assumption is not uncommon, many other commands only accept flags before positional arguments. (the original `k6 run` command also accepts flags after the positional argument). + +## Benchmarking + +Setting the `XK6_TS_BENCHMARK` environment variable to `true` will log the time spent on TypeScript/JavaScript bundling. This time also includes downloading any remote modules. diff --git a/loader.go b/loader.go index 305c680..3a9f0a1 100644 --- a/loader.go +++ b/loader.go @@ -4,6 +4,7 @@ package ts import ( "os" "path/filepath" + "time" "github.com/sirupsen/logrus" "github.com/szkiba/k6pack" @@ -65,11 +66,18 @@ func redirectStdin() { logrus.WithError(err).Fatal() } + packStarted := time.Now() + jsScript, err := k6pack.Pack(string(source), opts) if err != nil { logrus.WithError(err).Fatal() } + if os.Getenv("XK6_TS_BENCHMARK") == "true" { + duration := time.Since(packStarted) + logrus.WithField("extension", "xk6-ts").WithField("duration", duration).Info("Bundling completed in ", duration) + } + os.Args[scriptIndex] = "-" reader, writer, err := os.Pipe()