How to use cause method in stryker-parent

Best JavaScript code snippet using stryker-parent

correct_restrictions.py

Source:correct_restrictions.py Github

copy

Full Screen

...32 restrictions = self.prep_restrictions(self.cause_set_version_id)33 # run the more code system specific replacements34 if self.verbose:35 print("[{}] Setting restricted cause".format(str(datetime.now())))36 manual_restrictions = self.set_restricted_cause(df)37 # identify the restrictions38 if self.verbose:39 print("[{}] Marking restrictions".format(str(datetime.now())))40 merged_restrictions = self.identify_restrictions(manual_restrictions,41 restrictions)42 # good place to save diagnostics43 if self.collect_diagnostics:44 self.diag_df = merged_restrictions.copy()45 # Replace the cause46 if self.verbose:47 print("[{}] Replacing cause".format(str(datetime.now())))48 # where the row represents a restriction violation, replace the code id49 # and the cause id with the restriction code/cause50 merged_restrictions.loc[51 merged_restrictions.restricted == 1,52 'code_id'] = merged_restrictions['restricted_code_id']53 merged_restrictions.loc[54 merged_restrictions.restricted == 1,55 'cause_id'] = merged_restrictions['restricted_cause_id']56 # then collapse57 # identify the restrictions58 if self.verbose:59 print("[{}] Collapsing".format(str(datetime.now())))60 merged_restrictions = merged_restrictions.groupby(61 self.groupby_cols, as_index=False)['deaths'].sum()62 return merged_restrictions63 def get_diagnostic_dataframe(self):64 """Return an evaluation of success of restrictions corrections65 Perhaps return a dataframe which is just the subset of the original66 that violated some age and sex restriction67 """68 if self.diag_df is None:69 raise AssertionError(70 "Need to run get_computed_dataframe once "71 "with collect_diagnostics = True")72 return self.diag_df73 def prep_restrictions(self, cause_set_version_id):74 """Get all the needed restrictions data75 Implemented by pulling from central get_causes function,76 then subsetting to just the restriction info for each cause_id.77 """78 df = get_current_cause_hierarchy(79 cause_set_version_id=cause_set_version_id,80 **self.standard_cache_options81 )82 df = df[['acause', 'cause_id', 'male',83 'female', 'yll_age_start', 'yll_age_end']]84 return df85 def prep_code_metadata(self):86 df = get_cause_map(87 self.code_system_id,88 **self.standard_cache_options89 )90 df = df[['code_id', 'value', 'cause_id']]91 df = df.rename(columns={'value': 'raw_cause'})92 return df93 def set_restricted_cause(self, df):94 """Run a set of manual replacements, according to expert opinion."""95 # based on first letter of icd code, certain values chould be filled in96 mapping_icd10 = {'A': 'B99.9', 'B': 'B99.9', 'C': 'D49.9',97 'D': 'D49.9', 'I': 'I99.9', 'J': 'J98.9',98 'K': 'K92.9', 'V': 'Y89', 'Y': 'Y89'}99 # add value field100 df = add_code_metadata(101 df, ['value'], self.code_system_id,102 **self.standard_cache_options103 )104 report_if_merge_fail(df, 'value', 'code_id')105 df = df.rename(columns={'value': 'raw_cause'})106 # generate new column called "restricted_cause"107 # ZZZ is the default for all code systems...

Full Screen

Full Screen

recode.py

Source:recode.py Github

copy

Full Screen

