Skip to content

feat(internal): add esmodule support #1738

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 2 commits into from
Oct 12, 2023
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
11 changes: 9 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions packages/batch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,8 @@
"batch-processing",
"serverless",
"nodejs"
]
}
],
"devDependencies": {
"@aws-lambda-powertools/testing-utils": "file:../testing"
}
}
4 changes: 2 additions & 2 deletions packages/batch/tests/unit/BatchProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @group unit/batch/class/batchprocessor
*/
import type { Context } from 'aws-lambda';
import { ContextExamples as dummyContext } from '@aws-lambda-powertools/commons';
import context from '@aws-lambda-powertools/testing-utils/context';
import {
BatchProcessor,
EventType,
Expand All @@ -27,7 +27,7 @@ import {
describe('Class: AsyncBatchProcessor', () => {
const ENVIRONMENT_VARIABLES = process.env;
const options: BatchProcessingOptions = {
context: dummyContext.helloworldContext,
context,
};

beforeEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions packages/batch/tests/unit/BatchProcessorSync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @group unit/batch/class/batchprocessorsync
*/
import type { Context } from 'aws-lambda';
import { ContextExamples as dummyContext } from '@aws-lambda-powertools/commons';
import context from '@aws-lambda-powertools/testing-utils/context';
import {
BatchProcessorSync,
EventType,
Expand All @@ -27,7 +27,7 @@ import {
describe('Class: BatchProcessor', () => {
const ENVIRONMENT_VARIABLES = process.env;
const options: BatchProcessingOptions = {
context: dummyContext.helloworldContext,
context,
};

beforeEach(() => {
Expand Down
19 changes: 7 additions & 12 deletions packages/batch/tests/unit/processPartialResponse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import type {
KinesisStreamEvent,
SQSEvent,
} from 'aws-lambda';
import {
ContextExamples as dummyContext,
Events as dummyEvent,
} from '@aws-lambda-powertools/commons';
import context from '@aws-lambda-powertools/testing-utils/context';
import {
BatchProcessor,
processPartialResponse,
Expand All @@ -38,9 +35,8 @@ import assert from 'node:assert';

describe('Function: processPartialResponse()', () => {
const ENVIRONMENT_VARIABLES = process.env;
const context = dummyContext;
const options: BatchProcessingOptions = {
context: dummyContext.helloworldContext,
context,
};

beforeEach(() => {
Expand Down Expand Up @@ -114,7 +110,7 @@ describe('Function: processPartialResponse()', () => {
};

// Act
const result = await handler(event, context.helloworldContext);
const result = await handler(event, context);

// Assess
expect(result).toStrictEqual({ batchItemFailures: [] });
Expand All @@ -141,7 +137,7 @@ describe('Function: processPartialResponse()', () => {
};

// Act
const result = await handler(event, context.helloworldContext);
const result = await handler(event, context);

// Assess
expect(result).toStrictEqual({ batchItemFailures: [] });
Expand All @@ -168,7 +164,7 @@ describe('Function: processPartialResponse()', () => {
};

// Act
const result = await handler(event, context.helloworldContext);
const result = await handler(event, context);

// Assess
expect(result).toStrictEqual({ batchItemFailures: [] });
Expand All @@ -177,7 +173,6 @@ describe('Function: processPartialResponse()', () => {
test('Process partial response through handler for SQS records with incorrect event type', async () => {
// Prepare
const processor = new BatchProcessor(EventType.SQS);
const event = dummyEvent.Custom;

const handler = async (
event: SQSEvent,
Expand All @@ -192,7 +187,7 @@ describe('Function: processPartialResponse()', () => {

try {
// Act
await handler(event as unknown as SQSEvent, context.helloworldContext);
await handler({} as unknown as SQSEvent, context);
} catch (error) {
// Assess
assert(error instanceof UnexpectedBatchTypeError);
Expand Down Expand Up @@ -228,7 +223,7 @@ describe('Function: processPartialResponse()', () => {
};

// Act
const result = await handler(event, context.helloworldContext);
const result = await handler(event, context);

// Assess
expect(result).toStrictEqual({ batchItemFailures: [] });
Expand Down
19 changes: 7 additions & 12 deletions packages/batch/tests/unit/processPartialResponseSync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import type {
KinesisStreamEvent,
SQSEvent,
} from 'aws-lambda';
import {
ContextExamples as dummyContext,
Events as dummyEvent,
} from '@aws-lambda-powertools/commons';
import context from '@aws-lambda-powertools/testing-utils/context';
import {
BatchProcessorSync,
processPartialResponseSync,
Expand All @@ -38,9 +35,8 @@ import assert from 'node:assert';

describe('Function: processPartialResponse()', () => {
const ENVIRONMENT_VARIABLES = process.env;
const context = dummyContext;
const options: BatchProcessingOptions = {
context: dummyContext.helloworldContext,
context,
};

beforeEach(() => {
Expand Down Expand Up @@ -114,7 +110,7 @@ describe('Function: processPartialResponse()', () => {
};

// Act
const result = handler(event, context.helloworldContext);
const result = handler(event, context);

// Assess
expect(result).toStrictEqual({ batchItemFailures: [] });
Expand All @@ -141,7 +137,7 @@ describe('Function: processPartialResponse()', () => {
};

// Act
const result = handler(event, context.helloworldContext);
const result = handler(event, context);

// Assess
expect(result).toStrictEqual({ batchItemFailures: [] });
Expand All @@ -168,7 +164,7 @@ describe('Function: processPartialResponse()', () => {
};

// Act
const result = handler(event, context.helloworldContext);
const result = handler(event, context);

// Assess
expect(result).toStrictEqual({ batchItemFailures: [] });
Expand All @@ -177,7 +173,6 @@ describe('Function: processPartialResponse()', () => {
test('Process partial response through handler for SQS records with incorrect event type', () => {
// Prepare
const processor = new BatchProcessorSync(EventType.SQS);
const event = dummyEvent.Custom;

const handler = (
event: SQSEvent,
Expand All @@ -188,7 +183,7 @@ describe('Function: processPartialResponse()', () => {

try {
// Act
handler(event as unknown as SQSEvent, context.helloworldContext);
handler({} as unknown as SQSEvent, context);
} catch (error) {
// Assess
assert(error instanceof UnexpectedBatchTypeError);
Expand Down Expand Up @@ -224,7 +219,7 @@ describe('Function: processPartialResponse()', () => {
};

// Act
const result = handler(event, context.helloworldContext);
const result = handler(event, context);

// Assess
expect(result).toStrictEqual({ batchItemFailures: [] });
Expand Down
9 changes: 6 additions & 3 deletions packages/commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"lint-staged": {
"*.{js,ts}": "npm run lint-fix"
},
"homepage": "https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/packages/metrics#readme",
"homepage": "https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/packages/commons#readme",
"license": "MIT-0",
"type": "module",
"exports": {
Expand Down Expand Up @@ -70,5 +70,8 @@
"powertools",
"serverless",
"nodejs"
]
}
],
"devDependencies": {
"@aws-lambda-powertools/testing-utils": "file:../testing"
}
}
2 changes: 0 additions & 2 deletions packages/commons/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
export { isRecord, isString, isTruthy, isNullOrUndefined } from './guards.js';
export { Utility } from './Utility.js';
export { EnvironmentVariablesService } from './config/EnvironmentVariablesService.js';
export * as ContextExamples from './samples/resources/contexts/index.js';
export * as Events from './samples/resources/events/index.js';
export { addUserAgentMiddleware, isSdkClient } from './awsSdkUtils.js';
export { cleanupMiddlewares } from './middleware/cleanupMiddlewares.js';
export {
Expand Down
1 change: 0 additions & 1 deletion packages/commons/src/samples/resources/contexts/index.ts

This file was deleted.

This file was deleted.

This file was deleted.

Loading