Skip to content
Merged
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
11 changes: 9 additions & 2 deletions src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ function createSimpleClient(serverUrl) {
let image = isFilePath ? imageBuffer : imageBuffer.toString('base64');
let type = isFilePath ? 'file-path' : 'base64';

let {
fullPage,
threshold,
properties: userProperties,
...rest
} = options;

let httpStart = Date.now();
const { status, json } = await httpPost(
`${serverUrl}/screenshot`,
Expand All @@ -207,8 +214,8 @@ function createSimpleClient(serverUrl) {
name,
image,
type,
properties: options,
fullPage: options.fullPage || false,
properties: { ...rest, ...userProperties },
fullPage: fullPage || false,
},
DEFAULT_TIMEOUT_MS
);
Expand Down
30 changes: 30 additions & 0 deletions tests/sdk/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,36 @@ describe('client/index httpPost integration tests', () => {
assert.deepStrictEqual(req.body.properties, { browser: 'chrome' });
});

it('flattens nested properties into top-level properties', async () => {
await vizzlyScreenshot('test', Buffer.from('data'), {
properties: { url: 'http://localhost:3000/page' },
});

assert.strictEqual(requests.length, 1);
assert.deepStrictEqual(requests[0].body.properties, {
url: 'http://localhost:3000/page',
});
});

it('excludes SDK options from properties', async () => {
await vizzlyScreenshot('test', Buffer.from('data'), {
fullPage: true,
threshold: 0.1,
properties: { url: 'http://localhost:3000' },
browser: 'firefox',
});

assert.strictEqual(requests.length, 1);
let { properties, fullPage } = requests[0].body;
assert.strictEqual(fullPage, true);
assert.deepStrictEqual(properties, {
browser: 'firefox',
url: 'http://localhost:3000',
});
assert.strictEqual(properties.fullPage, undefined);
assert.strictEqual(properties.threshold, undefined);
});

it('sends Connection: close header to disable keep-alive', async () => {
await vizzlyScreenshot('test', Buffer.from('data'));

Expand Down