Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/cli/src/constructs/__tests__/api-check.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,34 @@ describe('ApiCheck', () => {
}))
}, DEFAULT_TEST_TIMEOUT)

it('should synthesize requests that treat binary-labelled responses as text', async () => {
const output = await parseProject(
fixt,
'--config',
fixt.abspath('test-cases/test-treat-response-body-as-text/checkly.config.js'),
)

expect(output).toEqual(expect.objectContaining({
diagnostics: expect.objectContaining({
fatal: false,
}),
payload: expect.objectContaining({
resources: expect.arrayContaining([
expect.objectContaining({
logicalId: 'check',
type: 'check',
member: true,
payload: expect.objectContaining({
request: expect.objectContaining({
treatResponseBodyAsText: true,
}),
}),
}),
]),
}),
}))
}, DEFAULT_TEST_TIMEOUT)

describe('retryStrategy', () => {
it('should synthesize `onlyOn`', async () => {
const output = await parseProject(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'checkly'

const config = defineConfig({
projectName: 'Check Fixture',
logicalId: 'check-fixture',
checks: {
checkMatch: '**/*.check.js',
},
})

export default config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ApiCheck, AssertionBuilder } from 'checkly/constructs'

new ApiCheck('check', {
name: 'Treat response body as text check',
request: {
method: 'GET',
url: 'https://binary-labelled-text.example.test',
treatResponseBodyAsText: true,
assertions: [
AssertionBuilder.textBody().contains('OK'),
],
},
})
4 changes: 4 additions & 0 deletions packages/cli/src/constructs/api-request-codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export function valueForRequest (
builder.boolean('skipSSL', request.skipSSL)
}

if (request.treatResponseBodyAsText === true) {
builder.boolean('treatResponseBodyAsText', request.treatResponseBodyAsText)
}

if (request.body !== undefined && request.body !== '') {
builder.string('body', request.body)
}
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/constructs/api-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ export interface Request {
*/
skipSSL?: boolean

/**
* Whether to treat the response body as text even when the response Content-Type is marked as binary.
* @defaultValue false
*/
treatResponseBodyAsText?: boolean

/**
* Assertions to validate the HTTP response.
* Check the main Checkly documentation on assertions for specific values like regular expressions
Expand Down
Loading