-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.index.js
41 lines (32 loc) · 1.31 KB
/
test.index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { describe, it, beforeEach, afterEach, test } from "node:test"
import assert from "node:assert"
import fs from "node:fs"
import os from "node:os"
import path from "node:path"
import exec from "elliotisms/lib/exec.js"
const originalImagePath = "./test.jpg"
describe("tests", async () => {
beforeEach(async (t) => {
t.tempFilePath = path.join(os.tmpdir(), "test.jpg")
await fs.promises.copyFile(originalImagePath, t.tempFilePath)
})
afterEach(async (t) => {
// await fs.promises.unlink(tempFilePath);
// if (newFileName) {
// await fs.promises.unlink(newFileName); // Delete the renamed file
// await fs.promises.copyFile(tempFilePath, originalImagePath); // Restore the original
// }
})
it("should run index.js, rename the image, and return no errors", async (t) => {
await exec(`node ./index.js "${t.tempFilePath}"`)
let filesInTMP = await fs.promises.readdir(os.tmpdir())
let hasTheRenamedFile =
filesInTMP.find(
(file) => file.endsWith(".jpg") && file !== "test.jpg" && file.indexOf("watermelon") > -1
) !== undefined
assert.ok(
hasTheRenamedFile,
"correct new JPG file was found after running index.js: " + filesInTMP
)
})
})