From 2e10f2712149cee5cc6797a607598e57fa510a61 Mon Sep 17 00:00:00 2001 From: Oscar Reyes Date: Wed, 14 Aug 2024 15:32:47 -0600 Subject: [PATCH] updating tyk example (#3968) * updating tyk example * updating tyk recipe --- ...vices-with-tyk-opentelemetry-tracetest.mdx | 254 ++++---- examples/quick-start-tyk/.env.template | 7 +- examples/quick-start-tyk/Dockerfile.tracetest | 11 + ...docker-compose.yml => docker-compose.yaml} | 61 +- .../otel-collector => }/otel-collector.yml | 6 +- examples/quick-start-tyk/package-lock.json | 545 ------------------ examples/quick-start-tyk/package.json | 23 - examples/quick-start-tyk/playwright.config.ts | 41 -- examples/quick-start-tyk/playwright/auth.ts | 34 -- .../quick-start-tyk/playwright/home.spec.ts | 37 -- examples/quick-start-tyk/resources/apply.sh | 17 + .../quick-start-tyk/resources/datastore.yaml | 12 + examples/quick-start-tyk/resources/run.sh | 16 + examples/quick-start-tyk/resources/script.js | 58 ++ examples/quick-start-tyk/resources/test.yaml | 29 + examples/quick-start-tyk/tsconfig.json | 10 - 16 files changed, 321 insertions(+), 840 deletions(-) create mode 100644 examples/quick-start-tyk/Dockerfile.tracetest rename examples/quick-start-tyk/{docker-compose.yml => docker-compose.yaml} (75%) rename examples/quick-start-tyk/{deployments/otel-collector => }/otel-collector.yml (86%) delete mode 100644 examples/quick-start-tyk/package-lock.json delete mode 100644 examples/quick-start-tyk/package.json delete mode 100644 examples/quick-start-tyk/playwright.config.ts delete mode 100644 examples/quick-start-tyk/playwright/auth.ts delete mode 100644 examples/quick-start-tyk/playwright/home.spec.ts create mode 100644 examples/quick-start-tyk/resources/apply.sh create mode 100644 examples/quick-start-tyk/resources/datastore.yaml create mode 100644 examples/quick-start-tyk/resources/run.sh create mode 100644 examples/quick-start-tyk/resources/script.js create mode 100644 examples/quick-start-tyk/resources/test.yaml delete mode 100644 examples/quick-start-tyk/tsconfig.json diff --git a/docs/docs/examples-tutorials/recipes/testing-distributed-services-with-tyk-opentelemetry-tracetest.mdx b/docs/docs/examples-tutorials/recipes/testing-distributed-services-with-tyk-opentelemetry-tracetest.mdx index 0241bc96a6..bd1a6b7fd7 100644 --- a/docs/docs/examples-tutorials/recipes/testing-distributed-services-with-tyk-opentelemetry-tracetest.mdx +++ b/docs/docs/examples-tutorials/recipes/testing-distributed-services-with-tyk-opentelemetry-tracetest.mdx @@ -50,11 +50,10 @@ cd tracetest/examples/quick-start-tyk **Tracetest Account**: -- Copy the `.env.template` file to `.env`. -- Log into **the** [Tracetest app](https://app.tracetest.io/). -- This example is configured to use the OpenTelemetry Collector. Ensure the environment you will be utilizing to run this example is also configured to use the OpenTelemetry Tracing Backend by clicking on Settings, Tracing Backend, OpenTelemetry, and Save. -- Configure your environment to use [the agent](https://docs.tracetest.io/concepts/agent), then click the Settings link, and from the Agent tab select the "Run Agent Locally" option. -- Fill out the [token](https://docs.tracetest.io/concepts/environment-tokens) and [agent api key](https://docs.tracetest.io/concepts/agent) details by editing your .env file. You can find these values in the Settings area for your environment. +- Sign up to [`app.tracetest.io`](https://app.tracetest.io) or follow the [get started](/getting-started/installation) docs. +- Have access to the environment's [agent API key](https://app.tracetest.io/retrieve-token). + +**Docker**: Have [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/) installed on your machine. ## Project Structure @@ -111,30 +110,49 @@ You can find the Tyk Gateway apps and configuration in the `deployments/tyk-gate The tracetest setup is composed by the `tracetest-e2e` and the `tracetest-agent` services under the `docker-compose.yml` file. ```yaml title=docker-compose.yml -# Tracetest x Playwright -tracetest-e2e: - build: . - command: npm test +# Cloud-based Managed Tracetest +tracetest-agent: + image: kubeshop/tracetest-agent:latest environment: - - POKESHOP_DEMO_URL=${POKESHOP_DEMO_URL} - - TRACETEST_API_TOKEN=${TRACETEST_API_TOKEN} - - TYK_AUTH_KEY=${TYK_AUTH_KEY} + # Get the required information here: https://app.tracetest.io/retrieve-token + - TRACETEST_API_KEY=${TRACETEST_TOKEN} + - TRACETEST_ENVIRONMENT_ID=${TRACETEST_ENVIRONMENT_ID} + +tracetest-apply: + build: + dockerfile: Dockerfile.tracetest + volumes: + - ./resources:/resources + environment: + TRACETEST_TOKEN: ${TRACETEST_TOKEN} + TRACETEST_ENVIRONMENT_ID: ${TRACETEST_ENVIRONMENT_ID} + entrypoint: + - bash + - /resources/apply.sh + networks: + default: null depends_on: - tracetest-agent: - condition: service_started api: - condition: service_healthy - worker: condition: service_started - tyk-gateway: + tracetest-agent: condition: service_started -tracetest-agent: +tracetest-run: + build: + dockerfile: Dockerfile.tracetest + volumes: + - ./resources:/resources environment: - TRACETEST_DEV: ${TRACETEST_DEV} - TRACETEST_API_KEY: ${TRACETEST_AGENT_API_KEY} - TRACETEST_SERVER_URL: ${TRACETEST_SERVER_URL} - image: kubeshop/tracetest-agent:latest + TRACETEST_TOKEN: ${TRACETEST_TOKEN} + TRACETEST_ENVIRONMENT_ID: ${TRACETEST_ENVIRONMENT_ID} + entrypoint: + - bash + - /resources/run.sh + networks: + default: null + depends_on: + tracetest-apply: + condition: service_completed_successfully ``` ### 3. Services under Test @@ -223,137 +241,121 @@ worker: Copy the `.env.template` and create a `.env` file in the same directory. Add token and Cloud Agent endpoint. ```txt title=.env -TRACETEST_API_TOKEN= -TRACETEST_AGENT_API_KEY= +# Get the required information here: https://app.tracetest.io/retrieve-token + +TRACETEST_TOKEN="" +TRACETEST_ENVIRONMENT_ID="" + POKESHOP_DEMO_URL=http://tyk-gateway:8080 TYK_AUTH_KEY=28d220fd77974a4facfb07dc1e49c2aa - ``` ## The Tracetest End To End Script -The `playwright/home.spec.ts` file contains the script that will execute the trace-based tests against the Pokeshop App proxied by a Tyk endpoint. +The `resources/script.js` file contains the script that will execute the trace-based tests against the Pokeshop App proxied by a Tyk endpoint. ### Steps Executed by the Script 1. Create a new key in the Tyk Gateway. -2. Create a new test definition in Tracetest (using the async import service from the Pokeshop Demo). -3. Run the Playwright Test. -4. Report back the results. - -```typescript title=playwright/home.spec.ts -import { test, expect } from "@playwright/test"; -import { getKey } from "./auth"; -import Tracetest, { Types } from "@tracetest/playwright"; - -const { TRACETEST_API_TOKEN = "" } = process.env; - -let tracetest: Types.TracetestPlaywright | undefined = undefined; - -test.describe.configure({ mode: "serial" }); - -const definition = ` -type: Test -spec: - id: UGxheXdyaWdodDogaW1wb3J0cyBhIHBva2Vtb24= - name: "Playwright: imports a pokemon" - trigger: - type: playwright - specs: - - selector: span[tracetest.span.type="http"] span[tracetest.span.type="http"] - name: "All HTTP Spans: Status code is 200" - assertions: - - attr:http.status_code = 200 - - selector: span[tracetest.span.type="database"] - name: "All Database Spans: Processing time is less than 100ms" - assertions: - - attr:tracetest.span.duration < 2s - outputs: - - name: MY_OUTPUT - selector: span[tracetest.span.type="general" name="Tracetest trigger"] - value: attr:name -`; - -test.beforeAll(async () => { - tracetest = await Tracetest({ apiToken: TRACETEST_API_TOKEN }); - - await tracetest.setOptions({ - "Playwright: imports a pokemon": { - definition, +3. Import a Pokemon. + +```typescript title=resources/script.js +const { expect } = require('@playwright/test'); + +const URL = 'http://tyk-gateway:8080'; +const API_KEY = '28d220fd77974a4facfb07dc1e49c2aa'; + +const getKey = async () => { + const params = { + headers: { + 'Content-Type': 'application/json', + 'x-tyk-authorization': API_KEY, + 'Response-Type': 'application/json', + }, + }; + + const data = { + alias: 'website', + expires: -1, + access_rights: { + 1: { + api_id: '1', + api_name: 'pokeshop', + versions: ['Default'], + }, }, + }; + + const res = await fetch(`${URL}/tyk/keys/create`, { + ...params, + method: 'POST', + body: JSON.stringify(data), }); -}); -test.beforeEach(async ({ page, context }, { title }) => { - // sets the auth headers for the page requests + const { key } = await res.json(); + + return key; +}; + +async function importPokemon(page) { const key = await getKey(); - await context.setExtraHTTPHeaders({ + + await page.setExtraHTTPHeaders({ Authorization: `Bearer ${key}`, }); - await page.goto("/"); - await tracetest?.capture(title, page); -}); + await page.goto(URL); -// optional step to break the playwright script in case a Tracetest test fails -test.afterAll(async ({}, testInfo) => { - testInfo.setTimeout(80000); - await tracetest?.summary(); -}); + expect(await page.getByText('Pokeshop')).toBeTruthy(); -test("Playwright: imports a pokemon", async ({ page }) => { - expect(await page.getByText("Pokeshop")).toBeTruthy(); + await page.click('text=Import'); + await page.getByLabel('ID').fill('143'); - await page.click("text=Import"); + await Promise.all([ + page.waitForResponse((resp) => resp.url().includes('/pokemon/import') && resp.status() === 200), + page.getByRole('button', { name: 'OK', exact: true }).click(), + ]); +} - await page.getByLabel("ID").fill(Math.floor(Math.random() * 101).toString()); - await page.getByRole("button", { name: "OK", exact: true }).click(); -}); +module.exports = { importPokemon }; ``` The output from the Playwright tests will show the test results with links to the Tracetest App. ```bash title=Terminal -WARN[0000] The "TRACETEST_SERVER_URL" variable is not set. Defaulting to a blank string. [+] Running 2/2 - ✔ worker Pulled 1.1s - ✔ api Pulled 1.1s -[+] Creating 9/0 - ✔ Container quick-start-tyk-tyk-redis-1 Running 0.0s - ✔ Container quick-start-tyk-otel-collector-1 Running 0.0s - ✔ Container quick-start-tyk-cache-1 Running 0.0s - ✔ Container quick-start-tyk-queue-1 Running 0.0s - ✔ Container quick-start-tyk-tracetest-agent-1 Running 0.0s - ✔ Container quick-start-tyk-postgres-1 Running 0.0s - ✔ Container quick-start-tyk-tyk-gateway-1 Running 0.0s - ✔ Container quick-start-tyk-worker-1 Running 0.0s - ✔ Container quick-start-tyk-api-1 Running 0.0s -[+] Running 3/3 - ✔ Container quick-start-tyk-postgres-1 Healthy 0.5s - ✔ Container quick-start-tyk-cache-1 Healthy 0.5s - ✔ Container quick-start-tyk-queue-1 Healthy 0.5s + ✔ worker Pulled 0.9s + ✔ api Pulled 0.8s +[+] Creating 8/0 + ✔ Container quick-start-tyk-tracetest-agent-1 Running 0.0s + ✔ Container quick-start-tyk-postgres-1 Running 0.0s + ✔ Container quick-start-tyk-jaeger-1 Running 0.0s + ✔ Container quick-start-tyk-tyk-redis-1 Running 0.0s + ✔ Container quick-start-tyk-cache-1 Running 0.0s + ✔ Container quick-start-tyk-otel-collector-1 Running 0.0s + ✔ Container quick-start-tyk-queue-1 Running 0.0s + ✔ Container quick-start-tyk-tyk-gateway-1 Running 0.0s +[+] Running 7/7 + ✔ Container quick-start-tyk-jaeger-1 Healthy 0.5s + ✔ Container quick-start-tyk-postgres-1 Healthy 3.2s + ✔ Container quick-start-tyk-cache-1 Healthy 3.2s + ✔ Container quick-start-tyk-queue-1 Healthy 3.2s + ✔ Container quick-start-tyk-worker-1 Started 0.2s + ✔ Container quick-start-tyk-api-1 Started 0.1s + ✔ Container quick-start-tyk-tracetest-apply-1 Started 0.2s [+] Running 2/2 - ✔ worker Pulled 1.2s - ✔ api Pulled 1.1s - -> quick-start-tyk@1.0.0 test -> playwright test - - -Running 1 test using 1 worker -[chromium] › home.spec.ts:59:5 › Playwright: imports a pokemon - -Successful: 1 -Failed: 0 - -[✔️ Playwright: imports a pokemon] #20 - https://app.tracetest.io/organizations//environments//test/UGxheXdyaWdodDogaW1wb3J0cyBhIHBva2Vtb24=/run/20 - - 1 passed (14.1s) - -To open last HTML report run: - - npx playwright show-report - + ✔ api Pulled 0.8s + ✔ worker Pulled 0.8s +Configuring Tracetest + SUCCESS Successfully configured Tracetest CLI +Running Trace-Based Tests... +✔ RunGroup: #QMjWZ5jIR (https://app.tracetest.io/organizations/ttorg_ced62e34638d965e/environments/ttenv_b42fa137465c6e04/run/QMjWZ5jIR) + Summary: 1 passed, 0 failed, 0 pending + ✔ Import Pokemon (https://app.tracetest.io/organizations/ttorg_ced62e34638d965e/environments/ttenv_b42fa137465c6e04/test/4_IKfPlIg/run/13/test) - trace id: 1554d5d5904daa17f2a6854a7d7608e5 + ✔ Import should return 200 + ✔ All Database Spans: Processing time is less than 1s + ✔ Import Pokemon Span Should be Present + ✔ Redis should return in 20ms ``` ### Tracetest App Results @@ -365,7 +367,7 @@ To open last HTML report run: Spin up the deployment and test execution. ```bash title=Terminal -docker-compose run tracetest-e2e +docker-compose run tracetest-run ``` This will trigger the Docker Compose setup and immediately run the [trace-based tests using the Tracetest Playwright integration](../../tools-and-integrations/playwright.mdx) as part of the `tracetest-e2e` service. diff --git a/examples/quick-start-tyk/.env.template b/examples/quick-start-tyk/.env.template index ba37b6b2c9..6df15f397e 100644 --- a/examples/quick-start-tyk/.env.template +++ b/examples/quick-start-tyk/.env.template @@ -1,4 +1,7 @@ -TRACETEST_API_TOKEN= -TRACETEST_AGENT_API_KEY= +# Get the required information here: https://app.tracetest.io/retrieve-token + +TRACETEST_TOKEN="" +TRACETEST_ENVIRONMENT_ID="" + POKESHOP_DEMO_URL=http://tyk-gateway:8080 TYK_AUTH_KEY=28d220fd77974a4facfb07dc1e49c2aa diff --git a/examples/quick-start-tyk/Dockerfile.tracetest b/examples/quick-start-tyk/Dockerfile.tracetest new file mode 100644 index 0000000000..883f239155 --- /dev/null +++ b/examples/quick-start-tyk/Dockerfile.tracetest @@ -0,0 +1,11 @@ +FROM alpine + +WORKDIR /app +ARG TRACETEST_IMAGE_VERSION=v1.4.0 + +RUN apk --update add bash jq curl +RUN curl -L https://raw.githubusercontent.com/kubeshop/tracetest/main/install-cli.sh | bash -s -- $TRACETEST_IMAGE_VERSION + +WORKDIR /resources + +ENTRYPOINT ["echo", "Tracetest CLI installed"] diff --git a/examples/quick-start-tyk/docker-compose.yml b/examples/quick-start-tyk/docker-compose.yaml similarity index 75% rename from examples/quick-start-tyk/docker-compose.yml rename to examples/quick-start-tyk/docker-compose.yaml index f51793f964..37f781a43f 100755 --- a/examples/quick-start-tyk/docker-compose.yml +++ b/examples/quick-start-tyk/docker-compose.yaml @@ -1,29 +1,48 @@ version: '3.3' services: - # Tracetest x Playwright - tracetest-e2e: - build: . - command: npm test + # Cloud-based Managed Tracetest + tracetest-agent: + image: kubeshop/tracetest-agent:latest environment: - - POKESHOP_DEMO_URL=${POKESHOP_DEMO_URL} - - TRACETEST_API_TOKEN=${TRACETEST_API_TOKEN} - - TYK_AUTH_KEY=${TYK_AUTH_KEY} + # Get the required information here: https://app.tracetest.io/retrieve-token + - TRACETEST_API_KEY=${TRACETEST_TOKEN} + - TRACETEST_ENVIRONMENT_ID=${TRACETEST_ENVIRONMENT_ID} + + tracetest-apply: + build: + dockerfile: Dockerfile.tracetest + volumes: + - ./resources:/resources + environment: + TRACETEST_TOKEN: ${TRACETEST_TOKEN} + TRACETEST_ENVIRONMENT_ID: ${TRACETEST_ENVIRONMENT_ID} + entrypoint: + - bash + - /resources/apply.sh + networks: + default: null depends_on: - tracetest-agent: - condition: service_started api: - condition: service_healthy - worker: condition: service_started - tyk-gateway: + tracetest-agent: condition: service_started - tracetest-agent: + tracetest-run: + build: + dockerfile: Dockerfile.tracetest + volumes: + - ./resources:/resources environment: - TRACETEST_DEV: ${TRACETEST_DEV} - TRACETEST_API_KEY: ${TRACETEST_AGENT_API_KEY} - TRACETEST_SERVER_URL: ${TRACETEST_SERVER_URL} - image: kubeshop/tracetest-agent:latest + TRACETEST_TOKEN: ${TRACETEST_TOKEN} + TRACETEST_ENVIRONMENT_ID: ${TRACETEST_ENVIRONMENT_ID} + entrypoint: + - bash + - /resources/run.sh + networks: + default: null + depends_on: + tracetest-apply: + condition: service_completed_successfully # Tyk Gateway tyk-gateway: @@ -96,6 +115,10 @@ services: ports: - 8081:8081 depends_on: + tyk-gateway: + condition: service_started + worker: + condition: service_started postgres: condition: service_healthy cache: @@ -126,9 +149,9 @@ services: # Collector otel-collector: - image: otel/opentelemetry-collector-contrib:0.59.0 + image: otel/opentelemetry-collector-contrib:0.100.0 volumes: - - ./deployments/otel-collector/otel-collector.yml:/etc/otel-collector.yml + - ./otel-collector.yml:/etc/otel-collector.yml command: ['--config=/etc/otel-collector.yml'] ports: - 4318:4318 diff --git a/examples/quick-start-tyk/deployments/otel-collector/otel-collector.yml b/examples/quick-start-tyk/otel-collector.yml similarity index 86% rename from examples/quick-start-tyk/deployments/otel-collector/otel-collector.yml rename to examples/quick-start-tyk/otel-collector.yml index 0290489168..88bf3ef5fb 100644 --- a/examples/quick-start-tyk/deployments/otel-collector/otel-collector.yml +++ b/examples/quick-start-tyk/otel-collector.yml @@ -12,8 +12,8 @@ processors: batch: exporters: - jaeger: - endpoint: jaeger:14250 + otlp/jaeger: + endpoint: jaeger:4317 tls: insecure: true otlp: @@ -26,7 +26,7 @@ service: traces: receivers: [otlp] processors: [] - exporters: [jaeger] + exporters: [otlp/jaeger] traces/1: receivers: [otlp] processors: [batch] diff --git a/examples/quick-start-tyk/package-lock.json b/examples/quick-start-tyk/package-lock.json deleted file mode 100644 index c9aa8c3873..0000000000 --- a/examples/quick-start-tyk/package-lock.json +++ /dev/null @@ -1,545 +0,0 @@ -{ - "name": "quick-start-tyk", - "version": "1.0.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "quick-start-tyk", - "version": "1.0.0", - "license": "ISC", - "dependencies": { - "node-fetch": "^2.7.0" - }, - "devDependencies": { - "@playwright/test": "^1.41.2", - "@tracetest/playwright": "^0.0.37", - "@types/node": "^20.11.20", - "@types/node-fetch": "^2.6.11", - "dotenv": "^16.4.5" - } - }, - "node_modules/@playwright/test": { - "version": "1.41.2", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.41.2.tgz", - "integrity": "sha512-qQB9h7KbibJzrDpkXkYvsmiDJK14FULCCZgEcoe2AvFAS64oCirWTwzTlAYEbKaRxWs5TFesE1Na6izMv3HfGg==", - "dev": true, - "dependencies": { - "playwright": "1.41.2" - }, - "bin": { - "playwright": "cli.js" - }, - "engines": { - "node": ">=16" - } - }, - "node_modules/@tracetest/client": { - "version": "0.0.37", - "resolved": "https://registry.npmjs.org/@tracetest/client/-/client-0.0.37.tgz", - "integrity": "sha512-I7VoiUEwm4NwbKOj+k5tV1j6mtdk/oDdrIiVzRa8kl+nSWILw6ks2yDQNsOs3YJxwmSLLZkueAEwZiqhZEp3QQ==", - "dev": true, - "dependencies": { - "axios": "^1.6.7", - "env-ci": "^11.0.0", - "js-yaml": "^4.1.0", - "tsimportlib": "^0.0.5", - "uuid": "^9.0.1" - } - }, - "node_modules/@tracetest/playwright": { - "version": "0.0.37", - "resolved": "https://registry.npmjs.org/@tracetest/playwright/-/playwright-0.0.37.tgz", - "integrity": "sha512-OHLCFWSVVf3nUsta97jcYnUY02F1V1PGXI/eNSpy224gAxh/D9/U6x8+JvUbSjRuPT5rkm6Z8fIummXYPhGw4g==", - "dev": true, - "dependencies": { - "@tracetest/client": "^0.0.37" - }, - "peerDependencies": { - "@playwright/test": "^1.41.1" - } - }, - "node_modules/@types/node": { - "version": "20.11.20", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.20.tgz", - "integrity": "sha512-7/rR21OS+fq8IyHTgtLkDK949uzsa6n8BkziAKtPVpugIkO6D+/ooXMvzXxDnZrmtXVfjb1bKQafYpb8s89LOg==", - "dev": true, - "dependencies": { - "undici-types": "~5.26.4" - } - }, - "node_modules/@types/node-fetch": { - "version": "2.6.11", - "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.11.tgz", - "integrity": "sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==", - "dev": true, - "dependencies": { - "@types/node": "*", - "form-data": "^4.0.0" - } - }, - "node_modules/argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true - }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true - }, - "node_modules/axios": { - "version": "1.6.8", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", - "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", - "dev": true, - "dependencies": { - "follow-redirects": "^1.15.6", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", - "dev": true, - "dependencies": { - "path-key": "^3.1.0", - "shebang-command": "^2.0.0", - "which": "^2.0.1" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "dev": true, - "engines": { - "node": ">=0.4.0" - } - }, - "node_modules/dotenv": { - "version": "16.4.5", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", - "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", - "dev": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://dotenvx.com" - } - }, - "node_modules/env-ci": { - "version": "11.0.0", - "resolved": "https://registry.npmjs.org/env-ci/-/env-ci-11.0.0.tgz", - "integrity": "sha512-apikxMgkipkgTvMdRT9MNqWx5VLOci79F4VBd7Op/7OPjjoanjdAvn6fglMCCEf/1bAh8eOiuEVCUs4V3qP3nQ==", - "dev": true, - "dependencies": { - "execa": "^8.0.0", - "java-properties": "^1.0.2" - }, - "engines": { - "node": "^18.17 || >=20.6.1" - } - }, - "node_modules/execa": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/execa/-/execa-8.0.1.tgz", - "integrity": "sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg==", - "dev": true, - "dependencies": { - "cross-spawn": "^7.0.3", - "get-stream": "^8.0.1", - "human-signals": "^5.0.0", - "is-stream": "^3.0.0", - "merge-stream": "^2.0.0", - "npm-run-path": "^5.1.0", - "onetime": "^6.0.0", - "signal-exit": "^4.1.0", - "strip-final-newline": "^3.0.0" - }, - "engines": { - "node": ">=16.17" - }, - "funding": { - "url": "https://github.com/sindresorhus/execa?sponsor=1" - } - }, - "node_modules/follow-redirects": { - "version": "1.15.6", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", - "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", - "dev": true, - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, - "node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dev": true, - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, - "node_modules/get-stream": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-8.0.1.tgz", - "integrity": "sha512-VaUJspBffn/LMCJVoMvSAdmscJyS1auj5Zulnn5UoYcY531UWmdwhRWkcGKnGU93m5HSXP9LP2usOryrBtQowA==", - "dev": true, - "engines": { - "node": ">=16" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/human-signals": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-5.0.0.tgz", - "integrity": "sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==", - "dev": true, - "engines": { - "node": ">=16.17.0" - } - }, - "node_modules/is-stream": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-3.0.0.tgz", - "integrity": "sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==", - "dev": true, - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/isexe": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", - "dev": true - }, - "node_modules/java-properties": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/java-properties/-/java-properties-1.0.2.tgz", - "integrity": "sha512-qjdpeo2yKlYTH7nFdK0vbZWuTCesk4o63v5iVOlhMQPfuIZQfW/HI35SjfhA+4qpg36rnFSvUK5b1m+ckIblQQ==", - "dev": true, - "engines": { - "node": ">= 0.6.0" - } - }, - "node_modules/js-yaml": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", - "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", - "dev": true, - "dependencies": { - "argparse": "^2.0.1" - }, - "bin": { - "js-yaml": "bin/js-yaml.js" - } - }, - "node_modules/merge-stream": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", - "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", - "dev": true - }, - "node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "dev": true, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "dev": true, - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mimic-fn": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", - "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==", - "dev": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/node-fetch": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", - "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", - "dependencies": { - "whatwg-url": "^5.0.0" - }, - "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } - } - }, - "node_modules/npm-run-path": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.3.0.tgz", - "integrity": "sha512-ppwTtiJZq0O/ai0z7yfudtBpWIoxM8yE6nHi1X47eFR2EWORqfbu6CnPlNsjeN683eT0qG6H/Pyf9fCcvjnnnQ==", - "dev": true, - "dependencies": { - "path-key": "^4.0.0" - }, - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/npm-run-path/node_modules/path-key": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-key/-/path-key-4.0.0.tgz", - "integrity": "sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==", - "dev": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/onetime": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/onetime/-/onetime-6.0.0.tgz", - "integrity": "sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==", - "dev": true, - "dependencies": { - "mimic-fn": "^4.0.0" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/path-key": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", - "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/playwright": { - "version": "1.41.2", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.41.2.tgz", - "integrity": "sha512-v0bOa6H2GJChDL8pAeLa/LZC4feoAMbSQm1/jF/ySsWWoaNItvrMP7GEkvEEFyCTUYKMxjQKaTSg5up7nR6/8A==", - "dev": true, - "dependencies": { - "playwright-core": "1.41.2" - }, - "bin": { - "playwright": "cli.js" - }, - "engines": { - "node": ">=16" - }, - "optionalDependencies": { - "fsevents": "2.3.2" - } - }, - "node_modules/playwright-core": { - "version": "1.41.2", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.41.2.tgz", - "integrity": "sha512-VaTvwCA4Y8kxEe+kfm2+uUUw5Lubf38RxF7FpBxLPmGe5sdNkSg5e3ChEigaGrX7qdqT3pt2m/98LiyvU2x6CA==", - "dev": true, - "bin": { - "playwright-core": "cli.js" - }, - "engines": { - "node": ">=16" - } - }, - "node_modules/proxy-from-env": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", - "dev": true - }, - "node_modules/shebang-command": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", - "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", - "dev": true, - "dependencies": { - "shebang-regex": "^3.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/shebang-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", - "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/signal-exit": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", - "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", - "dev": true, - "engines": { - "node": ">=14" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/strip-final-newline": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-3.0.0.tgz", - "integrity": "sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==", - "dev": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" - }, - "node_modules/tsimportlib": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/tsimportlib/-/tsimportlib-0.0.5.tgz", - "integrity": "sha512-qWQv/C3YB4Pwj77Z2HlORfy5EsWHcSYt66VQlMM0xZiKXwtoe1SxfpzmHX62sdJgzU6esrBGtyRIlx6O2OFPrQ==", - "dev": true - }, - "node_modules/undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", - "dev": true - }, - "node_modules/uuid": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", - "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", - "dev": true, - "funding": [ - "https://github.com/sponsors/broofa", - "https://github.com/sponsors/ctavan" - ], - "bin": { - "uuid": "dist/bin/uuid" - } - }, - "node_modules/webidl-conversions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" - }, - "node_modules/whatwg-url": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", - "dependencies": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" - } - }, - "node_modules/which": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", - "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", - "dev": true, - "dependencies": { - "isexe": "^2.0.0" - }, - "bin": { - "node-which": "bin/node-which" - }, - "engines": { - "node": ">= 8" - } - } - } -} diff --git a/examples/quick-start-tyk/package.json b/examples/quick-start-tyk/package.json deleted file mode 100644 index 4670b8ad88..0000000000 --- a/examples/quick-start-tyk/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "quick-start-tyk", - "version": "1.0.0", - "description": "## Quick Start", - "main": "index.js", - "scripts": { - "pw:open": "playwright test --ui", - "test": "playwright test" - }, - "keywords": [], - "author": "", - "license": "ISC", - "devDependencies": { - "@playwright/test": "^1.41.2", - "@tracetest/playwright": "^0.0.37", - "@types/node": "^20.11.20", - "@types/node-fetch": "^2.6.11", - "dotenv": "^16.4.5" - }, - "dependencies": { - "node-fetch": "^2.7.0" - } -} diff --git a/examples/quick-start-tyk/playwright.config.ts b/examples/quick-start-tyk/playwright.config.ts deleted file mode 100644 index a43bba6b1d..0000000000 --- a/examples/quick-start-tyk/playwright.config.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { defineConfig, devices } from '@playwright/test'; -require('dotenv').config(); - -/** - * See https://playwright.dev/docs/test-configuration. - */ -export default defineConfig({ - testDir: './playwright', - /* Run tests in files in parallel */ - fullyParallel: true, - /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, - /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: 'html', - /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ - use: { - /* Base URL to use in actions like `await page.goto('/')`. */ - // baseURL: 'http://127.0.0.1:3000', - baseURL: process.env.POKESHOP_DEMO_URL, - - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: 'on-first-retry', - }, - - /* Configure projects for major browsers */ - projects: [ - { - name: 'chromium', - use: { - ...devices['Desktop Chrome'], - launchOptions: { - args: ['--disable-web-security'], - }, - }, - }, - ], -}); diff --git a/examples/quick-start-tyk/playwright/auth.ts b/examples/quick-start-tyk/playwright/auth.ts deleted file mode 100644 index 5524572768..0000000000 --- a/examples/quick-start-tyk/playwright/auth.ts +++ /dev/null @@ -1,34 +0,0 @@ -import fetch from 'node-fetch'; -const { POKESHOP_DEMO_URL = '', TYK_AUTH_KEY = '' } = process.env; - -export const getKey = async () => { - const params = { - headers: { - 'Content-Type': 'application/json', - 'x-tyk-authorization': TYK_AUTH_KEY, - 'Response-Type': 'application/json', - }, - }; - - const data = { - alias: 'website', - expires: -1, - access_rights: { - 1: { - api_id: '1', - api_name: 'pokeshop', - versions: ['Default'], - }, - }, - }; - - const res = await fetch(`${POKESHOP_DEMO_URL}/tyk/keys/create`, { - ...params, - method: 'POST', - body: JSON.stringify(data), - }); - - const { key } = (await res.json()) as { key: string }; - - return key; -}; diff --git a/examples/quick-start-tyk/playwright/home.spec.ts b/examples/quick-start-tyk/playwright/home.spec.ts deleted file mode 100644 index 1c551cca6d..0000000000 --- a/examples/quick-start-tyk/playwright/home.spec.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { test, expect } from '@playwright/test'; -import { getKey } from './auth'; -import Tracetest, { Types } from '@tracetest/playwright'; - -const { TRACETEST_API_TOKEN = '' } = process.env; - -let tracetest: Types.TracetestPlaywright | undefined = undefined; - -test.beforeAll(async () => { - // 1: Create a new Tracetest instance - tracetest = await Tracetest({ apiToken: TRACETEST_API_TOKEN }); -}); - -test.beforeEach(async ({ page, context }, { title }) => { - const key = await getKey(); - await context.setExtraHTTPHeaders({ - Authorization: `Bearer ${key}`, - }); - - await page.goto('/'); - // 2: Capture the initial page - await tracetest?.capture(title, page); -}); - -test.afterAll(async ({}, testInfo) => { - // 3: Summary of the test (optional, but recommended) - await tracetest?.summary(); -}); - -test('Playwright: imports a pokemon', async ({ page }) => { - expect(await page.getByText('Pokeshop')).toBeTruthy(); - - await page.click('text=Import'); - - await page.getByLabel('ID').fill(Math.floor(Math.random() * 101).toString()); - await page.getByRole('button', { name: 'OK', exact: true }).click(); -}); diff --git a/examples/quick-start-tyk/resources/apply.sh b/examples/quick-start-tyk/resources/apply.sh new file mode 100644 index 0000000000..13b878ba47 --- /dev/null +++ b/examples/quick-start-tyk/resources/apply.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +set -e + +TOKEN=$TRACETEST_TOKEN +ENVIRONMENT_ID=$TRACETEST_ENVIRONMENT_ID + +apply() { + echo "Configuring TraceTest" + tracetest configure --token $TOKEN --environment $ENVIRONMENT_ID + + echo "Applying Resources" + tracetest apply datastore -f /resources/datastore.yaml + tracetest apply test -f /resources/test.yaml +} + +apply diff --git a/examples/quick-start-tyk/resources/datastore.yaml b/examples/quick-start-tyk/resources/datastore.yaml new file mode 100644 index 0000000000..72f8294fcd --- /dev/null +++ b/examples/quick-start-tyk/resources/datastore.yaml @@ -0,0 +1,12 @@ +type: DataStore +spec: + id: current + name: jaeger + type: jaeger + default: true + jaeger: + endpoint: jaeger:16685 + headers: + "": "" + tls: + insecure: true diff --git a/examples/quick-start-tyk/resources/run.sh b/examples/quick-start-tyk/resources/run.sh new file mode 100644 index 0000000000..05d0f41724 --- /dev/null +++ b/examples/quick-start-tyk/resources/run.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -e + +TOKEN=$TRACETEST_TOKEN +ENVIRONMENT_ID=$TRACETEST_ENVIRONMENT_ID + +run() { + echo "Configuring Tracetest" + tracetest configure --token $TOKEN --environment $ENVIRONMENT_ID + + echo "Running Trace-Based Tests..." + tracetest run test -f /resources/test.yaml +} + +run diff --git a/examples/quick-start-tyk/resources/script.js b/examples/quick-start-tyk/resources/script.js new file mode 100644 index 0000000000..5c93300510 --- /dev/null +++ b/examples/quick-start-tyk/resources/script.js @@ -0,0 +1,58 @@ +const { expect } = require('@playwright/test'); + +const URL = 'http://tyk-gateway:8080'; +const API_KEY = '28d220fd77974a4facfb07dc1e49c2aa'; + +const getKey = async () => { + const params = { + headers: { + 'Content-Type': 'application/json', + 'x-tyk-authorization': API_KEY, + 'Response-Type': 'application/json', + }, + }; + + const data = { + alias: 'website', + expires: -1, + access_rights: { + 1: { + api_id: '1', + api_name: 'pokeshop', + versions: ['Default'], + }, + }, + }; + + const res = await fetch(`${URL}/tyk/keys/create`, { + ...params, + method: 'POST', + body: JSON.stringify(data), + }); + + const { key } = await res.json(); + + return key; +}; + +async function importPokemon(page) { + const key = await getKey(); + + await page.setExtraHTTPHeaders({ + Authorization: `Bearer ${key}`, + }); + + await page.goto(URL); + + expect(await page.getByText('Pokeshop')).toBeTruthy(); + + await page.click('text=Import'); + await page.getByLabel('ID').fill('143'); + + await Promise.all([ + page.waitForResponse((resp) => resp.url().includes('/pokemon/import') && resp.status() === 200), + page.getByRole('button', { name: 'OK', exact: true }).click(), + ]); +} + +module.exports = { importPokemon }; diff --git a/examples/quick-start-tyk/resources/test.yaml b/examples/quick-start-tyk/resources/test.yaml new file mode 100644 index 0000000000..b9e9b20eb2 --- /dev/null +++ b/examples/quick-start-tyk/resources/test.yaml @@ -0,0 +1,29 @@ +type: Test +spec: + id: 4_IKfPlIg + name: Import Pokemon + trigger: + type: "playwrightengine" + playwrightEngine: + target: http://tyk-gateway:8080 + script: script.js + method: importPokemon + specs: + - selector: span[tracetest.span.type="http" name="POST /pokemon/import" + http.method="POST"] + name: Import should return 200 + assertions: + - attr:http.status_code = 200 + - selector: span[tracetest.span.type="database"] + name: "All Database Spans: Processing time is less than 1s" + assertions: + - attr:tracetest.span.duration < 1s + - selector: span[tracetest.span.type="general" name="import pokemon"] + name: Import Pokemon Span Should be Present + assertions: + - attr:tracetest.selected_spans.count = 1 + - selector: span[tracetest.span.type="database" name="get pokemon_143" + db.system="redis" db.operation="get" db.redis.database_index="0"] + name: Redis should return in 20ms + assertions: + - attr:tracetest.span.duration < 20ms diff --git a/examples/quick-start-tyk/tsconfig.json b/examples/quick-start-tyk/tsconfig.json deleted file mode 100644 index 3ffa57bad5..0000000000 --- a/examples/quick-start-tyk/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "compilerOptions": { - "target": "es2016", - "module": "commonjs", - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "strict": true, - "skipLibCheck": true - } -}