How to use onGoingPromise method in stryker-parent

Best JavaScript code snippet using stryker-parent

LiveOrder.Model.js

Source:LiveOrder.Model.js Github

copy

Full Screen

1// LiveOrder.Model.js2// -----------------------3// Model for showing information about an open order4define('LiveOrder.Model', ['Order.Model', 'OrderLine.Model', 'OrderLine.Collection', 'ItemDetails.Model', 'Session'], function (OrderModel, OrderLineModel, OrderLineCollection, ItemDetailsModel, Session)5{6 'use strict';7 var LiveOrderLine = {};8 LiveOrderLine.Model = OrderLineModel.extend({9 urlRoot: _.getAbsoluteUrl('services/live-order-line.ss')10 });11 LiveOrderLine.Collection = OrderLineCollection.extend({12 model: LiveOrderLine.Model13 , url: _.getAbsoluteUrl('services/live-order-line.ss')14 });15 return OrderModel.extend({16 urlRoot: _.getAbsoluteUrl('services/live-order.ss')17 , linesCollection: LiveOrderLine.Collection18 // redefine url to avoid possible cache problems from browser19 , url: function()20 {21 var base_url = OrderModel.prototype.url.apply(this, arguments);22 return base_url + '&t=' + new Date().getTime();23 }24 , initialize: function ()25 {26 // call the initialize of the parent object, equivalent to super()27 OrderModel.prototype.initialize.apply(this, arguments);28 // Some actions in the live order may change the url of the checkout so to be sure we re send all the touchpoints29 this.on('change:touchpoints', function (model, touchpoints)30 {31 Session.set('touchpoints', touchpoints);32 });33 }34 , getLatestAddition: function ()35 {36 var model = null;37 if (this.get('latest_addition'))38 {39 model = this.get('lines').get(this.get('latest_addition'));40 }41 if (!model && this.get('lines').length)42 {43 model = this.get('lines').at(0);44 }45 return model;46 }47 , wrapOptionsSuccess: function (options)48 {49 var self = this50 , application = this.application;51 // if passing a succes function we need to wrap it52 options = options || {};53 options.success = _.wrap(options.success || jQuery.noop, function (fn, item_model, result)54 {55 // This method is called in 2 ways by doing a sync and by doing a save56 // if its a save result will be the raw object57 var attributes = result;58 // If its a sync resilt will be a string59 if (_.isString(result))60 {61 attributes = item_model;62 }63 // Tho this should be a restfull api, the live-order-line returns the full live-order back (lines and summary are interconnected)64 self.set(attributes);65 // Calls the original success function66 fn.apply(self, _.toArray(arguments).slice(1));67 var line = self.get('lines').get(self.get('latest_addition'))68 , item = line && line.get('item');69 item && application && application.trackEvent && application.trackEvent({70 category: 'add-to-cart'71 , action: 'button'72 , label: item.get('_url') + item.getQueryString()73 , value: 174 });75 });76 options.killerId = application && application.killerId;77 return options;78 }79 , addItem: function (item, options)80 {81 // Calls the addItems funtion passing the item as an array of 1 item82 return this.addItems([item], options);83 }84 , addItems: function (items, options)85 {86 // Obteins the Collection constructor87 var LinesCollection = this.linesCollection;88 // Prepares the input for the new collection89 var lines = _.map(items, function (item)90 {91 var line_options = item.getItemOptionsForCart();92 return {93 item: {94 internalid: item.get('internalid')95 }96 , quantity: item.get('quantity')97 , options: _.values(line_options).length ? line_options : null98 };99 });100 // Creates the Colection101 var self = this102 , lines_collection = new LinesCollection(lines);103 // add the dummy line for optimistic add to cart - when the request come back with the real data the collection will be reseted.104 if (this.optimistic)105 {106 var price = this.optimistic.item.getPrice()107 , dummy_line = new OrderLineModel({108 quantity: this.optimistic.quantity109 , item: this.optimistic.item.attributes110 , rate_formatted: price.price_formatted111 , rate: price.price112 });113 dummy_line.get('item').itemOptions = this.optimistic.item.itemOptions;114 // search the item in the cart to merge the quantities115 if (self.application.loadCart().state() === 'resolved')116 {117 var itemCart = SC.Utils.findItemInCart(self.optimistic.item, self.application.getCart());118 if (itemCart) 119 {120 itemCart.set('quantity', itemCart.get('quantity') + parseInt(this.optimistic.quantity, 10));121 dummy_line = itemCart;122 }123 else124 {125 this.get('lines').add(dummy_line);126 }127 }128 else129 {130 dummy_line.set('quantity', 0);131 }132 this.optimisticLine = dummy_line;133 this.trigger('change');134 }135 // Saves it136 var promise = lines_collection.sync('create', lines_collection, this.wrapOptionsSuccess(options));137 if (promise)138 {139 promise.fail(function()140 {141 // if any error we must revert the optimistic changes.142 if (self.optimistic)143 {144 if (self.application.loadCart().state() === 'resolved')145 {146 var itemCart = SC.Utils.findItemInCart(self.optimistic.item, self.application.getCart());147 if (itemCart) 148 {149 itemCart.set('quantity', itemCart.get('quantity') - parseInt(self.optimistic.quantity, 10));150 if (!itemCart.get('quantity'))151 {152 self.get('lines').remove(itemCart);153 }154 }155 self.set('latest_addition', self.get('latest_addition_original'));156 self.trigger('change');157 }158 }159 });160 }161 return promise;162 }163 , updateItem: function (line_id, item, options)164 {165 var line = this.get('lines').get(line_id)166 , line_options = item.getItemOptionsForCart();167 line.set({168 quantity: item.get('quantity')169 , options: _.values(line_options).length ? line_options : null170 });171 line.ongoingPromise = line.save({}, this.wrapOptionsSuccess(options));172 return line.ongoingPromise;173 }174 , updateLine: function (line, options)175 {176 // Makes sure the quantity is a number177 line.set('quantity', parseInt(line.get('quantity'), 10));178 line.ongoingPromise = line.save({}, this.wrapOptionsSuccess(options));179 return line.ongoingPromise;180 }181 , removeLine: function (line, options)182 {183 line.ongoingPromise = line.destroy(this.wrapOptionsSuccess(options));184 return line.ongoingPromise;185 }186 // submit invoked when the user place/submit the order187 , submit: function ()188 {189 this.set('internalid', null);190 var self = this191 , creditcard = this.get('paymentmethods').findWhere({type: 'creditcard'})192 , paypal = this.get('paymentmethods').findWhere({type: 'paypal'});193 if (creditcard && !creditcard.get('creditcard'))194 {195 this.get('paymentmethods').remove(creditcard);196 }197 if (paypal && !paypal.get('complete'))198 {199 this.get('paymentmethods').remove(paypal);200 }201 return this.save().fail(function ()202 {203 self.set('internalid', 'cart');204 }).done(function ()205 {206 self.application.trackEvent && self.application.trackEvent({207 category: 'place-order'208 , action: 'button'209 , label: ''210 , value: 1211 });212 });213 }214 , save: function ()215 {216 if (this.get('confirmation'))217 {218 return jQuery.Deferred().resolve();219 }220 return OrderModel.prototype.save.apply(this, arguments);221 }222 , getTotalItemCount: function ()223 {224 return _.reduce(this.get('lines').pluck('quantity'), function (memo, quantity)225 {226 return memo + (parseFloat(quantity) || 1);227 }, 0);228 }229 , parse: function (response, options)230 {231 if (options && !options.parse)232 {233 return;234 }235 return response;236 }237 // Returns the order's lines that have not set its addresses to Multi Ship To yet238 , getUnsetLines: function ()239 {240 return this.get('lines').filter(function (line) { return !line.get('shipaddress') && line.get('isshippable'); });241 }242 // Returns the order's line that are NON Shippable243 , getNonShippableLines: function ()244 {245 return this.get('lines').filter(function (line) { return !line.get('isshippable'); });246 }247 // Returns the list of lines already set its shipping address248 , getSetLines: function ()249 {250 return this.get('lines').filter(function (line) { return line.get('shipaddress') && line.get('isshippable'); });251 }252 // Returns the order's line that are shippable without taking into account if their have or not set a shipaddress253 , getShippableLines: function ()254 {255 return this.get('lines').filter(function (line) { return line.get('isshippable'); });256 }257 // Returns an array containing the cart items ids258 , getItemsIds: function ()259 {260 return this.get('lines').map(function(line){return line.get('item').get('internalid');});261 }262 //Determines if at least one item is shippable263 , getIfThereAreDeliverableItems: function ()264 {265 return this.get('lines').length !== this.getNonShippableLines().length;266 }267 });...

