Skip to content

Commit

Permalink
Add test for finding nested dir at path.basename(cwd) (#1)
Browse files Browse the repository at this point in the history
* Addition testing for edge cases

* Return absolute path if found regardless of cwd
* Return undefined for non-existant absolute path
* Find nested path in basename of cwd

* Tweak variable name
  • Loading branch information
coreyfarrell authored and sholladay committed Apr 24, 2019
1 parent bb10d62 commit 94fafd1
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ const name = {
packageDirectory: 'find-up',
packageJson: 'package.json',
fixtureDirectory: 'fixture',
modulesDirectory: 'node_modules',
baz: 'baz.js',
qux: 'qux.js'
};

// These paths are relative to the project root
const relative = {
fixtureDirectory: name.fixtureDirectory
fixtureDirectory: name.fixtureDirectory,
modulesDirectory: name.modulesDirectory
};
relative.baz = path.join(relative.fixtureDirectory, name.baz);
relative.qux = path.join(relative.fixtureDirectory, name.qux);
Expand Down Expand Up @@ -188,6 +190,22 @@ test('sync (nested descendant directory)', t => {
t.is(foundPath, absolute.barDir);
});

test('async (nested descendant directory, custom cwd)', async t => {
const filePath = await findUp(relative.barDir, {
cwd: relative.modulesDirectory
});

t.is(filePath, absolute.barDir);
});

test('sync (nested descendant directory, custom cwd)', t => {
const filePath = findUp.sync(relative.barDir, {
cwd: relative.modulesDirectory
});

t.is(filePath, absolute.barDir);
});

test('async (nested cousin directory, custom cwd)', async t => {
const foundPath = await findUp(relative.barDir, {
cwd: relative.fixtureDirectory
Expand Down Expand Up @@ -220,6 +238,46 @@ test('sync (ancestor directory, custom cwd)', t => {
t.is(foundPath, absolute.fixtureDirectory);
});

test('async (absolute directory)', async t => {
const filePath = await findUp(absolute.barDir);

t.is(filePath, absolute.barDir);
});

test('sync (absolute directory)', t => {
const filePath = findUp.sync(absolute.barDir);

t.is(filePath, absolute.barDir);
});

test('async (not found, absolute file)', async t => {
const filePath = await findUp(path.resolve('somenonexistentfile.js'));

t.is(filePath, undefined);
});

test('sync (not found, absolute file)', t => {
const filePath = findUp.sync(path.resolve('somenonexistentfile.js'));

t.is(filePath, undefined);
});

test('async (absolute directory, disjoint cwd)', async t => {
const filePath = await findUp(absolute.barDir, {
cwd: t.context.disjoint
});

t.is(filePath, absolute.barDir);
});

test('sync (absolute directory, disjoint cwd)', t => {
const filePath = findUp.sync(absolute.barDir, {
cwd: t.context.disjoint
});

t.is(filePath, absolute.barDir);
});

test('async (not found)', async t => {
const foundPath = await findUp('somenonexistentfile.js');

Expand Down

0 comments on commit 94fafd1

Please sign in to comment.