1
- import { beforeEach , deepClone , describe , expect , test , vi } from 'vitest'
1
+ import { beforeEach , describe , expect , test , vi } from 'vitest'
2
2
3
3
import { svelteTesting } from '../vite.js'
4
4
import { IS_JEST } from './utils.js'
@@ -15,41 +15,41 @@ describe.skipIf(IS_JEST)('vite plugin', () => {
15
15
noExternal : false ,
16
16
} )
17
17
18
- const config = { }
19
- subject . config ( config )
18
+ const result = { }
19
+ subject . config ( result )
20
20
21
- expect ( config ) . toEqual ( { } )
21
+ expect ( result ) . toEqual ( { } )
22
22
} )
23
23
24
24
test ( 'does not modify config if not Vitest' , ( ) => {
25
25
vi . stubEnv ( 'VITEST' , '' )
26
26
27
27
const subject = svelteTesting ( )
28
- const config = { }
29
28
30
- subject . config ( config )
29
+ const result = { }
30
+ subject . config ( result )
31
31
32
- expect ( config ) . toEqual ( { } )
32
+ expect ( result ) . toEqual ( { } )
33
33
} )
34
34
35
35
test . each ( [
36
36
{
37
- config : { resolve : { conditions : [ 'node' ] } } ,
37
+ config : ( ) => ( { resolve : { conditions : [ 'node' ] } } ) ,
38
38
expectedConditions : [ 'browser' , 'node' ] ,
39
39
} ,
40
40
{
41
- config : { resolve : { conditions : [ 'svelte' , 'node' ] } } ,
41
+ config : ( ) => ( { resolve : { conditions : [ 'svelte' , 'node' ] } } ) ,
42
42
expectedConditions : [ 'svelte' , 'browser' , 'node' ] ,
43
43
} ,
44
44
] ) (
45
45
'adds browser condition if necessary' ,
46
46
( { config, expectedConditions } ) => {
47
47
const subject = svelteTesting ( )
48
- const viteConfig = deepClone ( config )
49
48
50
- subject . config ( viteConfig )
49
+ const result = config ( )
50
+ subject . config ( result )
51
51
52
- expect ( viteConfig ) . toMatchObject ( {
52
+ expect ( result ) . toMatchObject ( {
53
53
resolve : {
54
54
conditions : expectedConditions ,
55
55
} ,
@@ -59,26 +59,26 @@ describe.skipIf(IS_JEST)('vite plugin', () => {
59
59
60
60
test . each ( [
61
61
{
62
- config : { } ,
62
+ config : ( ) => ( { } ) ,
63
63
expectedConditions : [ ] ,
64
64
} ,
65
65
{
66
- config : { resolve : { conditions : [ ] } } ,
66
+ config : ( ) => ( { resolve : { conditions : [ ] } } ) ,
67
67
expectedConditions : [ ] ,
68
68
} ,
69
69
{
70
- config : { resolve : { conditions : [ 'svelte' ] } } ,
70
+ config : ( ) => ( { resolve : { conditions : [ 'svelte' ] } } ) ,
71
71
expectedConditions : [ 'svelte' ] ,
72
72
} ,
73
73
] ) (
74
74
'skips browser condition if possible' ,
75
75
( { config, expectedConditions } ) => {
76
76
const subject = svelteTesting ( )
77
- const viteConfig = deepClone ( config )
78
77
79
- subject . config ( viteConfig )
78
+ const result = config ( )
79
+ subject . config ( result )
80
80
81
- expect ( viteConfig ) . toMatchObject ( {
81
+ expect ( result ) . toMatchObject ( {
82
82
resolve : {
83
83
conditions : expectedConditions ,
84
84
} ,
@@ -88,27 +88,27 @@ describe.skipIf(IS_JEST)('vite plugin', () => {
88
88
89
89
test . each ( [
90
90
{
91
- config : { } ,
91
+ config : ( ) => ( { } ) ,
92
92
expectedSetupFiles : [ expect . stringMatching ( / s r c \/ v i t e s t .j s $ / u) ] ,
93
93
} ,
94
94
{
95
- config : { test : { setupFiles : [ ] } } ,
95
+ config : ( ) => ( { test : { setupFiles : [ ] } } ) ,
96
96
expectedSetupFiles : [ expect . stringMatching ( / s r c \/ v i t e s t .j s $ / u) ] ,
97
97
} ,
98
98
{
99
- config : { test : { setupFiles : 'other-file.js' } } ,
99
+ config : ( ) => ( { test : { setupFiles : 'other-file.js' } } ) ,
100
100
expectedSetupFiles : [
101
101
'other-file.js' ,
102
102
expect . stringMatching ( / s r c \/ v i t e s t .j s $ / u) ,
103
103
] ,
104
104
} ,
105
105
] ) ( 'adds cleanup' , ( { config, expectedSetupFiles } ) => {
106
106
const subject = svelteTesting ( )
107
- const viteConfig = deepClone ( config )
108
107
109
- subject . config ( viteConfig )
108
+ const result = config ( )
109
+ subject . config ( result )
110
110
111
- expect ( viteConfig ) . toMatchObject ( {
111
+ expect ( result ) . toMatchObject ( {
112
112
test : {
113
113
setupFiles : expectedSetupFiles ,
114
114
} ,
@@ -117,28 +117,28 @@ describe.skipIf(IS_JEST)('vite plugin', () => {
117
117
118
118
test . each ( [
119
119
{
120
- config : { ssr : { noExternal : [ ] } } ,
120
+ config : ( ) => ( { ssr : { noExternal : [ ] } } ) ,
121
121
expectedNoExternal : [ '@testing-library/svelte' ] ,
122
122
} ,
123
123
{
124
- config : { } ,
124
+ config : ( ) => ( { } ) ,
125
125
expectedNoExternal : [ '@testing-library/svelte' ] ,
126
126
} ,
127
127
{
128
- config : { ssr : { noExternal : 'other-file.js' } } ,
128
+ config : ( ) => ( { ssr : { noExternal : 'other-file.js' } } ) ,
129
129
expectedNoExternal : [ 'other-file.js' , '@testing-library/svelte' ] ,
130
130
} ,
131
131
{
132
- config : { ssr : { noExternal : / o t h e r / u } } ,
132
+ config : ( ) => ( { ssr : { noExternal : / o t h e r / u } } ) ,
133
133
expectedNoExternal : [ / o t h e r / u, '@testing-library/svelte' ] ,
134
134
} ,
135
135
] ) ( 'adds noExternal rule' , ( { config, expectedNoExternal } ) => {
136
136
const subject = svelteTesting ( )
137
- const viteConfig = deepClone ( config )
138
137
139
- subject . config ( viteConfig )
138
+ const result = config ( )
139
+ subject . config ( result )
140
140
141
- expect ( viteConfig ) . toMatchObject ( {
141
+ expect ( result ) . toMatchObject ( {
142
142
ssr : {
143
143
noExternal : expectedNoExternal ,
144
144
} ,
@@ -147,24 +147,24 @@ describe.skipIf(IS_JEST)('vite plugin', () => {
147
147
148
148
test . each ( [
149
149
{
150
- config : { ssr : { noExternal : true } } ,
150
+ config : ( ) => ( { ssr : { noExternal : true } } ) ,
151
151
expectedNoExternal : true ,
152
152
} ,
153
153
{
154
- config : { ssr : { noExternal : '@testing-library/svelte' } } ,
154
+ config : ( ) => ( { ssr : { noExternal : '@testing-library/svelte' } } ) ,
155
155
expectedNoExternal : '@testing-library/svelte' ,
156
156
} ,
157
157
{
158
- config : { ssr : { noExternal : / s v e l t e / u } } ,
158
+ config : ( ) => ( { ssr : { noExternal : / s v e l t e / u } } ) ,
159
159
expectedNoExternal : / s v e l t e / u,
160
160
} ,
161
161
] ) ( 'skips noExternal if able' , ( { config, expectedNoExternal } ) => {
162
162
const subject = svelteTesting ( )
163
- const viteConfig = deepClone ( config )
164
163
165
- subject . config ( viteConfig )
164
+ const result = config ( )
165
+ subject . config ( result )
166
166
167
- expect ( viteConfig ) . toMatchObject ( {
167
+ expect ( result ) . toMatchObject ( {
168
168
ssr : {
169
169
noExternal : expectedNoExternal ,
170
170
} ,
@@ -173,11 +173,11 @@ describe.skipIf(IS_JEST)('vite plugin', () => {
173
173
174
174
test ( 'bails on noExternal if input is unexpected' , ( ) => {
175
175
const subject = svelteTesting ( )
176
- const viteConfig = deepClone ( { ssr : { noExternal : false } } )
177
176
178
- subject . config ( viteConfig )
177
+ const result = { ssr : { noExternal : false } }
178
+ subject . config ( result )
179
179
180
- expect ( viteConfig ) . toMatchObject ( {
180
+ expect ( result ) . toMatchObject ( {
181
181
ssr : {
182
182
noExternal : false ,
183
183
} ,
0 commit comments