Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Jun 5, 2023
1 parent 1759d1c commit 2874dcd
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions test/find.js
@@ -1,32 +1,30 @@
const t = require('tap')
const { join } = require('path')
const { tmpdir } = require('os')
const find = require('../lib/find.js')

t.test('find the git dir many folders up', t => {
const root = t.testdir({
'.git': { index: 'hello' },
a: { b: { c: { d: { e: {} } } } },
})
const path = `${root}/a/b/c/d/e`
return t.resolveMatch(find({ cwd: path }), root)
return t.resolveMatch(find({ cwd: join(root, 'a/b/c/d/e') }), root)
})

t.test('stop before root dir', t => {
const root = t.testdir({
'.git': { index: 'hello' },
a: { b: { c: { d: { e: {} } } } },
})
const path = `${root}/a/b/c/d/e`
return t.resolveMatch(find({ cwd: path, root: join(root, 'a') }), null)
return t.resolveMatch(find({ cwd: join(root, 'a/b/c/d/e'), root: join(root, 'a') }), null)
})

t.test('stop at root dir', t => {
const root = t.testdir({
'.git': { index: 'hello' },
a: { b: { c: { d: { e: {} } } } },
})
const path = `${root}/a/b/c/d/e`
return t.resolveMatch(find({ cwd: path, root }), root)
return t.resolveMatch(find({ cwd: join(root, 'a/b/c/d/e'), root }), root)
})

t.test('find the git dir at current level', t => {
Expand All @@ -38,13 +36,31 @@ t.test('find the git dir at current level', t => {

t.test('no git dir to find', t => {
// this will fail if your tmpdir is in a git repo, I suppose
const path = require('os').tmpdir()
return t.resolveMatch(find({ cwd: path }), null)
return t.resolveMatch(find({ cwd: tmpdir() }), null)
})

t.test('default to cwd', t => {
// this will fail if your tmpdir is in a git repo, I suppose
const path = require('os').tmpdir()
process.chdir(path)
const dir = process.cwd()
t.teardown(() => process.chdir(dir))
process.chdir(tmpdir())
return t.resolveMatch(find(), null)
})

t.test('mock is', async t => {
await t.test('no git dir to find', async t => {
const seen = []
const mockFind = t.mock('../lib/find.js', {
'../lib/is.js': async ({ cwd }) => {
seen.push(cwd)
return false
},
})
// this will fail if your tmpdir is in a git repo, I suppose
await t.resolveMatch(mockFind({ cwd: tmpdir() }), null)

console.error(seen)

t.strictSame(seen, [...new Set(seen)])
})
})

0 comments on commit 2874dcd

Please sign in to comment.