How to use skipSnapshot method in ava

Best JavaScript code snippet using ava

update-image-hoc.jsx

Source:update-image-hoc.jsx Github

copy

Full Screen

1import paper from '@scratch/paper';2import PropTypes from 'prop-types';3import log from '../log/log';4import bindAll from 'lodash.bindall';5import React from 'react';6import omit from 'lodash.omit';7import {connect} from 'react-redux';8import {undoSnapshot} from '../reducers/undo';9import {setSelectedItems} from '../reducers/selected-items';10import {updateViewBounds} from '../reducers/view-bounds';11import {getSelectedLeafItems} from '../helper/selection';12import {getRaster, hideGuideLayers, showGuideLayers} from '../helper/layer';13import {commitRectToBitmap, commitOvalToBitmap, commitSelectionToBitmap, getHitBounds} from '../helper/bitmap';14import {performSnapshot} from '../helper/undo';15import {scaleWithStrokes} from '../helper/math';16import {17 ART_BOARD_WIDTH, ART_BOARD_HEIGHT, SVG_ART_BOARD_WIDTH, SVG_ART_BOARD_HEIGHT,18 setWorkspaceBounds19} from '../helper/view';20import Modes, {BitmapModes} from '../lib/modes';21import Formats, {isBitmap, isVector} from '../lib/format';22const UpdateImageHOC = function (WrappedComponent) {23 class UpdateImageWrapper extends React.Component {24 constructor (props) {25 super(props);26 bindAll(this, [27 'handleUpdateImage',28 'handleUpdateBitmap',29 'handleUpdateVector'30 ]);31 }32 /**33 * @param {?boolean} skipSnapshot True if the call to update image should not trigger saving34 * an undo state. For instance after calling undo.35 * @param {?Formats} formatOverride Normally the mode is used to determine the format of the image,36 * but the format used can be overridden here. In particular when converting between formats,37 * the does not accurately represent the format.38 */39 handleUpdateImage (skipSnapshot, formatOverride) {40 // If in the middle of switching formats, rely on the current mode instead of format.41 const actualFormat = formatOverride ? formatOverride :42 BitmapModes[this.props.mode] ? Formats.BITMAP : Formats.VECTOR;43 if (isBitmap(actualFormat)) {44 this.handleUpdateBitmap(skipSnapshot);45 } else if (isVector(actualFormat)) {46 this.handleUpdateVector(skipSnapshot);47 }48 // Any time an image update is made, recalculate the bounds of the artwork49 setWorkspaceBounds();50 this.props.updateViewBounds(paper.view.matrix);51 }52 handleUpdateBitmap (skipSnapshot) {53 if (!getRaster().loaded) {54 // In general, callers of updateImage should wait for getRaster().loaded = true before55 // calling updateImage.56 // However, this may happen if the user is rapidly undoing/redoing. In this case it's safe57 // to skip the update.58 log.warn('Bitmap layer should be loaded before calling updateImage.');59 return;60 }61 // Anything that is selected is on the vector layer waiting to be committed to the bitmap layer.62 // Plaster the selection onto the raster layer before exporting, if there is a selection.63 const plasteredRaster = getRaster().getSubRaster(getRaster().bounds); // Clone the raster layer64 plasteredRaster.remove(); // Don't insert65 const selectedItems = getSelectedLeafItems();66 if (selectedItems.length === 1) {67 const item = selectedItems[0];68 if (item instanceof paper.Raster) {69 if (!item.loaded ||70 (item.data &&71 item.data.expanded &&72 !item.data.expanded.loaded)) {73 // This may get logged when rapidly undoing/redoing or changing costumes,74 // in which case the warning is not relevant.75 log.warn('Bitmap layer should be loaded before calling updateImage.');76 return;77 }78 commitSelectionToBitmap(item, plasteredRaster);79 } else if (item instanceof paper.Shape && item.type === 'rectangle') {80 commitRectToBitmap(item, plasteredRaster);81 } else if (item instanceof paper.Shape && item.type === 'ellipse') {82 commitOvalToBitmap(item, plasteredRaster);83 } else if (item instanceof paper.PointText) {84 const bounds = item.drawnBounds;85 const textRaster = item.rasterize(72, false /* insert */, bounds);86 plasteredRaster.drawImage(87 textRaster.canvas,88 new paper.Point(Math.floor(bounds.x), Math.floor(bounds.y))89 );90 }91 }92 const rect = getHitBounds(plasteredRaster);93 // Use 1x1 instead of 0x0 for getting imageData since paper.js automagically94 // returns the full artboard in the case of getImageData(0x0).95 // Bitmaps need a non-zero width/height in order to be saved as PNG.96 if (rect.width === 0 || rect.height === 0) {97 rect.width = rect.height = 1;98 }99 const imageData = plasteredRaster.getImageData(rect);100 this.props.onUpdateImage(101 false /* isVector */,102 imageData,103 (ART_BOARD_WIDTH / 2) - rect.x,104 (ART_BOARD_HEIGHT / 2) - rect.y);105 if (!skipSnapshot) {106 performSnapshot(this.props.undoSnapshot, Formats.BITMAP);107 }108 }109 handleUpdateVector (skipSnapshot) {110 // Remove viewbox (this would make it export at MAX_WORKSPACE_BOUNDS)111 let workspaceMask;112 if (paper.project.activeLayer.clipped) {113 for (const child of paper.project.activeLayer.children) {114 if (child.isClipMask()) {115 workspaceMask = child;116 break;117 }118 }119 paper.project.activeLayer.clipped = false;120 workspaceMask.remove();121 }122 const guideLayers = hideGuideLayers(true /* includeRaster */);123 // Export at 0.5x124 scaleWithStrokes(paper.project.activeLayer, .5, new paper.Point());125 const bounds = paper.project.activeLayer.drawnBounds;126 // `bounds.x` and `bounds.y` are relative to the top left corner,127 // but if there is no content in the active layer, they default to 0,128 // making the "Scratch space" rotation center ((SVG_ART_BOARD_WIDTH / 2), (SVG_ART_BOARD_HEIGHT / 2)),129 // aka the upper left corner. Special-case this to be (0, 0), which is the center of the art board.130 const centerX = bounds.width === 0 ? 0 : (SVG_ART_BOARD_WIDTH / 2) - bounds.x;131 const centerY = bounds.height === 0 ? 0 : (SVG_ART_BOARD_HEIGHT / 2) - bounds.y;132 this.props.onUpdateImage(133 true /* isVector */,134 paper.project.exportSVG({135 asString: true,136 bounds: 'content',137 matrix: new paper.Matrix().translate(-bounds.x, -bounds.y)138 }),139 centerX,140 centerY);141 scaleWithStrokes(paper.project.activeLayer, 2, new paper.Point());142 paper.project.activeLayer.applyMatrix = true;143 showGuideLayers(guideLayers);144 // Add back viewbox145 if (workspaceMask) {146 paper.project.activeLayer.addChild(workspaceMask);147 workspaceMask.clipMask = true;148 }149 if (!skipSnapshot) {150 performSnapshot(this.props.undoSnapshot, Formats.VECTOR);151 }152 }153 render () {154 const componentProps = omit(this.props, [155 'format',156 'onUpdateImage',157 'undoSnapshot'158 ]);159 return (160 <WrappedComponent161 onUpdateImage={this.handleUpdateImage}162 {...componentProps}163 />164 );165 }166 }167 UpdateImageWrapper.propTypes = {168 format: PropTypes.oneOf(Object.keys(Formats)),169 mode: PropTypes.oneOf(Object.keys(Modes)).isRequired,170 onUpdateImage: PropTypes.func.isRequired,171 undoSnapshot: PropTypes.func.isRequired,172 updateViewBounds: PropTypes.func.isRequired173 };174 const mapStateToProps = state => ({175 format: state.scratchPaint.format,176 mode: state.scratchPaint.mode,177 undoState: state.scratchPaint.undo178 });179 const mapDispatchToProps = dispatch => ({180 setSelectedItems: format => {181 dispatch(setSelectedItems(getSelectedLeafItems(), isBitmap(format)));182 },183 undoSnapshot: snapshot => {184 dispatch(undoSnapshot(snapshot));185 },186 updateViewBounds: matrix => {187 dispatch(updateViewBounds(matrix));188 }189 });190 return connect(191 mapStateToProps,192 mapDispatchToProps193 )(UpdateImageWrapper);194};...

Full Screen

Full Screen

analog-clock.component.js

Source:analog-clock.component.js Github

copy

Full Screen

1/**2# Analog Clock3<b8r-component4 name="analog-clock-js"5 path="../components/analog-clock.component.js"6>7</b8r-component>8Here's a pure JS version of the old analog clock component.9*/10const colors = [11 { description: 'very dark grey', value: '#222' },12 { description: 'dark grey', value: '#444' },13 { description: 'grey', value: '#666' },14 { description: 'light grey', value: '#ddd' },15 { description: 'off-white', value: '#f7f7f7' },16 { description: 'red', value: 'blue' },17 { description: 'green', value: 'blue' },18 { description: 'blue', value: 'blue' }19]20const timePartsRegEx = /\d+|AM|PM/g21const localTime = () => {22 return new Date().toLocaleString('en-US').split(',').pop().match(timePartsRegEx)23}24const fiveSecondsToMidnight = () => [11, 59, 55, 'PM']25const drinkOClock = () => [5, 0, 15, 'PM']26export const timeFromTimezone = timezone => {27 return () => () => new Date().toLocaleString('en-US', { timezone }).split(',').pop().match(timePartsRegEx)28}29const zuluTime = () => timeFromTimezone('Zulu')30const sydneyTime = () => timeFromTimezone('Australia/Sydney')31export const configuration = [32 {33 name: 'faceColor',34 values: colors35 },36 {37 name: 'tickColor',38 values: colors39 },40 {41 name: 'handColor',42 values: colors43 },44 {45 name: 'secondHandColor',46 values: colors47 },48 {49 name: 'logoUrl',50 values: [51 { description: 'no logo', value: null },52 { description: 'b8r logo greyscale', value: 'images/bindinator-logo-notext-mono.svg' }53 ]54 },55 {56 name: 'getHMS',57 values: [58 { description: 'local time', value: localTime },59 { description: 'time in Sydney', value: sydneyTime },60 { description: 'GMT', value: zuluTime },61 { description: 'five seconds to midnight', value: fiveSecondsToMidnight },62 { description: 'it’s 5PM somewhere…', value: drinkOClock }63 ]64 }65]66export const examples = [67 {68 name: 'local time',69 skipSnapshot: true70 },71 {72 skipSnapshot: true,73 name: 'no logo',74 settings: [75 { name: 'logoUrl', option: 0 }76 ]77 },78 {79 name: 'Sydney Time',80 skipSnapshot: true,81 settings: [82 { name: 'getHMS', option: 2 }83 ]84 },85 {86 name: 'GMT',87 skipSnapshot: true,88 settings: [89 { name: 'getHMS', option: 2 }90 ]91 },92 {93 name: 'fixed time (5PM)',94 settings: [95 { name: 'getHMS', option: 3 }96 ]97 },98 {99 name: 'fixed time (5 seconds to midnight)',100 settings: [101 { name: 'getHMS', option: 4 }102 ]103 }104]105export default {106 css: `107 ._component_ canvas { width: 128px; height: 128px; }108 `,109 html: `110 <canvas111 data-bind="112 attr(aria-label),attr(title)=clock showing $\{_component_.time}113 "114 width="256" height="256"115 ></canvas>`,116 initialValue: {117 faceColor: '#f7f7f7',118 tickColor: '#222',119 handColor: '#444',120 secondHandColor: 'red',121 logoUrl: 'images/bindinator-logo-notext-mono.svg',122 getHMS: localTime123 },124 load: async ({ get, set, findOne }) => {125 /* global Image */126 const { domInterval } = await import('../lib/dom-timers.js')127 const { getHMS, faceColor, tickColor, handColor, secondHandColor, logoUrl } = get()128 const clock = findOne('canvas')129 const g = clock.getContext('2d')130 let logo = false131 if (logoUrl) {132 logo = new Image()133 logo.src = logoUrl134 }135 g.fillStyle = faceColor136 const d2r = Math.PI / 180137 const drawRay = (width, angle, r0, r1, color = tickColor) => {138 g.strokeStyle = color139 g.lineWidth = width140 const radians = angle * d2r141 const sinR = Math.sin(radians)142 const cosR = Math.cos(radians)143 const x0 = 128 + r0 * sinR144 const y0 = 128 - r0 * cosR145 const x1 = 128 + r1 * sinR146 const y1 = 128 - r1 * cosR147 g.beginPath()148 g.moveTo(x0, y0)149 g.lineTo(x1, y1)150 g.stroke()151 }152 const update = () => {153 const [hours, minutes, seconds, pm] = getHMS()154 const timeText = `${hours}:${minutes}:${seconds} ${pm}`155 if (timeText !== get('time')) {156 set('time', timeText)157 g.clearRect(0, 0, 256, 256)158 g.beginPath()159 g.ellipse(128, 128, 128, 128, 0, 0, 2 * Math.PI)160 g.fill()161 g.drawImage(logo, 108, 160, 40, 29)162 for (let h = 0; h < 12; h++) {163 drawRay(6, h * 30, 96, 120, handColor)164 }165 const hourHand = (parseInt(hours, 10) % 12 * 30) + parseInt(minutes, 10) * 0.5166 const minuteHand = parseInt(minutes, 10) * 6 + parseInt(seconds, 10) * 0.1167 const secondHand = parseInt(seconds, 10) * 6 // + now.getMilliseconds() * 0.006;168 drawRay(6, hourHand, 0, 80)169 drawRay(4, minuteHand, 0, 116)170 drawRay(2, secondHand, 0, 116, secondHandColor)171 }172 }173 domInterval(clock, update, 16.6)174 }...

Full Screen

Full Screen

trigger.js

Source:trigger.js Github

copy

Full Screen

1/**2 * : staffomatic-component3 * Copyright © 2022, AG4 *5 * All files of this connector are licensed under the Apache 2.0 License. For details6 * see the file LICENSE on the toplevel directory.7 *8 */9const componentJson = require("../../component.json");10const {11 dataAndSnapshot,12 getMetadata,13 getElementDataFromResponse,14 endpointCall,15 } = require("../utils/helpers");16async function processTrigger(msg, cfg, snapshot, incomingMessageHeaders, tokenData) {17 snapshot.lastUpdated = snapshot.lastUpdated || new Date(0).getTime();18 const { snapshotKey, arraySplittingKey, syncParam, skipSnapshot } = cfg.nodeSettings;19 const trigger = componentJson.triggers[tokenData["function"]];20 const { pathName, method, requestContentType } = trigger.callParams;21 const bodyParams = trigger.bodyParams ? trigger.bodyParams.map(({ name }) => {22 return name;23 }) : [];24 const body = msg.data;25 let parameters = {};26 for (let param of bodyParams) {27 parameters[param] = body[param];28 }29 if (syncParam) {30 parameters[syncParam] = snapshot.lastUpdated;31 }32 const base = `https://app.staffomatic.app/v3/${config.company_domain}`;33 const url = base + setupUrlParamaters(pathName, body);34 const options = {35 method: method,36 headers: {37 Accept: 'application/json',38 'Content-Type': 'application/json',39 },40 params: parameters,41 };42 const { data } = await endpointCall(url, options, cfg);43 const newElement = {};44 newElement.metadata = getMetadata(msg.metadata);45 newElement.data = getElementDataFromResponse(arraySplittingKey,data);46 if(skipSnapshot){47 return newElement.data; 48 } else {49 await dataAndSnapshot(newElement,snapshot,snapshotKey, 'modified_at', this);50 }51}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1test.skipSnapshot('my snapshot', t => {2 t.snapshot({foo: 'bar'});3});4test('my snapshot', t => {5 t.skipSnapshot({foo: 'bar'});6});7test('my snapshot', t => {8 t.snapshot.skip({foo: 'bar'});9});10test('my snapshot', t => {11 t.snapshot({foo: 'bar'}, {skip: true});12});13test('my snapshot', t => {14 t.snapshot({foo: 'bar'});15 t.skipSnapshot({foo: 'bar'});16});17test('my snapshot', t => {18 t.snapshot({foo: 'bar'});19 t.snapshot.skip({foo: 'bar'});20});21test('my snapshot', t => {22 t.snapshot({foo: 'bar'});23 t.snapshot({foo: 'bar'}, {skip: true});24});25test('my snapshot', t => {26 t.snapshot({foo: 'bar'});27 t.snapshot({foo: 'bar'});28 t.skipSnapshot({foo: 'bar'});29});30test('my snapshot', t => {31 t.snapshot({foo: 'bar'});32 t.snapshot({foo: 'bar'});33 t.snapshot.skip({foo: 'bar'});34});35test('my snapshot', t => {36 t.snapshot({foo: 'bar'});37 t.snapshot({foo: 'bar'});38 t.snapshot({foo: 'bar'}, {skip: true});39});40test('my snapshot', t => {41 t.snapshot({foo: 'bar'});42 t.snapshot({foo: 'bar'});43 t.snapshot({foo: 'bar'});44 t.skipSnapshot({foo: 'bar'});45});

Full Screen

Using AI Code Generation

copy

Full Screen

1test.skipSnapshot('test', t => {2 t.snapshot('foo');3});4test.skipSnapshot('test', t => {5 t.snapshot('foo');6});7test.skipSnapshot('test', t => {8 t.snapshot('foo');9});10test.skipSnapshot('test', t => {11 t.snapshot('foo');12});13test.skipSnapshot('test', t => {14 t.snapshot('foo');15});16test.skipSnapshot('test', t => {17 t.snapshot('foo');18});19test.skipSnapshot('test', t => {20 t.snapshot('foo');21});22test.skipSnapshot('test', t => {23 t.snapshot('foo');24});25test.skipSnapshot('test', t => {26 t.snapshot('foo');27});28test.skipSnapshot('test', t => {29 t.snapshot('foo');30});31test.skipSnapshot('test', t => {32 t.snapshot('foo');33});34test.skipSnapshot('test', t => {35 t.snapshot('foo');36});37test.skipSnapshot('test', t => {38 t.snapshot('foo');39});40test.skipSnapshot('test', t => {41 t.snapshot('foo');42});43test.skipSnapshot('test', t => {44 t.snapshot('foo');45});46test.skipSnapshot('test', t => {

Full Screen

Using AI Code Generation

copy

Full Screen

1import test from 'ava';2import { skipSnapshot } from 'ava-skip-snapshot';3test('should skip snapshot', t => {4 skipSnapshot(t);5 t.snapshot('foo');6});7test('should not skip snapshot', t => {8 t.snapshot('bar');9});10{11 "ava": {12 }13}14import test from 'ava';15import { skipSnapshot } from 'ava-skip-snapshot';16test('should skip snapshot', t => {17 skipSnapshot(t);18 t.snapshot('foo');19});20test('should not skip snapshot', t => {21 t.snapshot('bar');22});23{24 "ava": {25 }26}27import test from 'ava';28import { skipSnapshot } from 'ava-skip-snapshot';29test('should skip snapshot', t => {30 skipSnapshot(t);31 t.snapshot('foo');32});33test('should not skip snapshot', t => {34 t.snapshot('bar');35});36{37 "ava": {38 }39}40import test from 'ava';41import { skipSnapshot } from 'ava-skip-snapshot';42test('should skip snapshot', t => {43 skipSnapshot(t);44 t.snapshot('foo');45});46test('should not skip snapshot', t => {47 t.snapshot('bar');48});49{50 "ava": {51 }52}53import test from 'ava';54import { skipSnapshot } from 'ava-skip-snapshot';55test('should skip snapshot', t => {56 skipSnapshot(t);57 t.snapshot('foo');58});59test('should not skip snapshot', t => {60 t.snapshot('bar');61});62{63 "ava": {64 }65}

Full Screen

Using AI Code Generation

copy

Full Screen

1test.skipSnapshot('snapshot test', t => {2 const obj = {a: 1, b: 2};3 t.snapshot(obj);4});5Object {6}7`;

Full Screen

Using AI Code Generation

copy

Full Screen

1import test from 'ava';2import {skipSnapshot} from 'ava-skip-snapshot';3test.skipSnapshot = skipSnapshot;4test('my test', t => {5 t.skipSnapshot();6});7import test from 'ava';8import {skipSnapshot} from 'ava-skip-snapshot';9test.skipSnapshot = skipSnapshot;10test('my test', t => {11 t.skipSnapshot();12});13import test from 'ava';14import {skipSnapshot} from 'ava-skip-snapshot';15test.skipSnapshot = skipSnapshot;16test('my test', t => {17 t.skipSnapshot();18});19import test from 'ava';20import {skipSnapshot} from 'ava-skip-snapshot';21test.skipSnapshot = skipSnapshot;22test('my test', t => {23 t.skipSnapshot();24});25import test from 'ava';26import {skipSnapshot} from 'ava-skip-snapshot';27test.skipSnapshot = skipSnapshot;28test('my test', t => {29 t.skipSnapshot();30});31import test from 'ava';32import {skipSnapshot} from 'ava-skip-snapshot';33test.skipSnapshot = skipSnapshot;34test('my test', t => {35 t.skipSnapshot();36});37import test from 'ava';38import {skipSnapshot} from 'ava-skip-snapshot';39test.skipSnapshot = skipSnapshot;40test('my test', t => {41 t.skipSnapshot();42});43import test from 'ava';44import {skipSnapshot} from 'ava-skip-snapshot';45test.skipSnapshot = skipSnapshot;46test('my test', t => {47 t.skipSnapshot();48});49import test from 'ava';50import {skipSnapshot} from 'ava-skip-snapshot';51test.skipSnapshot = skipSnapshot;

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ava automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful