@@ -12,7 +12,8 @@ import {
1212 DatabaseManager ,
1313 DatabaseItemImpl ,
1414 DatabaseContents ,
15- FullDatabaseOptions
15+ FullDatabaseOptions ,
16+ findSourceArchive
1617} from '../../databases' ;
1718import { Logger } from '../../logging' ;
1819import { QueryServerClient } from '../../queryserver-client' ;
@@ -179,7 +180,7 @@ describe('databases', () => {
179180 expect ( spy ) . to . have . been . calledWith ( mockEvent ) ;
180181 } ) ;
181182
182- it ( 'should add a database item source archive' , async function ( ) {
183+ it ( 'should add a database item source archive' , async function ( ) {
183184 const mockDbItem = createMockDB ( ) ;
184185 mockDbItem . name = 'xxx' ;
185186 await ( databaseManager as any ) . addDatabaseSourceArchiveFolder ( mockDbItem ) ;
@@ -478,6 +479,49 @@ describe('databases', () => {
478479 const db = createMockDB ( sourceLocationUri ( ) , Uri . file ( '/path/to/dir/dir.testproj' ) ) ;
479480 expect ( await db . isAffectedByTest ( '/path/to/test.ql' ) ) . to . false ;
480481 } ) ;
482+
483+ } ) ;
484+
485+ describe . only ( 'findSourceArchive' , function ( ) {
486+ // not sure why, but some of these tests take more than two second to run.
487+ this . timeout ( 5000 ) ;
488+
489+ [ 'src' , 'output/src_archive' ] . forEach ( name => {
490+ it ( `should find source folder in ${ name } ` , async ( ) => {
491+ const uri = Uri . file ( path . join ( dir . name , name ) ) ;
492+ fs . createFileSync ( path . join ( uri . fsPath , 'hucairz.txt' ) ) ;
493+ const srcUri = await findSourceArchive ( dir . name ) ;
494+ expect ( srcUri ! . fsPath ) . to . eq ( uri . fsPath ) ;
495+ } ) ;
496+
497+ it ( `should find source archive in ${ name } .zip` , async ( ) => {
498+ const uri = Uri . file ( path . join ( dir . name , name + '.zip' ) ) ;
499+ fs . createFileSync ( uri . fsPath ) ;
500+ const srcUri = await findSourceArchive ( dir . name ) ;
501+ expect ( srcUri ! . fsPath ) . to . eq ( uri . fsPath ) ;
502+ } ) ;
503+
504+ it ( `should prioritize ${ name } .zip over ${ name } ` , async ( ) => {
505+ const uri = Uri . file ( path . join ( dir . name , name + '.zip' ) ) ;
506+ fs . createFileSync ( uri . fsPath ) ;
507+
508+ const uriFolder = Uri . file ( path . join ( dir . name , name ) ) ;
509+ fs . createFileSync ( path . join ( uriFolder . fsPath , 'hucairz.txt' ) ) ;
510+
511+ const srcUri = await findSourceArchive ( dir . name ) ;
512+ expect ( srcUri ! . fsPath ) . to . eq ( uri . fsPath ) ;
513+ } ) ;
514+ } ) ;
515+
516+ it ( 'should prioritize src over output/src_archive' , async ( ) => {
517+ const uriSrc = Uri . file ( path . join ( dir . name , 'src.zip' ) ) ;
518+ fs . createFileSync ( uriSrc . fsPath ) ;
519+ const uriSrcArchive = Uri . file ( path . join ( dir . name , 'src.zip' ) ) ;
520+ fs . createFileSync ( uriSrcArchive . fsPath ) ;
521+
522+ const resultUri = await findSourceArchive ( dir . name ) ;
523+ expect ( resultUri ! . fsPath ) . to . eq ( uriSrc . fsPath ) ;
524+ } ) ;
481525 } ) ;
482526
483527 function createMockDB (
0 commit comments