<commit_before>// Internal: TestRunner is responsible for actually running through each
// suite of tests and executing the specs.
//
// It also presents the test results and ensures a report is sent to cavy-cli
// if necessary.
//
// component  - the Tester component within which the app is wrapped.
// testSuites - an array of TestScopes, each of which relate to a single suite
//              of tests.
// startDelay - length of time in ms that cavy should wait before starting
//              tests.
// reporter   - the function called with the test report as an argument once
//              all tests have finished.
//
export default class TestRunner {
  constructor(component, testSuites, startDelay, reporter, sendReport) {
    this.component = component;
    this.testSuites = testSuites;
    this.startDelay = startDelay;
    this.reporter = reporter;
    // Using the sendReport prop is deprecated - cavy checks whether the
    // cavy-cli server is listening and sends a report if true.
    this.shouldSendReport = sendReport;
    this.results = [];
    this.errorCount = 0;
  }

  // Internal: Start tests after optional delay time.
  async run() {
    if (this.startDelay) { await this.pause(this.startDelay)};
    this.runTestSuites();
  }

  // Internal: Synchronously runs each test suite one after the other,
  // sending a test report to cavy-cli if needed.
  async runTestSuites() {
    const start = new Date();
    console.log(`Cavy test suite started at ${start}.`);

    // Iterate through each suite...
    for (let i = 0; i < this.testSuites.length; i++) {
      // And then through the suite's test cases...
      for (let j = 0; j < this.testSuites[i].testCases.length; j++) {
        let scope = this.testSuites[i];
        // And run each test, within the test scope.
        await this.runTest(scope, scope.testCases[j]);
      }
    }<commit_msg>filter tests for 'focus' tests and run only them if present<commit_after>// Internal: TestRunner is responsible for actually running through each
// suite of tests and executing the specs.
//
// It also presents the test results and ensures a report is sent to cavy-cli
// if necessary.
//
// component  - the Tester component within which the app is wrapped.
// testSuites - an array of TestScopes, each of which relate to a single suite
//              of tests.
// startDelay - length of time in ms that cavy should wait before starting
//              tests.
// reporter   - the function called with the test report as an argument once
//              all tests have finished.
//
export default class TestRunner {
  constructor(component, testSuites, startDelay, reporter, sendReport) {
    this.component = component;
    this.testSuites = testSuites;
    this.startDelay = startDelay;
    this.reporter = reporter;
    // Using the sendReport prop is deprecated - cavy checks whether the
    // cavy-cli server is listening and sends a report if true.
    this.shouldSendReport = sendReport;
    this.results = [];
    this.errorCount = 0;
  }

  // Internal: Start tests after optional delay time.
  async run() {
    if (this.startDelay) { await this.pause(this.startDelay)};
    this.runTestSuites();
  }

  // Internal: Synchronously runs each test suite one after the other,
  // sending a test report to cavy-cli if needed.
  async runTestSuites() {
    const start = new Date();
    console.log(`Cavy test suite started at ${start}.`);

    // Setup collections for tests
    const focusedTests = [];
    const allTests = [];

    // Iterate through each suite...
    for (let i = 0; i < this.testSuites.length; i++) {
      // And then through the suite's test cases...
      for (let j = 0; j < this.testSuites[i].testCases.length; j++) {
        let scope = this.testSuites[i];
        // If the test has a 'focus' flag...
        if (scope.testCases[j].focus == 'focus') {
          // Add the test scope and the test to the focusedTests array...
          focusedTests.push({ scope, testCase: scope.testCases[j] });
        }
        // Add the test scope and the test to the allTests array...
        allTests.push({ scope, testCase: scope.testCases[j] });
      }
    }

    // If there are any focused tests, only run them, otherwise run all the tests
    const tests = focusedTests.length ? focusedTests : allTests;
    for (let i = 0; i < tests.length; i++) {
      const { scope, testCase } = tests[i];
      await this.runTest(scope, testCase);
    }
{'fraction_non_alphanumeric': 0.10170633138751684, 'fraction_numerical': 0.001571621014818141, 'mean_word_length': 2.566853482786229, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 3, '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': '3990884', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1242, 'n_words': 504}