<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

import { createSource } from "../../../reducers/sources";

import { getDirectories, createTree } from "../index";

function formatDirectories(source, parentMap, tree) {
  const paths = getDirectories(source, parentMap, tree);
  return paths.map(node => node.path);
}

function createSources(urls) {
  return urls.reduce((sources, url, index) => {
    const id = `a${index}`;
    sources[id] = createSource({ url, id });
    return sources;
  }, {});
}

describe("getDirectories", () => {
  it("gets a source's ancestor directories", function() {
    const sources = createSources([
      "http://a/b.js",
      "http://a/c.js",
      "http://b/c.js"
    ]);

    const debuggeeUrl = "http://a/";
    const { sourceTree, parentMap } = createTree({ sources, debuggeeUrl });
    expect(formatDirectories(sources.a0, parentMap, sourceTree)).toEqual(["a/b.js", "a"]);
    expect(formatDirectories(sources.a1, parentMap, sourceTree)).toEqual(["a/c.js", "a"]);
    expect(formatDirectories(sources.a2, parentMap, sourceTree)).toEqual(["b/c.js", "b"]);
  });
});<commit_msg>fix linting for getDirectories (#7019)<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

import { createSource } from "../../../reducers/sources";

import { getDirectories, createTree } from "../index";

function formatDirectories(source, parentMap, tree) {
  const paths = getDirectories(source, parentMap, tree);
  return paths.map(node => node.path);
}

function createSources(urls) {
  return urls.reduce((sources, url, index) => {
    const id = `a${index}`;
    sources[id] = createSource({ url, id });
    return sources;
  }, {});
}

describe("getDirectories", () => {
  it("gets a source's ancestor directories", function() {
    const sources = createSources([
      "http://a/b.js",
      "http://a/c.js",
      "http://b/c.js"
    ]);

    const debuggeeUrl = "http://a/";
    const { sourceTree, parentMap } = createTree({ sources, debuggeeUrl });
    expect(formatDirectories(sources.a0, parentMap, sourceTree)).toEqual([
      "a/b.js",
      "a"
    ]);
    expect(formatDirectories(sources.a1, parentMap, sourceTree)).toEqual([
      "a/c.js",
      "a"
    ]);
    expect(formatDirectories(sources.a2, parentMap, sourceTree)).toEqual([
      "b/c.js",
      "b"
    ]);
  });
});
{'fraction_non_alphanumeric': 0.17726759503199097, 'fraction_numerical': 0.006774557771923222, 'mean_word_length': 3.4226289517470883, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '5707908', 'n_tokens_mistral': 875, 'n_tokens_neox': 860, 'n_words': 217}