diff --git a/collector.config.yaml b/collector.config.yaml index 789109d..56512ae 100644 --- a/collector.config.yaml +++ b/collector.config.yaml @@ -18,6 +18,10 @@ exporters: endpoint: ${JAEGER_ENDPOINT} tls: insecure: true + otlp/trace: + endpoint: tracetest-agent:4317 + tls: + insecure: true service: pipelines: @@ -25,3 +29,7 @@ service: receivers: [otlp] processors: [] exporters: [logging, jaeger] + traces/1: + receivers: [otlp] + processors: [batch] + exporters: [otlp/trace] diff --git a/cypress/e2e/1-getting-started/home.cy.ts b/cypress/e2e/1-getting-started/home.cy.ts index 5e6268a..5374513 100644 --- a/cypress/e2e/1-getting-started/home.cy.ts +++ b/cypress/e2e/1-getting-started/home.cy.ts @@ -1,12 +1,43 @@ -import Tracetest from '@tracetest/cypress'; +import Tracetest, { Types } from '@tracetest/cypress'; const TRACETEST_API_TOKEN = Cypress.env('TRACETEST_API_TOKEN') || ''; -const tracetest = Tracetest(); +let tracetest: Types.TracetestCypress | undefined = undefined; + +const definition = ` + type: Test + spec: + id: aW1wb3J0cyBhIHBva2Vtb24= + name: imports a pokemon + trigger: + type: cypress + 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 + `; describe('Home', { defaultCommandTimeout: 60000 }, () => { before(done => { - tracetest.configure(TRACETEST_API_TOKEN).then(() => done()); + Tracetest({ apiToken: TRACETEST_API_TOKEN }).then(instance => { + tracetest = instance; + tracetest + .setOptions({ + 'imports a pokemon': { + definition, + }, + }) + .then(() => done()); + }); }); beforeEach(() => { @@ -15,11 +46,6 @@ describe('Home', { defaultCommandTimeout: 60000 }, () => { }); }); - afterEach(done => { - const definition = Cypress.env('definition') || ''; - tracetest.runTest(definition).then(() => done()); - }); - // uncomment to wait for trace tests to be done after(done => { tracetest.summary().then(() => done()); @@ -35,29 +61,7 @@ describe('Home', { defaultCommandTimeout: 60000 }, () => { cy.get('button').contains('OK').click(); }); - const definition = ` - type: Test - spec: - id: aW1wb3J0cyBhIHBva2Vtb24= - name: imports a pokemon - trigger: - type: cypress - 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 - `; - - it('imports a pokemon', { env: { definition } }, () => { + it('imports a pokemon', () => { cy.get('[data-cy="import-pokemon-button"]').click(); cy.get('[data-cy="import-pokemon-form"]').should('be.visible'); diff --git a/package-lock.json b/package-lock.json index 241d4c4..fe011f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,8 +10,8 @@ "license": "ISC", "dependencies": { "@opentelemetry/sdk-trace-base": "^1.18.1", - "@tracetest/cypress": "^0.0.21", - "@tracetest/playwright": "0.0.21" + "@tracetest/cypress": "^0.0.22", + "@tracetest/playwright": "0.0.22" }, "devDependencies": { "@mermaid-js/mermaid-cli": "^10.6.1", @@ -573,9 +573,9 @@ "dev": true }, "node_modules/@tracetest/core": { - "version": "0.0.21", - "resolved": "https://registry.npmjs.org/@tracetest/core/-/core-0.0.21.tgz", - "integrity": "sha512-2zx00cuN+aD5aeTivmvMBfmPLd6Uaj/fC0mrh1DXZyRcnik0uoOdfYXeHMBupqX2PPT2vl8wRVRBz1oDfs0UGg==", + "version": "0.0.22", + "resolved": "https://registry.npmjs.org/@tracetest/core/-/core-0.0.22.tgz", + "integrity": "sha512-jZbjCVTehn0Mi9bGkNdjvBxibroJNpUuqBh9J0zTkiE5Q+8Wzv5xP6F05NSuADhtJhw9P6G/+SIvjxDM4/ATSA==", "dependencies": { "js-yaml": "^4.1.0" }, @@ -584,19 +584,19 @@ } }, "node_modules/@tracetest/cypress": { - "version": "0.0.21", - "resolved": "https://registry.npmjs.org/@tracetest/cypress/-/cypress-0.0.21.tgz", - "integrity": "sha512-W4xeac6KumqE7QVE9eOLINdvE/tLHPeyuapCOyLEurU4ozCLtZz6ZZrz6P33P48Wpfi5ZcnhS0curzsl7J/7yA==", + "version": "0.0.22", + "resolved": "https://registry.npmjs.org/@tracetest/cypress/-/cypress-0.0.22.tgz", + "integrity": "sha512-r52KYVKUoGGkHg+Z1wX0JnqnF4Q7DSmwXRi2BkIXmk5f3S6HJVQL+ZfBQFs3XdrixvWVSg2ACUstzvCQT4766A==", "dependencies": { - "@tracetest/core": "^0.0.21" + "@tracetest/core": "^0.0.22" } }, "node_modules/@tracetest/playwright": { - "version": "0.0.21", - "resolved": "https://registry.npmjs.org/@tracetest/playwright/-/playwright-0.0.21.tgz", - "integrity": "sha512-eL4uVrtaEEX8TjmCCUw7SOO7ZYfos4aVUbC2u20qXzbbZQlFjaxXnf5G64b2HdrxEkVU9Ps/n5958PotMWr1OA==", + "version": "0.0.22", + "resolved": "https://registry.npmjs.org/@tracetest/playwright/-/playwright-0.0.22.tgz", + "integrity": "sha512-sP/wuCWsBTaFj6tFBBUKxqM1eyfWrQl+a7wV8ghnfdqRFDl8Y6Pe2dVZy6Pi2lBMbpwknxAaB6sAsfI9Xuwv0g==", "dependencies": { - "@tracetest/core": "^0.0.21" + "@tracetest/core": "^0.0.22" }, "peerDependencies": { "@playwright/test": "^1.40.1" diff --git a/package.json b/package.json index c662e48..33e2e05 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "scripts": { "cy:open": "cypress open", "cy:run": "cypress run", - "pr:run": "playwright test", - "pr:open": "playwright test --ui", + "pw:run": "playwright test", + "pw:open": "playwright test --ui", "generate-diagram": "mmdc" }, "author": "", @@ -30,7 +30,7 @@ }, "dependencies": { "@opentelemetry/sdk-trace-base": "^1.18.1", - "@tracetest/cypress": "^0.0.21", - "@tracetest/playwright": "0.0.21" + "@tracetest/cypress": "^0.0.22", + "@tracetest/playwright": "0.0.22" } } diff --git a/playwright/home.spec.ts b/playwright/home.spec.ts index d18ca15..1883f58 100644 --- a/playwright/home.spec.ts +++ b/playwright/home.spec.ts @@ -1,30 +1,52 @@ import { test, expect } from '@playwright/test'; -import Tracetest from '@tracetest/playwright'; +import Tracetest, { Types } from '@tracetest/playwright'; const { TRACETEST_API_TOKEN = '' } = process.env; -const tracetest = Tracetest(); +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 () => { - await tracetest.configure(TRACETEST_API_TOKEN); + tracetest = await Tracetest({ apiToken: TRACETEST_API_TOKEN }); + tracetest.setOptions({ + 'Playwright: imports a pokemon': { + definition, + }, + }); }); test.beforeEach(async ({ page }, { title }) => { await page.goto('/'); - await tracetest.capture(title, page); -}); - -test.afterEach(async ({}, { title, config }) => { - await tracetest.runTest(title, config.metadata.definition ?? ''); - config.metadata.definition = ''; + await tracetest?.capture(title, page); }); // optional step to break the playwright script in case a Tracetest test fails test.afterAll(async ({}, testInfo) => { testInfo.setTimeout(60000); - await tracetest.summary(); + await tracetest?.summary(); }); test('Playwright: creates a pokemon', async ({ page }) => { @@ -40,31 +62,7 @@ test('Playwright: creates a pokemon', async ({ page }) => { await page.getByRole('button', { name: 'OK', exact: true }).click(); }); -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('Playwright: imports a pokemon', async ({ page }, { config: { metadata } }) => { - // set the definition for the tracetest test - metadata.definition = definition; +test('Playwright: imports a pokemon', async ({ page }) => { expect(await page.getByText('Pokeshop')).toBeTruthy(); await page.click('text=Import');