@@ -16,7 +16,8 @@ import {
1616 getModifiedTime ,
1717 findOrCreateDvcYamlFile ,
1818 writeJson ,
19- writeCsv
19+ writeCsv ,
20+ isPathInProject
2021} from '.'
2122import { dvcDemoPath } from '../test/util'
2223import { DOT_DVC } from '../cli/dvc/constants'
@@ -408,3 +409,52 @@ describe('findOrCreateDvcYamlFile', () => {
408409 )
409410 } )
410411} )
412+
413+ describe ( 'isPathInProject' , ( ) => {
414+ it ( 'should return true if the path is in the project' , ( ) => {
415+ const path = join ( dvcDemoPath , 'dvc.yaml' )
416+ const dvcRoot = dvcDemoPath
417+ const subProjects : string [ ] = [ ]
418+ expect ( isPathInProject ( path , dvcRoot , subProjects ) ) . toBe ( true )
419+ } )
420+
421+ it ( 'should return false if the path is not in the project' , ( ) => {
422+ const path = resolve ( dvcDemoPath , '..' , 'dvc.yaml' )
423+ const dvcRoot = dvcDemoPath
424+ const subProjects : string [ ] = [ ]
425+ expect ( isPathInProject ( path , dvcRoot , subProjects ) ) . toBe ( false )
426+ } )
427+
428+ it ( 'should return false if the path is the project' , ( ) => {
429+ const path = dvcDemoPath
430+ const dvcRoot = dvcDemoPath
431+ const subProjects : string [ ] = [ ]
432+ expect ( isPathInProject ( path , dvcRoot , subProjects ) ) . toBe ( false )
433+ } )
434+
435+ it ( 'should return false if the path is in the project but also in a sub-project' , ( ) => {
436+ const path = join ( dvcDemoPath , 'nested1' , 'dvc.yaml' )
437+ const dvcRoot = dvcDemoPath
438+ const subProjects : string [ ] = [ join ( dvcDemoPath , 'nested1' ) ]
439+ expect ( isPathInProject ( path , dvcRoot , subProjects ) ) . toBe ( false )
440+ } )
441+
442+ it ( 'should return false if the path is in the project but also in one of many sub-projects' , ( ) => {
443+ const path = join ( dvcDemoPath , 'nested2' , 'dvc.yaml' )
444+ const dvcRoot = dvcDemoPath
445+ const subProjects : string [ ] = [
446+ join ( dvcDemoPath , 'nested1' ) ,
447+ join ( dvcDemoPath , 'nested2' ) ,
448+ join ( dvcDemoPath , 'nested3' ) ,
449+ join ( dvcDemoPath , 'nested4' )
450+ ]
451+ expect ( isPathInProject ( path , dvcRoot , subProjects ) ) . toBe ( false )
452+ } )
453+
454+ it ( 'should return true if the path is in the project but not in a sub-project' , ( ) => {
455+ const path = join ( dvcDemoPath , 'nested1' , 'dvc.yaml' )
456+ const dvcRoot = dvcDemoPath
457+ const subProjects : string [ ] = [ join ( dvcDemoPath , 'nested2' ) ]
458+ expect ( isPathInProject ( path , dvcRoot , subProjects ) ) . toBe ( true )
459+ } )
460+ } )
0 commit comments