我正在使用的库是结构化的
declare namespace foo {
function bar();
};
declare namespace foo.bar {
function baz();
};
Run Code Online (Sandbox Code Playgroud)
所以我需要模拟的两个函数是foo.bar()和foo.bar.baz().
模拟foo.bar()我以前使用
require('foo');
jest.mock('foo', () => ({
bar: () => mockedBar,
}));
Run Code Online (Sandbox Code Playgroud)
有什么方法可以嘲笑foo.bar.baz()吗?我试过了
jest.mock('foo.bar', () => ({
}));
Run Code Online (Sandbox Code Playgroud)
但它正在显示一条消息Cannot find module 'foo.bar' from 'functions.test.js'.
我目前有一个简单的 Lambda,由 SQS 队列触发并打印出触发它的事件。它与 CFN 一起部署,定义为:
PrintMessage:
Type: AWS::Lambda::Function
Properties:
Handler: index.handler
Runtime: python3.8
FunctionName: !Sub printMessage-${Environment}
MemorySize: 1024
Role: !Sub arn:aws:iam::${AWS::AccountId}:role/service-role/printMessageRole-${Environment}
Timeout: 900
Code:
ZipFile: |
import os
import json
def handler(event, context):
print("Event: {}".format(event))
PrintMessageEventSource:
Type: AWS::Lambda::EventSourceMapping
Properties:
BatchSize: 1
Enabled: true
EventSourceArn: !Sub arn:aws:sqs:${AWS::Region}:${AWS::AccountId}:printMessageQueue-${Environment}
FunctionName: !Sub printMessage-${Environment}
Run Code Online (Sandbox Code Playgroud)
此流程工作正常 - 编写任何内容来printMessageQueue触发 Lambda 并打印其内容。
我的问题是我需要使用另一个组件的逻辑,该逻辑更复杂并且包含多个依赖项,并且已经作为 Docker 映像部署到 ECR。到目前为止我所拥有的是:
PrintMessage:
Type: AWS::Lambda::Function
Properties:
Code:
ImageUri: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/component:${ImageTag}
FunctionName: !Sub printMessage-${Environment}
ImageConfig:
EntryPoint:
- python3
- print_message.py
MemorySize: 1024 …Run Code Online (Sandbox Code Playgroud)