|
1 | 1 | import { describe, it, before, after, afterEach } from 'node:test'
|
2 | 2 | import assert from 'node:assert/strict'
|
3 | 3 | import path from 'node:path'
|
| 4 | +import fs from 'node:fs/promises' |
4 | 5 | import { promisify } from 'node:util'
|
5 | 6 | import { exec } from 'node:child_process'
|
6 | 7 | import { EventEmitter } from 'node:events'
|
@@ -89,34 +90,36 @@ describe('checking for tar and gzip', () => {
|
89 | 90 | it('should find a usable version of tar', async () => {
|
90 | 91 | const unpacker = new Unpacker()
|
91 | 92 | await unpacker.setPath(tarball)
|
92 |
| - const hasTar = unpacker.checkCommands() |
| 93 | + const hasTar = await unpacker.checkCommands() |
93 | 94 | assert.strictEqual(/tar/.test(hasTar.tar.path), true)
|
94 | 95 | })
|
95 | 96 |
|
96 | 97 | it('should find a usable verion of gzip', async () => {
|
97 | 98 | const unpacker = new Unpacker()
|
98 | 99 | await unpacker.setPath(tarball)
|
99 |
| - const hasGzip = unpacker.checkCommands() |
| 100 | + const hasGzip = await unpacker.checkCommands() |
100 | 101 | assert.strictEqual(/gzip/.test(hasGzip.gzip.path), true)
|
101 | 102 | })
|
102 | 103 |
|
103 | 104 | it('should find a usable verion of unzip', async () => {
|
104 | 105 | const unpacker = new Unpacker()
|
105 | 106 | await unpacker.setPath(tinyZip)
|
106 |
| - const hasUnzip = unpacker.checkCommands() |
| 107 | + const hasUnzip = await unpacker.checkCommands() |
107 | 108 | assert.strictEqual(/unzip/.test(hasUnzip.unzip.path), true)
|
108 | 109 | })
|
109 | 110 | })
|
110 | 111 |
|
111 | 112 | 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 | + }) |
120 | 123 |
|
121 | 124 | it('should unpack and move a .tar.gz file', async () => {
|
122 | 125 | const unpacker = new Unpacker()
|
|
0 commit comments