@@ -2,7 +2,7 @@ import { expect, it, describe } from "vitest";
2
2
import { generateCode , parseCode } from "../src" ;
3
3
import { generate } from "./_utils" ;
4
4
5
- describe ( "magicast " , ( ) => {
5
+ describe ( "general " , ( ) => {
6
6
it ( "basic object and array" , ( ) => {
7
7
const mod = parseCode ( `export default { a: 1, b: { c: {} } }` ) ;
8
8
@@ -107,42 +107,6 @@ describe("magicast", () => {
107
107
) ;
108
108
} ) ;
109
109
110
- it ( "function wrapper" , ( ) => {
111
- const mod = parseCode ( `
112
- export const a: any = { foo: 1}
113
- export default defineConfig({
114
- // Modules
115
- modules: ["a"]
116
- })
117
- ` ) ;
118
-
119
- expect ( mod . exports . a . foo ) . toBe ( 1 ) ;
120
- expect ( mod . exports . default . $type ) . toBe ( "function-call" ) ;
121
- expect ( mod . exports . default . $callee ) . toBe ( "defineConfig" ) ;
122
- expect ( mod . exports . default . $args ) . toMatchInlineSnapshot ( `
123
- [
124
- {
125
- "modules": [
126
- "a",
127
- ],
128
- },
129
- ]
130
- ` ) ;
131
-
132
- const options = mod . exports . default . $args [ 0 ] ;
133
-
134
- options . modules ||= [ ] ;
135
- options . modules . push ( "b" ) ;
136
-
137
- expect ( generate ( mod ) ) . toMatchInlineSnapshot ( `
138
- "export const a: any = { foo: 1 };
139
- export default defineConfig({
140
- // Modules
141
- modules: [\\"a\\", \\"b\\"],
142
- });"
143
- ` ) ;
144
- } ) ;
145
-
146
110
it ( "delete property" , ( ) => {
147
111
const mod = parseCode ( `export default { a: 1, b: [1, { foo: 'bar' }] }` ) ;
148
112
@@ -165,43 +129,6 @@ describe("magicast", () => {
165
129
` ) ;
166
130
} ) ;
167
131
168
- it ( "array operations" , ( ) => {
169
- const mod = parseCode ( `export default [1, 2, 3, 4, 5]` ) ;
170
-
171
- expect ( mod . exports . default . length ) . toBe ( 5 ) ;
172
- expect ( mod . exports . default . includes ( 5 ) ) . toBe ( true ) ;
173
- expect ( mod . exports . default . includes ( 6 ) ) . toBe ( false ) ;
174
-
175
- const deleted = mod . exports . default . splice ( 1 , 3 , { foo : "bar" } , "bar" ) ;
176
-
177
- expect ( deleted ) . toEqual ( [ 2 , 3 , 4 ] ) ;
178
-
179
- expect ( generate ( mod ) ) . toMatchInlineSnapshot (
180
- `
181
- "export default [
182
- 1,
183
- {
184
- foo: \\"bar\\",
185
- },
186
- \\"bar\\",
187
- 5,
188
- ];"
189
- `
190
- ) ;
191
-
192
- const foundIndex = mod . exports . default . findIndex (
193
- ( item ) => item . foo === "bar"
194
- ) ;
195
- const found = mod . exports . default . find ( ( item ) => item . foo === "bar" ) ;
196
-
197
- expect ( foundIndex ) . toBe ( 1 ) ;
198
- expect ( found ) . toMatchInlineSnapshot ( `
199
- {
200
- "foo": "bar",
201
- }
202
- ` ) ;
203
- } ) ;
204
-
205
132
it ( "should preserve code styles" , ( ) => {
206
133
const mod = parseCode ( `
207
134
export const config = {
@@ -215,66 +142,4 @@ describe("magicast", () => {
215
142
}"
216
143
` ) ;
217
144
} ) ;
218
-
219
- it ( "array should be iterable" , ( ) => {
220
- const mod = parseCode ( `
221
- export const config = {
222
- array: ['a']
223
- }
224
- ` ) ;
225
- const arr = [ ...mod . exports . config . array ] ;
226
- expect ( arr ) . toMatchInlineSnapshot ( `
227
- [
228
- "a",
229
- ]
230
- ` ) ;
231
- } ) ;
232
-
233
- it ( "object property" , ( ) => {
234
- const mod = parseCode (
235
- `
236
- export default {
237
- foo: {
238
- ['a']: 1,
239
- ['a-b']: 2,
240
- foo() {}
241
- }
242
- }
243
- ` . trim ( )
244
- ) ;
245
-
246
- expect ( mod . exports . default . foo . a ) . toBe ( 1 ) ;
247
- expect ( mod . exports . default . foo [ "a-b" ] ) . toBe ( 2 ) ;
248
- expect ( Object . keys ( mod . exports . default . foo ) ) . toMatchInlineSnapshot ( `
249
- [
250
- "a",
251
- "a-b",
252
- "foo",
253
- ]
254
- ` ) ;
255
-
256
- mod . exports . default . foo [ "a-b-c" ] = 3 ;
257
-
258
- expect ( Object . keys ( mod . exports . default . foo ) ) . toMatchInlineSnapshot ( `
259
- [
260
- "a",
261
- "a-b",
262
- "foo",
263
- "a-b-c",
264
- ]
265
- ` ) ;
266
-
267
- mod . exports . default . foo [ "a-b" ] = "updated" ;
268
-
269
- expect ( generate ( mod ) ) . toMatchInlineSnapshot ( `
270
- "export default {
271
- foo: {
272
- [\\"a\\"]: 1,
273
- [\\"a-b\\"]: \\"updated\\",
274
- foo() {},
275
- \\"a-b-c\\": 3,
276
- },
277
- };"
278
- ` ) ;
279
- } ) ;
280
145
} ) ;
0 commit comments