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

chore(examples/docs): Updating the Tyk Example with E2E Tests #3698

Merged
merged 1 commit into from Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
@@ -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
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