forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_esmPaths.test.ts
More file actions
51 lines (44 loc) · 1.39 KB
/
function_esmPaths.test.ts
File metadata and controls
51 lines (44 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { Template } from '@aws-cdk/assertions';
import { CodeConfig } from '@aws-cdk/aws-lambda';
import { Stack } from '@aws-cdk/core';
import { NodejsFunction } from '../lib';
import { Bundling } from '../lib/bundling';
import { CallSite } from '../lib/util';
import * as util from '../lib/util';
jest.mock('../lib/bundling', () => {
return {
Bundling: {
bundle: jest.fn().mockReturnValue({
bind: (): CodeConfig => {
return {
s3Location: {
bucketName: 'my-bucket',
objectKey: 'my-key',
},
};
},
bindToResource: () => { return; },
}),
},
};
});
const actualFindDefiningFile = util.findDefiningFile;
jest.spyOn(util, 'findDefiningFile').mockImplementation((sites: CallSite[]): string => {
return 'file://' + actualFindDefiningFile(sites);
});
let stack: Stack;
beforeEach(() => {
stack = new Stack();
jest.clearAllMocks();
});
test('NodejsFunction with .ts handler, with ESM file:// paths', () => {
// WHEN
new NodejsFunction(stack, 'handler1');
expect(Bundling.bundle).toHaveBeenCalledWith(expect.objectContaining({
entry: expect.stringContaining('function_esmPaths.test.handler1.ts'), // Automatically finds .ts handler file
}));
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {
Handler: 'index.handler',
Runtime: 'nodejs14.x',
});
});