@@ -11,6 +11,7 @@ import fs from '../../../shared/fs/fs'
1111import crypto from 'crypto'
1212// @ts -ignore
1313import { BlobWriter } from '@zip.js/zip.js'
14+ import { assertLogsContain } from '../../globalSetup.test'
1415
1516describe ( 'zipStream' , function ( ) {
1617 let tmpDir : string
@@ -67,6 +68,25 @@ describe('zipStream', function () {
6768
6869 assert . strictEqual ( result . sizeInBytes , ( await fs . stat ( zipPath ) ) . size )
6970 } )
71+
72+ it ( 'only writes to target paths once' , async function ( ) {
73+ const testFilePath = path . join ( tmpDir , 'test.txt' )
74+ await fs . writeFile ( testFilePath , 'foo bar' )
75+ const testFilePath2 = path . join ( tmpDir , 'test2.txt' )
76+ await fs . writeFile ( testFilePath2 , 'foo bar' )
77+
78+ const zipStream = new ZipStream ( )
79+ zipStream . writeFile ( testFilePath , 'file.txt' )
80+ zipStream . writeFile ( testFilePath2 , 'file.txt' )
81+ const result = await zipStream . finalize ( )
82+
83+ const zipBuffer = result . streamBuffer . getContents ( )
84+ assert . ok ( zipBuffer )
85+ const zipEntries = await ZipStream . unzip ( zipBuffer )
86+
87+ assert . strictEqual ( zipEntries . length , 1 )
88+ assertLogsContain ( 'already added' , false , 'warn' )
89+ } )
7090} )
7191
7292async function verifyResult ( result : ZipStreamResult , zipPath : string ) {
0 commit comments