Full Screen

Full Screen

alpha-vantage.js

Source:alpha-vantage.js Github

copy

Full Screen

1const rp = require('request-promise-native');2const BASE_URI = 'https://www.alphavantage.co/query';3// Global variable to keep track API calls, make them synchronous to avoid calling it too frequently.4let ongoingPromise;5let lastCallTime;6//TO-DO add timeout in case remote server is slow.7// See https://www.npmjs.com/package/request#timeouts8const defaultRequest = rp.defaults({9 uri: BASE_URI,10 json: true,11 qs: {12 apikey: process.env.ALPHA_VANTAGE_API_KEY13 }14});15const basicErrorChecking = (response) => {16 if (!response) {17 return Promise.reject({message: 'Empty response'});18 }19 const message = response && (response.Information || response['Error Message']);20 if (message) {21 return Promise.reject(new Error(message));22 }23 return response;24};25// Always delay sending api by 1 sec if there is an ongoing promise26const delayedRequest = (params) => {27 let delayPromise = Promise.resolve();28 // Break the chain by joining promise29 // https://stackoverflow.com/questions/28250680/how-do-i-access-previous-promise-results-in-a-then-chain/2825070430 const time = new Date();31 if (ongoingPromise) {32 delayPromise = ongoingPromise.delay(15000).catch(() => {});33 } else if (lastCallTime && time - lastCallTime < 15000) {34 // According to https://www.alphavantage.co/premium/35 // Limit is 5 requests per minutes.36 const delay = 15000 - (time - lastCallTime);37 delayPromise = delayPromise.delay(delay);38 }39 let result = ongoingPromise = delayPromise.then(() => {40 lastCallTime = new Date();41 return defaultRequest(params).then(basicErrorChecking);42 });43 const clearOngoing = () => {44 // Clear ongoing if it's not updated by elsewhere.45 if (result === ongoingPromise) {46 ongoingPromise = null;47 }48 };49 result.then(clearOngoing, clearOngoing);50 return result;51};52exports.exchangeRate = () => {53 const params = {54 qs: {55 function: 'CURRENCY_EXCHANGE_RATE',56 from_currency: 'USD',57 to_currency: 'CAD',58 }59 };60 return delayedRequest(params);61};62// Expect symbol for TSX to have prefix "TSX:", e.g TSX:VFV63exports.dailyQuote = (symbol) => {64 const params = {65 qs: {66 function: 'TIME_SERIES_DAILY',67 symbol68 }69 };70 return delayedRequest(params);71};72// Expect symbol for TSX to NOT have prefix "TSX:", e.g VFV73// Different to daily quote, werid, I know.74exports.intraDayQuote = (symbol) => {75 if (symbol && symbol.startsWith('TSX:')) {76 symbol = symbol.replace('TSX:', '');77 }78 const params = {79 qs: {80 function: 'TIME_SERIES_INTRADAY',81 interval: '5min',82 symbol83 }84 };85 return delayedRequest(params);...

