-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Exists): API and Next app work well together
- Loading branch information
Showing
15 changed files
with
114 additions
and
100 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
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,73 @@ | ||
import path from 'path' | ||
|
||
import handler from '../exists' | ||
|
||
describe('Exists library', () => { | ||
const errorSchema = (message) => message | ||
|
||
describe('Expect result', () => { | ||
const successTest = async (expect, testPath) => { | ||
expect.hasAssertions() | ||
try { | ||
const verifiedPath = await handler.pathExists(testPath, errorSchema) | ||
|
||
const normalTestPath = path.normalize(testPath) | ||
expect(verifiedPath.endsWith(normalTestPath)).toBeTruthy() | ||
} catch (error) { | ||
expect(error).toBeUndefined() | ||
} | ||
} | ||
|
||
test('* Real relative file exists', async () => { | ||
const testPath = 'test/fixtures/exists.txt' | ||
await successTest(expect, testPath) | ||
}) | ||
|
||
test('* Real relative folder exists', async () => { | ||
const testPath = 'test/fixtures' | ||
await successTest(expect, testPath) | ||
}) | ||
|
||
test('* Real absolute file exists', async () => { | ||
const testPath = '/test/fixtures/exists.txt' | ||
await successTest(expect, testPath) | ||
}) | ||
|
||
test('* Real absolute folder exists', async () => { | ||
const testPath = '/test/fixtures' | ||
await successTest(expect, testPath) | ||
}) | ||
|
||
test('* Real root absolute file exists', async () => { | ||
const testPath = path.join(__dirname, '../../../../../public/test/fixtures/exists.txt') | ||
await successTest(expect, testPath) | ||
}) | ||
|
||
test('* Real root absolute folder exists', async () => { | ||
const testPath = path.join(__dirname, '../../../../../public/test/fixtures') | ||
await successTest(expect, testPath) | ||
}) | ||
}) | ||
|
||
describe('Expect result', () => { | ||
const failureTest = async (expect, testPath) => { | ||
expect.hasAssertions() | ||
try { | ||
const verifiedPath = await handler.pathExists(testPath) | ||
expect(verifiedPath).toBeUndefined() | ||
} catch (error) { | ||
expect(error.isBoom).toBeTruthy() | ||
} | ||
} | ||
|
||
test('* Fake absolute path does not exists', async () => { | ||
const testPath = '/test/fixtures/fakeFolder' | ||
await failureTest(expect, testPath) | ||
}) | ||
|
||
test('* Safe path throws error', async () => { | ||
const testPath = true | ||
await failureTest(expect, testPath) | ||
}) | ||
}) | ||
}) |
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