Skip to content

Commit 4c5fc17

Browse files
committed
Add before unit test to create test/static/albums directory if not present before unpacking tests.
1 parent 1731286 commit 4c5fc17

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ tmp
1717
*.config.bk
1818
*.config.test
1919
images/*_original
20+
test/static/albums/*
21+
!test/static/albums
2022

2123
# Diagnostic reports (https://nodejs.org/api/report.html)
2224
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

test/first-test.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, it, before, after, afterEach } from 'node:test'
22
import assert from 'node:assert/strict'
33
import path from 'node:path'
4+
import fs from 'node:fs/promises'
45
import { promisify } from 'node:util'
56
import { exec } from 'node:child_process'
67
import { EventEmitter } from 'node:events'
@@ -89,34 +90,36 @@ describe('checking for tar and gzip', () => {
8990
it('should find a usable version of tar', async () => {
9091
const unpacker = new Unpacker()
9192
await unpacker.setPath(tarball)
92-
const hasTar = unpacker.checkCommands()
93+
const hasTar = await unpacker.checkCommands()
9394
assert.strictEqual(/tar/.test(hasTar.tar.path), true)
9495
})
9596

9697
it('should find a usable verion of gzip', async () => {
9798
const unpacker = new Unpacker()
9899
await unpacker.setPath(tarball)
99-
const hasGzip = unpacker.checkCommands()
100+
const hasGzip = await unpacker.checkCommands()
100101
assert.strictEqual(/gzip/.test(hasGzip.gzip.path), true)
101102
})
102103

103104
it('should find a usable verion of unzip', async () => {
104105
const unpacker = new Unpacker()
105106
await unpacker.setPath(tinyZip)
106-
const hasUnzip = unpacker.checkCommands()
107+
const hasUnzip = await unpacker.checkCommands()
107108
assert.strictEqual(/unzip/.test(hasUnzip.unzip.path), true)
108109
})
109110
})
110111

111112
describe('successfully unpack some archives', () => {
112-
// afterEach(async () => {
113-
// try {
114-
// const result = await cmd(`rm -rf ${destination}/*`)
115-
// debug(result)
116-
// } catch (e) {
117-
// debug(e)
118-
// }
119-
// })
113+
before(async () => {
114+
try {
115+
const result = await fs.stat(destination)
116+
if (!result.isDirectory()) {
117+
await cmd(`mkdir -p ${destination}`)
118+
}
119+
} catch (e) {
120+
debug(`Missing the test destination dir: ${destination}`)
121+
}
122+
})
120123

121124
it('should unpack and move a .tar.gz file', async () => {
122125
const unpacker = new Unpacker()

0 commit comments

Comments
 (0)