1import pandas as pd2import numpy as np3from cod_prep.claude.cod_process import CodProcess4from cod_prep.downloaders.causes import (5 add_cause_metadata,6 get_all_related_causes7)8from cod_prep.downloaders.nids import add_nid_metadata9from cod_prep.claude.configurator import Configurator10import warnings11class Recoder(CodProcess):12 id_cols = ['nid', 'extract_type_id', 'location_id', 'year_id',13 'age_group_id', 'sex_id', 'cause_id',14 'site_id']15 val_cols = ['deaths', 'deaths_rd', 'deaths_corr', 'deaths_raw']16 def __init__(self, cause_meta_df, source, code_system_id, data_type_id):17 self.source = source18 self.code_system_id = code_system_id19 self.data_type_id = data_type_id20 self.cause_meta_df = cause_meta_df21 self.conf = Configurator("standard")22 self.vr_indicators_path = self.conf.get_resource('vr_indicators')23 self.cache_options = {24 'force_rerun': False,25 'block_rerun': True,26 'cache_results': False,27 'cache_dir': self.conf.get_directory('db_cache')28 }29 def get_computed_dataframe(self, df):30 if 'data_type_id' not in df.columns:31 df = add_nid_metadata(df, "data_type_id", **self.cache_options)32 df = self.recode(df)33 df = self.conform_secret_causes(df)34 df = self.clean_up(df)35 return df36 def get_diagnostic_dataframe(self):37 """Return diagnostics."""38 pass39 def recode_sids(self, df):40 path_to_4_stars_sheet = self.conf.get_resource("four_star_locations")41 four_five_star_locs = pd.read_csv(path_to_4_stars_sheet)42 four_five_star_locs = four_five_star_locs[['location_id']]43 four_five_star_locs = four_five_star_locs.location_id.unique()44 less_than_four_star = ~df['location_id'].isin(four_five_star_locs)45 is_sids = df['cause_id'] == 68646 df.loc[is_sids & less_than_four_star, 'cause_id'] = 38047 return df48 def clean_up(self, df):49 """Group rogue duplicates."""50 df = df.groupby(self.id_cols, as_index=False)[self.val_cols].sum()51 return df52 def conform_secret_causes(self, df):53 df = add_cause_metadata(54 df, add_cols=['secret_cause', 'parent_id'],55 cause_meta_df=self.cause_meta_df,56 **self.cache_options57 )58 injuries_replace_parents = [722, 720, 719]59 replaced_injuries = df['cause_id'].isin(injuries_replace_parents)60 df.loc[replaced_injuries, 'parent_id'] = 72361 secret_causes = df['secret_cause'] == 162 not_cc_code = df['cause_id'] != 91963 len_before = len(df)64 if df['parent_id'].isnull().values.any():65 raise AssertionError(66 'There are missing parent cause_ids'67 )68 df.loc[secret_causes & not_cc_code, 'cause_id'] = df['parent_id']69 len_after = len(df)70 if len_before != len_after:71 raise AssertionError(72 'The length of the dataframe has changed from {} to {}'.format(73 len_before, len_after74 )75 )76 df.drop(['parent_id', 'secret_cause'], axis=1, inplace=True)77 return df78 def drop_leukemia_subtypes(self, df):79 leuk_subtypes = get_all_related_causes('neo_leukemia', self.cause_meta_df)80 leuk_subtypes.remove(487)81 df.loc[82 (df['cause_id'].isin(leuk_subtypes)) & (df['deaths_rd'] > 0) &83 (df['deaths_raw'] <= 0), 'cause_id'84 ] = 48785 return df86 87 def recode(self, df):88 89 cause_metadata_df = self.cause_meta_df90 cause_metadata_df = cause_metadata_df[["cause_id",91 "path_to_top_parent",92 "acause"]]93 ckd_cause_ids = get_all_related_causes('ckd', cause_metadata_df)94 ckd_cause_ids.remove(593)95 ckd_less_other = df['cause_id'].isin(ckd_cause_ids)96 neonate = df['age_group_id'].isin([2, 3])97 df.loc[ckd_less_other & neonate, 'cause_id'] = 65298 resp_ids = [509, 515, 516, 520]99 is_cert_resp_causes = df['cause_id'].isin(resp_ids)100 df.loc[is_cert_resp_causes & neonate, 'cause_id'] = 322101 is_asthma = df['cause_id'] == 515102 df.loc[is_asthma & (df['age_group_id'] == 4), 'cause_id'] = 322103 maternal_cause_ids = get_all_related_causes(366, cause_metadata_df)104 maternal_cause_ids = df['cause_id'].isin(maternal_cause_ids)105 non_maternal_ages = np.logical_not(106 df['age_group_id'].isin([7, 8, 9, 10, 11, 12, 13, 14, 15, 22])107 )108 df.loc[maternal_cause_ids & non_maternal_ages, 'cause_id'] = 919109 alzheimers = df['cause_id'] == 543110 under_40 = df['age_group_id'].isin(range(1, 13, 1))111 df.loc[alzheimers & under_40, 'cause_id'] = 919112 cong_causes = get_all_related_causes('cong', cause_metadata_df)113 congenital = df['cause_id'].isin(cong_causes)114 over_70 = df['age_group_id'].isin([19, 20, 30, 31, 32, 235])115 df.loc[congenital & over_70, "cause_id"] = 919116 hepatitis = get_all_related_causes(400, cause_metadata_df)117 hepatitis = df['cause_id'].isin(hepatitis)118 if self.code_system_id in [7, 9]:119 df.loc[hepatitis & neonate, "cause_id"] = 380120 else:121 df.loc[hepatitis & neonate, "cause_id"] = 384122 inj_disaster_light = df['cause_id'] == 984123 df.loc[inj_disaster_light, 'cause_id'] = 716124 if self.code_system_id not in [1, 6]:125 ckd_diabetes = df['cause_id'].isin([997, 998])126 df.loc[ckd_diabetes, 'cause_id'] = 589127 if self.code_system_id not in [1, 6, 9]:128 diabetes_subtypes = df['cause_id'].isin([975, 976])129 df.loc[diabetes_subtypes, 'cause_id'] = 587130 diabetes_type_2 = df['cause_id'] == 976131 under_15 = df['age_group_id'] < 8132 df.loc[diabetes_type_2 & under_15, 'cause_id'] = 975133 iron_or_iodine = df['cause_id'].isin([388, 390])134 df.loc[iron_or_iodine, 'cause_id'] = 919135 under_1 = df['age_group_id'] < 5136 cvd_ihd = df['cause_id'] == 493137 df.loc[cvd_ihd & under_1, 'cause_id'] = 643138 if 686 in df.cause_id.unique():139 df = self.recode_sids(df)140 df.loc[df.cause_id.isin([344, 409, 410,141 542, 558, 669,142 680, 961]), 'cause_id'] = 919143 if self.data_type_id not in [6, 7, 8]:144 df.loc[df['cause_id'] == 687, 'cause_id'] = 919145 one_to_14 = df['age_group_id'].isin([5, 6, 7])146 cvd_ihd = df['cause_id'] == 493147 df.loc[cvd_ihd & one_to_14, 'cause_id'] = 507148 cancer_recodes = get_all_related_causes([411, 414, 423, 426, 429, 432,149 435, 438, 441, 444, 450, 453,150 456, 459, 462, 465, 468, 474,151 486, 483], cause_metadata_df)152 cancer_recodes = df['cause_id'].isin(cancer_recodes)153 cancer_ages = df['age_group_id'].isin(range(2, 8, 1))154 df.loc[cancer_recodes & cancer_ages, "cause_id"] = 489155 not_icd10 = self.code_system_id != 1156 neo_meso = df['cause_id'] == 483157 df.loc[neo_meso & not_icd10, "cause_id"] = 489158 if self.source.endswith("AAMSP"):159 digest_hernia = df['cause_id'].isin([531])160 df.loc[digest_hernia, "cause_id"] = 919161 if self.source == "":162 homicide_and_suicide = df['cause_id'].isin([724, 725, 726, 727, 941,163 718, 719, 720, 721, 722, 723])164 bad_years = df['year_id'].isin(range(2007, 2015))165 # _unintent166 df.loc[bad_years & homicide_and_suicide, "cause_id"] = 919167 inj_war = get_all_related_causes(945, cause_metadata_df)168 is_inj_war = df['cause_id'].isin(inj_war)169 jamaica = df['location_id'] == 115170 year_2005 = df['year_id'] == 2005171 vr = df['data_type_id'] == 9172 df.loc[is_inj_war & jamaica & year_2005 & vr, 'cause_id'] = 724173 inj_mech_gun = df['cause_id'] == 705174 year_2006 = df['year_id'] == 2006175 df.loc[inj_mech_gun & year_2006 & jamaica & vr, 'cause_id'] = 724176 if self.source == "ICD10":177 digest_ibd = df['cause_id'] == 532178 suriname = df['location_id'] == 118179 year_1995_2012 = df['year_id'].isin(range(1995, 2013, 1))180 df.loc[digest_ibd & suriname & year_1995_2012, 'cause_id'] = 526181 endo_prodcedural = df['cause_id'] == 624182 df.loc[endo_prodcedural, 'cause_id'] = 708183 schizo = df['cause_id'] == 559184 tibet = df['location_id'] == 518185 df.loc[schizo & tibet, 'cause_id'] = 919186 hiv = get_all_related_causes(298, cause_metadata_df)187 hiv = df['cause_id'].isin(hiv)188 pre_1980 = df['year_id'] < 1980189 df.loc[hiv & pre_1980, 'cause_id'] = 919190 diabetes_causes = get_all_related_causes(587, cause_metadata_df)191 diabetes = df['cause_id'].isin(diabetes_causes)192 df.loc[neonate & diabetes, 'cause_id'] = 380193 under_20 = df['age_group_id'].isin(range(0, 8, 1))194 stroke = get_all_related_causes(195 'cvd_stroke', cause_metadata_df196 )197 stroke_deaths = df['cause_id'].isin(stroke)198 va = df['data_type_id'] == 8199 200 df.loc[under_20 & stroke_deaths & va, 'cause_id'] = 491201 over_95 = df['age_group_id'] == 235202 inj_trans_road_pedal = df['cause_id'] == 691203 df.loc[over_95 & inj_trans_road_pedal, 'cause_id'] = 919204 df.loc[schizo, 'cause_id'] = 919205 if self.source == "Russia_FMD_1999_2011":206 cvd_pvd = df['cause_id'] == 502207 df.loc[cvd_pvd, 'cause_id'] = 491208 if self.source == "":209 sui_homi_causes = [717, 718, 719, 720, 721, 722, 723,210 724, 725, 726, 727, 941]211 sui_homi = df['cause_id'].isin(sui_homi_causes)212 bad_years = df['year_id'].isin(range(2007, 2015))213 df.loc[sui_homi & bad_years, 'cause_id'] = 919214 if "India_MCCD" in self.source:215 non_neonates = np.logical_not(df['age_group_id'].isin([2, 3]))216 neonatal_sepsis = df['cause_id'].isin([])217 df.loc[non_neonates & neonatal_sepsis, 'cause_id'] = 380218 if self.source == "India_SCD_states_rural":219 warnings.warn("Implement SCD rd artifact recode")220 inj_war_execution = df['cause_id'] == 854221 if self.source == "ICD9_BTL":222 ecuador = df['location_id'] == 122223 year_1980_1990 = df['year_id'].isin(range(1980, 1991, 1))224 df.loc[inj_war_execution & ecuador & year_1980_1990,225 'cause_id'] = 855226 bih = df['location_id'] == 44227 year_1985_1991 = df['year_id'].isin([1985, 1986, 1987, 1988,228 1989, 1990, 1991])229 df.loc[inj_war_execution & bih &230 year_1985_1991, 'cause_id'] = 855231 warnings.warn("BTL cancer recode needed")232 if self.source == "ICD10":233 irq = df['location_id'] == 143234 year_2008 = df['year_id'] == 2008235 df.loc[inj_war_execution & year_2008 & irq, 'cause_id'] = 855236 if self.source == "ICD9_detail":237 if ((df['location_id'] == 43) & (df['year_id'] == 1997)).any():238 warnings.warn("Albania homicide recode needed")239 if self.source == "ICD9_USSR_Tabulated":240 warnings.warn("Missing some homicide fixes for TJK, ARM here.")241 df = self.drop_leukemia_subtypes(df)242 if self.data_type_id in [1, 3, 5, 7]:243 maternal_causes = get_all_related_causes('maternal', cause_metadata_df)244 injury_causes = get_all_related_causes('_inj', cause_metadata_df)245 maternal = df['cause_id'].isin(maternal_causes)246 inj = df['cause_id'].isin(injury_causes)247 df.loc[~(maternal | inj), 'cause_id'] = 919248 if self.data_type_id == 5:249 df.loc[~maternal, 'cause_id'] = 919...

