diff --git a/package-lock.json b/package-lock.json index d1ed03580..fa73a4fa5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3327,6 +3327,21 @@ "node": ">=14" } }, + "node_modules/@playwright/test": { + "version": "1.40.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.40.1.tgz", + "integrity": "sha512-EaaawMTOeEItCRvfmkI9v6rBkF1svM8wjl/YPRrg2N2Wmp+4qJYkWtJsbew1szfKKDm6fPLy4YAanBhIlf9dWw==", + "dev": true, + "dependencies": { + "playwright": "1.40.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=16" + } + }, "node_modules/@sinclair/typebox": { "version": "0.27.8", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", @@ -13712,6 +13727,36 @@ "node": ">=4" } }, + "node_modules/playwright": { + "version": "1.40.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.40.1.tgz", + "integrity": "sha512-2eHI7IioIpQ0bS1Ovg/HszsN/XKNwEG1kbzSDDmADpclKc7CyqkHw7Mg2JCz/bbCxg25QUPcjksoMW7JcIFQmw==", + "dev": true, + "dependencies": { + "playwright-core": "1.40.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=16" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.40.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.40.1.tgz", + "integrity": "sha512-+hkOycxPiV534c4HhpfX6yrlawqVUzITRKwHAmYfmsVreltEl6fAZJ3DPfLMOODw0H3s1Itd6MDCWmP1fl/QvQ==", + "dev": true, + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=16" + } + }, "node_modules/postcss-selector-parser": { "version": "6.0.13", "dev": true, @@ -16524,7 +16569,6 @@ "dotenv": "16.3.1", "git-repo-info": "2.1.1", "glob": "10.3.1", - "handlebars": "4.7.8", "indent-string": "4.0.0", "json5": "2.2.3", "jwt-decode": "3.1.2", @@ -16542,6 +16586,7 @@ "checkly": "bin/run" }, "devDependencies": { + "@playwright/test": "1.40.1", "@types/config": "3.3.3", "@types/glob": "8.0.0", "@types/jest": "29.5.3", @@ -19296,6 +19341,15 @@ "version": "0.11.0", "optional": true }, + "@playwright/test": { + "version": "1.40.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.40.1.tgz", + "integrity": "sha512-EaaawMTOeEItCRvfmkI9v6rBkF1svM8wjl/YPRrg2N2Wmp+4qJYkWtJsbew1szfKKDm6fPLy4YAanBhIlf9dWw==", + "dev": true, + "requires": { + "playwright": "1.40.1" + } + }, "@sinclair/typebox": { "version": "0.27.8", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", @@ -20683,6 +20737,7 @@ "@oclif/plugin-not-found": "2.3.23", "@oclif/plugin-plugins": "2.3.0", "@oclif/plugin-warn-if-update-available": "2.0.24", + "@playwright/test": "1.40.1", "@types/config": "3.3.3", "@types/glob": "8.0.0", "@types/jest": "29.5.3", @@ -20705,10 +20760,9 @@ "dotenv": "16.3.1", "git-repo-info": "2.1.1", "glob": "10.3.1", - "handlebars": "4.7.8", "indent-string": "4.0.0", "jest": "29.6.2", - "json5": "*", + "json5": "2.2.3", "jwt-decode": "3.1.2", "log-symbols": "4.1.0", "luxon": "3.3.0", @@ -26369,6 +26423,22 @@ } } }, + "playwright": { + "version": "1.40.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.40.1.tgz", + "integrity": "sha512-2eHI7IioIpQ0bS1Ovg/HszsN/XKNwEG1kbzSDDmADpclKc7CyqkHw7Mg2JCz/bbCxg25QUPcjksoMW7JcIFQmw==", + "dev": true, + "requires": { + "fsevents": "2.3.2", + "playwright-core": "1.40.1" + } + }, + "playwright-core": { + "version": "1.40.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.40.1.tgz", + "integrity": "sha512-+hkOycxPiV534c4HhpfX6yrlawqVUzITRKwHAmYfmsVreltEl6fAZJ3DPfLMOODw0H3s1Itd6MDCWmP1fl/QvQ==", + "dev": true + }, "postcss-selector-parser": { "version": "6.0.13", "dev": true, diff --git a/packages/cli/e2e/__tests__/fixtures/test-playwright-project/checkly.config.original.ts b/packages/cli/e2e/__tests__/fixtures/test-playwright-project/checkly.config.original.ts new file mode 100644 index 000000000..f0a82ffd0 --- /dev/null +++ b/packages/cli/e2e/__tests__/fixtures/test-playwright-project/checkly.config.original.ts @@ -0,0 +1,21 @@ +import { defineConfig } from 'checkly' + +const config = defineConfig({ + projectName: 'Test Playwright Project', + logicalId: 'test-playwright-project', + repoUrl: 'https://github.com/checkly/checkly-cli', + checks: { + locations: ['us-east-1', 'eu-west-1'], + tags: ['mac'], + runtimeId: '2022.10', + checkMatch: '**/*.check.ts', + browserChecks: { + testMatch: '**/__checks__/*.test.ts', + }, + }, + cli: { + runLocation: 'us-east-1', + }, +}) + +export default config diff --git a/packages/cli/e2e/__tests__/fixtures/test-playwright-project/checkly.config.ts b/packages/cli/e2e/__tests__/fixtures/test-playwright-project/checkly.config.ts new file mode 100644 index 000000000..f0a82ffd0 --- /dev/null +++ b/packages/cli/e2e/__tests__/fixtures/test-playwright-project/checkly.config.ts @@ -0,0 +1,21 @@ +import { defineConfig } from 'checkly' + +const config = defineConfig({ + projectName: 'Test Playwright Project', + logicalId: 'test-playwright-project', + repoUrl: 'https://github.com/checkly/checkly-cli', + checks: { + locations: ['us-east-1', 'eu-west-1'], + tags: ['mac'], + runtimeId: '2022.10', + checkMatch: '**/*.check.ts', + browserChecks: { + testMatch: '**/__checks__/*.test.ts', + }, + }, + cli: { + runLocation: 'us-east-1', + }, +}) + +export default config diff --git a/packages/cli/e2e/__tests__/fixtures/test-playwright-project/playwright.config.ts b/packages/cli/e2e/__tests__/fixtures/test-playwright-project/playwright.config.ts new file mode 100644 index 000000000..dc5021457 --- /dev/null +++ b/packages/cli/e2e/__tests__/fixtures/test-playwright-project/playwright.config.ts @@ -0,0 +1,23 @@ +import { defineConfig, devices } from '@playwright/test' + +export default defineConfig({ + testDir: 'tests', + timeout: 1234, + use: { + baseURL: 'http://127.0.0.1:3000', + extraHTTPHeaders: { + foo: 'bar', + }, + }, + expect: { + toMatchSnapshot: { + maxDiffPixelRatio: 1, + }, + }, + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + ], +}) diff --git a/packages/cli/e2e/__tests__/sync-playwright.spec.ts b/packages/cli/e2e/__tests__/sync-playwright.spec.ts new file mode 100644 index 000000000..3c7f3c43d --- /dev/null +++ b/packages/cli/e2e/__tests__/sync-playwright.spec.ts @@ -0,0 +1,36 @@ +import { runChecklyCli } from '../run-checkly' +import * as path from 'path' +import { loadChecklyConfig } from '../../src/services/checkly-config-loader' +import * as fs from 'fs' + +describe('sync-playwright', () => { + // Since we are modifying the file let's keep it clean after each test + afterEach(() => { + const configPath = path.join(__dirname, 'fixtures', 'test-playwright-project') + fs.copyFileSync(path.join(configPath, 'checkly.config.original.ts'), path.join(configPath, 'checkly.config.ts')) + }) + + it('should copy playwright config into checkly config', async () => { + const { status, stdout } = await runChecklyCli({ + args: ['sync-playwright'], + directory: path.join(__dirname, 'fixtures', 'test-playwright-project'), + }) + expect(status).toBe(0) + expect(stdout).toContain('Successfully sync') + const checklyConfig = await loadChecklyConfig(path.join(__dirname, 'fixtures', 'test-playwright-project')) + expect(checklyConfig.config?.checks?.browserChecks?.playwrightConfig).toBeDefined() + expect(checklyConfig.config?.checks?.browserChecks?.playwrightConfig?.timeout).toEqual(1234) + expect(checklyConfig.config?.checks?.browserChecks?.playwrightConfig?.use).toBeDefined() + expect(checklyConfig.config?.checks?.browserChecks?.playwrightConfig?.use?.baseURL).toEqual('http://127.0.0.1:3000') + expect(checklyConfig.config?.checks?.browserChecks?.playwrightConfig?.expect).toBeDefined() + }) + + it('should fail if no playwright config file exists', async () => { + const { status, stdout } = await runChecklyCli({ + args: ['sync-playwright'], + directory: path.join(__dirname, 'fixtures', 'test-project'), + }) + expect(status).toBe(1) + expect(stdout).toContain('Could not find any playwright.config file.') + }) +}) diff --git a/packages/cli/package.json b/packages/cli/package.json index a32553bcc..8434454ff 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -107,6 +107,7 @@ "@types/tunnel": "0.0.3", "@types/uuid": "9.0.1", "@types/ws": "8.5.5", + "@playwright/test": "1.40.1", "config": "3.3.9", "cross-env": "7.0.3", "jest": "29.6.2", diff --git a/packages/create-cli/e2e/__tests__/bootstrap.spec.ts b/packages/create-cli/e2e/__tests__/bootstrap.spec.ts index f0f296d8a..30d9f24b4 100644 --- a/packages/create-cli/e2e/__tests__/bootstrap.spec.ts +++ b/packages/create-cli/e2e/__tests__/bootstrap.spec.ts @@ -13,6 +13,8 @@ const E2E_PROJECT_PREFIX = 'e2e-test-project-' function cleanupProjects () { rimraf.sync(`${path.join(__dirname, 'fixtures', 'empty-project', E2E_PROJECT_PREFIX)}*`, { glob: true }) rimraf.windowsSync(`${path.join(__dirname, 'fixtures', 'empty-project', E2E_PROJECT_PREFIX)}*`, { glob: true }) + rimraf.sync(path.join(__dirname, 'fixtures', 'playwright-project', '__checks__'), { glob: true }) + rimraf.sync(path.join(__dirname, 'fixtures', 'playwright-project', 'checkly.config.ts'), { glob: true }) } function expectVersionAndName ({ @@ -272,4 +274,38 @@ describe('bootstrap', () => { expect(fs.existsSync(path.join(projectFolder, 'node_modules'))).toBe(false) expect(fs.existsSync(path.join(projectFolder, '.git'))).toBe(false) }, 15000) + + it('Should copy the playwright config', () => { + const directory = path.join(__dirname, 'fixtures', 'playwright-project') + const commandOutput = runChecklyCreateCli({ + directory, + promptsInjection: [true, false, false, true], + }) + + expectVersionAndName({ commandOutput, latestVersion, greeting }) + + const { status, stdout, stderr } = commandOutput + + expect(stdout).toContain('Downloading example template...') + expect(stdout).toContain('Example template copied!') + expect(stdout).not.toContain('Installing packages') + expect(stdout).not.toContain('Packages installed successfully') + // no git initialization message + + expect(stdout).toContain('No worries. Just remember to install the dependencies after this setup') + expect(stdout).toContain('Copying your playwright config') + expect(stdout).toContain('Playwright config copied!') + + expectCompleteCreation({ commandOutput, projectFolder: directory }) + + expect(stderr).toBe('') + expect(status).toBe(0) + + expect(fs.existsSync(path.join(directory, 'package.json'))).toBe(true) + expect(fs.existsSync(path.join(directory, 'checkly.config.ts'))).toBe(true) + expect(fs.existsSync(path.join(directory, '__checks__', 'api.check.ts'))).toBe(true) + + // node_modules nor .git shouldn't exist + expect(fs.existsSync(path.join(directory, 'node_modules'))).toBe(false) + }, 15000) }) diff --git a/packages/create-cli/e2e/__tests__/fixtures/playwright-project/package.json b/packages/create-cli/e2e/__tests__/fixtures/playwright-project/package.json new file mode 100644 index 000000000..19b996ea4 --- /dev/null +++ b/packages/create-cli/e2e/__tests__/fixtures/playwright-project/package.json @@ -0,0 +1,16 @@ +{ + "name": "dummy-project", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "devDependencies": { + "checkly": "latest", + "ts-node": "latest", + "typescript": "latest" + } +} \ No newline at end of file diff --git a/packages/create-cli/e2e/__tests__/fixtures/playwright-project/playwright.config.ts b/packages/create-cli/e2e/__tests__/fixtures/playwright-project/playwright.config.ts new file mode 100644 index 000000000..dc5021457 --- /dev/null +++ b/packages/create-cli/e2e/__tests__/fixtures/playwright-project/playwright.config.ts @@ -0,0 +1,23 @@ +import { defineConfig, devices } from '@playwright/test' + +export default defineConfig({ + testDir: 'tests', + timeout: 1234, + use: { + baseURL: 'http://127.0.0.1:3000', + extraHTTPHeaders: { + foo: 'bar', + }, + }, + expect: { + toMatchSnapshot: { + maxDiffPixelRatio: 1, + }, + }, + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + ], +})