11const t = require ( 'tap' )
22const { join } = require ( 'path' )
3+ const { tmpdir } = require ( 'os' )
34const find = require ( '../lib/find.js' )
45
56t . test ( 'find the git dir many folders up' , t => {
67 const root = t . testdir ( {
78 '.git' : { index : 'hello' } ,
89 a : { b : { c : { d : { e : { } } } } } ,
910 } )
10- const path = `${ root } /a/b/c/d/e`
11- return t . resolveMatch ( find ( { cwd : path } ) , root )
11+ return t . resolveMatch ( find ( { cwd : join ( root , 'a/b/c/d/e' ) } ) , root )
1212} )
1313
1414t . test ( 'stop before root dir' , t => {
1515 const root = t . testdir ( {
1616 '.git' : { index : 'hello' } ,
1717 a : { b : { c : { d : { e : { } } } } } ,
1818 } )
19- const path = `${ root } /a/b/c/d/e`
20- return t . resolveMatch ( find ( { cwd : path , root : join ( root , 'a' ) } ) , null )
19+ return t . resolveMatch ( find ( { cwd : join ( root , 'a/b/c/d/e' ) , root : join ( root , 'a' ) } ) , null )
2120} )
2221
2322t . test ( 'stop at root dir' , t => {
2423 const root = t . testdir ( {
2524 '.git' : { index : 'hello' } ,
2625 a : { b : { c : { d : { e : { } } } } } ,
2726 } )
28- const path = `${ root } /a/b/c/d/e`
29- return t . resolveMatch ( find ( { cwd : path , root } ) , root )
27+ return t . resolveMatch ( find ( { cwd : join ( root , 'a/b/c/d/e' ) , root } ) , root )
3028} )
3129
3230t . test ( 'find the git dir at current level' , t => {
@@ -38,13 +36,31 @@ t.test('find the git dir at current level', t => {
3836
3937t . test ( 'no git dir to find' , t => {
4038 // this will fail if your tmpdir is in a git repo, I suppose
41- const path = require ( 'os' ) . tmpdir ( )
42- return t . resolveMatch ( find ( { cwd : path } ) , null )
39+ return t . resolveMatch ( find ( { cwd : tmpdir ( ) } ) , null )
4340} )
4441
4542t . test ( 'default to cwd' , t => {
4643 // this will fail if your tmpdir is in a git repo, I suppose
47- const path = require ( 'os' ) . tmpdir ( )
48- process . chdir ( path )
44+ const dir = process . cwd ( )
45+ t . teardown ( ( ) => process . chdir ( dir ) )
46+ process . chdir ( tmpdir ( ) )
4947 return t . resolveMatch ( find ( ) , null )
5048} )
49+
50+ t . test ( 'mock is' , async t => {
51+ await t . test ( 'no git dir to find' , async t => {
52+ const seen = [ ]
53+ const mockFind = t . mock ( '../lib/find.js' , {
54+ '../lib/is.js' : async ( { cwd } ) => {
55+ seen . push ( cwd )
56+ return false
57+ } ,
58+ } )
59+ // this will fail if your tmpdir is in a git repo, I suppose
60+ await t . resolveMatch ( mockFind ( { cwd : tmpdir ( ) } ) , null )
61+
62+ console . error ( seen )
63+
64+ t . strictSame ( seen , [ ...new Set ( seen ) ] )
65+ } )
66+ } )
0 commit comments