-
-
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.
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
- Loading branch information
1 parent
15addba
commit 8836dfa
Showing
3 changed files
with
44 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* @file Unit Tests - readFile | ||
* @module tsconfig-utils/internal/tests/unit/readFile | ||
*/ | ||
|
||
import pathe from '@flex-development/pathe' | ||
import fs from 'node:fs' | ||
import { URL, pathToFileURL } from 'node:url' | ||
import testSubject from '../read-file' | ||
|
||
describe('unit:internal/readFile', () => { | ||
it('should return file content', () => { | ||
// Arrange | ||
const id: URL = new URL('tsconfig.json', pathToFileURL('.' + pathe.sep)) | ||
|
||
// Act + Expect | ||
expect(testSubject(id)).to.equal(fs.readFileSync(id, 'utf8')) | ||
}) | ||
}) |
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,24 @@ | ||
/** | ||
* @file Internal - readFile | ||
* @module tsconfig-utils/internal/readFile | ||
*/ | ||
|
||
import type { NodeError } from '@flex-development/errnode' | ||
import fs from 'node:fs' | ||
import type { URL } from 'node:url' | ||
import validateURLString from './validate-url-string' | ||
|
||
/** | ||
* Reads the file at the given module `id`. | ||
* | ||
* @param {URL | string} id - Module id to evaluate | ||
* @return {string} File content at `id` | ||
* @throws {NodeError<Error | TypeError>} If `id` is not a string or an instance | ||
* of {@linkcode URL}, or if error occurs while reading file | ||
*/ | ||
const readFile = (id: URL | string): string => { | ||
validateURLString(id, 'id') | ||
return fs.readFileSync(id, 'utf8') | ||
} | ||
|
||
export default readFile |