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

Enable TypeScript support when running k6 via docker #4199

Open
wingy3181 opened this issue Jan 20, 2025 · 0 comments
Open

Enable TypeScript support when running k6 via docker #4199

wingy3181 opened this issue Jan 20, 2025 · 0 comments
Assignees

Comments

@wingy3181
Copy link

Brief summary

K6_COMPATIBILITY_MODE=experimental_enhanced doesn't seem to work when running k6 through docker

Did not see any docs with regards to not working via docker at https://grafana.com/docs/k6/latest/using-k6/javascript-typescript-compatibility-mode/

k6 version

0.56.0

OS

macOS 12

Docker version and image (if applicable)

Docker version 27.4.0, build bde2b89

Steps to reproduce the problem

import { sleep } from "k6";
import http from "k6/http";
import type { Options } from "k6/options";

export const options: Options = {
  vus: 10,
  duration: "30s"
};

export default function () {
  http.get("https://test.k6.io");
  sleep(1);
}

docker run --rm -i -e K6_COMPATIBILITY_MODE=experimental_enhanced grafana/k6 run --verbose - <script.ts

Looking at the source, I think it's because it looks at the filename suffix and because it is piped into the docker container, i am assuming there is no filename?
See

if ps.compatibilityMode == lib.CompatibilityModeExperimentalEnhanced && strings.HasSuffix(filename, ".ts") {

Expected behaviour

To strip the types with esbuild and run the script

OR if not possible update the docs to mention this

Actual behaviour

Outputs


         /\      Grafana   /‾‾/  
    /\  /  \     |\  __   /  /   
   /  \/    \    | |/ /  /   ‾‾\ 
  /          \   |   (  |  (‾)  |
 / __________ \  |_|\_\  \_____/ 

time="2025-01-20T01:02:28Z" level=debug msg="Logger format: TEXT"
time="2025-01-20T01:02:28Z" level=debug msg="k6 version: v0.56.0 (commit/50afb99947, go1.23.4, linux/arm64)"
time="2025-01-20T01:02:28Z" level=debug msg="Resolving and reading test '-'..."
time="2025-01-20T01:02:28Z" level=debug msg="'-' resolved to 'file:///-' and successfully loaded 244 bytes!"
time="2025-01-20T01:02:28Z" level=debug msg="Gathering k6 runtime options..."
time="2025-01-20T01:02:28Z" level=debug msg="Initializing k6 runner for '-' (file:///-)..."
time="2025-01-20T01:02:28Z" level=debug msg="Detecting test type for..." test_path="file:///-"
time="2025-01-20T01:02:28Z" level=debug msg="Trying to load as a JS test..." test_path="file:///-"
time="2025-01-20T01:02:28Z" level=debug msg="Everything has finished, exiting k6 with an error!" error="could not initialize '-': could not load JS test 'file:///-': GoError: file:///-: Line 3:30 Unexpected string (and 1 more errors)\n"
time="2025-01-20T01:02:28Z" level=error msg="GoError: file:///-: Line 3:30 Unexpected string (and 1 more errors)\n" hint="script exception"
@wingy3181 wingy3181 added the bug label Jan 20, 2025
@wingy3181 wingy3181 changed the title Enable TypeScript support via docker Enable TypeScript support when running k6 via docker Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants