11import * as tsModule from 'typescript' ;
2- import { describe , expect } from 'vitest' ;
2+ import { describe , expect , vi } from 'vitest' ;
3+ import { osAgnosticPath } from '@code-pushup/test-utils' ;
34import { loadTargetConfig } from './utils.js' ;
45
56describe ( 'loadTargetConfig' , ( ) => {
6- const parseConfigFileTextToJsonSpy = vi . spyOn (
7- tsModule ,
8- 'parseConfigFileTextToJson' ,
9- ) ;
7+ const readConfigFileSpy = vi . spyOn ( tsModule , 'readConfigFile' ) ;
108 const parseJsonConfigFileContentSpy = vi . spyOn (
119 tsModule ,
1210 'parseJsonConfigFileContent' ,
1311 ) ;
1412
15- it ( 'should return the parsed content of a tsconfig file and ist TypeScript helper to parse it' , async ( ) => {
16- await expect (
13+ it ( 'should return the parsed content of a tsconfig file and ist TypeScript helper to parse it' , ( ) => {
14+ expect (
1715 loadTargetConfig (
18- 'packages/plugin-typescript/mocks/fixtures/basic-setup/tsconfig.init.json' ,
16+ osAgnosticPath (
17+ 'packages/plugin-typescript/mocks/fixtures/basic-setup/tsconfig.init.json' ,
18+ ) ,
1919 ) ,
20- ) . resolves . toStrictEqual (
20+ ) . toStrictEqual (
2121 expect . objectContaining ( {
2222 fileNames : expect . any ( Array ) ,
2323 options : {
2424 module : 1 ,
25- configFilePath : undefined ,
25+ configFilePath : expect . stringContaining ( 'tsconfig.init.json' ) ,
2626 esModuleInterop : true ,
2727 forceConsistentCasingInFileNames : true ,
2828 skipLibCheck : true ,
@@ -31,25 +31,39 @@ describe('loadTargetConfig', () => {
3131 } ,
3232 } ) ,
3333 ) ;
34- expect ( parseConfigFileTextToJsonSpy ) . toHaveBeenCalledTimes ( 1 ) ;
35- expect ( parseConfigFileTextToJsonSpy ) . toHaveBeenCalledWith (
36- 'packages/plugin-typescript/mocks/fixtures/basic-setup/ tsconfig.init.json',
37- expect . stringContaining ( '/* Projects */' ) ,
34+ expect ( readConfigFileSpy ) . toHaveBeenCalledTimes ( 1 ) ;
35+ expect ( readConfigFileSpy ) . toHaveBeenCalledWith (
36+ expect . stringContaining ( ' tsconfig.init.json') ,
37+ expect . any ( Function ) ,
3838 ) ;
3939 expect ( parseJsonConfigFileContentSpy ) . toHaveBeenCalledTimes ( 1 ) ;
40- expect ( parseJsonConfigFileContentSpy ) . toHaveBeenCalledWith (
40+ } ) ;
41+
42+ it ( 'should return the parsed content of a tsconfig file that extends another config' , ( ) => {
43+ expect (
44+ loadTargetConfig (
45+ 'packages/plugin-typescript/mocks/fixtures/basic-setup/tsconfig.extends-extending.json' ,
46+ ) ,
47+ ) . toStrictEqual (
4148 expect . objectContaining ( {
42- compilerOptions : expect . objectContaining ( {
43- esModuleInterop : true ,
44- forceConsistentCasingInFileNames : true ,
45- module : 'commonjs' ,
46- skipLibCheck : true ,
47- strict : true ,
48- target : 'es2016' ,
49+ fileNames : expect . arrayContaining ( [
50+ // from tsconfig.extends-base.json#includes and tsconfig.extends-extending.json#excludes
51+ expect . stringMatching ( / s r c [ / \\ ] 0 - n o - d i a g n o s t i c s [ / \\ ] / ) ,
52+ ] ) ,
53+ options : expect . objectContaining ( {
54+ // Options from tsconfig.extends-base.json
55+ rootDir : expect . stringMatching ( / b a s i c - s e t u p $ / ) ,
56+ // Options from tsconfig.extends-extending.json
57+ module : 1 ,
58+ configFilePath : expect . stringContaining (
59+ 'tsconfig.extends-extending.json' ,
60+ ) ,
61+ verbatimModuleSyntax : true , // Overrides base config's false
4962 } ) ,
5063 } ) ,
51- expect . any ( Object ) ,
52- expect . any ( String ) ,
5364 ) ;
65+
66+ expect ( readConfigFileSpy ) . toHaveBeenCalledTimes ( 1 ) ;
67+ expect ( parseJsonConfigFileContentSpy ) . toHaveBeenCalledTimes ( 1 ) ;
5468 } ) ;
5569} ) ;
0 commit comments