From 75c0efe9f21e63f894de9e227b5dc90c01214989 Mon Sep 17 00:00:00 2001 From: Pepe Cano <825430+ppcano@users.noreply.github.com> Date: Mon, 23 Jun 2025 18:08:46 +0200 Subject: [PATCH 1/2] Add basic TS test --- k6/foundations/01.basic.ts | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 k6/foundations/01.basic.ts diff --git a/k6/foundations/01.basic.ts b/k6/foundations/01.basic.ts new file mode 100644 index 00000000..38dc07c1 --- /dev/null +++ b/k6/foundations/01.basic.ts @@ -0,0 +1,42 @@ +import http from 'k6/http'; +import { check, sleep } from 'k6'; + +const BASE_URL: string = __ENV.BASE_URL || 'http://localhost:3333'; + +export const options = { + vus: 5, + duration: '5s', +}; + +interface Restrictions { + maxCaloriesPerSlice: number; + mustBeVegetarian: boolean; + excludedIngredients: string[]; + excludedTools: string[]; + maxNumberOfToppings: number; + minNumberOfToppings: number; +} + +export default function (): void { + const restrictions: Restrictions = { + maxCaloriesPerSlice: 500, + mustBeVegetarian: false, + excludedIngredients: ["pepperoni"], + excludedTools: ["knife"], + maxNumberOfToppings: 6, + minNumberOfToppings: 2, + }; + + const res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), { + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'token abcdef0123456789', + }, + }); + + check(res, { "status is 200": (res) => res.status === 200 }); + + const responseBody = res.json() as { pizza: { name: string; ingredients: string[] } }; + console.log(`${responseBody.pizza.name} (${responseBody.pizza.ingredients.length} ingredients)`); + sleep(1); +} From 623b7da4cab6e7039b8a64beb678625040d39b39 Mon Sep 17 00:00:00 2001 From: Pepe Cano <825430+ppcano@users.noreply.github.com> Date: Thu, 10 Jul 2025 16:25:24 +0200 Subject: [PATCH 2/2] Update GH action to run TS foundation test --- .github/workflows/build-and-test.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index 0cfe1340..06d14676 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -85,6 +85,11 @@ jobs: env: ACT: ${{ env.ACT }} + - name: Run k6 foundations TS tests + run: ./scripts/run-tests.sh -t **/k6/foundations/*.ts -u http://localhost:3333 + env: + ACT: ${{ env.ACT }} + - name: Run k6 internal tests run: ./scripts/run-tests.sh -t **/k6/internal/*.js -u http://localhost:3333 env: