diff --git a/types/amzn__synthetics-playwright/.npmignore b/types/amzn__synthetics-playwright/.npmignore new file mode 100644 index 00000000000000..680c524577719f --- /dev/null +++ b/types/amzn__synthetics-playwright/.npmignore @@ -0,0 +1,5 @@ +* +!**/*.d.ts +!**/*.d.cts +!**/*.d.mts +!**/*.d.*.ts \ No newline at end of file diff --git a/types/amzn__synthetics-playwright/amzn__synthetics-playwright-tests.ts b/types/amzn__synthetics-playwright/amzn__synthetics-playwright-tests.ts new file mode 100644 index 00000000000000..5b97e34b1e97e1 --- /dev/null +++ b/types/amzn__synthetics-playwright/amzn__synthetics-playwright-tests.ts @@ -0,0 +1,54 @@ +import { synthetics } from "@amzn/synthetics-playwright"; +import type { Browser, BrowserContext, LaunchOptions, Page } from "@playwright/test"; + +export const handler = async () => { + const launchOptions: LaunchOptions = await synthetics.getDefaultLaunchOptions(); + const browser: Browser = await synthetics.launch(launchOptions); + const page: Page = await synthetics.newPage(browser); + + await page.goto("https://example.com"); + await page.screenshot({ path: "/tmp/example.png" }); + + await synthetics.close(); +}; + +export const runTestStep = ( + stepName: string, + runTestsAndReturnNextPage: () => Promise, +): Promise => { + return synthetics.executeStep(stepName, async () => { + const nextPage = await runTestsAndReturnNextPage(); + return nextPage; + }); +}; + +export const testWithBrowserContext = async () => { + const browser: Browser = await synthetics.launch(); + const context: BrowserContext = await browser.newContext(); + const page: Page = await synthetics.newPage(context); + + await page.goto("https://example.com"); + await synthetics.close(); +}; + +export const testExecuteStepWithConfig = async () => { + const browser: Browser = await synthetics.launch(); + const page: Page = await synthetics.newPage(browser); + + await synthetics.executeStep( + "test step", + async () => { + await page.goto("https://example.com"); + return page.title(); + }, + { + continueOnStepFailure: true, + screenshotOnStepStart: true, + screenshotOnStepSuccess: false, + screenshotOnStepFailure: true, + }, + page, + ); + + await synthetics.close(); +}; diff --git a/types/amzn__synthetics-playwright/index.d.ts b/types/amzn__synthetics-playwright/index.d.ts new file mode 100644 index 00000000000000..7cbf49dacd467e --- /dev/null +++ b/types/amzn__synthetics-playwright/index.d.ts @@ -0,0 +1,30 @@ +import type { Browser, BrowserContext, BrowserType, LaunchOptions, Page } from "@playwright/test"; + +export interface StepConfig { + readonly continueOnHttpStepFailure?: boolean | undefined; + readonly continueOnStepFailure?: boolean | undefined; + readonly screenshotOnStepFailure?: boolean | undefined; + readonly screenshotOnStepStart?: boolean | undefined; + readonly screenshotOnStepSuccess?: boolean | undefined; + readonly stepDurationMetric?: boolean | undefined; + readonly stepsReport?: boolean | undefined; + readonly stepSuccessMetric?: boolean | undefined; +} + +export interface SyntheticsType { + readonly close: () => Promise; + readonly executeStep: ( + stepName: string, + func: () => Promise, + stepConfig?: StepConfig, + page?: Page, + ) => Promise; + readonly getDefaultLaunchOptions: () => Promise; + readonly getPage: (browser: Browser | BrowserContext) => Promise; + readonly launch: BrowserType["launch"]; + readonly newPage: (browser: Browser | BrowserContext) => Promise; +} + +export const synthetics: SyntheticsType; + +export {}; diff --git a/types/amzn__synthetics-playwright/package.json b/types/amzn__synthetics-playwright/package.json new file mode 100644 index 00000000000000..10b7a435d5aa5c --- /dev/null +++ b/types/amzn__synthetics-playwright/package.json @@ -0,0 +1,22 @@ +{ + "private": true, + "name": "@types/amzn__synthetics-playwright", + "version": "10.0.9999", + "nonNpm": true, + "nonNpmDescription": "Library functions available for Node.js canary scripts using Playwright", + "projects": [ + "https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html" + ], + "devDependencies": { + "@types/amzn__synthetics-playwright": "workspace:." + }, + "peerDependencies": { + "@playwright/test": "^1.53.0" + }, + "owners": [ + { + "name": "Andor Kovács", + "githubUsername": "kovacsandor" + } + ] +} diff --git a/types/amzn__synthetics-playwright/tsconfig.json b/types/amzn__synthetics-playwright/tsconfig.json new file mode 100644 index 00000000000000..09b98257132178 --- /dev/null +++ b/types/amzn__synthetics-playwright/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "node16", + "lib": [ + "es2018" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "amzn__synthetics-playwright-tests.ts" + ] +} diff --git a/types/expect-cookies/package.json b/types/expect-cookies/package.json index 72f5db4de695f5..df0394b81e2e98 100644 --- a/types/expect-cookies/package.json +++ b/types/expect-cookies/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@types/expect-cookies", - "version": "0.2.9999", + "version": "0.3.9999", "projects": [ "https://github.com/gregl83/expect-cookies" ],