Skip to content

Commit

Permalink
Use temp directory
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Dec 20, 2024
1 parent 23dd767 commit ceaf6ba
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require("node:path");
const fs = require("node:fs");
const os = require("node:os");
const { URL } = require("node:url");

const test = require("ava");
Expand Down Expand Up @@ -534,7 +535,6 @@ test("Keep a cache, don’t reuse with if the image changes, check promise equal
outputDir: "./test/img/",
});

fs.unlinkSync("./test/generated-modify-bio.jpg");
fs.copyFileSync("./test/modify-bio-grayscale.jpg", "./test/generated-modify-bio.jpg");

let promise2 = eleventyImage("./test/generated-modify-bio.jpg", {
Expand All @@ -545,19 +545,23 @@ test("Keep a cache, don’t reuse with if the image changes, check promise equal
});

test("Keep a cache, don’t reuse with if the image changes, check output", async t => {
fs.copyFileSync("./test/modify2-bio-original.jpg", "./test/generated-modify2-bio.jpg");
let outputPathTemp = path.join(os.tmpdir(), "generated-modify2-bio.jpg");

let stats1 = await eleventyImage("./test/generated-modify2-bio.jpg", {
fs.copyFileSync("./test/modify2-bio-original.jpg", outputPathTemp);

let stats1 = await eleventyImage(outputPathTemp, {
outputDir: "./test/img/",
});

fs.unlinkSync("./test/generated-modify2-bio.jpg");
fs.copyFileSync("./test/modify2-bio-grayscale.jpg", "./test/generated-modify2-bio.jpg");
fs.unlinkSync(outputPathTemp);
fs.copyFileSync("./test/modify2-bio-grayscale.jpg", outputPathTemp);

let stats2 = await eleventyImage("./test/generated-modify2-bio.jpg", {
let stats2 = await eleventyImage(outputPathTemp, {
outputDir: "./test/img/",
});

fs.unlinkSync(outputPathTemp);

t.notDeepEqual(stats1, stats2);

t.is(stats1.jpeg.length, 1);
Expand Down

0 comments on commit ceaf6ba

Please sign in to comment.