-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:privatenumber/fs.promises.exists
- Loading branch information
Showing
3 changed files
with
139 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,100 @@ | ||
import { test } from 'uvu'; | ||
import path from 'path'; | ||
import { suite, Test } from 'uvu'; | ||
import * as assert from 'uvu/assert'; // eslint-disable-line node/file-extension-in-import | ||
import fsExists from '../src/index'; | ||
|
||
test('exists', async () => { | ||
const exists = await fsExists('./package.json'); | ||
assert.is(exists, true); | ||
}); | ||
// https://github.com/lukeed/uvu/issues/43 | ||
function describe(name: string, function_: (test: Test) => void) { | ||
const s = suite(name); | ||
function_(s); | ||
s.run(); | ||
} | ||
|
||
test('doesn\'t exist', async () => { | ||
const exists = await fsExists('./random-non-existent-file'); | ||
assert.is(exists, false); | ||
}); | ||
const fixturePath = 'test/fixture/CASE-SENSITIVE/case-insensitive/file.txt'; | ||
const existentPath = { | ||
relativeShort: fixturePath, | ||
relative: `./${fixturePath}`, | ||
absolute: path.resolve(fixturePath), | ||
caseInsensitive: fixturePath.toUpperCase(), | ||
}; | ||
|
||
test('case-sensitive: doesn\'t exist', async () => { | ||
const exists = await fsExists('PACKAGE.json', true); | ||
assert.is(exists, false); | ||
}); | ||
const nonExistenent = { | ||
file: 'random-non-existent-file', | ||
directory: 'random-non-existent-dir/random-non-existent-file', | ||
}; | ||
|
||
test('case-sensitive: exists', async () => { | ||
const exists = await fsExists('package.json', true); | ||
assert.is(exists, true); | ||
}); | ||
describe('basic', (test) => { | ||
test('exists', async () => { | ||
const exists = await fsExists(existentPath.relativeShort); | ||
assert.is(exists, true); | ||
}); | ||
|
||
test('case-insensitive: exist 1', async () => { | ||
const exists = await fsExists('PACKAGE.json', false); | ||
assert.is(exists, 'package.json'); | ||
test('doesnt exist', async () => { | ||
const exists = await fsExists(nonExistenent.file); | ||
assert.is(exists, false); | ||
}); | ||
}); | ||
|
||
test('case-insensitive: exists 2', async () => { | ||
const exists = await fsExists('package.json', false); | ||
assert.is(exists, 'package.json'); | ||
}); | ||
describe('case sensitive', (test) => { | ||
test('exists - relative path', async () => { | ||
const exists = await fsExists(existentPath.relative, true); | ||
assert.is(exists, true); | ||
}); | ||
|
||
test('exists - relative path with no ./', async () => { | ||
const exists = await fsExists(existentPath.relativeShort, true); | ||
assert.is(exists, true); | ||
}); | ||
|
||
test('exists - absolute path', async () => { | ||
const exists = await fsExists(existentPath.absolute, true); | ||
assert.is(exists, true); | ||
}); | ||
|
||
test('exists - case insensitive', async () => { | ||
const exists = await fsExists(existentPath.caseInsensitive, true); | ||
assert.is(exists, false); | ||
}); | ||
|
||
test('case-insensitive: doesn\'t exists', async () => { | ||
const exists = await fsExists('random-non-existent-file.json', false); | ||
assert.is(exists, false); | ||
test('file doesnt exist', async () => { | ||
const exists = await fsExists(nonExistenent.file, true); | ||
assert.is(exists, false); | ||
}); | ||
|
||
test('directory doesnt exist', async () => { | ||
const exists = await fsExists(nonExistenent.directory, true); | ||
assert.is(exists, false); | ||
}); | ||
}); | ||
|
||
test.run(); | ||
describe('case insensitive', (test) => { | ||
test('exists - relative path', async () => { | ||
const exists = await fsExists(existentPath.relative, false); | ||
assert.is(exists, existentPath.relative); | ||
}); | ||
|
||
test('exists - relative path with no ./', async () => { | ||
const exists = await fsExists(existentPath.relativeShort, false); | ||
assert.is(exists, existentPath.relativeShort); | ||
}); | ||
|
||
test('exists - absolute path', async () => { | ||
const exists = await fsExists(existentPath.absolute, false); | ||
assert.is(exists, existentPath.absolute); | ||
}); | ||
|
||
test('exists - case insensitive', async () => { | ||
const exists = await fsExists(existentPath.caseInsensitive, false); | ||
assert.is(exists, existentPath.relativeShort); | ||
}); | ||
|
||
test('file doesnt exist', async () => { | ||
const exists = await fsExists('file.txt', false); | ||
assert.is(exists, false); | ||
}); | ||
|
||
test('directory doesnt exist', async () => { | ||
const exists = await fsExists('some-dir/file.txt', false); | ||
assert.is(exists, false); | ||
}); | ||
}); |