在 CDK-Workshop(打字稿)中进行测试时遇到问题:nodejs14.x 不允许使用内联源

Having Problems with tests in CDK-Workshop (typescript): Inline source not allowed for nodejs14.x

我目前正在通过亚马逊提供的 cdk-workshop 工作:https://cdkworkshop.com. I followed all the steps (at least I hope) and have created a test program and deployed it. I the current step I am tasked to create assertion tests for my constructs: https://cdkworkshop.com/20-typescript/70-advanced-topics/100-construct-testing/1000-assertion-test.html

但是已经在第一个测试中(DynamoDB Table 已创建),车间要求我 运行

$ npm run build && npx jest

我遇到了麻烦:

谷歌搜索错误“nodejs14.x 不允许内联源”对我没有帮助。

有关额外信息,我将添加确切的代码以及我的 package.json:

另外,我只是运行 cdk deploy 和workshop 的基础程序可以被我调用。 有人知道如何解决这个问题吗?

这看起来像是 CDK 中的错误,他们应该能够在我们只是 运行 测试时告诉我们。

我用了runtime: lambda.Runtime.NODEJS_10_X,。实际上,您只是想测试 HitCounter 创建 DynamoDB table 所以我相信您可以使用这样的东西:

test('Dynamo DB table created', () => {
    const stack = new cdk.Stack();

    new HitCounter(stack, 'MyTestConstruct', {
        downstream: new lambda.Function(stack, 'TestFunction', {
            runtime: lambda.Runtime.NODEJS_10_X,
            code: lambda.Code.fromInline('test'),
            handler: 'index.handler'
        }),
    });

    expectCDK(stack).to(haveResource('AWS::DynamoDB::Table'))
})