Full Screen

Full Screen

promised.ts

Source:promised.ts Github

copy

Full Screen

1export class Promised<T> {2 fn: () => Promise<T>3 ongoingPromise: Promise<T>4 cached: boolean5 cachedValue: T6 cachedErr: any7 id: number8 constructor(fn: () => Promise<T>) {9 this.fn = fn10 this.id = 011 this.reset()12 }13 reset() {14 this.ongoingPromise = null15 this.cached = false16 this.cachedValue = null17 this.cachedErr = null18 this.id++19 }20 get value(): Promise<T> {21 if (this.cached) {22 if (this.cachedErr) {23 return Promise.reject(this.cachedErr)24 }25 return Promise.resolve(this.cachedValue)26 }27 if (this.ongoingPromise) {28 return this.ongoingPromise29 }30 const id = this.id31 return this.ongoingPromise = Promise.resolve(this.fn()).then(e => {32 if (id === this.id) {33 this.cached = true34 this.cachedValue = e35 }36 return e37 }).catch(e => {38 if (id === this.id) {39 this.cached = true40 this.cachedErr = e41 }42 throw e43 })44 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const Parent = require('stryker-parent');2const parent = new Parent();3parent.onGoingPromise();4const Child = require('stryker-child');5const child = new Child();6child.onGoingPromise();7const Child = require('stryker-child');8class Parent {9 onGoingPromise() {10 return new Child().onGoingPromise();11 }12}13class Child {14 onGoingPromise() {15 return new Promise((resolve, reject) => {16 setTimeout(() => {17 console.log('Promise resolved!');18 resolve();19 }, 1000);20 });21 }22}23module.exports = Child;

Full Screen

Using AI Code Generation

copy

Full Screen

1const strykerParent = require('stryker-parent');2const path = require('path');3const strykerConfig = {4 mochaOptions: {5 }6};7const strykerOptions = {8};9const stryker = new strykerParent.Stryker(strykerConfig, strykerOptions);10stryker.runMutationTest()11 .then(() => {12 console.log('Done!');13 })14 .catch((error) => {15 console.error('Failed to run mutation test', error);16 });17{18 "scripts": {19 },20 "dependencies": {21 },22 "devDependencies": {23 }24}

Full Screen

Using AI Code Generation

copy

Full Screen

1var stryker = require('stryker-parent');2var promise = stryker.onGoingPromise();3promise.then(function(result){4 console.log(result);5});6var stryker = require('stryker-child');7var promise = stryker.onGoingPromise();8promise.then(function(result){9 console.log(result);10});11var stryker = require('stryker-child');12var promise = stryker.onGoingPromise();13promise.then(function(result){14 console.log(result);15});16var stryker = require('stryker-child');17var promise = stryker.onGoingPromise();18promise.then(function(result){19 console.log(result);20});21var stryker = require('stryker-child');22var promise = stryker.onGoingPromise();23promise.then(function(result){24 console.log(result);25});26var stryker = require('stryker-child');27var promise = stryker.onGoingPromise();28promise.then(function(result){29 console.log(result);30});31var stryker = require('stryker-child');32var promise = stryker.onGoingPromise();33promise.then(function(result){34 console.log(result);35});36var stryker = require('stryker-child');37var promise = stryker.onGoingPromise();38promise.then(function(result){39 console.log(result);40});41var stryker = require('stryker-child');42var promise = stryker.onGoingPromise();43promise.then(function(result){44 console.log(result);45});46var stryker = require('stryker-child');47var promise = stryker.onGoingPromise();48promise.then(function(result){49 console.log(result);50});51var stryker = require('stryker-child');52var promise = stryker.onGoingPromise();53promise.then(function(result){54 console.log(result);55});

Full Screen

Using AI Code Generation

copy

Full Screen

1const strykerParent = require('stryker-parent');2const onGoingPromise = strykerParent.onGoingPromise;3async function test() {4 await onGoingPromise;5 console.log('done');6}7test();8const onGoingPromise = require('stryker-parent').onGoingPromise;9async function test() {10 await onGoingPromise;11 console.log('done');12}13test();14const { onGoingPromise } = require('stryker-parent');15async function test() {16 await onGoingPromise;17 console.log('done');18}19test();20const { onGoingPromise: ongoing } = require('stryker-parent');21async function test() {22 await ongoing;23 console.log('done');24}25test();26const { onGoingPromise: ongoing } = require('stryker-parent');27async function test() {28 await ongoing;29 console.log('done');30}31test();32const { onGoingPromise: ongoing } = require('stryker-parent');33async function test() {34 await ongoing;35 console.log('done');36}37test();38const { onGoingPromise: ongoing } = require('stryker-parent');39async function test() {40 await ongoing;41 console.log('done');42}43test();44const { onGoingPromise: ongoing } = require('stryker-parent');45async function test() {46 await ongoing;47 console.log('done');48}49test();50const { onGoingPromise: ongoing } = require('stryker-parent');51async function test() {52 await ongoing;53 console.log('done');54}55test();

Full Screen

Using AI Code Generation

copy

Full Screen

1const onGoingPromise = require('stryker-parent').onGoingPromise;2onGoingPromise(function (resolve, reject) {3 resolve("Promise Resolved");4});5const onGoingPromise = require('stryker-parent').onGoingPromise;6onGoingPromise(function (resolve, reject) {7 reject("Promise Rejected");8});9const onGoingPromise = require('stryker-parent').onGoingPromise;10onGoingPromise(function (resolve, reject) {11 throw new Error("Promise Thrown");12});13const onGoingPromise = require('stryker-parent').onGoingPromise;14onGoingPromise(function (resolve, reject) {15 setTimeout(function () {16 resolve("Promise Resolved");17 }, 1000);18});19const onGoingPromise = require('stryker-parent').onGoingPromise;20onGoingPromise(function (resolve, reject) {21 setTimeout(function () {22 reject("Promise Rejected");23 }, 1000);24});25const onGoingPromise = require('stryker-parent').onGoingPromise;26onGoingPromise(function (resolve, reject) {27 setTimeout(function () {28 throw new Error("Promise Thrown");29 }, 1000);30});31const onGoingPromise = require('stryker-parent').onGoingPromise;32onGoingPromise(function (resolve, reject) {33 setTimeout(function () {34 throw new Error("Promise Thrown");35 }, 1000);36});37const onGoingPromise = require('stryker-parent').onGoingPromise;38onGoingPromise(function (resolve, reject) {39 setTimeout(function () {40 throw new Error("Promise Thrown");41 }, 1000);42});43const onGoingPromise = require('stryker-parent').onGoingPromise;44onGoingPromise(function (resolve, reject) {45 setTimeout(function () {46 throw new Error("Promise Thrown");47 }, 1000);48});

Full Screen

Using AI Code Generation

copy

Full Screen

1const strykerParent = require('stryker-parent');2const stryker = strykerParent.create('stryker');3function test() {4 return stryker.onGoingPromise;5}6module.exports = test;7const test = require('./test');8test().then(() => {9 console.log('done');10});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { onGoingPromise } = require('stryker-parent');2const promise = onGoingPromise();3promise.then(() => {4});5promise.resolve();6module.exports = function (config) {7 config.set({8 commandRunner: {9 },10 });11};

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 stryker-parent 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