Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export Options type #36

Merged
merged 1 commit into from
Jul 3, 2024
Merged

Export Options type #36

merged 1 commit into from
Jul 3, 2024

Conversation

antrew
Copy link
Contributor

@antrew antrew commented Jul 2, 2024

This pull request exports the type Options so that the type can be used in tests.

Background: I want to test multiple CDK Stacks in my project and I have written a wrapper to reduce duplication in my tests.

Here is my wrapper:

import { App, Stack } from 'aws-cdk-lib';
import { Environment } from '@/environment-data';
import 'jest-cdk-snapshot';
import { Options } from 'jest-cdk-snapshot';

export function testStackSnapshot(stackClass: typeof Stack, jestCdkSnapshotOptions?: Options) {
// I need Options here                                                               ^^^^^^^
  const app = new App();
  const stack = new stackClass(app, 'dummy-id', {
    env: {
      account: Environment.dev,
      region: 'eu-west-1',
    },
  });
  expect(stack).toMatchCdkSnapshot(jestCdkSnapshotOptions);
}

Here is a test example:

import { testStackSnapshot } from '@/tests/test-stack-snapshot';
import { FrontendStack } from '@/frontend/frontend-stack';

it('should match the saved snapshot', () => {
  testStackSnapshot(FrontendStack, {
    propertyMatchers: {
      Resources: {
        deploymonalisaCustomResourceC20061ED: {
          Properties: {
            SourceObjectKeys: expect.any(Array),
          },
        },
      },
    },
  });
});

@hupe1980 hupe1980 self-requested a review July 3, 2024 19:26
Copy link
Owner

@hupe1980 hupe1980 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thx

@hupe1980 hupe1980 merged commit ba37d31 into hupe1980:master Jul 3, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants