Skip to content

Commit 6e200b2

Browse files
committed
add module loading tests
1 parent 679638e commit 6e200b2

23 files changed

+309
-2
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
2+
3+
// This should fail because it's ESM syntax in a CJS context
4+
export const handler = async (event) => {
5+
return "This should fail";
6+
};

test/handlers/extensionless/index

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
2+
3+
'use strict';
4+
// This is a CommonJS module without file extension
5+
6+
module.exports.handler = async (event) => {
7+
return "Hello from extensionless CJS";
8+
};

test/handlers/pkg-less/cjsAndMjs.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
2+
3+
import { someESMFunction } from './esmModule.js'; // ESM import
4+
5+
module.exports.handler = async (event) => { // CJS export
6+
return someESMFunction(event);
7+
};
8+
9+
export const esm = 'This is ESM syntax'; // ESM export
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
2+
3+
'use strict';
4+
5+
const { getMessage } = require('./cjsModule.cjs')
6+
7+
exports.handler = async (_event) => {
8+
return getMessage();
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/** Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
2+
3+
'use strict';
4+
5+
// This static import is not allowed in CJS
6+
import { getMessage } from './esmModule';
7+
8+
module.exports.handler = async () => {
9+
return getMessage();
10+
};

test/handlers/pkg-less/cjsInMjs.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
2+
3+
'use strict';
4+
5+
// This should fail because it's CJS syntax in a ESM context
6+
module.exports.handler = async (_event) => {
7+
return 'This should fail';
8+
};

test/handlers/pkg-less/cjsModule.cjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
2+
3+
'use strict';
4+
5+
module.exports.getMessage = () => {
6+
return "Hello from CJS!";
7+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
2+
3+
import { getMessage } from './cjsModule.cjs';
4+
5+
export const handler = async (_event) => {
6+
return getMessage();
7+
};

test/handlers/pkg-less/esmInCjs.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
2+
3+
// This should fail because it's ESM syntax in a CJS context
4+
export const handler = async (_event) => {
5+
return 'This should fail';
6+
};

0 commit comments

Comments
 (0)