From 380ec1ea6a6d48b7600c7ca8392a6038618e08ad Mon Sep 17 00:00:00 2001 From: Oscar Reyes Date: Fri, 1 Mar 2024 10:24:48 -0600 Subject: [PATCH] chore(examples/docs): Updating the Tyk Example with E2E Tests (#3698) --- examples/quick-start-tyk/package-lock.json | 52 +++++++++++++++++++ examples/quick-start-tyk/package.json | 4 ++ examples/quick-start-tyk/playwright/auth.ts | 3 +- .../quick-start-tyk/playwright/home.spec.ts | 35 ++----------- 4 files changed, 61 insertions(+), 33 deletions(-) diff --git a/examples/quick-start-tyk/package-lock.json b/examples/quick-start-tyk/package-lock.json index 8e7c64235a..34fed7b8e9 100644 --- a/examples/quick-start-tyk/package-lock.json +++ b/examples/quick-start-tyk/package-lock.json @@ -8,10 +8,14 @@ "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.30", "@types/node": "^20.11.20", + "@types/node-fetch": "^2.6.11", "dotenv": "^16.4.5" } }, @@ -61,6 +65,16 @@ "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", @@ -198,6 +212,25 @@ "node": ">= 0.6" } }, + "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/playwright": { "version": "1.41.2", "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.41.2.tgz", @@ -234,11 +267,30 @@ "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", "dev": true }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, "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/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" + } } } } diff --git a/examples/quick-start-tyk/package.json b/examples/quick-start-tyk/package.json index 261d3f8541..6fc51db8d0 100644 --- a/examples/quick-start-tyk/package.json +++ b/examples/quick-start-tyk/package.json @@ -14,6 +14,10 @@ "@playwright/test": "^1.41.2", "@tracetest/playwright": "^0.0.30", "@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/auth.ts b/examples/quick-start-tyk/playwright/auth.ts index 379754a183..5524572768 100644 --- a/examples/quick-start-tyk/playwright/auth.ts +++ b/examples/quick-start-tyk/playwright/auth.ts @@ -1,4 +1,5 @@ -const { POKESHOP_DEMO_URL = '', TYK_AUTH_KEY = '' } = process.env; +import fetch from 'node-fetch'; +const { POKESHOP_DEMO_URL = '', TYK_AUTH_KEY = '' } = process.env; export const getKey = async () => { const params = { diff --git a/examples/quick-start-tyk/playwright/home.spec.ts b/examples/quick-start-tyk/playwright/home.spec.ts index 5b923293d9..1c551cca6d 100644 --- a/examples/quick-start-tyk/playwright/home.spec.ts +++ b/examples/quick-start-tyk/playwright/home.spec.ts @@ -6,38 +6,9 @@ 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 () => { + // 1: Create a new Tracetest instance tracetest = await Tracetest({ apiToken: TRACETEST_API_TOKEN }); - - await tracetest.setOptions({ - 'Playwright: imports a pokemon': { - definition, - }, - }); }); test.beforeEach(async ({ page, context }, { title }) => { @@ -47,12 +18,12 @@ test.beforeEach(async ({ page, context }, { title }) => { }); await page.goto('/'); + // 2: Capture the initial page await tracetest?.capture(title, page); }); -// optional step to break the playwright script in case a Tracetest test fails test.afterAll(async ({}, testInfo) => { - testInfo.setTimeout(80000); + // 3: Summary of the test (optional, but recommended) await tracetest?.summary(); });