Full Screen

Full Screen

donationCauseControllers.js

Source:donationCauseControllers.js Github

copy

Full Screen

1const DonationCause = require('../schemas/DonationCauseSchema');2const fileSizeFormatter = require('../utilities/fileSizeFormatter');3const User = require('../schemas/UserSchema');4// add a new donation cuase administrator Post == ok5const handleAddDonateCuase = async (req, res, next) => {6 const file = {7 name: req.file.originalname,8 path: req.file.path,9 type: req.file.mimetype,10 size: fileSizeFormatter(req.file.size, 2), // 0.0011 };12 const newDonationCause = {13 ...JSON.parse(req.body.cause),14 image: file,15 };16 try {17 const response = await DonationCause.create(newDonationCause);18 res.json(response);19 } catch (error) {20 next(error);21 }22};23// Get All Cuases24const getAllCuases = async (req, res, next) => {25 try {26 const allCuases = await DonationCause.find({});27 res.json(allCuases);28 } catch (error) {29 next(error);30 }31};32// Delete sigle Cuase33const deleteCuase = async (req, res, next) => {34 try {35 const id = req.query.id;36 const query = { _id: id };37 const sigleCuasedelete = await DonationCause.findOneAndDelete(query);38 res.json(sigleCuasedelete);39 } catch (error) {40 next(error);41 }42};43//Update sigle Cause44const updateACause = async (req, res, next) => {45 const { id } = req.query;46 let editedDonationCause = {};47 if (req.file) {48 const file = {49 name: req.file.originalname,50 path: req.file.path,51 type: req.file.mimetype,52 size: fileSizeFormatter(req.file.size, 2), // 0.0053 };54 editedDonationCause = {55 ...JSON.parse(req.body.cause),56 image: file,57 };58 } else {59 editedDonationCause = {60 ...JSON.parse(req.body.cause),61 };62 }63 try {64 const response = await DonationCause.findOneAndUpdate(65 { _id: id },66 editedDonationCause,67 { new: true }68 );69 res.json(response);70 } catch (error) {71 next(error);72 }73};74// take donations75const takeDonations = async (req, res, next) => {76 const { amount, donarId, causeId } = req.body;77 try {78 const cause = await DonationCause.findOne({ _id: causeId });79 let updateFields = {}; // field inside this object will be udpated80 // check if the donar previously donated or not81 const isDonarAvailAble =82 cause?.donars && cause?.donars.find((d) => d.donarId === donarId);83 if (isDonarAvailAble) {84 // update the previous donation amount of donars and increase the raised amount85 const mapDonars = cause.donars.map((d) => {86 if (d.donarId === donarId) {87 return {88 _id: d._id,89 donarId: d.donarId,90 amount: d.amount + Number(amount),91 isPaid: d.isPaid,92 }; //increase the previous given amount of donars93 } else {94 // return {donarId: d.donarId, amount: d.amount, _id: d._id};95 return d;96 }97 });98 updateFields = {99 donars: mapDonars,100 raised: cause?.raised + Number(amount),101 };102 } else {103 // add the new donar in donars array and increase the raised amount104 updateFields = {105 donars: [106 ...cause?.donars,107 { donarId, amount: Number(amount), isPaid: false },108 ],109 raised: cause?.raised + Number(amount),110 };111 }112 // check if the goal achieved or not113 if (updateFields?.raised >= 50000) {114 return res.json({115 message: 'goal allready achieved',116 });117 }118 const updatedCause = await DonationCause.findOneAndUpdate(119 { _id: causeId },120 updateFields,121 { new: true }122 );123 res.json(updatedCause);124 } catch (error) {125 next(error);126 }127};128const updateDonarPaymentStatus = async (req, res, next) => {129 const { donarId, causeId, isPaid } = req.body;130 try {131 const cause = await DonationCause.findOne({ _id: causeId });132 let updateFields = {}; // field inside this object will be udpated133 // check if the donar is available or not134 const isDonarAvailAble =135 cause?.donars && cause?.donars.find((d) => d.donarId === donarId);136 if (isDonarAvailAble) {137 // update the payment status of donars138 const mapDonars = cause.donars.map((d) => {139 if (d.donarId === donarId) {140 return {141 _id: d._id,142 donarId: d.donarId,143 amount: d.amount,144 isPaid,145 }; //increase the previous given amount of donars146 } else {147 return d;148 }149 });150 updateFields = {151 donars: mapDonars,152 };153 } else {154 return res.json({155 message: "user donesn't exist",156 });157 }158 const updatedCause = await DonationCause.findOneAndUpdate(159 { _id: causeId },160 updateFields,161 { new: true }162 );163 res.json(updatedCause);164 } catch (error) {165 next(error);166 }167};168const getAllDonarInfo = async (req, res, next) => {169 try {170 const allCauses = await DonationCause.find();171 const allUsers = await User.find();172 allDonars = [];173 if (allCauses && allCauses.length >= 1) {174 allDonars = allCauses175 .map((cause) => {176 if (cause?.donars && cause?.donars.length >= 1) {177 const causeInfo = {178 _id: cause?._id,179 title: cause?.title,180 image: cause?.image,181 description: cause?.description,182 category: cause?.category,183 goal: cause?.goal,184 raised: cause?.raised,185 date: cause?.date,186 };187 return { causeInfo, donarInfo: cause?.donars };188 } else {189 return false;190 }191 })192 .flat()193 .filter((allInfo) => allInfo)194 .map((info) => {195 // get all the donarInfo from the user collection196 const donarInfo = info.donarInfo.map((d) => {197 const donar = allUsers.find(198 (user) => user._id.toString() === d.donarId199 );200 const infoOfDonarWithAll = {201 donar,202 _id: d.donarId,203 amount: d.amount,204 isPaid: d.isPaid,205 };206 return infoOfDonarWithAll;207 });208 const AllInfoOfDonar = {209 causeInfo: info.causeInfo,210 donarInfo,211 };212 return AllInfoOfDonar;213 });214 }215 res.json(allDonars);216 } catch (error) {217 next(error);218 }219};220const getSpecificUserDonationInfo = async (req, res, next) => {221 try {222 const { uId } = req.query;223 const allCauses = await DonationCause.find();224 const allCausesWithMyDonation = allCauses.map((cause) => {225 let UserDonations = cause.donars.filter((d) => d.donarId === uId);226 return {227 _id: cause?._id,228 title: cause?.title,229 image: cause?.image,230 description: cause?.description,231 category: cause?.category,232 goal: cause?.goal,233 raised: cause?.raised,234 date: cause?.date,235 donars: UserDonations,236 };237 });238 res.json(allCausesWithMyDonation);239 } catch (error) {240 next(error);241 }242};243module.exports = {244 handleAddDonateCuase,245 getAllCuases,246 deleteCuase,247 updateACause,248 takeDonations,249 getAllDonarInfo,250 updateDonarPaymentStatus,251 getSpecificUserDonationInfo,...

