@@ -5,7 +5,11 @@ import type { Span } from '@opentelemetry/api'
5
5
import { afterEach , beforeEach , describe , expect , it , MockInstance , vi } from 'vitest'
6
6
7
7
import type { PluginContext } from './plugin-context.js'
8
- import { setSkewProtection , shouldEnableSkewProtection } from './skew-protection.js'
8
+ import {
9
+ EnabledOrDisabledReason ,
10
+ setSkewProtection ,
11
+ shouldEnableSkewProtection ,
12
+ } from './skew-protection.js'
9
13
10
14
// Mock fs promises
11
15
vi . mock ( 'node:fs/promises' , ( ) => ( {
@@ -52,7 +56,7 @@ describe('shouldEnableSkewProtection', () => {
52
56
53
57
expect ( result ) . toEqual ( {
54
58
enabled : false ,
55
- enabledOrDisabledReason : 'off-default' ,
59
+ enabledOrDisabledReason : EnabledOrDisabledReason . OPT_OUT_DEFAULT ,
56
60
} )
57
61
} )
58
62
} )
@@ -65,7 +69,7 @@ describe('shouldEnableSkewProtection', () => {
65
69
66
70
expect ( result ) . toEqual ( {
67
71
enabled : true ,
68
- enabledOrDisabledReason : 'on-env-var' ,
72
+ enabledOrDisabledReason : EnabledOrDisabledReason . OPT_IN_ENV_VAR ,
69
73
} )
70
74
} )
71
75
@@ -76,7 +80,7 @@ describe('shouldEnableSkewProtection', () => {
76
80
77
81
expect ( result ) . toEqual ( {
78
82
enabled : true ,
79
- enabledOrDisabledReason : 'on-env-var' ,
83
+ enabledOrDisabledReason : EnabledOrDisabledReason . OPT_IN_ENV_VAR ,
80
84
} )
81
85
} )
82
86
} )
@@ -89,7 +93,7 @@ describe('shouldEnableSkewProtection', () => {
89
93
90
94
expect ( result ) . toEqual ( {
91
95
enabled : false ,
92
- enabledOrDisabledReason : 'off-env-var' ,
96
+ enabledOrDisabledReason : EnabledOrDisabledReason . OPT_OUT_ENV_VAR ,
93
97
} )
94
98
} )
95
99
@@ -100,7 +104,7 @@ describe('shouldEnableSkewProtection', () => {
100
104
101
105
expect ( result ) . toEqual ( {
102
106
enabled : false ,
103
- enabledOrDisabledReason : 'off-env-var' ,
107
+ enabledOrDisabledReason : EnabledOrDisabledReason . OPT_OUT_ENV_VAR ,
104
108
} )
105
109
} )
106
110
} )
@@ -113,7 +117,7 @@ describe('shouldEnableSkewProtection', () => {
113
117
114
118
expect ( result ) . toEqual ( {
115
119
enabled : true ,
116
- enabledOrDisabledReason : 'on-ff' ,
120
+ enabledOrDisabledReason : EnabledOrDisabledReason . OPT_IN_FF ,
117
121
} )
118
122
} )
119
123
@@ -124,7 +128,7 @@ describe('shouldEnableSkewProtection', () => {
124
128
125
129
expect ( result ) . toEqual ( {
126
130
enabled : false ,
127
- enabledOrDisabledReason : 'off-default' ,
131
+ enabledOrDisabledReason : EnabledOrDisabledReason . OPT_OUT_DEFAULT ,
128
132
} )
129
133
} )
130
134
} )
@@ -138,7 +142,7 @@ describe('shouldEnableSkewProtection', () => {
138
142
139
143
expect ( result ) . toEqual ( {
140
144
enabled : false ,
141
- enabledOrDisabledReason : 'off-no-valid-deploy-id' ,
145
+ enabledOrDisabledReason : EnabledOrDisabledReason . OPT_OUT_NO_VALID_DEPLOY_ID ,
142
146
} )
143
147
} )
144
148
@@ -150,7 +154,7 @@ describe('shouldEnableSkewProtection', () => {
150
154
151
155
expect ( result ) . toEqual ( {
152
156
enabled : false ,
153
- enabledOrDisabledReason : 'off-no-valid-deploy-id' ,
157
+ enabledOrDisabledReason : EnabledOrDisabledReason . OPT_OUT_NO_VALID_DEPLOY_ID ,
154
158
} )
155
159
} )
156
160
@@ -163,7 +167,7 @@ describe('shouldEnableSkewProtection', () => {
163
167
164
168
expect ( result ) . toEqual ( {
165
169
enabled : false ,
166
- enabledOrDisabledReason : 'off-no-valid-deploy-id-env-var' ,
170
+ enabledOrDisabledReason : EnabledOrDisabledReason . OPT_OUT_NO_VALID_DEPLOY_ID_ENV_VAR ,
167
171
} )
168
172
} )
169
173
} )
@@ -177,7 +181,7 @@ describe('shouldEnableSkewProtection', () => {
177
181
178
182
expect ( result ) . toEqual ( {
179
183
enabled : false ,
180
- enabledOrDisabledReason : 'off-env-var' ,
184
+ enabledOrDisabledReason : EnabledOrDisabledReason . OPT_OUT_ENV_VAR ,
181
185
} )
182
186
} )
183
187
@@ -189,7 +193,7 @@ describe('shouldEnableSkewProtection', () => {
189
193
190
194
expect ( result ) . toEqual ( {
191
195
enabled : true ,
192
- enabledOrDisabledReason : 'on-env-var' ,
196
+ enabledOrDisabledReason : EnabledOrDisabledReason . OPT_IN_ENV_VAR ,
193
197
} )
194
198
} )
195
199
} )
@@ -248,7 +252,10 @@ describe('setSkewProtection', () => {
248
252
it ( 'should set span attribute and return early when disabled' , async ( ) => {
249
253
await setSkewProtection ( mockCtx , mockSpan )
250
254
251
- expect ( mockSpan . setAttribute ) . toHaveBeenCalledWith ( 'skewProtection' , 'off-default' )
255
+ expect ( mockSpan . setAttribute ) . toHaveBeenCalledWith (
256
+ 'skewProtection' ,
257
+ EnabledOrDisabledReason . OPT_OUT_DEFAULT ,
258
+ )
252
259
expect ( mkdir ) . not . toHaveBeenCalled ( )
253
260
expect ( writeFile ) . not . toHaveBeenCalled ( )
254
261
expect ( consoleSpy . log ) . not . toHaveBeenCalled ( )
@@ -264,7 +271,7 @@ describe('setSkewProtection', () => {
264
271
265
272
expect ( mockSpan . setAttribute ) . toHaveBeenCalledWith (
266
273
'skewProtection' ,
267
- 'off-no-valid-deploy-id-env-var' ,
274
+ EnabledOrDisabledReason . OPT_OUT_NO_VALID_DEPLOY_ID_ENV_VAR ,
268
275
)
269
276
expect ( consoleSpy . warn ) . toHaveBeenCalledWith (
270
277
'NETLIFY_NEXT_SKEW_PROTECTION environment variable is set to true, but skew protection is currently unavailable for CLI deploys. Skew protection will not be enabled.' ,
@@ -280,7 +287,10 @@ describe('setSkewProtection', () => {
280
287
281
288
await setSkewProtection ( mockCtx , mockSpan )
282
289
283
- expect ( mockSpan . setAttribute ) . toHaveBeenCalledWith ( 'skewProtection' , 'on-env-var' )
290
+ expect ( mockSpan . setAttribute ) . toHaveBeenCalledWith (
291
+ 'skewProtection' ,
292
+ EnabledOrDisabledReason . OPT_IN_ENV_VAR ,
293
+ )
284
294
expect ( consoleSpy . log ) . toHaveBeenCalledWith (
285
295
'Setting up Next.js Skew Protection due to NETLIFY_NEXT_SKEW_PROTECTION=true environment variable.' ,
286
296
)
@@ -319,7 +329,10 @@ describe('setSkewProtection', () => {
319
329
320
330
await setSkewProtection ( mockCtx , mockSpan )
321
331
322
- expect ( mockSpan . setAttribute ) . toHaveBeenCalledWith ( 'skewProtection' , 'on-ff' )
332
+ expect ( mockSpan . setAttribute ) . toHaveBeenCalledWith (
333
+ 'skewProtection' ,
334
+ EnabledOrDisabledReason . OPT_IN_FF ,
335
+ )
323
336
expect ( consoleSpy . log ) . toHaveBeenCalledWith ( 'Setting up Next.js Skew Protection.' )
324
337
expect ( process . env . NEXT_DEPLOYMENT_ID ) . toBe ( 'test-deploy-id' )
325
338
expect ( mkdir ) . toHaveBeenCalledWith ( '/test/path' , { recursive : true } )
0 commit comments