Skip to content

test(maintenance): switch tracer to vitest #3285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
"packages/idempotency",
"packages/jmespath",
"packages/logger",
"packages/tracer",
]
fail-fast: false
steps:
Expand Down Expand Up @@ -89,14 +90,12 @@ jobs:
nodeVersion: ${{ matrix.version }}
- name: Run linting
run: |
npm run lint -w -w packages/tracer \
-w packages/metrics \
npm run lint -w packages/metrics \
-w packages/parameters \
-w packages/parser
- name: Run unit tests
run: |
npm t -w packages/tracer \
-w packages/metrics \
npm t -w packages/metrics \
-w packages/parameters \
-w packages/parser
check-examples:
Expand Down
1 change: 0 additions & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
npm t \
-w packages/metrics \
-w packages/tracer \
-w packages/parameters \
-w packages/parser

Expand Down
2 changes: 1 addition & 1 deletion packages/logger/tests/unit/initializeLogger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('Log levels', () => {
level: 'INFO',
message: 'Hello, world!',
sampling_rate: 0,
service: 'service_undefined',
service: 'hello-world',
timestamp: '2016-06-20T12:08:10.000Z',
xray_trace_id: '1-abcdef12-3456abcdef123456abcdef12',
},
Expand Down
2 changes: 2 additions & 0 deletions packages/testing/src/setupEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,5 @@ if (
process.env.AWS_REGION = 'eu-west-1';
}
process.env._HANDLER = 'index.handler';
process.env.POWERTOOLS_SERVICE_NAME = 'hello-world';
process.env.AWS_XRAY_LOGGING_LEVEL = 'silent';
31 changes: 0 additions & 31 deletions packages/tracer/jest.config.cjs

This file was deleted.

15 changes: 8 additions & 7 deletions packages/tracer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
"access": "public"
},
"scripts": {
"test": "npm run test:unit",
"test:unit": "jest --group=unit --detectOpenHandles --coverage --verbose",
"jest": "jest --detectOpenHandles --verbose",
"test:e2e:nodejs18x": "RUNTIME=nodejs18x jest --group=e2e",
"test:e2e:nodejs20x": "RUNTIME=nodejs20x jest --group=e2e",
"test:e2e": "jest --group=e2e",
"watch": "jest --watch",
"test": "vitest --run tests/unit",
"test:unit": "vitest --run tests/unit",
"test:unit:coverage": "vitest --run tests/unit --coverage.enabled --coverage.thresholds.100 --coverage.include='src/**'",
"test:unit:types": "echo 'Not Implemented'",
"test:unit:watch": "vitest tests/unit",
"test:e2e:nodejs18x": "RUNTIME=nodejs18x vitest --run tests/e2e",
"test:e2e:nodejs20x": "RUNTIME=nodejs20x vitest --run tests/e2e",
"test:e2e": "vitest --run tests/e2e",
"build:cjs": "tsc --build tsconfig.json && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
"build:esm": "tsc --build tsconfig.esm.json && echo '{ \"type\": \"module\" }' > lib/esm/package.json",
"build": "npm run build:esm & npm run build:cjs",
Expand Down
4 changes: 2 additions & 2 deletions packages/tracer/src/Tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class Tracer extends Utility implements TracerInterface {
* @deprecated Use {@link captureAWSv3Client} instead.
* @param service - AWS SDK v2 client
*/
public captureAWSClient<T>(service: T): T {
/* v8 ignore start */ public captureAWSClient<T>(service: T): T {
if (!this.isTracingEnabled()) return service;

try {
Expand All @@ -338,7 +338,7 @@ class Tracer extends Utility implements TracerInterface {
throw error;
}
}
}
} /* v8 ignore stop */

/**
* Patch an AWS SDK v3 client and create traces when your application makes calls to that AWS service.
Expand Down
6 changes: 1 addition & 5 deletions packages/tracer/tests/e2e/decorator.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
/**
* Test tracer when using the decorator instrumentation
*
* @group e2e/tracer/decorator
*/
import { join } from 'node:path';
import { TestStack } from '@aws-lambda-powertools/testing-utils';
import { TestDynamodbTable } from '@aws-lambda-powertools/testing-utils/resources/dynamodb';
import { TestNodejsFunction } from '@aws-lambda-powertools/testing-utils/resources/lambda';
import { getTraces } from '@aws-lambda-powertools/testing-utils/utils/xray-traces';
import type { EnrichedXRayTraceDocumentParsed } from 'packages/testing/lib/cjs/types.js';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { invokeAllTestCases } from '../helpers/invokeAllTests.js';
import {
RESOURCE_NAME_PREFIX,
Expand Down
6 changes: 1 addition & 5 deletions packages/tracer/tests/e2e/manual.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
/**
* Test tracer when instrumenting the lambda function manually
*
* @group e2e/tracer/manual
*/
import { join } from 'node:path';
import { TestStack } from '@aws-lambda-powertools/testing-utils';
import { TestDynamodbTable } from '@aws-lambda-powertools/testing-utils/resources/dynamodb';
import { TestNodejsFunction } from '@aws-lambda-powertools/testing-utils/resources/lambda';
import { getTraces } from '@aws-lambda-powertools/testing-utils/utils/xray-traces';
import type { EnrichedXRayTraceDocumentParsed } from 'packages/testing/lib/cjs/types.js';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { invokeAllTestCases } from '../helpers/invokeAllTests.js';
import {
RESOURCE_NAME_PREFIX,
Expand Down
6 changes: 1 addition & 5 deletions packages/tracer/tests/e2e/middy.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
/**
* Test tracer when using the Middy.js instrumentation
*
* @group e2e/tracer/middy
*/
import { join } from 'node:path';
import { TestStack } from '@aws-lambda-powertools/testing-utils';
import { TestDynamodbTable } from '@aws-lambda-powertools/testing-utils/resources/dynamodb';
import { TestNodejsFunction } from '@aws-lambda-powertools/testing-utils/resources/lambda';
import { getTraces } from '@aws-lambda-powertools/testing-utils/utils/xray-traces';
import type { EnrichedXRayTraceDocumentParsed } from 'packages/testing/lib/cjs/types.js';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { invokeAllTestCases } from '../helpers/invokeAllTests.js';
import {
RESOURCE_NAME_PREFIX,
Expand Down
17 changes: 0 additions & 17 deletions packages/tracer/tests/helpers/populateEnvironmentVariables.ts

This file was deleted.

20 changes: 8 additions & 12 deletions packages/tracer/tests/unit/EnvironmentVariablesService.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
/**
* Test EnvironmentVariablesService class
*
* @group unit/tracer/all
*/
import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';
import { EnvironmentVariablesService } from '../../src/config/EnvironmentVariablesService.js';

describe('Class: EnvironmentVariablesService', () => {
const ENVIRONMENT_VARIABLES = process.env;

beforeEach(() => {
jest.resetModules();
vi.resetModules();
process.env = { ...ENVIRONMENT_VARIABLES };
});

Expand All @@ -18,7 +14,7 @@ describe('Class: EnvironmentVariablesService', () => {
});

describe('Method: getTracingEnabled', () => {
test('It returns the value of the environment variable POWERTOOLS_TRACE_ENABLED', () => {
it('returns the value of the environment variable POWERTOOLS_TRACE_ENABLED', () => {
// Prepare
process.env.POWERTOOLS_TRACE_ENABLED = 'false';
const service = new EnvironmentVariablesService();
Expand All @@ -32,7 +28,7 @@ describe('Class: EnvironmentVariablesService', () => {
});

describe('Method: getTracingCaptureResponse', () => {
test('It returns the value of the environment variable POWERTOOLS_TRACER_CAPTURE_RESPONSE', () => {
it('returns the value of the environment variable POWERTOOLS_TRACER_CAPTURE_RESPONSE', () => {
// Prepare
process.env.POWERTOOLS_TRACER_CAPTURE_RESPONSE = 'false';
const service = new EnvironmentVariablesService();
Expand All @@ -46,7 +42,7 @@ describe('Class: EnvironmentVariablesService', () => {
});

describe('Method: getTracingCaptureError', () => {
test('It returns the value of the environment variable POWERTOOLS_TRACER_CAPTURE_ERROR', () => {
it('returns the value of the environment variable POWERTOOLS_TRACER_CAPTURE_ERROR', () => {
// Prepare
process.env.POWERTOOLS_TRACER_CAPTURE_ERROR = 'false';
const service = new EnvironmentVariablesService();
Expand All @@ -60,7 +56,7 @@ describe('Class: EnvironmentVariablesService', () => {
});

describe('Method: getCaptureHTTPsRequests', () => {
test('It returns the value of the environment variable POWERTOOLS_TRACER_CAPTURE_HTTPS_REQUESTS', () => {
it('returns the value of the environment variable POWERTOOLS_TRACER_CAPTURE_HTTPS_REQUESTS', () => {
// Prepare
process.env.POWERTOOLS_TRACER_CAPTURE_HTTPS_REQUESTS = 'false';
const service = new EnvironmentVariablesService();
Expand All @@ -74,7 +70,7 @@ describe('Class: EnvironmentVariablesService', () => {
});

describe('Method: getSamLocal', () => {
test('It returns the value of the environment variable AWS_SAM_LOCAL', () => {
it('returns the value of the environment variable AWS_SAM_LOCAL', () => {
// Prepare
process.env.AWS_SAM_LOCAL = 'true';
const service = new EnvironmentVariablesService();
Expand All @@ -88,7 +84,7 @@ describe('Class: EnvironmentVariablesService', () => {
});

describe('Method: getAwsExecutionEnv', () => {
test('It returns the value of the environment variable AWS_EXECUTION_ENV', () => {
it('returns the value of the environment variable AWS_EXECUTION_ENV', () => {
// Prepare
process.env.AWS_EXECUTION_ENV = 'nodejs20.x';
const service = new EnvironmentVariablesService();
Expand Down
Loading