Skip to content

Commit

Permalink
✅ Allow mocked serialize to accept options
Browse files Browse the repository at this point in the history
  • Loading branch information
wwilsman committed Oct 19, 2020
1 parent aa1e71e commit 14a522d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions packages/sdk-utils/test/helper.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
const createTestServer = require('@percy/core/test/helpers/server');
const sdk = {};

// mock serialization script
const serializeDOM = (options) => {
let doc = (options.dom || document).documentElement;
if (options.domTransformation) options.domTransformation(doc);
return doc.outerHTML;
};

sdk.setup = async function setup() {
// mock percy server
sdk.server = await createTestServer({
'/percy/dom.js': () => [200, 'application/javascript', (
`window.PercyDOM = { serialize: ${sdk.serialize.toString()} }`)],
`window.PercyDOM = { serialize: ${sdk.serializeDOM.toString()} }`)],
'/percy/healthcheck': () => [200, 'application/json', (
{ success: true, config: { snapshot: { widths: [1280] } } })],
'/percy/snapshot': () => [200, 'application/json', { success: true }]
Expand All @@ -14,7 +21,7 @@ sdk.setup = async function setup() {
// reset things
delete process.env.PERCY_CLI_API;
delete process.env.PERCY_LOGLEVEL;
sdk.serialize = () => document.documentElement.outerHTML;
sdk.serializeDOM = serializeDOM;
sdk.stdio[1] = []; sdk.stdio[2] = [];

let utils = require('..');
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-utils/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ describe('SDK Utils', () => {
it('fetches @percy/dom from the CLI API and caches the result', async () => {
({ fetchPercyDOM } = sdk.rerequire('..'));
await expect(fetchPercyDOM()).resolves.toEqual(
'window.PercyDOM = { serialize: () => document.documentElement.outerHTML }');
`window.PercyDOM = { serialize: ${sdk.serializeDOM.toString()} }`);
await expect(fetchPercyDOM()).resolves.toBeDefined();
expect(sdk.server.requests).toEqual([['/percy/dom.js']]);
});
Expand Down

0 comments on commit 14a522d

Please sign in to comment.