diff --git a/examples/advanced-project-js/README.md b/examples/advanced-project-js/README.md index 5b8e021f3..10eeacd69 100644 --- a/examples/advanced-project-js/README.md +++ b/examples/advanced-project-js/README.md @@ -15,6 +15,8 @@ npm create checkly@latest -- --template advanced-project This project has examples of all Checkly check types and showcases some advanced features. It also adds a GitHub Actions workflow. +- Running `npx checkly pw-test` will use the `playwright.config.ts` file and run the test suite in Checkly. + - Running `npx checkly test` will look for `.check.js` files and `.spec.js` in `__checks__` directories and execute them in a dry run. - Running `npx checkly deploy` will deploy your checks to Checkly, attach alert channels, and run them on a 10m schedule in the @@ -30,6 +32,7 @@ Run the core CLI commands with `npx checkly ` | Command | Action | |:---------------------|:-------------------------------------------------| | `npx checkly test` | Dry run all the checks in your project | +| `npx checkly pw-test`| Run playwright tests in your project | | `npx checkly deploy` | Deploy your checks to the Checkly cloud | | `npx checkly login` | Log in to your Checkly account | | `npx checkly --help` | Show help for each command. | @@ -38,11 +41,14 @@ Run the core CLI commands with `npx checkly ` ## Adding and running `@playwright/test` -You can add `@playwright/test` to this project to get full code completion and run `.spec.js` files for local debugging. -It's best to install the Playwright npm package version that matches your [Checkly runtime](https://www.checklyhq.com/docs/cli/npm-packages/). +Run `npm install` to install all required dependencies. + + `@playwright/test` will give you full code completion and run `.spec.js` files for local debugging. + +If you're using MultiStep or Browser Checks, make sure to install the Playwright npm package version that matches your [Checkly runtime](https://www.checklyhq.com/docs/cli/npm-packages/). ```bash -npm install --save-dev @playwright/test@1.38.1 +npm install --save-dev @playwright/test@1.54.1 ``` ## Questions? diff --git a/examples/advanced-project-js/checkly.config.js b/examples/advanced-project-js/checkly.config.js index 7da4b71ab..27d21fcc6 100644 --- a/examples/advanced-project-js/checkly.config.js +++ b/examples/advanced-project-js/checkly.config.js @@ -43,6 +43,15 @@ const config = defineConfig({ * */ testMatch: '**/__checks__/**/*.spec.js', }, + playwrightConfigPath: './playwright.config.js', + playwrightChecks: [ + { + logicalId: 'playwright-check-suite', + name: 'Playwright Check Suite JS', + //Use `testCommand: npx playwright test` to filter the tests you want to run + } + ], + ], }, cli: { /* The default datacenter location to use when running npx checkly test */ diff --git a/examples/advanced-project-js/package.json b/examples/advanced-project-js/package.json index a1a702c52..68e6e8d1b 100644 --- a/examples/advanced-project-js/package.json +++ b/examples/advanced-project-js/package.json @@ -10,6 +10,8 @@ "author": "", "license": "ISC", "devDependencies": { - "checkly": "latest" + "@playwright/test": "^1", + "checkly": "latest", + "jiti": "^1" } } diff --git a/examples/advanced-project-js/playwright.config.js b/examples/advanced-project-js/playwright.config.js new file mode 100644 index 000000000..032678b7b --- /dev/null +++ b/examples/advanced-project-js/playwright.config.js @@ -0,0 +1,43 @@ +const { defineConfig, devices } = require('@playwright/test'); +const path = require('path'); + +const AUTH_FILE = '.auth/user.json'; + +const config = defineConfig({ + timeout: 30000, + use: { + baseURL: 'https://www.danube-web.shop', + viewport: { width: 1280, height: 720 }, + }, + projects: [ + { + name: 'login-setup', + testMatch: /.*\.setup.ts/, + use: { + ...devices['Desktop Chrome'], + }, + }, + { + name: 'Firefox', + testDir: './src/tests/', + use: { + ...devices['Desktop Firefox'], + storageState: path.resolve(__dirname, AUTH_FILE), + }, + dependencies: ["login-setup"], + }, + { + name: 'Chromium', + testDir: './src/tests/', + use: { + ...devices['Desktop Chrome'], + storageState: path.resolve(__dirname, AUTH_FILE), + // Optionally add Checkly user-agent + userAgent: devices['Desktop Chrome'].userAgent + ' (Checkly, https://www.checklyhq.com)', + }, + dependencies: ['login-setup'], + }, + ] +}); + +module.exports = config; diff --git a/examples/advanced-project-js/src/playwright/homepage.spec.js b/examples/advanced-project-js/src/playwright/homepage.spec.js new file mode 100644 index 000000000..aea2f38a6 --- /dev/null +++ b/examples/advanced-project-js/src/playwright/homepage.spec.js @@ -0,0 +1,9 @@ +const { test, expect } = require('@playwright/test'); + +test('webshop homepage @homepage', async ({ page }) => { + const response = await page.goto(''); + + expect(response?.status()).toBeLessThan(400); + await expect(page).toHaveTitle(/Danube WebShop/); + await page.screenshot({ path: 'homepage.jpg' }); +}); \ No newline at end of file diff --git a/examples/advanced-project-js/src/playwright/login.spec.js b/examples/advanced-project-js/src/playwright/login.spec.js new file mode 100644 index 000000000..0ed49f542 --- /dev/null +++ b/examples/advanced-project-js/src/playwright/login.spec.js @@ -0,0 +1,17 @@ +const { test } = require('@playwright/test'); + +test('login', { + tag: '@login', +}, async ({ page }) => { + // navigate to our target web page + await page.goto(''); + + // click on the login button and go through the login procedure + await page.click('#login'); + await page.type('#n-email', 'user@email.com'); + await page.type('#n-password2', 'supersecure1'); + await page.click('#goto-signin-btn'); + + // wait until the login confirmation message is shown + await page.waitForSelector('#login-message', { visible: true }); +}); \ No newline at end of file diff --git a/examples/advanced-project/README.md b/examples/advanced-project/README.md index ed3bbbec5..f0b6ef145 100644 --- a/examples/advanced-project/README.md +++ b/examples/advanced-project/README.md @@ -3,7 +3,7 @@ This example project shows how you can use the Checkly CLI in a monitoring as code (MaC) workflow. We are using the https://checklyhq.com website as a monitoring target. -1. Write API Checks and Playwright-powered Browser Checks. +1. Write API Checks and Playwright-powered Browser Checks or fully native Playwright Check Suites. 2. Add Alert Channels, and dry-run your Checks on 20+ global locations. 3. Test -> Deploy: now you have your app monitored around the clock. All from your code base. @@ -15,6 +15,7 @@ npm create checkly@latest -- --template advanced-project This project has examples of all Checkly check types and showcases some advanced features. It also adds a GitHub Actions workflow. +- Running `npx checkly pw-test` will use the `playwright.config.ts` file and run the test suite in Checkly. - Running `npx checkly test` will look for `.check.ts` files and `.spec.ts` in `__checks__` directories and execute them in a dry run. - Running `npx checkly deploy` will deploy your checks to Checkly, attach alert channels, and run them on a 10m schedule in the @@ -30,6 +31,7 @@ Run the core CLI commands with `npx checkly ` | Command | Action | |:---------------------|:-------------------------------------------------| | `npx checkly test` | Dry run all the checks in your project | +| `npx checkly pw-test`| Run playwright tests in your project | | `npx checkly deploy` | Deploy your checks to the Checkly cloud | | `npx checkly login` | Log in to your Checkly account | | `npx checkly --help` | Show help for each command. | @@ -38,14 +40,17 @@ Run the core CLI commands with `npx checkly ` ## Adding and running `@playwright/test` -You can add `@playwright/test` to this project to get full code completion and run `.spec.ts` files for local debugging. -It's best to install the Playwright npm package version that matches your [Checkly runtime](https://www.checklyhq.com/docs/cli/npm-packages/). +Run `npm install` to install all required dependencies. + + `@playwright/test` will give you full code completion and run `.spec.js` files for local debugging. + +If you're using MultiStep or Browser Checks, make sure to install the Playwright npm package version that matches your [Checkly runtime](https://www.checklyhq.com/docs/cli/npm-packages/). ```bash -npm install --save-dev @playwright/test@1.38.1 +npm install --save-dev @playwright/test@1.54.1 ``` ## Questions? -Check [our CLI docs](https://www.checklyhq.com/docs/cli/), the [main Checkly docs](https://checklyhq.com/docs) or +Check [the CLI docs](https://www.checklyhq.com/docs/cli/), the [main Checkly docs](https://checklyhq.com/docs) or join our [Slack community](https://checklyhq.com/slack). diff --git a/examples/advanced-project/checkly.config.ts b/examples/advanced-project/checkly.config.ts index 4453499e2..ee1852001 100644 --- a/examples/advanced-project/checkly.config.ts +++ b/examples/advanced-project/checkly.config.ts @@ -45,6 +45,16 @@ const config = defineConfig({ * */ testMatch: '**/__checks__/**/*.spec.ts', }, + + // Playwright Check Suites definition, run the whole Playwright Test Suite in a Check + playwrightConfigPath: './playwright.config.ts', + playwrightChecks: [ + { + logicalId: 'playwright-check-suite', + name: 'Playwright Check Suite TS', + //Use `testCommand: npx playwright test` to filter the tests you want to run + } + ], }, cli: { /* The default datacenter location to use when running npx checkly test */ diff --git a/examples/advanced-project/package.json b/examples/advanced-project/package.json index 4e5fdd55c..e0c9b7e13 100644 --- a/examples/advanced-project/package.json +++ b/examples/advanced-project/package.json @@ -10,6 +10,7 @@ "author": "", "license": "ISC", "devDependencies": { + "@playwright/test": "^1", "checkly": "latest", "jiti": "^2" } diff --git a/examples/advanced-project/playwright.config.ts b/examples/advanced-project/playwright.config.ts new file mode 100644 index 000000000..4d9f162d0 --- /dev/null +++ b/examples/advanced-project/playwright.config.ts @@ -0,0 +1,54 @@ +import { defineConfig, devices } from "@playwright/test" + +/** + * Read environment variables from file. + * https://github.com/motdotla/dotenv + */ +import dotenv from "dotenv" +import path from "path" +dotenv.config({ path: path.resolve(__dirname, ".env") }) + +export const AUTH_FILE = ".auth/user.json" + +/** + * See https://playwright.dev/docs/test-configuration. + */ + +export default defineConfig({ + timeout: 30000, + use: { + baseURL: "https://www.checklyhq.com", + viewport: { width: 1280, height: 720 }, + trace: "on", + + }, + projects: [ + { + name: 'login-setup', + testMatch: /.*\.setup.ts/, + use: { + ...devices['Desktop Chrome'], + }, + }, + { + name: 'Firefox', + testDir: './src/tests/', + use: { + ...devices['Desktop Firefox'], + storageState: path.resolve(__dirname, AUTH_FILE), + }, + dependencies: ["login-setup"], + }, + { + name: 'Chromium', + testDir: './src/tests/', + use: { + ...devices['Desktop Chrome'], + storageState: path.resolve(__dirname, AUTH_FILE), + // Optionally add Checkly user-agent + userAgent: `${devices['Desktop Chrome'].userAgent} (Checkly, https://www.checklyhq.com)`, + }, + dependencies: ["login-setup"], + }, + ] +}); diff --git a/examples/advanced-project/src/__checks__/synthetics/07-playwright-techniques.spec.ts b/examples/advanced-project/src/__checks__/synthetics/07-playwright-techniques.spec.ts deleted file mode 100644 index 1ad64aed1..000000000 --- a/examples/advanced-project/src/__checks__/synthetics/07-playwright-techniques.spec.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { test, expect } from '@playwright/test'; -import AxeBuilder from '@axe-core/playwright'; - -// In this series of checks, we'll demonstrate some more advanced techniques -// for testing your web page with Playwright. All of these techniques can be -// used wherever you use Playwright. - -test('Book details with request interception', async ({ page }) => { - // Here we want to check the content of a book's details, but the stock - // value is dynamic. How can we stabilize it? With request interception - // read more here: https://www.checklyhq.com/learn/playwright/intercept-requests/ - await page.route('*/**/api/books/23', async route => { //wait for requests that match this pattern. - const response = await route.fetch(); - const json = await response.json(); // Capture the response JSON - json.stock = "0" // modify the JSON to have a stable value - await route.fulfill({ response, json }); // return the modified JSON - }); - await page.goto('https://danube-web.shop/books/23'); - // Removed for brevity: checks of the book's title, genre, etc. - await expect(page.getByRole('button', { name: 'Add to cart' })).toBeVisible(); - await expect(page.locator('#app-content')).toContainText("Left in stock: 0"); -}); - -test('Visual Regression Testing', async ({ page }) => { - // A visual regression check that will compare a saved screenshot to a - // current screenshot. To store an initial screenshot, run `npx checkly test --update-snapshots` - await page.goto('https://danube-web.shop/') - await expect(page).toHaveScreenshot({ maxDiffPixelRatio: 0.2 }) - await expect(page).toHaveScreenshot({ maxDiffPixels: 1000 }) - await expect(page).toHaveScreenshot({ threshold: 0.2 }) -}); - -test('Accessibility issues', async ({ page }) => { - // Uses the Axe library to perform accessibility testing on our site. - // axe-core is part of the Checkly runtime as of the 2024.02 version. - // Read more: https://www.checklyhq.com/blog/integrating-accessibility-checks-in-playwright-tes/ - await page.goto('https://danube-web.shop/'); - const accessibilityScanResults = await new AxeBuilder({ page }).analyze(); - expect(accessibilityScanResults.violations).toHaveLength(8); // ideally we'd find zero issues -}); diff --git a/examples/advanced-project/src/__checks__/synthetics/08-playwright-techniques.check.ts b/examples/advanced-project/src/__checks__/synthetics/08-playwright-techniques.check.ts deleted file mode 100644 index a90aa02c1..000000000 --- a/examples/advanced-project/src/__checks__/synthetics/08-playwright-techniques.check.ts +++ /dev/null @@ -1,19 +0,0 @@ -import * as path from 'path' -import { BrowserCheck } from 'checkly/constructs' -import { syntheticGroup } from '../utils/website-groups.check' - -// Even though there are multiple test() function calls in the .spec -// file, they will all run and report as a single Checkly monitor. -// Since one of the tests compares a current screenshot to a stored one, -// this check is deactivated, until you a store a known good screenshot. -// Run `npx checkly test --update-snapshots` before activiating this check. - -new BrowserCheck('playwright-techniques', { - name: 'Playwright techniques demo', - group: syntheticGroup, - activated: false, - code: { - entrypoint: path.join(__dirname, '07-playwright-techniques.spec.ts') - }, - runParallel: true, -}) diff --git a/examples/advanced-project/src/tests/homepage.spec.ts b/examples/advanced-project/src/tests/homepage.spec.ts new file mode 100644 index 000000000..efd8c1c28 --- /dev/null +++ b/examples/advanced-project/src/tests/homepage.spec.ts @@ -0,0 +1,9 @@ +import { expect, test } from "@playwright/test" + +test("Visit Checkly home page", async ({ page }) => { + await page.goto("/") + + await expect(page).toHaveTitle(/Checkly/) + + // More test code ... +}) \ No newline at end of file diff --git a/examples/advanced-project/src/tests/login.setup.ts b/examples/advanced-project/src/tests/login.setup.ts new file mode 100644 index 000000000..3a53ae72e --- /dev/null +++ b/examples/advanced-project/src/tests/login.setup.ts @@ -0,0 +1,15 @@ +import { test as setup } from "@playwright/test" + +const AUTH_FILE = ".auth/user.json" + +setup("Log into Checkly", async ({ page }) => { + await page.goto("/") + + // Perform your login actions which will set cookies and localstorage entries + // ... + + // Use storage state to write the browser state to disk + // More info: https://playwright.dev/docs/api/class-browsercontext#browser-context-storage-state + await page.context().storageState({ path: AUTH_FILE }) + console.log(`Wrote storage state to ${AUTH_FILE}`) +}) diff --git a/examples/boilerplate-project-js/README.md b/examples/boilerplate-project-js/README.md index 1c1a4fdb2..19a654c17 100644 --- a/examples/boilerplate-project-js/README.md +++ b/examples/boilerplate-project-js/README.md @@ -20,10 +20,15 @@ This project has the basic boilerplate files needed to get you started. ├── __checks__ │   ├── api.check.js │   └── homepage.spec.js +├── tests +│   ├── docspage.spec.js +│   └── landingpage.spec.js ├── checkly.config.js └── package.json ``` +- Running `npx checkly pw-test` will use the `playwright.config.ts` file and run the test suite in Checkly. +- - Running `npx checkly test` will look for `.check.js` files and `.spec.js` in `__checks__` directories and execute them in a dry run. - Running `npx checkly deploy` will deploy your checks to Checkly, attach alert channels, and run them on a 10m schedule in the @@ -36,6 +41,7 @@ Run the core CLI commands with `npx checkly ` | Command | Action | |:---------------------|:-------------------------------------------------| | `npx checkly test` | Dry run all the checks in your project | +| `npx checkly pw-test`| Run playwright tests in your project | | `npx checkly deploy` | Deploy your checks to the Checkly cloud | | `npx checkly login` | Log in to your Checkly account | | `npx checkly --help` | Show help for each command. | @@ -44,11 +50,14 @@ Run the core CLI commands with `npx checkly ` ## Adding and running `@playwright/test` -You can add `@playwright/test` to this project to get full code completion and run `.spec.js` files for local debugging. -It's best to install the Playwright npm package version that matches your [Checkly runtime](https://www.checklyhq.com/docs/cli/npm-packages/). +Run `npm install` to install all required dependencies. + + `@playwright/test` will give you full code completion and run `.spec.js` files for local debugging. + +If you're using MultiStep or Browser Checks, make sure to install the Playwright npm package version that matches your [Checkly runtime](https://www.checklyhq.com/docs/cli/npm-packages/). ```bash -npm install --save-dev @playwright/test@1.38.1 +npm install --save-dev @playwright/test@1.54.1 ``` ## Questions? diff --git a/examples/boilerplate-project-js/checkly.config.js b/examples/boilerplate-project-js/checkly.config.js index 850931a58..33e47506a 100644 --- a/examples/boilerplate-project-js/checkly.config.js +++ b/examples/boilerplate-project-js/checkly.config.js @@ -34,6 +34,15 @@ const config = defineConfig({ * */ testMatch: '**/__checks__/**/*.spec.js', }, + // Playwright Check Suites definition, run the whole Playwright Test Suite in a Check + playwrightConfigPath: './playwright.config.js', + playwrightChecks: [ + { + logicalId: 'playwright-check-suite', + name: 'Playwright Check Suite Simple JS', + //Use `testCommand: npx playwright test` to filter the tests you want to run + } + ], }, cli: { /* The default datacenter location to use when running npx checkly test */ diff --git a/examples/boilerplate-project-js/playwright.config.js b/examples/boilerplate-project-js/playwright.config.js new file mode 100644 index 000000000..4ea8d9c3e --- /dev/null +++ b/examples/boilerplate-project-js/playwright.config.js @@ -0,0 +1,42 @@ +const { defineConfig, devices } = require('@playwright/test'); + +module.exports = defineConfig({ + timeout: 30000, + // Look for test files in the "tests" directory, relative to this configuration file. + testDir: './tests', + + // Run all tests in parallel. + fullyParallel: true, + + // Fail the build on CI if you accidentally left test.only in the source code. + forbidOnly: !!process.env.CI, + + // Retry tests on CI only. + retries: process.env.CI ? 2 : 0, + + // Opt out of parallel tests on CI. + workers: process.env.CI ? 1 : undefined, + + // Reporter to use + reporter: 'html', + + use: { + // Base URL to use in actions like `await page.goto('/')`. + baseURL: "https://www.checklyhq.com", + viewport: { width: 1280, height: 720 }, + // Always collect trace + trace: 'on', + }, + // Configure projects for major browsers. + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + { + name: 'firefox', + use: { ...devices['Desktop Firefox'] }, + }, + ], + +}); \ No newline at end of file diff --git a/examples/boilerplate-project-js/tests/docspage.spec.js b/examples/boilerplate-project-js/tests/docspage.spec.js new file mode 100644 index 000000000..a3f0559ee --- /dev/null +++ b/examples/boilerplate-project-js/tests/docspage.spec.js @@ -0,0 +1,9 @@ +import { expect, test } from "@playwright/test" + +test("Visit Checkly home page", async ({ page }) => { + await page.goto("/docs") + + await expect(page).toHaveTitle(/Checkly/) + + // More test code ... +}) diff --git a/examples/boilerplate-project-js/tests/landingpage.spec.js b/examples/boilerplate-project-js/tests/landingpage.spec.js new file mode 100644 index 000000000..e69de29bb diff --git a/examples/boilerplate-project/README.md b/examples/boilerplate-project/README.md index 20b79b481..2acabd0dd 100644 --- a/examples/boilerplate-project/README.md +++ b/examples/boilerplate-project/README.md @@ -20,12 +20,20 @@ This project has the basic boilerplate files needed to get you started. ├── __checks__ │   ├── api.check.ts │   └── homepage.spec.ts +├── tests +│   ├── docspage.spec.ts +│   └── landingpage.spec.ts ├── checkly.config.ts -└── package.json +├── checkly.config.ts +├── package.json +└── package-lock.json ``` +- Running `npx checkly pw-test` will use the `playwright.config.ts` file and run the test suite in Checkly. - Running `npx checkly test` will look for `.check.ts` files and `.spec.ts` in `__checks__` directories and execute them in a dry run. +- Running `npx checkly test --record` will run all checks in a test session for you to preview in the UI. + - Running `npx checkly deploy` will deploy your checks to Checkly, attach alert channels, and run them on a 10m schedule in the region `us-east-1` and `eu-west-1` @@ -36,6 +44,7 @@ Run the core CLI commands with `npx checkly ` | Command | Action | |:---------------------|:-------------------------------------------------| | `npx checkly test` | Dry run all the checks in your project | +| `npx checkly pw-test`| Run playwright tests in your project | | `npx checkly deploy` | Deploy your checks to the Checkly cloud | | `npx checkly login` | Log in to your Checkly account | | `npx checkly --help` | Show help for each command. | @@ -44,11 +53,14 @@ Run the core CLI commands with `npx checkly ` ## Adding and running `@playwright/test` -You can add `@playwright/test` to this project to get full code completion and run `.spec.ts` files for local debugging. -It's best to install the Playwright npm package version that matches your [Checkly runtime](https://www.checklyhq.com/docs/cli/npm-packages/). +Run `npm install` to install all required dependencies. + + `@playwright/test` will give you full code completion and run `.spec.js` files for local debugging. + +If you're using MultiStep or Browser Checks, make sure to install the Playwright npm package version that matches your [Checkly runtime](https://www.checklyhq.com/docs/cli/npm-packages/). ```bash -npm install --save-dev @playwright/test@1.38.1 +npm install --save-dev @playwright/test@1.54.1 ``` ## Questions? diff --git a/examples/boilerplate-project/checkly.config.ts b/examples/boilerplate-project/checkly.config.ts index f0ea3cb7b..1f23cde55 100644 --- a/examples/boilerplate-project/checkly.config.ts +++ b/examples/boilerplate-project/checkly.config.ts @@ -34,6 +34,16 @@ const config = defineConfig({ * */ testMatch: '**/__checks__/**/*.spec.ts', }, + + // Playwright Check Suites definition, run the whole Playwright Test Suite in a Check + playwrightConfigPath: './playwright.config.ts', + playwrightChecks: [ + { + logicalId: 'playwright-check-suite', + name: 'Playwright Check Suite Simple TS', + //Use `testCommand: npx playwright test` to filter the tests you want to run + } + ], }, cli: { /* The default datacenter location to use when running npx checkly test */ diff --git a/examples/boilerplate-project/package.json b/examples/boilerplate-project/package.json index a059fa37b..d5fa24d96 100644 --- a/examples/boilerplate-project/package.json +++ b/examples/boilerplate-project/package.json @@ -1,5 +1,5 @@ { - "name": "boilerlate-project", + "name": "boilerplate-project", "version": "1.0.0", "description": "", "main": "index.js", @@ -10,6 +10,7 @@ "author": "", "license": "ISC", "devDependencies": { + "@playwright/test": "^1", "checkly": "latest", "jiti": "^2" } diff --git a/examples/boilerplate-project/playwright.config.ts b/examples/boilerplate-project/playwright.config.ts new file mode 100644 index 000000000..27363045f --- /dev/null +++ b/examples/boilerplate-project/playwright.config.ts @@ -0,0 +1,42 @@ +import { defineConfig, devices } from '@playwright/test'; + +export default defineConfig({ + timeout: 30000, + // Look for test files in the "tests" directory, relative to this configuration file. + testDir: './tests', + + // Run all tests in parallel. + fullyParallel: true, + + // Fail the build on CI if you accidentally left test.only in the source code. + forbidOnly: !!process.env.CI, + + // Retry tests on CI only. + retries: process.env.CI ? 2 : 0, + + // Opt out of parallel tests on CI. + workers: process.env.CI ? 1 : undefined, + + // Reporter to use + reporter: 'html', + + use: { + // Base URL to use in actions like `await page.goto('/')`. + baseURL: "https://www.checklyhq.com", + viewport: { width: 1280, height: 720 }, + // Always collect trace + trace: 'on', + }, + // Configure projects for major browsers. + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + { + name: 'firefox', + use: { ...devices['Desktop Firefox'] }, + }, + ], + +}); \ No newline at end of file diff --git a/examples/boilerplate-project/tests/docspage.spec.ts b/examples/boilerplate-project/tests/docspage.spec.ts new file mode 100644 index 000000000..a3f0559ee --- /dev/null +++ b/examples/boilerplate-project/tests/docspage.spec.ts @@ -0,0 +1,9 @@ +import { expect, test } from "@playwright/test" + +test("Visit Checkly home page", async ({ page }) => { + await page.goto("/docs") + + await expect(page).toHaveTitle(/Checkly/) + + // More test code ... +}) diff --git a/examples/boilerplate-project/tests/landingpage.spec.ts b/examples/boilerplate-project/tests/landingpage.spec.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/create-cli/e2e/__tests__/bootstrap.spec.ts b/packages/create-cli/e2e/__tests__/bootstrap.spec.ts index ff9cd39f0..a97a2232d 100644 --- a/packages/create-cli/e2e/__tests__/bootstrap.spec.ts +++ b/packages/create-cli/e2e/__tests__/bootstrap.spec.ts @@ -222,7 +222,7 @@ describe('bootstrap', () => { const projectFolder = path.join(directory, newProjectName) const commandOutput = await runChecklyCreateCli({ directory, - promptsInjection: [newProjectName, template, false, false], + promptsInjection: [newProjectName, template, false, false, false], }) expectVersionAndName({ commandOutput, latestVersion, greeting }) diff --git a/packages/create-cli/src/actions/playwright.ts b/packages/create-cli/src/actions/playwright.ts index 78c451a93..20af2faeb 100644 --- a/packages/create-cli/src/actions/playwright.ts +++ b/packages/create-cli/src/actions/playwright.ts @@ -15,7 +15,7 @@ export async function copyPlaywrightConfig (dirPath: string, playwrightConfigFil return } - const checklyConfig = getChecklyConfigFile() + const checklyConfig = getChecklyConfigFile(dirPath) if (!checklyConfig) { return handleError(copySpinner, 'Could not find your checkly config file') } @@ -44,7 +44,7 @@ function handleError (copySpinner: ora.Ora, message: string | unknown) { process.exit(1) } -function getChecklyConfigFile (): { checklyConfig: string, fileName: string } | undefined { +function getChecklyConfigFile (dirPath?: string): { checklyConfig: string, fileName: string } | undefined { const filenames = [ 'checkly.config.ts', 'checkly.config.mts', @@ -55,7 +55,7 @@ function getChecklyConfigFile (): { checklyConfig: string, fileName: string } | ] let config for (const configFile of filenames) { - const dir = path.resolve(path.dirname(configFile)) + const dir = dirPath || path.resolve(path.dirname(configFile)) if (!fs.existsSync(path.resolve(dir, configFile))) { continue }