Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(internal): add esmodule support (#1738)
Browse files Browse the repository at this point in the history
* feat(testing): add esmodule support

* chore(all): update imports
dreamorosi authored Oct 12, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent aec327b commit 90a7523
Showing 118 changed files with 409 additions and 1,828 deletions.
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
@@ -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
@@ -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,
@@ -27,7 +27,7 @@ import {
describe('Class: AsyncBatchProcessor', () => {
const ENVIRONMENT_VARIABLES = process.env;
const options: BatchProcessingOptions = {
context: dummyContext.helloworldContext,
context,
};

beforeEach(() => {
4 changes: 2 additions & 2 deletions packages/batch/tests/unit/BatchProcessorSync.test.ts
Original file line number Diff line number Diff line change
@@ -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,
@@ -27,7 +27,7 @@ import {
describe('Class: BatchProcessor', () => {
const ENVIRONMENT_VARIABLES = process.env;
const options: BatchProcessingOptions = {
context: dummyContext.helloworldContext,
context,
};

beforeEach(() => {
19 changes: 7 additions & 12 deletions packages/batch/tests/unit/processPartialResponse.test.ts
Original file line number Diff line number Diff line change
@@ -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,
@@ -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(() => {
@@ -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: [] });
@@ -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: [] });
@@ -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: [] });
@@ -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,
@@ -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);
@@ -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: [] });
19 changes: 7 additions & 12 deletions packages/batch/tests/unit/processPartialResponseSync.test.ts
Original file line number Diff line number Diff line change
@@ -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,
@@ -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(() => {
@@ -114,7 +110,7 @@ describe('Function: processPartialResponse()', () => {
};

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

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

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

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

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

// Assess
expect(result).toStrictEqual({ batchItemFailures: [] });
@@ -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,
@@ -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);
@@ -224,7 +219,7 @@ describe('Function: processPartialResponse()', () => {
};

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

// Assess
expect(result).toStrictEqual({ batchItemFailures: [] });
9 changes: 6 additions & 3 deletions packages/commons/package.json
Original file line number Diff line number Diff line change
@@ -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": {
@@ -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 {
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

0 comments on commit 90a7523

Please sign in to comment.