Skip to content

Commit

Permalink
test(logger): add env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgevrgs committed Sep 24, 2024
1 parent b9b455e commit 1dda2ff
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/integration/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ describe('fastifyAwsPowertool logger integration', () => {
let plugin: FastifyPluginAsync;

beforeEach(async () => {
vi.stubEnv(
'_X_AMZN_TRACE_ID',
'Root=1-5759e988-bd862e3fe1be46a994272793;Parent=557abcec3ee5a047;Sampled=1',
);
vi.stubEnv('AWS_LAMBDA_FUNCTION_NAME', 'my-lambda-function');
vi.stubEnv('AWS_LAMBDA_FUNCTION_MEMORY_SIZE', '128');
vi.stubEnv('AWS_LAMBDA_FUNCTION_VERSION', '$LATEST');
vi.stubEnv('POWERTOOLS_LOG_LEVEL', 'DEBUG');
vi.stubEnv('POWERTOOLS_SERVICE_NAME', 'hello-world');

vi.mock('node:console', () => ({
...vi.importActual('node:console'),
Console: vi.fn().mockImplementation(() => ({
log: vi.fn(),
debug: vi.fn(),
info: vi.fn(),
warn: vi.fn(),
error: vi.fn(),
})),
}));

vi.useFakeTimers();

plugin = async (instance) => {
Expand Down Expand Up @@ -59,6 +80,7 @@ describe('fastifyAwsPowertool logger integration', () => {
afterEach(async () => {
vi.useRealTimers();
vi.restoreAllMocks();
vi.resetModules();

await app.close();
});
Expand Down

0 comments on commit 1dda2ff

Please sign in to comment.