Skip to content

Commit 318d27c

Browse files
committed
feat(internal): add esmodule support (#1738)
* feat(testing): add esmodule support * chore(all): update imports
1 parent 75388b4 commit 318d27c

File tree

117 files changed

+403
-1796
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+403
-1796
lines changed

Diff for: package-lock.json

+9-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/batch/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,8 @@
7777
"batch-processing",
7878
"serverless",
7979
"nodejs"
80-
]
81-
}
80+
],
81+
"devDependencies": {
82+
"@aws-lambda-powertools/testing-utils": "file:../testing"
83+
}
84+
}

Diff for: packages/batch/tests/unit/BatchProcessor.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @group unit/batch/class/batchprocessor
55
*/
66
import type { Context } from 'aws-lambda';
7-
import { ContextExamples as dummyContext } from '@aws-lambda-powertools/commons';
7+
import context from '@aws-lambda-powertools/testing-utils/context';
88
import {
99
BatchProcessor,
1010
EventType,
@@ -27,7 +27,7 @@ import {
2727
describe('Class: AsyncBatchProcessor', () => {
2828
const ENVIRONMENT_VARIABLES = process.env;
2929
const options: BatchProcessingOptions = {
30-
context: dummyContext.helloworldContext,
30+
context,
3131
};
3232

3333
beforeEach(() => {

Diff for: packages/batch/tests/unit/BatchProcessorSync.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @group unit/batch/class/batchprocessorsync
55
*/
66
import type { Context } from 'aws-lambda';
7-
import { ContextExamples as dummyContext } from '@aws-lambda-powertools/commons';
7+
import context from '@aws-lambda-powertools/testing-utils/context';
88
import {
99
BatchProcessorSync,
1010
EventType,
@@ -27,7 +27,7 @@ import {
2727
describe('Class: BatchProcessor', () => {
2828
const ENVIRONMENT_VARIABLES = process.env;
2929
const options: BatchProcessingOptions = {
30-
context: dummyContext.helloworldContext,
30+
context,
3131
};
3232

3333
beforeEach(() => {

Diff for: packages/batch/tests/unit/processPartialResponse.test.ts

+7-12
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import type {
99
KinesisStreamEvent,
1010
SQSEvent,
1111
} from 'aws-lambda';
12-
import {
13-
ContextExamples as dummyContext,
14-
Events as dummyEvent,
15-
} from '@aws-lambda-powertools/commons';
12+
import context from '@aws-lambda-powertools/testing-utils/context';
1613
import {
1714
BatchProcessor,
1815
processPartialResponse,
@@ -38,9 +35,8 @@ import assert from 'node:assert';
3835

3936
describe('Function: processPartialResponse()', () => {
4037
const ENVIRONMENT_VARIABLES = process.env;
41-
const context = dummyContext;
4238
const options: BatchProcessingOptions = {
43-
context: dummyContext.helloworldContext,
39+
context,
4440
};
4541

4642
beforeEach(() => {
@@ -114,7 +110,7 @@ describe('Function: processPartialResponse()', () => {
114110
};
115111

116112
// Act
117-
const result = await handler(event, context.helloworldContext);
113+
const result = await handler(event, context);
118114

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

143139
// Act
144-
const result = await handler(event, context.helloworldContext);
140+
const result = await handler(event, context);
145141

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

170166
// Act
171-
const result = await handler(event, context.helloworldContext);
167+
const result = await handler(event, context);
172168

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

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

193188
try {
194189
// Act
195-
await handler(event as unknown as SQSEvent, context.helloworldContext);
190+
await handler({} as unknown as SQSEvent, context);
196191
} catch (error) {
197192
// Assess
198193
assert(error instanceof UnexpectedBatchTypeError);
@@ -228,7 +223,7 @@ describe('Function: processPartialResponse()', () => {
228223
};
229224

230225
// Act
231-
const result = await handler(event, context.helloworldContext);
226+
const result = await handler(event, context);
232227

233228
// Assess
234229
expect(result).toStrictEqual({ batchItemFailures: [] });

Diff for: packages/batch/tests/unit/processPartialResponseSync.test.ts

+7-12
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import type {
99
KinesisStreamEvent,
1010
SQSEvent,
1111
} from 'aws-lambda';
12-
import {
13-
ContextExamples as dummyContext,
14-
Events as dummyEvent,
15-
} from '@aws-lambda-powertools/commons';
12+
import context from '@aws-lambda-powertools/testing-utils/context';
1613
import {
1714
BatchProcessorSync,
1815
processPartialResponseSync,
@@ -38,9 +35,8 @@ import assert from 'node:assert';
3835

3936
describe('Function: processPartialResponse()', () => {
4037
const ENVIRONMENT_VARIABLES = process.env;
41-
const context = dummyContext;
4238
const options: BatchProcessingOptions = {
43-
context: dummyContext.helloworldContext,
39+
context,
4440
};
4541

4642
beforeEach(() => {
@@ -114,7 +110,7 @@ describe('Function: processPartialResponse()', () => {
114110
};
115111

116112
// Act
117-
const result = handler(event, context.helloworldContext);
113+
const result = handler(event, context);
118114

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

143139
// Act
144-
const result = handler(event, context.helloworldContext);
140+
const result = handler(event, context);
145141

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

170166
// Act
171-
const result = handler(event, context.helloworldContext);
167+
const result = handler(event, context);
172168

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

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

189184
try {
190185
// Act
191-
handler(event as unknown as SQSEvent, context.helloworldContext);
186+
handler({} as unknown as SQSEvent, context);
192187
} catch (error) {
193188
// Assess
194189
assert(error instanceof UnexpectedBatchTypeError);
@@ -224,7 +219,7 @@ describe('Function: processPartialResponse()', () => {
224219
};
225220

226221
// Act
227-
const result = handler(event, context.helloworldContext);
222+
const result = handler(event, context);
228223

229224
// Assess
230225
expect(result).toStrictEqual({ batchItemFailures: [] });

Diff for: packages/commons/package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"lint-staged": {
2727
"*.{js,ts}": "npm run lint-fix"
2828
},
29-
"homepage": "https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/packages/metrics#readme",
29+
"homepage": "https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/packages/commons#readme",
3030
"license": "MIT-0",
3131
"type": "module",
3232
"exports": {
@@ -71,5 +71,8 @@
7171
"powertools",
7272
"serverless",
7373
"nodejs"
74-
]
75-
}
74+
],
75+
"devDependencies": {
76+
"@aws-lambda-powertools/testing-utils": "file:../testing"
77+
}
78+
}

Diff for: packages/commons/src/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
export { isRecord, isString, isTruthy, isNullOrUndefined } from './guards.js';
22
export { Utility } from './Utility.js';
33
export { EnvironmentVariablesService } from './config/EnvironmentVariablesService.js';
4-
export * as ContextExamples from './samples/resources/contexts/index.js';
5-
export * as Events from './samples/resources/events/index.js';
64
export { addUserAgentMiddleware, isSdkClient } from './awsSdkUtils.js';
75
export { cleanupMiddlewares } from './middleware/cleanupMiddlewares.js';
86
export {

Diff for: packages/commons/src/samples/resources/contexts/index.ts

-1
This file was deleted.

Diff for: packages/commons/src/samples/resources/events/aws/apigateway-authorizer.json

-5
This file was deleted.

Diff for: packages/commons/src/samples/resources/events/aws/apigateway-aws-proxy.json

-123
This file was deleted.

0 commit comments

Comments
 (0)