Files
lodestar/packages/cli/test/unit/util/gitData.test.ts
Lion - dapplion 15d8ae2c2c Simplify gitData and version guessing (#3992)
Don't print double slash in version string

Dont add git-data.json to NPM releases

Write git-data.json only in from source docker build

Remove numCommits

Test git-data.json generation from within the test

Move comment

Revert "Dont add git-data.json to NPM releases"

This reverts commit 5fe2d388825f3e3a834058478071e8364b0d761c.

Simplify gitData and version guessing

Run cmd
2022-05-10 12:07:27 +02:00

40 lines
1.3 KiB
TypeScript

import {expect} from "chai";
import child_process from "node:child_process";
import fs from "node:fs";
import path from "node:path";
import findUp from "find-up";
import {gitDataPath, readGitDataFile} from "../../../src/util/gitData/gitDataPath";
import {getGitData} from "../../../src/util";
const WRITE_GIT_DATA_CMD = "npm run write-git-data";
describe("util / gitData", () => {
before(() => {
const pkgJsonPath = findUp.sync("package.json", {cwd: __dirname});
if (!pkgJsonPath) {
throw Error("No package.json found");
}
const pkgJsonDir = path.resolve(path.dirname(pkgJsonPath));
child_process.execSync(WRITE_GIT_DATA_CMD, {cwd: pkgJsonDir});
});
it("gitData file must exist", () => {
const gitData = readGitDataFile();
expect(gitData).to.deep.equal(getGitData(), "Wrong git-data.json contents");
});
it("gitData path must be included in the package.json", () => {
const pkgJsonPath = findUp.sync("package.json", {cwd: __dirname});
if (!pkgJsonPath) {
throw Error("No package.json found");
}
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8")) as {files: string[]};
const gitDataPathFromPkgJson = path.relative(path.dirname(pkgJsonPath), gitDataPath);
expect(pkgJson.files).to.include(gitDataPathFromPkgJson, "package.json .files does not include gitData path");
});
});