<commit_before>"use strict";

// console color
const red = "\u001b[31m";
const reset = "\u001b[0m";

// environment
const { TARGET_URL } = process.env;

/** @type {import("nightwatch").NightwatchTestFunctions} */
module.exports = {
  /** @param {import("nightwatch").NightwatchBrowser} client */
  async ["Browser Test"](client) {
    const elements = await client.url(
      TARGET_URL || "http://127.0.0.1:8000/power.html",
    )
      .waitForElementPresent("#mocha-report .suite:nth-of-type(4)", 30000)
      .findElements("#mocha-report .test .error");

    const result = elements.value;
    const success = result == null;

    client.verify.ok(success, "Check error elements");
    if (success) {
      return;
    }

    // show error log
    for (const element of result) {
      const id = element.getId();
      const { value: error } = await client.elementIdText(id);
      client.verify.ok(false, `\n\n${red}${error}${reset}\n\n`);
    }
  },

  afterEach(client, done) {
    client.end();
    client.endSauce(done);
  },
};
<commit_msg>Catch NoSuchElementError<commit_after>"use strict";

// console color
const red = "\u001b[31m";
const reset = "\u001b[0m";

// environment
const { TARGET_URL } = process.env;

/** @type {import("nightwatch").NightwatchTestFunctions} */
module.exports = {
  /** @param {import("nightwatch").NightwatchBrowser} client */
  async ["Browser Test"](client) {
    let elements = null;
    let success = false;

    try {
      elements = await client.url(
        TARGET_URL || "http://127.0.0.1:8000/power.html",
      )
        .waitForElementPresent("#mocha-report .suite:nth-of-type(4)", 30000)
        .findElements("#mocha-report .test .error");
    } catch (e) {
      if (e.name === "NoSuchElementError") {
        success = true;
      } else {
        // unexpected error
        throw e;
      }
    }

    client.verify.ok(success, "Check error elements");
    if (success) {
      return;
    }

    // show error log
    const result = elements.value;
    for (const element of result) {
      const id = element.getId();
      const { value: error } = await client.elementIdText(id);
      client.verify.ok(false, `\n\n${red}${error}${reset}\n\n`);
    }
  },

  afterEach(client, done) {
    client.end();
    client.endSauce(done);
  },
};

{'fraction_non_alphanumeric': 0.16898349261511728, 'fraction_numerical': 0.021720243266724587, 'mean_word_length': 2.7630718954248366, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '6235854', 'n_tokens_mistral': 796, 'n_tokens_neox': 753, 'n_words': 157}