diff --git a/index.js b/index.js index 3d3cf99..1d9a2e1 100644 --- a/index.js +++ b/index.js @@ -43,7 +43,7 @@ module.exports = async function percySnapshot(driver, name, options) { name, url }); - return response.data; + return response?.body?.data; } catch (error) { // Handle errors log.error(`Could not take DOM snapshot "${name}"`); @@ -108,7 +108,7 @@ module.exports.percyScreenshot = async function percyScreenshot(driver, name, op snapshotName: name, options }); - return response.data; + return response?.body?.data; } catch (error) { // Handle errors log.error(`Could not take Screenshot "${name}"`); diff --git a/test/index.test.mjs b/test/index.test.mjs index f83bb41..53b405f 100644 --- a/test/index.test.mjs +++ b/test/index.test.mjs @@ -143,12 +143,8 @@ describe('percyScreenshot', () => { const considerElement = { getId: () => {} }; const mockElement = spyOn(element, 'getId').and.callFake(() => { return new Promise((resolve, _) => resolve('123')); }); const mockConsiderElement = spyOn(considerElement, 'getId').and.callFake(() => { return new Promise((resolve, _) => resolve('456')); }); - const mockresponse = { - success: 'true', - data: 'sync_data' - } const mockedPostCall = spyOn(percySnapshot, 'request').and.callFake(() => mockresponse); - const response = await percyScreenshot(driver, 'Snapshot 2', { ignoreRegionSeleniumElements: [element], considerRegionSeleniumElements: [considerElement] }); + await percyScreenshot(driver, 'Snapshot 2', { ignoreRegionSeleniumElements: [element], considerRegionSeleniumElements: [considerElement] }); expect(mockElement).toHaveBeenCalled(); expect(mockConsiderElement).toHaveBeenCalled(); @@ -158,7 +154,17 @@ describe('percyScreenshot', () => { consider_region_selenium_elements: ['456'] } })); - expect(response).toEqual(mockresponse.data); + }); + + it('receive data object from CLI response', async() => { + const mockResponse = { + success: true, + body: { data: { some_data: 'some_data ' } } + } + + spyOn(percySnapshot, 'request').and.callFake(() => mockResponse); + const response = await percyScreenshot(driver, 'Snapshot 1'); + expect(response).toEqual(mockResponse.body.data); }); it('posts driver details to the local percy server with ignore and consider region and sync', async () => {