-
-
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
135dfee
commit 3dd561d
Showing
4 changed files
with
84 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,18 @@ | ||
/** | ||
* @file Mock Utilities - loadCompilerOptions | ||
* @module mlly/utils/mocks/loadCompilerOptions | ||
*/ | ||
|
||
/** | ||
* `loadCompilerOptions` module type. | ||
*/ | ||
type Actual = typeof import('../load-compiler-options') | ||
|
||
/** | ||
* `loadCompilerOptions` module. | ||
* | ||
* @const {Actual} actual | ||
*/ | ||
const actual: Actual = await vi.importActual<Actual>('../load-compiler-options') | ||
|
||
export default vi.fn(actual.default) |
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 - loadPathAliases | ||
* @module tsconfig-utils/utils/tests/unit/loadPathAliases | ||
*/ | ||
|
||
import type { Spy } from '#tests/interfaces' | ||
import getTsconfigJson from '#tests/utils/get-tsconfig-json' | ||
import type { Paths } from '@flex-development/tsconfig-types' | ||
import loadCompilerOptions from '../load-compiler-options' | ||
import testSubject from '../load-path-aliases' | ||
|
||
vi.mock('../load-compiler-options') | ||
|
||
describe('unit:utils/loadPathAliases', () => { | ||
let id: string | ||
let loadCompilerOptionsMock: Spy<typeof loadCompilerOptions> | ||
|
||
beforeAll(() => { | ||
id = 'tsconfig.json' | ||
loadCompilerOptionsMock = | ||
loadCompilerOptions as unknown as typeof loadCompilerOptionsMock | ||
}) | ||
|
||
it('should return Paths object', () => { | ||
// Arrange | ||
const paths: Paths = getTsconfigJson(id)!.compilerOptions!.paths! | ||
|
||
// Act + Expect | ||
expect(testSubject(id)).to.deep.equal(paths) | ||
}) | ||
|
||
it('should return empty object if compilerOptions.paths 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 - loadPathAliases | ||
* @module tsconfig-utils/utils/loadPathAliases | ||
*/ | ||
|
||
import type { LoadTsconfigOptions } from '#src/interfaces' | ||
import type { Paths } from '@flex-development/tsconfig-types' | ||
import type { URL } from 'node:url' | ||
import loadCompilerOptions from './load-compiler-options' | ||
|
||
/** | ||
* Loads a [path alias configuration][1] from a [tsconfig][2] file. | ||
* | ||
* [1]: https://www.typescriptlang.org/tsconfig#paths | ||
* [2]: https://www.typescriptlang.org/tsconfig | ||
* | ||
* @param {URL | string} id - Module id of tsconfig file | ||
* @param {LoadTsconfigOptions} [options={}] - Tsconfig loading options | ||
* @return {Paths} Path alias configuration object | ||
*/ | ||
const loadPathAliases = ( | ||
id: URL | string, | ||
options: LoadTsconfigOptions = {} | ||
): Paths => loadCompilerOptions(id, options).paths ?? {} | ||
|
||
export default loadPathAliases |