{"size": 1338, "ext": "js", "max_stars_repo_path": "tests/getCollectionNewestGitCommitDate.js", "max_stars_repo_name": "saneef/eleventy-plugin-git-commit-date", "max_stars_repo_stars_event_min_datetime": "2021-09-25T14:11:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-22T10:52:26.000Z", "max_issues_repo_path": "tests/getCollectionNewestGitCommitDate.js", "max_issues_repo_name": "saneef/eleventy-plugin-git-commit-date", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/getCollectionNewestGitCommitDate.js", "max_forks_repo_name": "saneef/eleventy-plugin-git-commit-date", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 6, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.6341463415, "max_line_length": 95, "alphanum_fraction": 0.6950672646}
const test = require("ava");
const path = require("path");
const fs = require("fs/promises");
const { promisify } = require("util");
const rimraf = promisify(require("rimraf"));
const getCollectionNewestGitCommitDate = require("../src/getCollectionNewestGitCommitDate.js");

const outputBase = path.join("tests/output/");

test("Get newest commit date of collection", (t) => {
  const collection = [
    { inputPath: path.join(__dirname, "./fixtures/sample.md") },
    { inputPath: path.join(__dirname, "./fixtures/another-sample-file.md") },
  ];
  const date = getCollectionNewestGitCommitDate(collection);
  t.truthy(date);
  t.is(date.toISOString(), "2021-08-19T09:57:47.000Z");
});

test("Shouldn't get commit date from an empty collection", async (t) => {
  const collection = [];

  t.is(getCollectionNewestGitCommitDate(collection), undefined);
});

test("Shouldn't get commit date from collection of uncommited files", async (t) => {
  const collection = [
    { inputPath: path.join(outputBase, "test-01.md") },
    { inputPath: path.join(outputBase, "test-02.md") },
  ];

  await rimraf(outputBase);

  await fs.mkdir(outputBase, { recursive: true });
  await Promise.all(collection.map((p) => fs.writeFile(p.inputPath, "")));

  t.is(getCollectionNewestGitCommitDate(collection), undefined);

  await rimraf(outputBase);
});