Full Screen

Full Screen

error-cause.js

Source:error-cause.js Github

copy

Full Screen

1// Copyright 2021 the V8 project authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4// Flags: --harmony-error-cause5// Basic error6(function () {7 const err = Error('message', { cause: 'a cause' });8 assertEquals('a cause', err.cause);9 const descriptor = Object.getOwnPropertyDescriptor(err, 'cause');10 assertEquals('a cause', descriptor.value);11 assertFalse(descriptor.enumerable);12 assertTrue(descriptor.writable);13 assertTrue(descriptor.configurable);14})();15// No cause16(function () {17 const err = Error('message');18 assertEquals(undefined, err.cause);19})();20// Chained errors21(function () {22 async function fail() { throw new Error('caused by fail') }23 async function doJob() {24 await fail()25 .catch(err => {26 throw new Error('Found an error', { cause: err });27 });28 }29 async function main() {30 try {31 await doJob();32 } catch (e) {33 assertEquals('Found an error', e.message);34 assertEquals('caused by fail', e.cause.message);35 }36 }37 main();38})();39// AggregateError with cause40(function() {41 const err = AggregateError([1, 2, 3], 'aggregate errors', { cause: 'a cause' });42 assertEquals('a cause', err.cause);43 const descriptor = Object.getOwnPropertyDescriptor(err, 'cause');44 assertEquals('a cause', descriptor.value);45 assertFalse(descriptor.enumerable);46 assertTrue(descriptor.writable);47 assertTrue(descriptor.configurable);48})();49// Options is not an object50(function () {51 const err1 = Error('message', 42);52 assertEquals(undefined, err1.cause);53 const err2 = Error('message', null);54 assertEquals(undefined, err2.cause);55 const err3 = Error('message', [42]);56 assertEquals(undefined, err3.cause);57})();58// Options object does not contain 'cause'59(function () {60 const err = Error('message', { syy: 'A finnish cause' });61 assertEquals(undefined, err.cause);62 assertEquals(undefined, err.syy);63})();64// Options is a proxy65(function () {66 const options = { cause: 'a cause' };67 const proxy = new Proxy(options, { get: () => 'proxied cause'});68 const err = Error('message', proxy);69 assertEquals('proxied cause', err.cause);70})();71// Options is a proxy, but does not expose 'cause'72(function () {73 const options = { cause: 'a cause' };74 const proxy = new Proxy(options, {75 has: (_, key) => key != 'cause',76 get: () => 'proxied cause'77 })78 const err = Error('message', proxy);79 assertEquals(undefined, err.cause);80})();81// Options is a proxy, throw in 'get'82(function () {83 const options = { cause: 'a cause' };84 const proxy = new Proxy(options, {85 get: () => { throw Error('proxy get', { cause: 'no reason' }) },86 });87 try {88 Error('message', proxy);89 assertUnreachable();90 } catch(e) {91 assertEquals('proxy get', e.message);92 assertEquals('no reason', e.cause);93 }94})();95// Options is a proxy, throw in 'has'96(function () {97 const options = { cause: 'a cause' };98 const proxy = new Proxy(options, {99 has: () => { throw Error('proxy has', { cause: 'no reason' }) },100 });101 try {102 Error('message', proxy);103 assertUnreachable();104 } catch(e) {105 assertEquals('proxy has', e.message);106 assertEquals('no reason', e.cause);107 }108})();109// Cause in the options prototype chain110(function () {111 function Options() {};112 Options.prototype.cause = 'cause in the prototype';113 const options = new Options();114 const err = Error('message', options);115 assertEquals('cause in the prototype', err.cause);116})();117// Cause in the options prototype chain proxy118(function () {119 function Options() {};120 Options.prototype = new Proxy({ cause: 42 }, {121 get: (_ ,name) => {122 assertEquals('cause', name);123 return 'cause in the prototype'124 }});125 const options = new Options();126 const err = Error('message', options);127 assertEquals('cause in the prototype', err.cause);128})();129// Cause in the options prototype chain proxy and throw130(function () {131 function Options() {};132 Options.prototype = new Proxy({ cause: 42 }, { get: () => { throw Error('cause in the prototype')} });133 const options = new Options();134 try {135 Error('message', options);136 assertUnreachable();137 } catch(e) {138 assertEquals('cause in the prototype', e.message);139 }140})();141// Change Error.cause in the prototype142(function () {143 Error.prototype.cause = 'main cause';144 const err1 = new Error('err1');145 assertEquals('main cause', err1.cause);146 const desc1 = Object.getOwnPropertyDescriptor(err1, 'cause');147 assertEquals(undefined, desc1);148 const err2 = new Error('err2', { cause: 'another cause' });149 assertEquals(err2.cause, 'another cause');150 const desc2 = Object.getOwnPropertyDescriptor(err2, 'cause');151 assertFalse(desc2.enumerable);152 assertTrue(desc2.writable);153 assertTrue(desc2.configurable);154 const err3 = new Error('err3');155 err3.cause = 'after err3';156 assertEquals('after err3', err3.cause);157 const desc3 = Object.getOwnPropertyDescriptor(err3, 'cause');158 assertTrue(desc3.enumerable);159 assertTrue(desc3.writable);160 assertTrue(desc3.configurable);161})();162// Change prototype to throw in setter163(function() {164 const my_proto = {};165 Object.defineProperty(my_proto, 'cause', {set: function(x) { throw 'foo' } });166 Error.prototype.__proto__ = my_proto167 const err = Error('message', { cause: 'a cause' });168 assertEquals('a cause', err.cause);169})();170// Use defineProperty to change Error cause and throw171(function () {172 Object.defineProperty(Error.prototype, 'cause', {173 get: () => { throw Error('from get', { cause: 'inside get' }) },174 });175 const err1 = new Error('err1');176 try {177 err1.cause;178 assertUnreachable();179 } catch(e) {180 assertEquals('from get', e.message);181 assertEquals('inside get', e.cause);182 }183 const err2 = new Error('err2', { cause: 'another cause' });184 assertEquals('another cause', err2.cause);185})();186// Serialize and deserialize error object187(function () {188 const err = Error('message', { cause: 'a cause' });189 const worker = new Worker('onmessage = (msg) => postMessage(msg)', { type: 'string' });190 worker.postMessage(err);191 const serialized_err = worker.getMessage();192 assertEquals(err, serialized_err);193 const descriptor = Object.getOwnPropertyDescriptor(serialized_err, 'cause');194 assertEquals(descriptor.value, 'a cause');195 assertFalse(descriptor.enumerable);196 assertTrue(descriptor.writable);197 assertTrue(descriptor.configurable);...

