-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
small cleanup to index.js, started trying to figure out what a test w…
…ould be lol
- Loading branch information
1 parent
dc200b7
commit aa9fb3d
Showing
2 changed files
with
93 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
) | ||
|
||
}) | ||
}) |