Skip to content

Commit bdd9419

Browse files
committed
Test fixes
1 parent bf3124e commit bdd9419

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

test/unit-tests/api.utils.log.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@ describe('Log utility tests', function() {
99
});
1010

1111
afterEach(function() {
12-
// Clean up test environment variables
12+
// Clear all environment variables and restore original
1313
Object.keys(process.env).forEach(function(key) {
14-
if (key.startsWith('COUNTLY_SETTINGS__LOGS__')) {
15-
delete process.env[key];
16-
}
14+
delete process.env[key];
1715
});
16+
Object.assign(process.env, originalEnv);
1817

1918
// Clear require cache for log module and config to get fresh instances
2019
delete require.cache[require.resolve('../../api/utils/log.js')];
2120
delete require.cache[require.resolve('../../api/config.js')];
2221
});
2322

2423
after(function() {
25-
// Restore original environment
26-
process.env = originalEnv;
24+
// Final cleanup - restore original environment
25+
Object.keys(process.env).forEach(function(key) {
26+
delete process.env[key];
27+
});
28+
Object.assign(process.env, originalEnv);
2729
});
2830

2931
describe('Default log levels', function() {

test/unit-tests/plugins.pluginManager.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,24 @@ describe('PluginManager setConfigs with environment variables', function() {
1010
});
1111

1212
beforeEach(function() {
13-
// Clear any test environment variables
13+
// Clear all test environment variables to prevent pollution between tests
1414
for (var key in process.env) {
15-
if (key.startsWith('COUNTLY_SETTINGS__TEST')) {
15+
if (key.startsWith('COUNTLY_SETTINGS__')) {
1616
delete process.env[key];
1717
}
1818
}
1919

20+
// Clear require cache to get fresh pluginManager instance with no state
21+
delete require.cache[require.resolve('../../plugins/pluginManager.js')];
22+
2023
// Get pluginManager singleton instance
2124
pluginManager = require('../../plugins/pluginManager.js');
2225
});
2326

2427
after(function() {
2528
// Restore original environment
2629
Object.keys(process.env).forEach(function(key) {
27-
if (key.startsWith('COUNTLY_SETTINGS__')) {
28-
delete process.env[key];
29-
}
30+
delete process.env[key];
3031
});
3132
Object.assign(process.env, originalEnv);
3233
});

0 commit comments

Comments
 (0)