<commit_before>import assert from "assert";
import { join } from "path";
import {
  readdirSync,
  readFileSync,
  statSync,
} from "fs";
import { compile, transform } from "../lib/compiler.js";
import { prettyPrint } from "recast";

var jsFiles = Object.create(null);

function walk(dir) {
  readdirSync(dir).forEach(function (item) {
    var absPath = join(dir, item);
    var stat = statSync(absPath);
    if (stat.isDirectory()) {
      walk(absPath);
    } else if (item.endsWith(".js") &&
               stat.isFile()) {
      jsFiles[absPath] = readFileSync(absPath, "utf8");
    }
  });
}

walk(__dirname);

describe("compiler.transform", function () {
  function check(options) {
    Object.keys(jsFiles).forEach(function (absPath) {
      var code = jsFiles[absPath];
      assert.strictEqual(
        prettyPrint(compile(code, options).ast).code,
        prettyPrint(transform(options.parse(code), options)).code,
        "Transform mismatch for " + absPath
      );
    });
  }

  it("gives the same results as compile with babylon", function () {
    check({
      ast: true,
      parse: require("../lib/parsers/babylon.js").parse
    });
  });

  it("gives the same results as compile with acorn", function () {
    check({
      ast: true,
      parse: require("../lib/parsers/acorn.js").parse
    });
  });
});<commit_msg>Fix expensive transform tests by increasing timeouts to 5000ms.<commit_after>import assert from "assert";
import { join } from "path";
import {
  readdirSync,
  readFileSync,
  statSync,
} from "fs";
import { compile, transform } from "../lib/compiler.js";
import { prettyPrint } from "recast";

var jsFiles = Object.create(null);

function walk(dir) {
  readdirSync(dir).forEach(function (item) {
    var absPath = join(dir, item);
    var stat = statSync(absPath);
    if (stat.isDirectory()) {
      walk(absPath);
    } else if (item.endsWith(".js") &&
               stat.isFile()) {
      jsFiles[absPath] = readFileSync(absPath, "utf8");
    }
  });
}

walk(__dirname);

describe("compiler.transform", function () {
  function check(options) {
    Object.keys(jsFiles).forEach(function (absPath) {
      var code = jsFiles[absPath];
      assert.strictEqual(
        prettyPrint(compile(code, options).ast).code,
        prettyPrint(transform(options.parse(code), options)).code,
        "Transform mismatch for " + absPath
      );
    });
  }

  it("gives the same results as compile with babylon", function () {
    check({
      ast: true,
      parse: require("../lib/parsers/babylon.js").parse
    });
  }).timeout(5000);

  it("gives the same results as compile with acorn", function () {
    check({
      ast: true,
      parse: require("../lib/parsers/acorn.js").parse
    });
  }).timeout(5000);
});
{'fraction_non_alphanumeric': 0.15711175616835993, 'fraction_numerical': 0.0050798258345428155, 'mean_word_length': 3.0905044510385755, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2324655', 'n_tokens_mistral': 877, 'n_tokens_neox': 852, 'n_words': 198}