-
-
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
b484e64
commit 139f6c4
Showing
4 changed files
with
69 additions
and
1 deletion.
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,39 @@ | ||
/** | ||
* @file Unit Tests - loadLibConfig | ||
* @module tsconfig-utils/utils/tests/unit/loadLibConfig | ||
*/ | ||
|
||
import type { Spy } from '#tests/interfaces' | ||
import getTsconfigJson from '#tests/utils/get-tsconfig-json' | ||
import type { Lib } from '@flex-development/tsconfig-types' | ||
import loadCompilerOptions from '../load-compiler-options' | ||
import testSubject from '../load-lib-config' | ||
|
||
vi.mock('../load-compiler-options') | ||
|
||
describe('unit:utils/loadLibConfig', () => { | ||
let id: string | ||
let loadCompilerOptionsMock: Spy<typeof loadCompilerOptions> | ||
|
||
beforeAll(() => { | ||
id = 'tsconfig.json' | ||
loadCompilerOptionsMock = | ||
loadCompilerOptions as unknown as typeof loadCompilerOptionsMock | ||
}) | ||
|
||
it('should return Lib array', () => { | ||
// Arrange | ||
const lib: Lib[] = getTsconfigJson(id)!.compilerOptions!.lib! | ||
|
||
// Act + Expect | ||
expect(testSubject(id)).to.deep.equal(lib) | ||
}) | ||
|
||
it('should return empty array if compilerOptions.lib is NIL', () => { | ||
// Arrange | ||
loadCompilerOptionsMock.mockReturnValueOnce({}) | ||
|
||
// Act + Expect | ||
expect(testSubject(id)).to.deep.equal([]) | ||
}) | ||
}) |
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,26 @@ | ||
/** | ||
* @file Utilities - loadLibConfig | ||
* @module tsconfig-utils/utils/loadLibConfig | ||
*/ | ||
|
||
import type { LoadTsconfigOptions } from '#src/interfaces' | ||
import type { Lib } from '@flex-development/tsconfig-types' | ||
import type { URL } from 'node:url' | ||
import loadCompilerOptions from './load-compiler-options' | ||
|
||
/** | ||
* Loads [type definition configurations][1] from a [tsconfig][2] file. | ||
* | ||
* [1]: https://www.typescriptlang.org/tsconfig#lib | ||
* [2]: https://www.typescriptlang.org/tsconfig | ||
* | ||
* @param {URL | string} id - Module id of tsconfig file | ||
* @param {LoadTsconfigOptions} [options={}] - Tsconfig loading options | ||
* @return {Lib[]} Type definition configurations array | ||
*/ | ||
const loadLibConfig = ( | ||
id: URL | string, | ||
options: LoadTsconfigOptions = {} | ||
): Lib[] => loadCompilerOptions(id, options).lib ?? [] | ||
|
||
export default loadLibConfig |