1
mirror of https://github.com/jakejarvis/careful-downloader.git synced 2025-09-18 15:55:31 -04:00
Files
careful-downloader/test/index.js

51 lines
1.5 KiB
JavaScript

/* eslint-env mocha */
import fs from "fs-extra";
import path from "path";
import tempy from "tempy";
import { expect } from "chai";
import downloader from "../index.js";
it("verified checksum, hugo.exe was extracted", async function () {
this.timeout(30000); // increase timeout to an excessive 30 seconds for CI
const outDir = path.join(tempy.directory());
await downloader(
"https://github.com/gohugoio/hugo/releases/download/v0.88.1/hugo_extended_0.88.1_Windows-64bit.zip",
"https://github.com/gohugoio/hugo/releases/download/v0.88.1/hugo_0.88.1_checksums.txt",
{
destDir: outDir,
algorithm: "sha256",
encoding: "binary",
extract: true,
},
);
expect(fs.existsSync(path.join(outDir, "hugo.exe"))).to.be.true;
fs.removeSync(outDir);
});
it("incorrect checksum, not extracted", async function () {
this.timeout(30000); // increase timeout to an excessive 30 seconds for CI
const outDir = path.join(tempy.directory());
expect(async () => downloader(
// download mismatching versions to trigger error
"https://github.com/gohugoio/hugo/releases/download/v0.88.0/hugo_0.88.0_Windows-64bit.zip",
"https://github.com/gohugoio/hugo/releases/download/v0.88.1/hugo_0.88.1_checksums.txt",
{
destDir: outDir,
algorithm: "sha256",
encoding: "binary",
extract: false,
},
)).to.throw;
expect(fs.existsSync(path.join(outDir, "hugo.exe"))).to.be.false;
fs.removeSync(outDir);
});