cargo-semver-checks/__tests__/utils.test.ts
Mieszko Grodzicki ca4682c48b
Use folder-hash instead of hash-files. (#45)
* Use folder-hash instead of hash-files.

* Fix indentation in jest.config.js

* awaits in separate lines
2023-04-30 15:37:33 -04:00

25 lines
971 B
TypeScript

import * as fs from "fs";
import { join } from "path";
import * as crypto from "crypto";
import { hashFiles } from "../src/utils";
import { hashElement } from "folder-hash";
test("test hashFiles on ** pattern", async () => {
const tmpDir = await fs.promises.mkdtemp("cargo-semver-checks-action-test");
await fs.promises.writeFile(join(tmpDir, "Cargo.lock"), "test1");
await fs.promises.mkdir(join(tmpDir, "inner"));
await fs.promises.writeFile(join(tmpDir, "inner", "Cargo.lock"), "test2");
const hashAll = await hashFiles([join(tmpDir, "**", "Cargo.lock")]);
const hashNodeOuter = await hashElement(join(tmpDir, "Cargo.lock"));
const hashNodeInner = await hashElement(join(tmpDir, "inner", "Cargo.lock"));
await fs.promises.rm(tmpDir, { recursive: true });
const hasher = crypto.createHash("md5");
hasher.update(hashNodeOuter.hash);
hasher.update(hashNodeInner.hash);
expect(hashAll).toBe(hasher.digest("hex"));
});