Best JavaScript code snippet using stryker-parent
token-list.js
Source:token-list.js
1const Component = require('react').Component2const PropTypes = require('prop-types')3const h = require('react-hyperscript')4const inherits = require('util').inherits5const TokenTracker = require('eth-token-tracker')6const TokenCell = require('./token-cell.js')7const connect = require('react-redux').connect8const selectors = require('../../selectors/selectors')9const log = require('loglevel')10function mapStateToProps (state) {11 const ethTokens = state.metamask.tokens12 const pluginTokens = state.metamask.assets13 return {14 network: state.metamask.network,15 tokens: ethTokens,16 pluginTokens,17 userAddress: selectors.getSelectedAddress(state),18 assetImages: state.metamask.assetImages,19 }20}21const defaultTokens = []22const contracts = require('eth-contract-metadata')23for (const address in contracts) {24 const contract = contracts[address]25 if (contract.erc20) {26 contract.address = address27 defaultTokens.push(contract)28 }29}30TokenList.contextTypes = {31 t: PropTypes.func,32}33module.exports = connect(mapStateToProps)(TokenList)34inherits(TokenList, Component)35function TokenList () {36 this.state = {37 tokens: [],38 isLoading: true,39 network: null,40 }41 Component.call(this)42}43TokenList.prototype.render = function () {44 const { userAddress, pluginTokens, assetImages } = this.props45 const state = this.state46 const { tokens, isLoading, error } = state47 if (isLoading) {48 return this.message(this.context.t('loadingTokens'))49 }50 if (error) {51 log.error(error)52 return h('.hotFix', {53 style: {54 padding: '80px',55 },56 }, [57 this.context.t('troubleTokenBalances'),58 h('span.hotFix', {59 style: {60 color: 'rgba(247, 134, 28, 1)',61 cursor: 'pointer',62 },63 onClick: () => {64 global.platform.openWindow({65 url: `https://ethplorer.io/address/${userAddress}`,66 })67 },68 }, this.context.t('here')),69 ])70 }71 pluginTokens.forEach((pluginToken) => {72 // TODO: Proper decimal encoding:73 pluginToken.string = pluginToken.balance74 })75 return h('div', tokens.concat(pluginTokens).map((tokenData) => {76 tokenData.image = assetImages[tokenData.address]77 if (tokenData.customViewUrl) {78 tokenData.onClick = this.showPluginToken.bind(this, tokenData)79 }80 return h(TokenCell, tokenData)81 }))82}83TokenList.prototype.showPluginToken = function (tokenData) {84 const url = tokenData.customViewUrl85 global.platform.openWindow({ url })86}87TokenList.prototype.message = function (body) {88 return h('div', {89 style: {90 display: 'flex',91 height: '250px',92 alignItems: 'center',93 justifyContent: 'center',94 padding: '30px',95 },96 }, body)97}98TokenList.prototype.componentDidMount = function () {99 this.createFreshTokenTracker()100}101TokenList.prototype.createFreshTokenTracker = function () {102 if (this.tracker) {103 // Clean up old trackers when refreshing:104 this.tracker.stop()105 this.tracker.removeListener('update', this.balanceUpdater)106 this.tracker.removeListener('error', this.showError)107 }108 if (!global.ethereumProvider) return109 const { userAddress } = this.props110 this.tracker = new TokenTracker({111 userAddress,112 provider: global.ethereumProvider,113 tokens: this.props.tokens,114 pollingInterval: 8000,115 })116 // Set up listener instances for cleaning up117 this.balanceUpdater = this.updateBalances.bind(this)118 this.showError = (error) => {119 this.setState({ error, isLoading: false })120 }121 this.tracker.on('update', this.balanceUpdater)122 this.tracker.on('error', this.showError)123 this.tracker.updateBalances()124 .then(() => {125 this.updateBalances(this.tracker.serialize())126 })127 .catch((reason) => {128 log.error(`Problem updating balances`, reason)129 this.setState({ isLoading: false })130 })131}132TokenList.prototype.componentDidUpdate = function (prevProps) {133 const {134 network: oldNet,135 userAddress: oldAddress,136 tokens,137 } = prevProps138 const {139 network: newNet,140 userAddress: newAddress,141 tokens: newTokens,142 } = this.props143 const isLoading = newNet === 'loading'144 const missingInfo = !oldNet || !newNet || !oldAddress || !newAddress145 const sameUserAndNetwork = oldAddress === newAddress && oldNet === newNet146 const shouldUpdateTokens = isLoading || missingInfo || sameUserAndNetwork147 const oldTokensLength = tokens ? tokens.length : 0148 const tokensLengthUnchanged = oldTokensLength === newTokens.length149 if (tokensLengthUnchanged && shouldUpdateTokens) return150 this.setState({ isLoading: true })151 this.createFreshTokenTracker()152}153TokenList.prototype.updateBalances = function (tokens) {154 if (!this.tracker.running) {155 return156 }157 this.setState({ tokens, isLoading: false })158}159TokenList.prototype.componentWillUnmount = function () {160 if (!this.tracker) return161 this.tracker.stop()162 this.tracker.removeListener('update', this.balanceUpdater)163 this.tracker.removeListener('error', this.showError)164}165// function uniqueMergeTokens (tokensA, tokensB = []) {166// const uniqueAddresses = []167// const result = []168// tokensA.concat(tokensB).forEach((token) => {169// const normal = normalizeAddress(token.address)170// if (!uniqueAddresses.includes(normal)) {171// uniqueAddresses.push(normal)172// result.push(token)173// }174// })175// return result176// }...
main.ts
Source:main.ts
1import {StrykerOptions} from '@stryker-mutator/api/core';2import {Logger} from '@stryker-mutator/api/logging';3import {commonTokens, PluginContext} from '@stryker-mutator/api/plugin';4import {5 DryRunOptions,6 DryRunResult,7 MutantRunOptions,8 MutantRunResult,9 TestRunner10} from '@stryker-mutator/api/test-runner';11import * as pluginTokens from './plugin-tokens';12import FooTestRunnerConfigFileLoader from './foo-test-runner-config-file-loader';13import {Injector} from "typed-inject";14export class FooTestRunner implements TestRunner {15 public static inject = [16 commonTokens.logger,17 commonTokens.options,18 pluginTokens.configLoader,19 pluginTokens.processEnv,20 pluginTokens.fooTestRunnerVersion21 ] as const;22 constructor(23 private readonly log: Logger,24 private readonly options: StrykerOptions,25 private readonly configLoader: FooTestRunnerConfigFileLoader,26 private readonly processEnvRef: NodeJS.ProcessEnv,27 private readonly fooTestRunnerVersion: string28 ) {29 }30 public init(): Promise<void> {31 // TODO: Implement or remove32 }33 public dryRun(options: DryRunOptions): Promise<DryRunResult> {34 // TODO: Implement35 }36 public mutantRun(options: MutantRunOptions): Promise<MutantRunResult> {37 // TODO: Implement38 }39 public dispose(): Promise<void> {40 // TODO: Implement or remove41 }42}43export function fooTestRunnerFactory(injector: Injector<PluginContext>) {44 return injector45 .provideValue(pluginTokens.processEnv, process.env)46 .provideValue(pluginTokens.fooTestRunnerVersion, require('foo/package.json').version as string)47 .provideClass(pluginTokens.configLoader, FooTestRunnerConfigFileLoader)48 .injectClass(FooTestRunner);49}...
Using AI Code Generation
1var stryker = require('stryker-parent');2var tokens = stryker.pluginTokens();3console.log(tokens);4var stryker = require('stryker-parent');5var tokens = stryker.pluginTokens();6console.log(tokens);7var stryker = require('stryker-parent');8var tokens = stryker.pluginTokens();9console.log(tokens);10var stryker = require('stryker-parent');11var tokens = stryker.pluginTokens();12console.log(tokens);13var stryker = require('stryker-parent');14var tokens = stryker.pluginTokens();15console.log(tokens);16var stryker = require('stryker-parent');17var tokens = stryker.pluginTokens();18console.log(tokens);19var stryker = require('stryker-parent');20var tokens = stryker.pluginTokens();21console.log(tokens);22var stryker = require('stryker-parent');23var tokens = stryker.pluginTokens();24console.log(tokens);25var stryker = require('stryker-parent');26var tokens = stryker.pluginTokens();27console.log(tokens);28var stryker = require('stryker-parent');29var tokens = stryker.pluginTokens();30console.log(tokens);31var stryker = require('stryker-parent');32var tokens = stryker.pluginTokens();33console.log(tokens);
Using AI Code Generation
1var pluginTokens = require('stryker-parent').pluginTokens;2var Stryker = require('stryker');3var tokens = pluginTokens();4var stryker = new Stryker(tokens);5stryker.runMutationTest();6var pluginTokens = require('stryker-parent').pluginTokens;7var Stryker = require('stryker');8var tokens = pluginTokens();9var stryker = new Stryker(tokens);10stryker.runMutationTest();11var pluginTokens = require('stryker-parent').pluginTokens;12var Stryker = require('stryker');13var tokens = pluginTokens();14var stryker = new Stryker(tokens);15stryker.runMutationTest();16var pluginTokens = require('stryker-parent').pluginTokens;17var Stryker = require('stryker');18var tokens = pluginTokens();19var stryker = new Stryker(tokens);20stryker.runMutationTest();21var pluginTokens = require('stryker-parent').pluginTokens;22var Stryker = require('stryker');23var tokens = pluginTokens();24var stryker = new Stryker(tokens);25stryker.runMutationTest();26var pluginTokens = require('stryker-parent').pluginTokens;27var Stryker = require('stryker');
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!