1
- /**
2
- * Test EnvironmentVariablesService class
3
- *
4
- * @group unit/commons/environmentService
5
- */
1
+ import { afterAll , beforeEach , describe , expect , it , vi } from 'vitest' ;
6
2
import { EnvironmentVariablesService } from '../../src/index.js' ;
7
3
8
4
describe ( 'Class: EnvironmentVariablesService' , ( ) => {
9
5
const ENVIRONMENT_VARIABLES = process . env ;
10
6
11
7
beforeEach ( ( ) => {
12
- jest . resetModules ( ) ;
8
+ vi . resetModules ( ) ;
13
9
process . env = { ...ENVIRONMENT_VARIABLES } ;
14
10
} ) ;
15
11
@@ -18,7 +14,7 @@ describe('Class: EnvironmentVariablesService', () => {
18
14
} ) ;
19
15
20
16
describe ( 'Method: get' , ( ) => {
21
- test ( 'When the variable IS present, it returns the value of a runtime variable', ( ) => {
17
+ it ( ' returns the value of a runtime variable', ( ) => {
22
18
// Prepare
23
19
process . env . CUSTOM_VARIABLE = 'my custom value' ;
24
20
const service = new EnvironmentVariablesService ( ) ;
@@ -30,7 +26,7 @@ describe('Class: EnvironmentVariablesService', () => {
30
26
expect ( value ) . toEqual ( 'my custom value' ) ;
31
27
} ) ;
32
28
33
- test ( 'When the variable IS NOT present, it returns an empty string ', ( ) => {
29
+ it ( 'returns an empty string when the env variable is not present ', ( ) => {
34
30
// Prepare
35
31
process . env . CUSTOM_VARIABLE = undefined ;
36
32
const service = new EnvironmentVariablesService ( ) ;
@@ -44,7 +40,7 @@ describe('Class: EnvironmentVariablesService', () => {
44
40
} ) ;
45
41
46
42
describe ( 'Method: getServiceName' , ( ) => {
47
- test ( 'It returns the value of the environment variable POWERTOOLS_SERVICE_NAME', ( ) => {
43
+ it ( ' returns the value of the environment variable POWERTOOLS_SERVICE_NAME', ( ) => {
48
44
// Prepare
49
45
process . env . POWERTOOLS_SERVICE_NAME = 'shopping-cart-api' ;
50
46
const service = new EnvironmentVariablesService ( ) ;
@@ -58,7 +54,7 @@ describe('Class: EnvironmentVariablesService', () => {
58
54
} ) ;
59
55
60
56
describe ( 'Method: getXrayTraceId' , ( ) => {
61
- test ( 'It returns the value of the environment variable _X_AMZN_TRACE_ID', ( ) => {
57
+ it ( ' returns the value of the environment variable _X_AMZN_TRACE_ID', ( ) => {
62
58
// Prepare
63
59
process . env . _X_AMZN_TRACE_ID = 'abcd123456789' ;
64
60
const service = new EnvironmentVariablesService ( ) ;
@@ -69,7 +65,7 @@ describe('Class: EnvironmentVariablesService', () => {
69
65
// Assess
70
66
expect ( value ) . toEqual ( 'abcd123456789' ) ;
71
67
} ) ;
72
- test ( 'It returns the value of the Root X-Ray segment ID properly formatted', ( ) => {
68
+ it ( ' returns the value of the Root X-Ray segment ID properly formatted', ( ) => {
73
69
// Prepare
74
70
process . env . _X_AMZN_TRACE_ID =
75
71
'Root=1-5759e988-bd862e3fe1be46a994272793;Parent=557abcec3ee5a047;Sampled=1' ;
@@ -82,7 +78,7 @@ describe('Class: EnvironmentVariablesService', () => {
82
78
expect ( value ) . toEqual ( '1-5759e988-bd862e3fe1be46a994272793' ) ;
83
79
} ) ;
84
80
85
- test ( 'It returns the value of the Root X-Ray segment ID properly formatted', ( ) => {
81
+ it ( ' returns the value of the Root X-Ray segment ID properly formatted', ( ) => {
86
82
// Prepare
87
83
process . env . _X_AMZN_TRACE_ID = undefined ;
88
84
const service = new EnvironmentVariablesService ( ) ;
@@ -96,7 +92,7 @@ describe('Class: EnvironmentVariablesService', () => {
96
92
} ) ;
97
93
98
94
describe ( 'Method: getXrayTraceSampled' , ( ) => {
99
- test ( 'It returns true if the Sampled flag is set in the _X_AMZN_TRACE_ID environment variable', ( ) => {
95
+ it ( ' returns true if the Sampled flag is set in the _X_AMZN_TRACE_ID environment variable', ( ) => {
100
96
// Prepare
101
97
process . env . _X_AMZN_TRACE_ID =
102
98
'Root=1-5759e988-bd862e3fe1be46a994272793;Parent=557abcec3ee5a047;Sampled=1' ;
@@ -109,7 +105,7 @@ describe('Class: EnvironmentVariablesService', () => {
109
105
expect ( value ) . toEqual ( true ) ;
110
106
} ) ;
111
107
112
- test ( 'It returns false if the Sampled flag is not set in the _X_AMZN_TRACE_ID environment variable', ( ) => {
108
+ it ( ' returns false if the Sampled flag is not set in the _X_AMZN_TRACE_ID environment variable', ( ) => {
113
109
// Prepare
114
110
process . env . _X_AMZN_TRACE_ID =
115
111
'Root=1-5759e988-bd862e3fe1be46a994272793;Parent=557abcec3ee5a047' ;
@@ -122,7 +118,7 @@ describe('Class: EnvironmentVariablesService', () => {
122
118
expect ( value ) . toEqual ( false ) ;
123
119
} ) ;
124
120
125
- it ( 'It returns false when no _X_AMZN_TRACE_ID environment variable is present' , ( ) => {
121
+ it ( 'returns false when no _X_AMZN_TRACE_ID environment variable is present' , ( ) => {
126
122
// Prepare
127
123
process . env . _X_AMZN_TRACE_ID = undefined ;
128
124
const service = new EnvironmentVariablesService ( ) ;
@@ -150,8 +146,8 @@ describe('Class: EnvironmentVariablesService', () => {
150
146
[ '0' , false ] ,
151
147
] ;
152
148
153
- test . each ( valuesToTest ) (
154
- 'it takes string "%s" and returns %s' ,
149
+ it . each ( valuesToTest ) (
150
+ 'takes string "%s" and returns %s' ,
155
151
( input , output ) => {
156
152
// Prepare
157
153
const service = new EnvironmentVariablesService ( ) ;
@@ -164,7 +160,7 @@ describe('Class: EnvironmentVariablesService', () => {
164
160
} ) ;
165
161
166
162
describe ( 'Method: isDevMode' , ( ) => {
167
- test ( 'it returns true if the environment variable POWERTOOLS_DEV is "true"', ( ) => {
163
+ it ( ' returns true if the environment variable POWERTOOLS_DEV is "true"', ( ) => {
168
164
// Prepare
169
165
process . env . POWERTOOLS_DEV = 'true' ;
170
166
const service = new EnvironmentVariablesService ( ) ;
@@ -176,7 +172,7 @@ describe('Class: EnvironmentVariablesService', () => {
176
172
expect ( value ) . toEqual ( true ) ;
177
173
} ) ;
178
174
179
- test ( 'it returns false if the environment variable POWERTOOLS_DEV is "false"', ( ) => {
175
+ it ( ' returns false if the environment variable POWERTOOLS_DEV is "false"', ( ) => {
180
176
// Prepare
181
177
process . env . POWERTOOLS_DEV = 'false' ;
182
178
const service = new EnvironmentVariablesService ( ) ;
@@ -188,7 +184,7 @@ describe('Class: EnvironmentVariablesService', () => {
188
184
expect ( value ) . toEqual ( false ) ;
189
185
} ) ;
190
186
191
- test ( 'it returns false if the environment variable POWERTOOLS_DEV is NOT set', ( ) => {
187
+ it ( ' returns false if the environment variable POWERTOOLS_DEV is NOT set', ( ) => {
192
188
// Prepare
193
189
process . env . POWERTOOLS_DEV = 'somethingsilly' ;
194
190
const service = new EnvironmentVariablesService ( ) ;
@@ -200,7 +196,7 @@ describe('Class: EnvironmentVariablesService', () => {
200
196
expect ( value ) . toEqual ( false ) ;
201
197
} ) ;
202
198
203
- test ( 'it returns false if the environment variable POWERTOOLS_DEV is "somethingsilly"', ( ) => {
199
+ it ( ' returns false if the environment variable POWERTOOLS_DEV is "somethingsilly"', ( ) => {
204
200
// Prepare
205
201
process . env . POWERTOOLS_DEV = 'somethingsilly' ;
206
202
const service = new EnvironmentVariablesService ( ) ;
0 commit comments