Skip to content

Commit 2f50f59

Browse files
authored
feat: support group and group defaults in PlaywrightCheck, deprecate groupName (#1149)
1 parent 7097889 commit 2f50f59

File tree

10 files changed

+415
-28
lines changed

10 files changed

+415
-28
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules/

packages/cli/src/constructs/__tests__/fixtures/playwright-check/package-lock.json

Lines changed: 76 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "playwright-check-fixture",
3+
"devDependencies": {
4+
"@playwright/test": "^1.55.1"
5+
}
6+
}

packages/cli/src/constructs/__tests__/fixtures/playwright-check/playwright.config.ts

Whitespace-only changes.
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
import path from 'node:path'
2+
3+
import { describe, it, expect, beforeEach, vi } from 'vitest'
4+
import { AxiosHeaders } from 'axios'
5+
6+
import { CheckGroupV2, Diagnostics, PlaywrightCheck } from '../index'
7+
import { Project, Session } from '../project'
8+
import { checklyStorage } from '../../rest/api'
9+
10+
describe('PlaywrightCheck', () => {
11+
beforeEach(() => {
12+
vi.resetAllMocks()
13+
vi.spyOn(checklyStorage, 'uploadCodeBundle').mockResolvedValue({
14+
data: { key: 'mock-upload-key' },
15+
status: 201,
16+
statusText: 'Created',
17+
headers: new AxiosHeaders(),
18+
config: {
19+
headers: new AxiosHeaders(),
20+
},
21+
})
22+
})
23+
24+
it('should synthesize groupName', async () => {
25+
Session.project = new Project('project-id', {
26+
name: 'Test Project',
27+
repoUrl: 'https://github.com/checkly/checkly-cli',
28+
})
29+
30+
const group = new CheckGroupV2('group', {
31+
name: 'Test Group',
32+
})
33+
34+
const check = new PlaywrightCheck('foo', {
35+
name: 'Test Check',
36+
groupName: 'Test Group',
37+
playwrightConfigPath: path.resolve(__dirname, './fixtures/playwright-check/playwright.config.ts'),
38+
})
39+
40+
const diags = new Diagnostics()
41+
await check.validate(diags)
42+
43+
expect(diags.isFatal()).toEqual(false)
44+
45+
const bundle = await check.bundle()
46+
const payload = bundle.synthesize()
47+
48+
expect(payload.groupId).toEqual(group.ref())
49+
})
50+
51+
it('should synthesize group', async () => {
52+
Session.project = new Project('project-id', {
53+
name: 'Test Project',
54+
repoUrl: 'https://github.com/checkly/checkly-cli',
55+
})
56+
57+
const group = new CheckGroupV2('group', {
58+
name: 'Test Group',
59+
})
60+
61+
const check = new PlaywrightCheck('foo', {
62+
name: 'Test Check',
63+
group,
64+
playwrightConfigPath: path.resolve(__dirname, './fixtures/playwright-check/playwright.config.ts'),
65+
})
66+
67+
const diags = new Diagnostics()
68+
await check.validate(diags)
69+
70+
expect(diags.isFatal()).toEqual(false)
71+
72+
const bundle = await check.bundle()
73+
const payload = bundle.synthesize()
74+
75+
expect(payload.groupId).toEqual(group.ref())
76+
})
77+
78+
it('should synthesize groupId', async () => {
79+
Session.project = new Project('project-id', {
80+
name: 'Test Project',
81+
repoUrl: 'https://github.com/checkly/checkly-cli',
82+
})
83+
84+
const group = new CheckGroupV2('group', {
85+
name: 'Test Group',
86+
})
87+
88+
const check = new PlaywrightCheck('foo', {
89+
name: 'Test Check',
90+
groupId: group.ref(),
91+
playwrightConfigPath: path.resolve(__dirname, './fixtures/playwright-check/playwright.config.ts'),
92+
})
93+
94+
const diags = new Diagnostics()
95+
await check.validate(diags)
96+
97+
expect(diags.isFatal()).toEqual(false)
98+
99+
const bundle = await check.bundle()
100+
const payload = bundle.synthesize()
101+
102+
expect(payload.groupId).toEqual(group.ref())
103+
})
104+
105+
describe('validation', () => {
106+
it('should warn that groupName is deprecated', async () => {
107+
Session.project = new Project('project-id', {
108+
name: 'Test Project',
109+
repoUrl: 'https://github.com/checkly/checkly-cli',
110+
})
111+
112+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
113+
const group = new CheckGroupV2('group', {
114+
name: 'Test Group',
115+
})
116+
117+
const check = new PlaywrightCheck('foo', {
118+
name: 'Test Check',
119+
groupName: 'Test Group',
120+
playwrightConfigPath: path.resolve(__dirname, './fixtures/playwright-check/playwright.config.ts'),
121+
})
122+
123+
const diags = new Diagnostics()
124+
await check.validate(diags)
125+
126+
expect(diags.isFatal()).toEqual(false)
127+
expect(diags.observations).toEqual(expect.arrayContaining([
128+
expect.objectContaining({
129+
message: expect.stringContaining('Property "groupName" is deprecated and will eventually be removed.'),
130+
}),
131+
]))
132+
})
133+
134+
it('should error if groupName is not found', async () => {
135+
Session.project = new Project('project-id', {
136+
name: 'Test Project',
137+
repoUrl: 'https://github.com/checkly/checkly-cli',
138+
})
139+
140+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
141+
const group = new CheckGroupV2('group', {
142+
name: 'Test Group',
143+
})
144+
145+
const check = new PlaywrightCheck('foo', {
146+
name: 'Test Check',
147+
groupName: 'Missing Group',
148+
playwrightConfigPath: path.resolve(__dirname, './fixtures/playwright-check/playwright.config.ts'),
149+
})
150+
151+
const diags = new Diagnostics()
152+
await check.validate(diags)
153+
154+
expect(diags.isFatal()).toEqual(true)
155+
expect(diags.observations).toEqual(expect.arrayContaining([
156+
expect.objectContaining({
157+
message: expect.stringContaining('The value provided for property "groupName" is not valid.'),
158+
}),
159+
]))
160+
})
161+
162+
it('should error if both group and groupName are set', async () => {
163+
Session.project = new Project('project-id', {
164+
name: 'Test Project',
165+
repoUrl: 'https://github.com/checkly/checkly-cli',
166+
})
167+
168+
const group = new CheckGroupV2('group', {
169+
name: 'Test Group',
170+
})
171+
172+
const check = new PlaywrightCheck('foo', {
173+
name: 'Test Check',
174+
group,
175+
groupName: 'Test Group',
176+
playwrightConfigPath: path.resolve(__dirname, './fixtures/playwright-check/playwright.config.ts'),
177+
})
178+
179+
const diags = new Diagnostics()
180+
await check.validate(diags)
181+
182+
expect(diags.isFatal()).toEqual(true)
183+
expect(diags.observations).toEqual(expect.arrayContaining([
184+
expect.objectContaining({
185+
message: expect.stringContaining('Property "groupName" cannot be set when "group" is set.'),
186+
}),
187+
]))
188+
})
189+
190+
it('should error if both groupId and groupName are set', async () => {
191+
Session.project = new Project('project-id', {
192+
name: 'Test Project',
193+
repoUrl: 'https://github.com/checkly/checkly-cli',
194+
})
195+
196+
const group = new CheckGroupV2('group', {
197+
name: 'Test Group',
198+
})
199+
200+
const check = new PlaywrightCheck('foo', {
201+
name: 'Test Check',
202+
groupId: group.ref(),
203+
groupName: 'Test Group',
204+
playwrightConfigPath: path.resolve(__dirname, './fixtures/playwright-check/playwright.config.ts'),
205+
})
206+
207+
const diags = new Diagnostics()
208+
await check.validate(diags)
209+
210+
expect(diags.isFatal()).toEqual(true)
211+
expect(diags.observations).toEqual(expect.arrayContaining([
212+
expect.objectContaining({
213+
message: expect.stringContaining('Property "groupName" cannot be set when "group" is set.'),
214+
}),
215+
]))
216+
})
217+
})
218+
})

packages/cli/src/constructs/check-group-v1.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,10 @@ export class CheckGroupV1 extends Construct {
500500
}
501501
}
502502

503+
allowInChecklyConfig () {
504+
return true
505+
}
506+
503507
synthesize () {
504508
return {
505509
name: this.name,

packages/cli/src/constructs/construct-diagnostics.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,25 @@ export class InvalidPropertyValueDiagnostic extends ErrorDiagnostic {
1818
}
1919
}
2020

21+
export class ConflictingPropertyDiagnostic extends ErrorDiagnostic {
22+
property1: string
23+
property2: string
24+
25+
constructor (property1: string, property2: string, error: Error) {
26+
super({
27+
title: `Conflicting property`,
28+
message:
29+
`Property "${property1}" cannot be set when "${property2}" is set.`
30+
+ `\n\n`
31+
+ `Hint: ${error.message}`,
32+
error,
33+
})
34+
35+
this.property1 = property1
36+
this.property2 = property2
37+
}
38+
}
39+
2140
export class DeprecatedPropertyDiagnostic extends WarningDiagnostic {
2241
property: string
2342

0 commit comments

Comments
 (0)