<commit_before>import * as React from 'react'
import { filter } from 'lodash'
import { mount, ReactWrapper } from 'enzyme'
import { PluginConstructor, PluginConfig } from '../core/PluginConfig'
import { ApplicationContext } from '../core/ApplicationContext'
import { ContextProvider } from '../core/ContextProvider'

export interface TestFixtureProps {
  plugins?: PluginConstructor[]
  markup: React.ReactElement<{}>
}

export class TestFixture {
  private reactWrapper: ReactWrapper
  private markup: React.ReactElement<{}>
  private appContext: ApplicationContext

  constructor({ plugins, markup }: TestFixtureProps) {
    this.appContext = new ApplicationContext(plugins)
    this.markup = markup
  }

  render() {
    if (!this.reactWrapper) {
      this.reactWrapper = mount(
        <ContextProvider appContext={this.appContext}>
          {this.markup}
        </ContextProvider>
      )
    }

    return this.reactWrapper.update()
  }

  stub<T extends PluginConfig>(ctor: PluginConstructor<T>, stubFn: (fn: T) => void) {
    const matches = filter(this.appContext.plugins, (x) => x instanceof ctor)
    matches.forEach(stubFn)

    return this
  }
}
<commit_msg>Add helper for getting component instance to TestFIxture<commit_after>import * as React from 'react'
import { filter } from 'lodash'
import { mount, ReactWrapper } from 'enzyme'
import { PluginConstructor, PluginConfig } from '../core/PluginConfig'
import { ApplicationContext } from '../core/ApplicationContext'
import { ContextProvider } from '../core/ContextProvider'

export interface TestFixtureProps {
  plugins?: PluginConstructor[]
  markup: React.ReactElement<{}>
}

export class TestFixture {
  private reactWrapper: ReactWrapper
  private markup: React.ReactElement<{}>
  private appContext: ApplicationContext

  constructor({ plugins, markup }: TestFixtureProps) {
    this.appContext = new ApplicationContext(plugins)
    this.markup = markup
  }

  render() {
    if (!this.reactWrapper) {
      this.reactWrapper = mount(
        <ContextProvider appContext={this.appContext}>
          {this.markup}
        </ContextProvider>
      )
    }

    return this.reactWrapper.update()
  }

  stub<T extends PluginConfig>(ctor: PluginConstructor<T>, stubFn: (fn: T) => void) {
    const matches = filter(this.appContext.plugins, (x) => x instanceof ctor)
    matches.forEach(stubFn)

    return this
  }

  getInstance<T>() {
    return this.render().childAt(0).instance() as any as T
  }
}

{'fraction_non_alphanumeric': 0.11510500807754442, 'fraction_numerical': 0.0004038772213247173, 'mean_word_length': 3.8664047151277012, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6412673', 'n_tokens_mistral': 720, 'n_tokens_neox': 695, 'n_words': 182}