简体   繁体   中英

TypeError: Cannot read property 'CONTEXT' of undefined

I am trying to add some tests for a new stack that I am creating in my CDK package. The stack that I am creating is as follows:

super_nova.ts

import { PublicHostedZone } from 'monocdk/aws-route53';
import { App, Construct, PhysicalName} from 'monocdk';
import { AccountPrincipal, CompositePrincipal, ManagedPolicy, Role, ServicePrincipal } from 'monocdk/aws-iam';

export interface SuperNovaStackProps {
    readonly env;
    readonly cellProps;
    readonly allowedAccountsToDelegate: string[];
}

export class SuperNovaStack {
    readonly hostedZone: PublicHostedZone;
    readonly superNovaRole: Role;

    constructor(scope: Construct, id: string, props: SuperNovaStackProps) {
        super(scope, id, {
            ...props,
            stackName: `${props.cellProps.cellName}SuperNovaStack`,
        });

        // https://w.amazon.com/bin/view/SuperNova/PreOnboardingSteps/#HCreateanIAMRoleandAddPermissionsPoliciesforSuperNovaUsingCDK28LookbelowforCFNinstructionsinstead29
        this.superNovaRole = new Role(this, 'SuperNovaRole', {
            roleName: 'Nova-DO-NOT-DELETE',
            assumedBy: new ServicePrincipal('nova.aws.internal'),
            managedPolicies: [
                ManagedPolicy.fromAwsManagedPolicyName('AmazonRoute53FullAccess'),
                ManagedPolicy.fromAwsManagedPolicyName('SecurityAudit'),
            ],
        });

        // Principals of AWS accounts that are allowed to create subdomains from the base domain. These are the enterprise accounts.
        const delegationPrincipal = new CompositePrincipal(
            ...props.allowedAccountsToDelegate.map((accountId) => new AccountPrincipal(accountId))
        );

        this.hostedZone = new PublicHostedZone(this, 'HostedZone', {
            comment: `SuperNova HostedZone. [DO NOT DELETE]`,
            crossAccountZoneDelegationPrincipal: delegationPrincipal,
            crossAccountZoneDelegationRoleName: 'fOSGlobalZoneDelegationRole',
        });
    }
}

And this is my test file for the same:

test_super_nova.ts

import { Stack } from 'monocdk';
import { SuperNovaStack } from '../super_nova';

describe('Super Nova stack creates', () => {
    let stack: Stack;
    let super_nova: SuperNovaStack;
    let testEnv: env;
    const internal_beta_account: cellProps = {
        cellName: 'beta-Enterprise',
        region: 'us-west-2',
        enterpriseIndex: 0,
        stage: 'beta',
        isPrimary: true,
        disableRollbackAlarm: false,
        componentAccounts: '456',
    };

    beforeAll(() => {
        testEnv = env.fromAccountAndRegion('123', 'us-west-2', 'fOSConfigCommonStack');
        const stack = new Stack();
        const super_nova = new SuperNovaStack(stack, 'SuperNova', {
            env: testEnv,
            cellProps: internal_beta_account,
            allowedAccountsToDelegate: ['456'],
        });
    });

    test('expected role', () => {
        expect(super_nova).toContain('fOSGlobalZoneDelegationRole');
    });
});

However, when I am trying to build this, I am getting the below error:

FAIL  dist/lib/__tests__/test_super_nova_stack.js
  ● Super Nova stack creates › expected role

TypeError: Cannot read property 'CONTEXT' of undefined

  22 |
  23 |     constructor(scope: Construct | App, id: string, props: SuperNovaStackProps) {
> 24 |         super(scope, id, {
     |         ^
  25 |             ...props,
  26 |             stackName: `${props.cellProps.cellName}SuperNovaStack`,

  at new SuperNovaStack (lib/super_nova.ts:24:9)

I tried searching for the same issue online but couldn't find anything relatable. I am fairly new to AWS-CDK and typescript and thus finding it difficult. Any help will be appreciated. Thanks!

should SuperNova class extend some class?. super meant to call base class constructor. I don't see any extends for SuperNova class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM