Skip to content

Commit fc7dc03

Browse files
committed
add environment detection tests and fix cache issue
1 parent b61134a commit fc7dc03

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/environment/EnvironmentDetector.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,17 @@ const discoverEnvironment = async (): Promise<IEnvironment> => {
6464
}
6565

6666
const _resolveEnvironment: EnvironmentProvider = async (): Promise<IEnvironment> => {
67-
console.log('resolvingenvion')
6867
if (environment) {
6968
return environment;
7069
}
7170

72-
let detectedEnvironment = undefined;
7371
if (config.environmentOverride) {
74-
detectedEnvironment = getEnvironmentFromOverride();
72+
LOG("Environment override supplied", config.environmentOverride);
73+
environment = getEnvironmentFromOverride();
74+
return environment;
7575
}
7676

77-
detectedEnvironment = await discoverEnvironment();
78-
environment = detectedEnvironment; // eslint-disable-line require-atomic-updates
77+
environment = await discoverEnvironment(); // eslint-disable-line require-atomic-updates
7978
return environment;
8079
};
8180

src/environment/__tests__/EnvironmentDetector.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as faker from 'faker';
22
import { cleanResolveEnvironment } from '../EnvironmentDetector';
3+
import config from '../../config/Configuration';
4+
import Environments from '../Environments';
35

46
beforeEach(() => {
57
process.env = {};
@@ -24,3 +26,14 @@ test('resolveEnvironment() returns DefaultEnvironment if nothing else was detect
2426
// assert
2527
expect(result.constructor.name).toBe('DefaultEnvironment');
2628
}, 10000);
29+
30+
test('resolveEnvironment() honors configured override', async () => {
31+
// arrange
32+
config.environmentOverride = Environments.Local;
33+
34+
// act
35+
const result = await cleanResolveEnvironment();
36+
37+
// assert
38+
expect(result.constructor.name).toBe('LocalEnvironment');
39+
});

0 commit comments

Comments
 (0)