Skip to content

Commit

Permalink
chore(examples/docs): Updating the Tyk Example with E2E Tests (#3698)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoscar authored Mar 1, 2024
1 parent 96200e1 commit 380ec1e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 33 deletions.
52 changes: 52 additions & 0 deletions examples/quick-start-tyk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions examples/quick-start-tyk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
3 changes: 2 additions & 1 deletion examples/quick-start-tyk/playwright/auth.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
35 changes: 3 additions & 32 deletions examples/quick-start-tyk/playwright/home.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand All @@ -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();
});

Expand Down

0 comments on commit 380ec1e

Please sign in to comment.