Skip to content

Commit ffcb8f9

Browse files
committed
test: remove duplicate test checks
1 parent 4802b56 commit ffcb8f9

File tree

1 file changed

+18
-36
lines changed

1 file changed

+18
-36
lines changed

packages/core/src/test/shared/utilities/zipStream.test.ts

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import assert from 'assert'
7-
import { ZipStream } from '../../../shared/utilities/zipStream'
7+
import { ZipStream, ZipStreamResult } from '../../../shared/utilities/zipStream'
88
import { makeTemporaryToolkitFolder } from '../../../shared/filesystemUtilities'
99
import path from 'path'
1010
import fs from '../../../shared/fs/fs'
@@ -26,37 +26,17 @@ describe('zipStream', function () {
2626
await zipStream.writeString('foo bar', 'file.txt')
2727
const result = await zipStream.finalize()
2828

29-
const zipBuffer = result.streamBuffer.getContents()
30-
assert.ok(zipBuffer)
31-
32-
const zipPath = path.join(tmpDir, 'test.zip')
33-
await fs.writeFile(zipPath, zipBuffer)
34-
const expectedMd5 = crypto
35-
.createHash('md5')
36-
.update(await fs.readFileBytes(zipPath))
37-
.digest('base64')
38-
assert.strictEqual(result.hash, expectedMd5)
39-
assert.strictEqual(result.sizeInBytes, (await fs.stat(zipPath)).size)
29+
await verifyResult(result, path.join(tmpDir, 'test.zip'))
4030
})
4131

4232
it('should create a zip stream from binary content', async function () {
4333
const zipStream = new ZipStream({ hashAlgorithm: 'md5' })
4434
await zipStream.writeData(Buffer.from('foo bar'), 'file.txt')
4535
const result = await zipStream.finalize()
4636

47-
const zipBuffer = result.streamBuffer.getContents()
48-
assert.ok(zipBuffer)
37+
await verifyResult(result, path.join(tmpDir, 'test.zip'))
4938

50-
const zipPath = path.join(tmpDir, 'test.zip')
51-
await fs.writeFile(zipPath, zipBuffer)
52-
const expectedMd5 = crypto
53-
.createHash('md5')
54-
.update(await fs.readFileBytes(zipPath))
55-
.digest('base64')
56-
assert.strictEqual(result.hash, expectedMd5)
57-
assert.strictEqual(result.sizeInBytes, (await fs.stat(zipPath)).size)
58-
59-
const zipContents = await ZipStream.unzip(zipBuffer)
39+
const zipContents = await ZipStream.unzip(result.streamBuffer.getContents() || Buffer.from(''))
6040
assert.strictEqual(zipContents.length, 1)
6141
assert.strictEqual(zipContents[0].filename, 'file.txt')
6242
})
@@ -69,18 +49,7 @@ describe('zipStream', function () {
6949
zipStream.writeFile(testFilePath, 'file.txt')
7050
const result = await zipStream.finalize()
7151

72-
const zipPath = path.join(tmpDir, 'test.zip')
73-
74-
const zipBuffer = result.streamBuffer.getContents()
75-
assert.ok(zipBuffer)
76-
77-
await fs.writeFile(zipPath, zipBuffer)
78-
const expectedMd5 = crypto
79-
.createHash('md5')
80-
.update(await fs.readFileBytes(zipPath))
81-
.digest('base64')
82-
assert.strictEqual(result.hash, expectedMd5)
83-
assert.strictEqual(result.sizeInBytes, (await fs.stat(zipPath)).size)
52+
await verifyResult(result, path.join(tmpDir, 'test.zip'))
8453
})
8554

8655
it('should unzip from a buffer', async function () {
@@ -104,3 +73,16 @@ describe('zipStream', function () {
10473
assert.strictEqual(result.sizeInBytes, (await fs.stat(zipPath)).size)
10574
})
10675
})
76+
77+
async function verifyResult(result: ZipStreamResult, zipPath: string) {
78+
const zipBuffer = result.streamBuffer.getContents()
79+
assert.ok(zipBuffer)
80+
81+
await fs.writeFile(zipPath, zipBuffer)
82+
const expectedMd5 = crypto
83+
.createHash('md5')
84+
.update(await fs.readFileBytes(zipPath))
85+
.digest('base64')
86+
assert.strictEqual(result.hash, expectedMd5)
87+
assert.strictEqual(result.sizeInBytes, (await fs.stat(zipPath)).size)
88+
}

0 commit comments

Comments
 (0)