|
| 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 | +}) |
0 commit comments