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

Viewed 308

I am currently working through the cdk-workshop provided by amazon: 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

However already in the first test (DynamoDB Table Created), where the workshop asks me to run

$ npm run build && npx jest

I am having trouble:

enter image description here

Googling for the error "Inline source not allowed for nodejs14.x" did not help me.

For extra information I will add the exact code as well as my package.json:

enter image description here enter image description here

Also, I just ran cdk deploy and the base program of the workshop works and can be called by me. Does anybody have an idea how to solve this problem?

1 Answers

It looks like a bug in the CDK, they should be able to tell when we are just running tests.

I used runtime: lambda.Runtime.NODEJS_10_X,. In reality, you just want to test that HitCounter creates a DynamoDB table so I believe it's ok for you to use something like this:

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'))
})
Related