Skip to content

Commit

Permalink
test: add test for sync-playwright feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrandiaz committed Jan 11, 2024
1 parent ce8c626 commit 27bafa2
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 3 deletions.
76 changes: 73 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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'] },
},
],
})
36 changes: 36 additions & 0 deletions packages/cli/e2e/__tests__/sync-playwright.spec.ts
Original file line number Diff line number Diff line change
@@ -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.')
})
})
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
36 changes: 36 additions & 0 deletions packages/create-cli/e2e/__tests__/bootstrap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ({
Expand Down Expand Up @@ -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)
})
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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'] },
},
],
})

0 comments on commit 27bafa2

Please sign in to comment.