UNPKG

suitest-js-api

Version:

Suitest is a test automation and device manipulation tool for living room devices and web browsers.

54 lines (45 loc) 1.19 kB
const makeChain = require('../utils/makeChain'); const { makeToStringComposer, makeThenComposer, makeToJSONComposer, abandonComposer, } = require('../composers'); const t = require('../texts'); const {validate, validators} = require('../validation'); const takeScreenshotFactory = (classInstance) => { const toJSON = () => ({type: 'takeScreenshot'}); const toStringComposer = makeToStringComposer(toJSON); const thenComposer = makeThenComposer(toJSON); const toJSONComposer = makeToJSONComposer(toJSON); const getComposers = (data) => { const output = [ toStringComposer, thenComposer, toJSONComposer, ]; if (!data.isAbandoned) { output.push(abandonComposer); } return output; }; /** * @param {'raw' | 'base64'} [dataFormat] * @returns {*} */ const takeScreenshotChain = (dataFormat = 'raw') => makeChain(classInstance, getComposers, { type: 'takeScreenshot', dataFormat: validate( validators.TAKE_SCREENSHOT, dataFormat, t.invalidInputMessage('takeScreenshot', 'Data format'), ), }); return { takeScreenshot: takeScreenshotChain, // For Unit Testing getComposers, toJSON, }; }; module.exports = takeScreenshotFactory;