-
-
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
3dd561d
commit b484e64
Showing
3 changed files
with
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @file Unit Tests - loadPluginConfigs | ||
* @module tsconfig-utils/utils/tests/unit/loadPluginConfigs | ||
*/ | ||
|
||
import type { Spy } from '#tests/interfaces' | ||
import type { Plugin } from '@flex-development/tsconfig-types' | ||
import loadCompilerOptions from '../load-compiler-options' | ||
import testSubject from '../load-plugin-configs' | ||
|
||
vi.mock('../load-compiler-options') | ||
|
||
describe('unit:utils/loadPluginConfigs', () => { | ||
let id: string | ||
let loadCompilerOptionsMock: Spy<typeof loadCompilerOptions> | ||
|
||
beforeAll(() => { | ||
id = 'tsconfig.json' | ||
loadCompilerOptionsMock = | ||
loadCompilerOptions as unknown as typeof loadCompilerOptionsMock | ||
}) | ||
|
||
it('should return Plugin object array', () => { | ||
// Arrange | ||
const plugins: Plugin[] = [{ name: 'typescript-styled-plugin' }] | ||
loadCompilerOptionsMock.mockReturnValueOnce({ plugins }) | ||
|
||
// Act + Expect | ||
expect(testSubject(id)).to.deep.equal(plugins) | ||
}) | ||
|
||
it('should return empty array if compilerOptions.plugins 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 - loadPluginConfigs | ||
* @module tsconfig-utils/utils/loadPluginConfigs | ||
*/ | ||
|
||
import type { LoadTsconfigOptions } from '#src/interfaces' | ||
import type { Plugin } from '@flex-development/tsconfig-types' | ||
import type { URL } from 'node:url' | ||
import loadCompilerOptions from './load-compiler-options' | ||
|
||
/** | ||
* Loads [language service plugin configurations][1] from a [tsconfig][2] file. | ||
* | ||
* [1]: https://www.typescriptlang.org/tsconfig#plugins | ||
* [2]: https://www.typescriptlang.org/tsconfig | ||
* | ||
* @param {URL | string} id - Module id of tsconfig file | ||
* @param {LoadTsconfigOptions} [options={}] - Tsconfig loading options | ||
* @return {Plugin[]} Language service plugin configurations array | ||
*/ | ||
const loadPluginConfigs = ( | ||
id: URL | string, | ||
options: LoadTsconfigOptions = {} | ||
): Plugin[] => loadCompilerOptions(id, options).plugins ?? [] | ||
|
||
export default loadPluginConfigs |