Skip to content

Commit a568152

Browse files
committed
chore: add explicit imports
1 parent 76f0678 commit a568152

File tree

8 files changed

+167
-165
lines changed

8 files changed

+167
-165
lines changed

packages/logger/tests/unit/configFromEnv.test.ts

Lines changed: 128 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*
44
* @group unit/logger/config
55
*/
6+
import { beforeEach, describe, expect, it, jest } from '@jest/globals';
67
import { EnvironmentVariablesService } from '../../src/config/EnvironmentVariablesService.js';
78

89
describe('Class: EnvironmentVariablesService', () => {
@@ -13,209 +14,185 @@ describe('Class: EnvironmentVariablesService', () => {
1314
process.env = { ...ENVIRONMENT_VARIABLES };
1415
});
1516

16-
afterAll(() => {
17-
process.env = ENVIRONMENT_VARIABLES;
18-
});
19-
20-
describe('Method: getAwsLogLevel', () => {
21-
it('returns the value of the environment variable AWS_LAMBDA_LOG_LEVEL and aliases it as needed', () => {
22-
// Prepare
23-
process.env.AWS_LAMBDA_LOG_LEVEL = 'FATAL';
24-
const service = new EnvironmentVariablesService();
17+
it('returns the value of the environment variable AWS_LAMBDA_LOG_LEVEL and aliases it as needed', () => {
18+
// Prepare
19+
process.env.AWS_LAMBDA_LOG_LEVEL = 'FATAL';
20+
const service = new EnvironmentVariablesService();
2521

26-
// Act
27-
const value = service.getAwsLogLevel();
22+
// Act
23+
const value = service.getAwsLogLevel();
2824

29-
// Assess
30-
expect(value).toEqual('CRITICAL');
31-
});
25+
// Assess
26+
expect(value).toEqual('CRITICAL');
3227
});
3328

34-
describe('Method: getAwsRegion', () => {
35-
test('it returns the value of the environment variable AWS_REGION', () => {
36-
// Prepare
37-
process.env.AWS_REGION = 'us-east-1';
38-
const service = new EnvironmentVariablesService();
29+
it('returns the value of the environment variable AWS_REGION', () => {
30+
// Prepare
31+
process.env.AWS_REGION = 'us-east-1';
32+
const service = new EnvironmentVariablesService();
3933

40-
// Act
41-
const value = service.getAwsRegion();
34+
// Act
35+
const value = service.getAwsRegion();
4236

43-
// Assess
44-
expect(value).toEqual('us-east-1');
45-
});
37+
// Assess
38+
expect(value).toEqual('us-east-1');
4639
});
4740

48-
describe('Method: getCurrentEnvironment', () => {
49-
test('it returns the value of the environment variable AWS_REGION', () => {
50-
// Prepare
51-
process.env.ENVIRONMENT = 'stage';
52-
const service = new EnvironmentVariablesService();
41+
it('returns the value of the environment variable AWS_REGION', () => {
42+
// Prepare
43+
process.env.ENVIRONMENT = 'stage';
44+
const service = new EnvironmentVariablesService();
5345

54-
// Act
55-
const value = service.getCurrentEnvironment();
46+
// Act
47+
const value = service.getCurrentEnvironment();
5648

57-
// Assess
58-
expect(value).toEqual('stage');
59-
});
49+
// Assess
50+
expect(value).toEqual('stage');
6051
});
6152

62-
describe('Method: getFunctionMemory', () => {
63-
test('it returns the value of the environment variable AWS_LAMBDA_FUNCTION_MEMORY_SIZE', () => {
64-
// Prepare
65-
process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE = '123456';
66-
const service = new EnvironmentVariablesService();
53+
it('returns the value of the environment variable AWS_LAMBDA_FUNCTION_MEMORY_SIZE', () => {
54+
// Prepare
55+
process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE = '123456';
56+
const service = new EnvironmentVariablesService();
6757

68-
// Act
69-
const value = service.getFunctionMemory();
58+
// Act
59+
const value = service.getFunctionMemory();
7060

71-
// Assess
72-
expect(value).toBe(123456);
73-
});
61+
// Assess
62+
expect(value).toBe(123456);
7463
});
7564

76-
describe('Method: getFunctionName', () => {
77-
test('it returns the value of the environment variable AWS_LAMBDA_FUNCTION_NAME', () => {
78-
// Prepare
79-
process.env.AWS_LAMBDA_FUNCTION_NAME = 'my-lambda-function';
80-
const service = new EnvironmentVariablesService();
65+
it('returns the value of the environment variable AWS_LAMBDA_FUNCTION_NAME', () => {
66+
// Prepare
67+
process.env.AWS_LAMBDA_FUNCTION_NAME = 'my-lambda-function';
68+
const service = new EnvironmentVariablesService();
8169

82-
// Act
83-
const value = service.getFunctionName();
70+
// Act
71+
const value = service.getFunctionName();
8472

85-
// Assess
86-
expect(value).toEqual('my-lambda-function');
87-
});
73+
// Assess
74+
expect(value).toEqual('my-lambda-function');
8875
});
8976

90-
describe('Method: getFunctionVersion', () => {
91-
test('it returns the value of the environment variable AWS_LAMBDA_FUNCTION_VERSION', () => {
92-
// Prepare
93-
process.env.AWS_LAMBDA_FUNCTION_VERSION = '1.4.0';
94-
const service = new EnvironmentVariablesService();
77+
it('returns the value of the environment variable AWS_LAMBDA_FUNCTION_VERSION', () => {
78+
// Prepare
79+
process.env.AWS_LAMBDA_FUNCTION_VERSION = '1.4.0';
80+
const service = new EnvironmentVariablesService();
9581

96-
// Act
97-
const value = service.getFunctionVersion();
82+
// Act
83+
const value = service.getFunctionVersion();
9884

99-
// Assess
100-
expect(value).toEqual('1.4.0');
101-
});
85+
// Assess
86+
expect(value).toEqual('1.4.0');
10287
});
10388

104-
describe('Method: getLogEvent', () => {
105-
test('it returns true if the environment variable POWERTOOLS_LOGGER_LOG_EVENT is "true"', () => {
106-
// Prepare
107-
process.env.POWERTOOLS_LOGGER_LOG_EVENT = 'true';
108-
const service = new EnvironmentVariablesService();
89+
it('returns true if the environment variable POWERTOOLS_LOGGER_LOG_EVENT is "true"', () => {
90+
// Prepare
91+
process.env.POWERTOOLS_LOGGER_LOG_EVENT = 'true';
92+
const service = new EnvironmentVariablesService();
10993

110-
// Act
111-
const value = service.getLogEvent();
94+
// Act
95+
const value = service.getLogEvent();
11296

113-
// Assess
114-
expect(value).toEqual(true);
115-
});
97+
// Assess
98+
expect(value).toEqual(true);
99+
});
116100

117-
test('it returns false if the environment variable POWERTOOLS_LOGGER_LOG_EVENT is "false"', () => {
118-
// Prepare
119-
process.env.POWERTOOLS_LOGGER_LOG_EVENT = 'false';
120-
const service = new EnvironmentVariablesService();
101+
it('returns false if the environment variable POWERTOOLS_LOGGER_LOG_EVENT is "false"', () => {
102+
// Prepare
103+
process.env.POWERTOOLS_LOGGER_LOG_EVENT = 'false';
104+
const service = new EnvironmentVariablesService();
121105

122-
// Act
123-
const value = service.getLogEvent();
106+
// Act
107+
const value = service.getLogEvent();
124108

125-
// Assess
126-
expect(value).toEqual(false);
127-
});
109+
// Assess
110+
expect(value).toEqual(false);
111+
});
128112

129-
test('it returns false if the environment variable POWERTOOLS_LOGGER_LOG_EVENT is "somethingsilly"', () => {
130-
// Prepare
131-
process.env.POWERTOOLS_LOGGER_LOG_EVENT = 'somethingsilly';
132-
const service = new EnvironmentVariablesService();
113+
it('returns false if the environment variable POWERTOOLS_LOGGER_LOG_EVENT is "somethingsilly"', () => {
114+
// Prepare
115+
process.env.POWERTOOLS_LOGGER_LOG_EVENT = 'somethingsilly';
116+
const service = new EnvironmentVariablesService();
133117

134-
// Act
135-
const value = service.getLogEvent();
118+
// Act
119+
const value = service.getLogEvent();
136120

137-
// Assess
138-
expect(value).toEqual(false);
139-
});
121+
// Assess
122+
expect(value).toEqual(false);
140123
});
141124

142-
describe('Method: getLogLevel', () => {
143-
test('it returns the value of the environment variable LOG_LEVEL when POWERTOOLS_LOG_LEVEL is not set', () => {
144-
// Prepare
145-
process.env.POWERTOOLS_LOG_LEVEL = undefined;
146-
process.env.LOG_LEVEL = 'ERROR';
147-
const service = new EnvironmentVariablesService();
125+
it('returns the value of the environment variable LOG_LEVEL when POWERTOOLS_LOG_LEVEL is not set', () => {
126+
// Prepare
127+
process.env.POWERTOOLS_LOG_LEVEL = undefined;
128+
process.env.LOG_LEVEL = 'ERROR';
129+
const service = new EnvironmentVariablesService();
148130

149-
// Act
150-
const value = service.getLogLevel();
131+
// Act
132+
const value = service.getLogLevel();
151133

152-
// Assess
153-
expect(value).toEqual('ERROR');
154-
});
134+
// Assess
135+
expect(value).toEqual('ERROR');
136+
});
155137

156-
test('it returns the value of the environment variable POWERTOOLS_LOG_LEVEL when LOG_LEVEL one is also set', () => {
157-
// Prepare
158-
process.env.LOG_LEVEL = 'WARN';
159-
process.env.POWERTOOLS_LOG_LEVEL = 'INFO';
160-
const service = new EnvironmentVariablesService();
138+
it('returns the value of the environment variable POWERTOOLS_LOG_LEVEL when LOG_LEVEL one is also set', () => {
139+
// Prepare
140+
process.env.LOG_LEVEL = 'WARN';
141+
process.env.POWERTOOLS_LOG_LEVEL = 'INFO';
142+
const service = new EnvironmentVariablesService();
161143

162-
// Act
163-
const value = service.getLogLevel();
144+
// Act
145+
const value = service.getLogLevel();
164146

165-
// Assess
166-
expect(value).toEqual('INFO');
167-
});
147+
// Assess
148+
expect(value).toEqual('INFO');
149+
});
168150

169-
test('it returns an empty value if neither POWERTOOLS_LOG_LEVEL nor LOG_LEVEL are set', () => {
170-
// Prepare
171-
process.env.LOG_LEVEL = undefined;
172-
process.env.POWERTOOLS_LOG_LEVEL = undefined;
173-
const service = new EnvironmentVariablesService();
151+
it('returns an empty value if neither POWERTOOLS_LOG_LEVEL nor LOG_LEVEL are set', () => {
152+
// Prepare
153+
process.env.LOG_LEVEL = undefined;
154+
process.env.POWERTOOLS_LOG_LEVEL = undefined;
155+
const service = new EnvironmentVariablesService();
174156

175-
// Act
176-
const value = service.getLogLevel();
157+
// Act
158+
const value = service.getLogLevel();
177159

178-
// Assess
179-
expect(value).toEqual('');
180-
});
160+
// Assess
161+
expect(value).toEqual('');
181162
});
182163

183-
describe('Method: getSampleRateValue', () => {
184-
test('it returns the value of the environment variable POWERTOOLS_LOGGER_SAMPLE_RATE', () => {
185-
// Prepare
186-
process.env.POWERTOOLS_LOGGER_SAMPLE_RATE = '0.01';
187-
const service = new EnvironmentVariablesService();
164+
it('returns the value of the environment variable POWERTOOLS_LOGGER_SAMPLE_RATE', () => {
165+
// Prepare
166+
process.env.POWERTOOLS_LOGGER_SAMPLE_RATE = '0.01';
167+
const service = new EnvironmentVariablesService();
188168

189-
// Act
190-
const value = service.getSampleRateValue();
169+
// Act
170+
const value = service.getSampleRateValue();
191171

192-
// Assess
193-
expect(value).toEqual(0.01);
194-
});
172+
// Assess
173+
expect(value).toEqual(0.01);
195174
});
196175

197-
describe('Method: getTimezone', () => {
198-
it('returns the value of the TZ environment variable when set', () => {
199-
// Prepare
200-
process.env.TZ = 'Europe/London';
201-
const service = new EnvironmentVariablesService();
176+
it('returns the value of the TZ environment variable when set', () => {
177+
// Prepare
178+
process.env.TZ = 'Europe/London';
179+
const service = new EnvironmentVariablesService();
202180

203-
// Act
204-
const value = service.getTimezone();
181+
// Act
182+
const value = service.getTimezone();
205183

206-
// Assess
207-
expect(value).toEqual('Europe/London');
208-
});
184+
// Assess
185+
expect(value).toEqual('Europe/London');
186+
});
209187

210-
it('returns the default UTC value when no TZ is set', () => {
211-
// Prepare
212-
const service = new EnvironmentVariablesService();
188+
it('returns the default UTC value when no TZ is set', () => {
189+
// Prepare
190+
const service = new EnvironmentVariablesService();
213191

214-
// Act
215-
const value = service.getTimezone();
192+
// Act
193+
const value = service.getTimezone();
216194

217-
// Assess
218-
expect(value).toEqual('UTC');
219-
});
195+
// Assess
196+
expect(value).toEqual('UTC');
220197
});
221198
});

packages/logger/tests/unit/formatters.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
import { AssertionError } from 'node:assert';
12
/**
23
* Test Logger formatter
34
*
45
* @group unit/logger/logFormatter
56
*/
6-
import { AssertionError } from 'node:assert';
7+
import {
8+
afterAll,
9+
beforeEach,
10+
describe,
11+
expect,
12+
it,
13+
jest,
14+
} from '@jest/globals';
715
import { EnvironmentVariablesService } from '../../src/config/EnvironmentVariablesService.js';
816
import { PowertoolsLogFormatter } from '../../src/formatter/PowertoolsLogFormatter.js';
917
import {

packages/logger/tests/unit/initializeLogger.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*
44
* @group unit/logger/logger/logLevels
55
*/
6+
import { beforeEach, describe, expect, it, jest } from '@jest/globals';
67
import { Logger } from '../../src/Logger.js';
78
import { LogJsonIndent, LogLevel } from '../../src/constants.js';
89

packages/logger/tests/unit/injectLambdaContext.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import context from '@aws-lambda-powertools/testing-utils/context';
12
/**
23
* Logger injectLambdaContext tests
34
*
45
* @group unit/logger/logger/injectLambdaContext
56
*/
6-
import context from '@aws-lambda-powertools/testing-utils/context';
7+
import { beforeEach, describe, expect, it, jest } from '@jest/globals';
78
import middy from '@middy/core';
89
import type { Context } from 'aws-lambda';
910
import { Logger } from '../../src/Logger.js';

packages/logger/tests/unit/logEvent.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import context from '@aws-lambda-powertools/testing-utils/context';
12
/**
23
* Logger log event tests
34
*
45
* @group unit/logger/logger/logEvent
56
*/
6-
import context from '@aws-lambda-powertools/testing-utils/context';
7+
import { beforeEach, describe, expect, it, jest } from '@jest/globals';
78
import middy from '@middy/core';
89
import type { Context } from 'aws-lambda';
910
import { Logger } from '../../src/Logger.js';

0 commit comments

Comments
 (0)