Full Screen

Full Screen

err.js

Source:err.js Github

copy

Full Screen

1var test = require('tape');2var ErrorWithCause = require('error-cause/Error');3var inspect = require('../');4test('type error', function (t) {5 t.plan(1);6 var aerr = new TypeError();7 aerr.foo = 555;8 aerr.bar = [1, 2, 3];9 var berr = new TypeError('tuv');10 berr.baz = 555;11 var cerr = new SyntaxError();12 cerr.message = 'whoa';13 cerr['a-b'] = 5;14 var withCause = new ErrorWithCause('foo', { cause: 'bar' });15 var withCausePlus = new ErrorWithCause('foo', { cause: 'bar' });16 withCausePlus.foo = 'bar';17 var withUndefinedCause = new ErrorWithCause('foo', { cause: undefined });18 var withEnumerableCause = new Error('foo');19 withEnumerableCause.cause = 'bar';20 var obj = [21 new TypeError(),22 new TypeError('xxx'),23 aerr,24 berr,25 cerr,26 withCause,27 withCausePlus,28 withUndefinedCause,29 withEnumerableCause30 ];31 t.equal(inspect(obj), '[ ' + [32 '[TypeError]',33 '[TypeError: xxx]',34 '{ [TypeError] foo: 555, bar: [ 1, 2, 3 ] }',35 '{ [TypeError: tuv] baz: 555 }',36 '{ [SyntaxError: whoa] message: \'whoa\', \'a-b\': 5 }',37 'cause' in Error.prototype ? '[Error: foo]' : '{ [Error: foo] [cause]: \'bar\' }',38 '{ [Error: foo] ' + ('cause' in Error.prototype ? '' : '[cause]: \'bar\', ') + 'foo: \'bar\' }',39 'cause' in Error.prototype ? '[Error: foo]' : '{ [Error: foo] [cause]: undefined }',40 '{ [Error: foo] cause: \'bar\' }'41 ].join(', ') + ' ]');...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var Stryker = require('stryker');2var StrykerParent = require('stryker-parent');3var stryker = new Stryker();4var strykerParent = new StrykerParent();5strykerParent.cause(stryker);6var Stryker = require('stryker');7var stryker = new Stryker();8var strykerParent = require('stryker-parent');9strykerParent.cause(stryker);10var Stryker = require('stryker');11var stryker = new Stryker();12var strykerParent = require('stryker-parent');13strykerParent.cause(stryker);14var Stryker = require('stryker');15var stryker = new Stryker();16var strykerParent = require('stryker-parent');17strykerParent.cause(stryker);18var Stryker = require('stryker');19var stryker = new Stryker();20var strykerParent = require('stryker-parent');21strykerParent.cause(stryker);22var Stryker = require('stryker');23var stryker = new Stryker();24var strykerParent = require('stryker-parent');25strykerParent.cause(stryker);26var Stryker = require('stryker');27var stryker = new Stryker();28var strykerParent = require('stryker-parent');29strykerParent.cause(stryker);30var Stryker = require('stryker');31var stryker = new Stryker();32var strykerParent = require('stryker-parent');33strykerParent.cause(stryker);34var Stryker = require('stryker');

Full Screen

Using AI Code Generation

copy

Full Screen

1var stryker = require('stryker-parent');2var strykerConfig = require('./stryker.conf.js');3stryker.run(strykerConfig);4module.exports = function(config) {5 config.set({6 mochaOptions: {7 }8 });9}

Full Screen

Using AI Code Generation

copy

Full Screen

1const strykerParent = require('stryker-parent');2const stryker = strykerParent.cause();3const strykerParent = require('stryker-parent');4const stryker = strykerParent.cause();5const strykerParent = require('stryker-parent');6const stryker = strykerParent.cause();7const strykerParent = require('stryker-parent');8const stryker = strykerParent.cause();9const strykerParent = require('stryker-parent');10const stryker = strykerParent.cause();11const strykerParent = require('stryker-parent');12const stryker = strykerParent.cause();13const strykerParent = require('stryker-parent');14const stryker = strykerParent.cause();15const strykerParent = require('stryker-parent');16const stryker = strykerParent.cause();17const strykerParent = require('stryker-parent');18const stryker = strykerParent.cause();19const strykerParent = require('stryker-parent');20const stryker = strykerParent.cause();21const strykerParent = require('stryker-parent');22const stryker = strykerParent.cause();23const strykerParent = require('stryker-parent');24const stryker = strykerParent.cause();25const strykerParent = require('stryker-parent');26const stryker = strykerParent.cause();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Parent } = require('stryker-parent');2const parent = new Parent();3parent.cause();4const { Child } = require('stryker-child');5const child = new Child();6module.exports = {7 Parent: class Parent {8 cause() {9 child.cause();10 }11 }12};13module.exports = {14 Child: class Child {15 cause() {16 throw new Error('I caused an error');17 }18 }19};20 at ChildProcess.child.on.code (C:\Users\user\AppData\Roaming\npm\node_modules\stryker-cli\node_modules\stryker\src\child-proxy\ChildProcessProxy.js:61:23)21 at ChildProcess.emit (events.js:198:13)22 at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2parent.cause('test error');3module.exports = function(config){4 config.set({5 });6};

Full Screen

Using AI Code Generation

copy

Full Screen

1const stryker = require('stryker-parent').default;2stryker({3});4const stryker = require('stryker-parent').default;5stryker({6});7const stryker = require('stryker-parent').default;8stryker({9});10const stryker = require('stryker-parent').default;11stryker({12});13const stryker = require('stryker-parent').default;14stryker({

Full Screen

Using AI Code Generation

copy

Full Screen

1const stryker = require('stryker-parent');2const reporter = require('stryker-html-reporter');3stryker({4});5{6 "scripts": {7 },8 "devDependencies": {9 }10}

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2strykerParent.cause('test');3module.exports = {4 cause: function (msg) {5 console.log('cause: ' + msg);6 }7};8{9}

Full Screen

Using AI Code Generation

copy

Full Screen

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

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