1
1
import path from 'path' ;
2
2
import { testSuite , expect } from 'manten' ;
3
3
import { createFixture } from 'fs-fixture' ;
4
- import { createTsconfigJson } from '../../../../utils.js' ;
4
+ import { createTsconfigJson , getTscTsconfig } from '../../../../utils.js' ;
5
5
import { parseTsconfig } from '#get-tsconfig' ;
6
6
7
7
export default testSuite ( ( { describe } ) => {
8
- describe ( 'resolves' , ( { test, runTestSuite } ) => {
8
+ describe ( 'resolves' , ( { test, describe , runTestSuite } ) => {
9
9
test ( 'handles missing extends' , async ( ) => {
10
10
const fixture = await createFixture ( {
11
11
'file.ts' : '' ,
@@ -21,6 +21,70 @@ export default testSuite(({ describe }) => {
21
21
await fixture . rm ( ) ;
22
22
} ) ;
23
23
24
+ describe ( 'circularity' , ( { test } ) => {
25
+ test ( 'self extend' , async ( { onTestFinish } ) => {
26
+ const fixture = await createFixture ( {
27
+ 'tsconfig.json' : createTsconfigJson ( {
28
+ extends : './tsconfig.json' ,
29
+ } ) ,
30
+ 'file.ts' : '' ,
31
+ } ) ;
32
+ onTestFinish ( ( ) => fixture . rm ( ) ) ;
33
+
34
+ const errorMessage = 'Circularity detected while resolving configuration' ;
35
+ await expect (
36
+ getTscTsconfig ( fixture . path ) ,
37
+ ) . rejects . toThrow ( errorMessage ) ;
38
+ expect (
39
+ ( ) => parseTsconfig ( path . join ( fixture . path , 'tsconfig.json' ) ) ,
40
+ ) . toThrow ( errorMessage ) ;
41
+
42
+ await fixture . rm ( ) ;
43
+ } ) ;
44
+
45
+ test ( 'recursive' , async ( { onTestFinish } ) => {
46
+ const fixture = await createFixture ( {
47
+ 'base.json' : createTsconfigJson ( {
48
+ extends : './tsconfig.json' ,
49
+ } ) ,
50
+ 'tsconfig.json' : createTsconfigJson ( {
51
+ extends : './base.json' ,
52
+ } ) ,
53
+ } ) ;
54
+ onTestFinish ( ( ) => fixture . rm ( ) ) ;
55
+
56
+ expect (
57
+ ( ) => parseTsconfig ( path . join ( fixture . path , 'tsconfig.json' ) ) ,
58
+ ) . toThrow ( 'Circularity detected while resolving configuration:' ) ;
59
+ } ) ;
60
+ } ) ;
61
+
62
+ test ( 'extends array with common base' , async ( { onTestFinish } ) => {
63
+ const fixture = await createFixture ( {
64
+ 'base.json' : createTsconfigJson ( { } ) ,
65
+ 'tsconfig-b.json' : createTsconfigJson ( {
66
+ extends : './base.json' ,
67
+ } ) ,
68
+ 'tsconfig-a.json' : createTsconfigJson ( {
69
+ extends : './base.json' ,
70
+ } ) ,
71
+ 'tsconfig.json' : createTsconfigJson ( {
72
+ extends : [
73
+ './tsconfig-a.json' ,
74
+ './tsconfig-b.json' ,
75
+ ] ,
76
+ } ) ,
77
+ 'file.ts' : '' ,
78
+ } ) ;
79
+ onTestFinish ( ( ) => fixture . rm ( ) ) ;
80
+
81
+ const expectedTsconfig = await getTscTsconfig ( fixture . path ) ;
82
+ delete expectedTsconfig . files ;
83
+
84
+ const tsconfig = parseTsconfig ( path . join ( fixture . path , 'tsconfig.json' ) ) ;
85
+ expect ( tsconfig ) . toStrictEqual ( expectedTsconfig ) ;
86
+ } ) ;
87
+
24
88
runTestSuite ( import ( './relative-path.spec.js' ) ) ;
25
89
runTestSuite ( import ( './absolute-path.spec.js' ) ) ;
26
90
runTestSuite ( import ( './node-modules.spec.js' ) ) ;
0 commit comments