@abdokouta/react-config 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,21 +1,21 @@
1
1
  /**
2
2
  * @fileoverview Tests for EnvDriver
3
- *
3
+ *
4
4
  * This test suite verifies the EnvDriver functionality including:
5
5
  * - Loading environment variables
6
6
  * - Getting values with dot notation
7
7
  * - Variable expansion
8
8
  * - Default values
9
9
  * - Type conversions
10
- *
10
+ *
11
11
  * @module @abdokouta/config
12
12
  * @category Tests
13
13
  */
14
14
 
15
- import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
16
- import { EnvDriver } from "@/drivers/env.driver";
15
+ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
16
+ import { EnvDriver } from '@/drivers/env.driver';
17
17
 
18
- describe("EnvDriver", () => {
18
+ describe('EnvDriver', () => {
19
19
  const originalEnv = process.env;
20
20
 
21
21
  beforeEach(() => {
@@ -28,12 +28,12 @@ describe("EnvDriver", () => {
28
28
  process.env = originalEnv;
29
29
  });
30
30
 
31
- describe("load", () => {
32
- it("should load environment variables", () => {
31
+ describe('load', () => {
32
+ it('should load environment variables', () => {
33
33
  // Arrange: Set env vars
34
- process.env.APP_NAME = "Test App";
35
- process.env.APP_PORT = "3000";
36
- process.env.APP_DEBUG = "true";
34
+ process.env.APP_NAME = 'Test App';
35
+ process.env.APP_PORT = '3000';
36
+ process.env.APP_DEBUG = 'true';
37
37
 
38
38
  const driver = new EnvDriver();
39
39
 
@@ -42,10 +42,10 @@ describe("EnvDriver", () => {
42
42
 
43
43
  // Assert: Config is loaded
44
44
  expect(config).toBeDefined();
45
- expect(typeof config).toBe("object");
45
+ expect(typeof config).toBe('object');
46
46
  });
47
47
 
48
- it("should handle empty environment", () => {
48
+ it('should handle empty environment', () => {
49
49
  // Arrange: Clear env
50
50
  process.env = {};
51
51
 
@@ -56,29 +56,29 @@ describe("EnvDriver", () => {
56
56
 
57
57
  // Assert: Empty config is returned
58
58
  expect(config).toBeDefined();
59
- expect(typeof config).toBe("object");
59
+ expect(typeof config).toBe('object');
60
60
  });
61
61
  });
62
62
 
63
- describe("get", () => {
63
+ describe('get', () => {
64
64
  beforeEach(() => {
65
65
  // Arrange: Set test env vars
66
- process.env.APP_NAME = "Test App";
67
- process.env.APP_PORT = "3000";
68
- process.env.DATABASE_HOST = "localhost";
69
- process.env.DATABASE_PORT = "5432";
66
+ process.env.APP_NAME = 'Test App';
67
+ process.env.APP_PORT = '3000';
68
+ process.env.DATABASE_HOST = 'localhost';
69
+ process.env.DATABASE_PORT = '5432';
70
70
  });
71
71
 
72
- it("should get environment variable", () => {
72
+ it('should get environment variable', () => {
73
73
  // Arrange: Create driver
74
74
  const driver = new EnvDriver();
75
75
  driver.load();
76
76
 
77
77
  // Act: Get value
78
- const appName = driver.get("APP_NAME");
78
+ const appName = driver.get('APP_NAME');
79
79
 
80
80
  // Assert: Value is returned
81
- expect(appName).toBe("Test App");
81
+ expect(appName).toBe('Test App');
82
82
  });
83
83
 
84
84
  it("should return default value when key doesn't exist", () => {
@@ -87,10 +87,10 @@ describe("EnvDriver", () => {
87
87
  driver.load();
88
88
 
89
89
  // Act: Get with default
90
- const value = driver.get("MISSING_KEY", "default");
90
+ const value = driver.get('MISSING_KEY', 'default');
91
91
 
92
92
  // Assert: Default is returned
93
- expect(value).toBe("default");
93
+ expect(value).toBe('default');
94
94
  });
95
95
 
96
96
  it("should return undefined when key doesn't exist and no default", () => {
@@ -99,78 +99,78 @@ describe("EnvDriver", () => {
99
99
  driver.load();
100
100
 
101
101
  // Act: Get without default
102
- const value = driver.get("MISSING_KEY");
102
+ const value = driver.get('MISSING_KEY');
103
103
 
104
104
  // Assert: Undefined is returned
105
105
  expect(value).toBeUndefined();
106
106
  });
107
107
 
108
- it("should handle numeric string values", () => {
108
+ it('should handle numeric string values', () => {
109
109
  // Arrange: Create driver
110
110
  const driver = new EnvDriver();
111
111
  driver.load();
112
112
 
113
113
  // Act: Get numeric value
114
- const port = driver.get("APP_PORT");
114
+ const port = driver.get('APP_PORT');
115
115
 
116
116
  // Assert: String is returned (no auto-conversion)
117
- expect(port).toBe("3000");
117
+ expect(port).toBe('3000');
118
118
  });
119
119
  });
120
120
 
121
- describe("has", () => {
121
+ describe('has', () => {
122
122
  beforeEach(() => {
123
123
  // Arrange: Set test env vars
124
- process.env.APP_NAME = "Test App";
125
- process.env.EMPTY_VAR = "";
124
+ process.env.APP_NAME = 'Test App';
125
+ process.env.EMPTY_VAR = '';
126
126
  });
127
127
 
128
- it("should return true for existing key", () => {
128
+ it('should return true for existing key', () => {
129
129
  // Arrange: Create driver
130
130
  const driver = new EnvDriver();
131
131
  driver.load();
132
132
 
133
133
  // Act: Check existence
134
- const exists = driver.has("APP_NAME");
134
+ const exists = driver.has('APP_NAME');
135
135
 
136
136
  // Assert: Key exists
137
137
  expect(exists).toBe(true);
138
138
  });
139
139
 
140
- it("should return false for missing key", () => {
140
+ it('should return false for missing key', () => {
141
141
  // Arrange: Create driver
142
142
  const driver = new EnvDriver();
143
143
  driver.load();
144
144
 
145
145
  // Act: Check existence
146
- const exists = driver.has("MISSING_KEY");
146
+ const exists = driver.has('MISSING_KEY');
147
147
 
148
148
  // Assert: Key doesn't exist
149
149
  expect(exists).toBe(false);
150
150
  });
151
151
 
152
- it("should return true for empty string value", () => {
152
+ it('should return true for empty string value', () => {
153
153
  // Arrange: Create driver
154
154
  const driver = new EnvDriver();
155
155
  driver.load();
156
156
 
157
157
  // Act: Check existence
158
- const exists = driver.has("EMPTY_VAR");
158
+ const exists = driver.has('EMPTY_VAR');
159
159
 
160
160
  // Assert: Key exists even with empty value
161
161
  expect(exists).toBe(true);
162
162
  });
163
163
  });
164
164
 
165
- describe("all", () => {
165
+ describe('all', () => {
166
166
  beforeEach(() => {
167
167
  // Arrange: Set test env vars
168
- process.env.APP_NAME = "Test App";
169
- process.env.APP_PORT = "3000";
170
- process.env.DATABASE_HOST = "localhost";
168
+ process.env.APP_NAME = 'Test App';
169
+ process.env.APP_PORT = '3000';
170
+ process.env.DATABASE_HOST = 'localhost';
171
171
  });
172
172
 
173
- it("should return all configuration", () => {
173
+ it('should return all configuration', () => {
174
174
  // Arrange: Create driver
175
175
  const driver = new EnvDriver();
176
176
  driver.load();
@@ -180,10 +180,10 @@ describe("EnvDriver", () => {
180
180
 
181
181
  // Assert: All config is returned
182
182
  expect(config).toBeDefined();
183
- expect(typeof config).toBe("object");
183
+ expect(typeof config).toBe('object');
184
184
  });
185
185
 
186
- it("should include all loaded variables", () => {
186
+ it('should include all loaded variables', () => {
187
187
  // Arrange: Create driver
188
188
  const driver = new EnvDriver();
189
189
  driver.load();
@@ -196,53 +196,53 @@ describe("EnvDriver", () => {
196
196
  });
197
197
  });
198
198
 
199
- describe("Variable Expansion", () => {
200
- it("should expand variables when enabled", () => {
199
+ describe('Variable Expansion', () => {
200
+ it('should expand variables when enabled', () => {
201
201
  // Arrange: Set vars with references
202
- process.env.BASE_URL = "http://localhost";
203
- process.env.API_URL = "${BASE_URL}/api";
202
+ process.env.BASE_URL = 'http://localhost';
203
+ process.env.API_URL = '${BASE_URL}/api';
204
204
 
205
205
  const driver = new EnvDriver({ expandVariables: true });
206
206
  driver.load();
207
207
 
208
208
  // Act: Get expanded value
209
- const apiUrl = driver.get("API_URL");
209
+ const apiUrl = driver.get('API_URL');
210
210
 
211
211
  // Assert: Variable is expanded (if implemented)
212
212
  expect(apiUrl).toBeDefined();
213
213
  });
214
214
  });
215
215
 
216
- describe("Edge Cases", () => {
217
- it("should handle special characters in values", () => {
216
+ describe('Edge Cases', () => {
217
+ it('should handle special characters in values', () => {
218
218
  // Arrange: Set var with special chars
219
- process.env.SPECIAL = "value with spaces & symbols!@#";
219
+ process.env.SPECIAL = 'value with spaces & symbols!@#';
220
220
 
221
221
  const driver = new EnvDriver();
222
222
  driver.load();
223
223
 
224
224
  // Act: Get value
225
- const value = driver.get("SPECIAL");
225
+ const value = driver.get('SPECIAL');
226
226
 
227
227
  // Assert: Special chars are preserved
228
- expect(value).toBe("value with spaces & symbols!@#");
228
+ expect(value).toBe('value with spaces & symbols!@#');
229
229
  });
230
230
 
231
- it("should handle multiline values", () => {
231
+ it('should handle multiline values', () => {
232
232
  // Arrange: Set multiline var
233
- process.env.MULTILINE = "line1\\nline2\\nline3";
233
+ process.env.MULTILINE = 'line1\\nline2\\nline3';
234
234
 
235
235
  const driver = new EnvDriver();
236
236
  driver.load();
237
237
 
238
238
  // Act: Get value
239
- const value = driver.get("MULTILINE");
239
+ const value = driver.get('MULTILINE');
240
240
 
241
241
  // Assert: Multiline is preserved
242
242
  expect(value).toBeDefined();
243
243
  });
244
244
 
245
- it("should handle empty environment", () => {
245
+ it('should handle empty environment', () => {
246
246
  // Arrange: Clear all env vars
247
247
  process.env = {};
248
248
 
@@ -250,10 +250,10 @@ describe("EnvDriver", () => {
250
250
 
251
251
  // Act: Load and get
252
252
  driver.load();
253
- const value = driver.get("ANY_KEY", "default");
253
+ const value = driver.get('ANY_KEY', 'default');
254
254
 
255
255
  // Assert: Default is returned
256
- expect(value).toBe("default");
256
+ expect(value).toBe('default');
257
257
  });
258
258
  });
259
259
  });