1
1
import os from "os" ;
2
- import { classNamesToTypeDefinitions , ExportType } from "../../lib/typescript" ;
2
+ import { join } from "path" ;
3
+ import { classNamesToTypeDefinitions } from "../../lib/typescript" ;
3
4
4
5
jest . mock ( "../../lib/prettier/can-resolve" , ( ) => ( {
5
6
canResolvePrettier : ( ) => false ,
6
7
} ) ) ;
8
+ const file = join ( __dirname , "test.d.ts" ) ;
7
9
8
10
describe ( "classNamesToTypeDefinitions (without Prettier)" , ( ) => {
9
11
beforeEach ( ( ) => {
@@ -16,6 +18,7 @@ describe("classNamesToTypeDefinitions (without Prettier)", () => {
16
18
banner : "" ,
17
19
classNames : [ "myClass" , "yourClass" ] ,
18
20
exportType : "named" ,
21
+ file,
19
22
} ) ;
20
23
21
24
expect ( definition ) . toEqual (
@@ -28,6 +31,7 @@ describe("classNamesToTypeDefinitions (without Prettier)", () => {
28
31
banner : "" ,
29
32
classNames : [ ] ,
30
33
exportType : "named" ,
34
+ file,
31
35
} ) ;
32
36
33
37
expect ( definition ) . toBeNull ( ) ;
@@ -38,6 +42,7 @@ describe("classNamesToTypeDefinitions (without Prettier)", () => {
38
42
banner : "" ,
39
43
classNames : [ "myClass" , "if" ] ,
40
44
exportType : "named" ,
45
+ file,
41
46
} ) ;
42
47
43
48
expect ( definition ) . toEqual ( "export declare const myClass: string;\n" ) ;
@@ -51,6 +56,7 @@ describe("classNamesToTypeDefinitions (without Prettier)", () => {
51
56
banner : "" ,
52
57
classNames : [ "myClass" , "invalid-variable" ] ,
53
58
exportType : "named" ,
59
+ file,
54
60
} ) ;
55
61
56
62
expect ( definition ) . toEqual ( "export declare const myClass: string;\n" ) ;
@@ -66,6 +72,7 @@ describe("classNamesToTypeDefinitions (without Prettier)", () => {
66
72
banner : "" ,
67
73
classNames : [ "myClass" , "yourClass" ] ,
68
74
exportType : "default" ,
75
+ file,
69
76
} ) ;
70
77
71
78
expect ( definition ) . toEqual (
@@ -78,6 +85,7 @@ describe("classNamesToTypeDefinitions (without Prettier)", () => {
78
85
banner : "" ,
79
86
classNames : [ ] ,
80
87
exportType : "default" ,
88
+ file,
81
89
} ) ;
82
90
83
91
expect ( definition ) . toBeNull ( ) ;
@@ -89,7 +97,9 @@ describe("classNamesToTypeDefinitions (without Prettier)", () => {
89
97
const definition = await classNamesToTypeDefinitions ( {
90
98
banner : "" ,
91
99
classNames : [ "myClass" ] ,
92
- exportType : "invalid" as ExportType ,
100
+ // @ts -expect-error -- invalid export type
101
+ exportType : "invalid" ,
102
+ file,
93
103
} ) ;
94
104
95
105
expect ( definition ) . toBeNull ( ) ;
@@ -103,6 +113,7 @@ describe("classNamesToTypeDefinitions (without Prettier)", () => {
103
113
classNames : [ "myClass" , "yourClass" ] ,
104
114
exportType : "default" ,
105
115
quoteType : "double" ,
116
+ file,
106
117
} ) ;
107
118
108
119
expect ( definition ) . toEqual (
@@ -116,6 +127,7 @@ describe("classNamesToTypeDefinitions (without Prettier)", () => {
116
127
classNames : [ "myClass" , "yourClass" ] ,
117
128
exportType : "named" ,
118
129
quoteType : "double" ,
130
+ file,
119
131
} ) ;
120
132
121
133
expect ( definition ) . toEqual (
@@ -131,6 +143,7 @@ describe("classNamesToTypeDefinitions (without Prettier)", () => {
131
143
classNames : [ "myClass" , "yourClass" ] ,
132
144
exportType : "default" ,
133
145
exportTypeName : "Classes" ,
146
+ file,
134
147
} ) ;
135
148
136
149
expect ( definition ) . toEqual (
@@ -144,6 +157,7 @@ describe("classNamesToTypeDefinitions (without Prettier)", () => {
144
157
classNames : [ "myClass" , "yourClass" ] ,
145
158
exportType : "default" ,
146
159
exportTypeInterface : "IStyles" ,
160
+ file,
147
161
} ) ;
148
162
149
163
expect ( definition ) . toEqual (
@@ -161,6 +175,7 @@ describe("classNamesToTypeDefinitions (without Prettier)", () => {
161
175
banner,
162
176
classNames : [ "myClass" , "yourClass" ] ,
163
177
exportType : "default" ,
178
+ file,
164
179
} ) ;
165
180
166
181
expect ( firstLine ( definition ! ) ) . toBe ( banner ) ;
@@ -172,6 +187,7 @@ describe("classNamesToTypeDefinitions (without Prettier)", () => {
172
187
banner,
173
188
classNames : [ "myClass" , "yourClass" ] ,
174
189
exportType : "named" ,
190
+ file,
175
191
} ) ;
176
192
177
193
expect ( firstLine ( definition ! ) ) . toBe ( banner ) ;
0 commit comments