From a23a0a251285cf2ef023cdd2b064d2f26cab687e Mon Sep 17 00:00:00 2001 From: Niranjan Jayakar Date: Tue, 9 Feb 2021 14:21:49 +0000 Subject: [PATCH] chore(codepipeline): migrate pipeline.test.ts to use jest (#12924) Move `pipeline.test.ts` to use native jest APIs instead of `nodeunitshim`. Motivation As part of the work for feature flags in v2, it's easier to inject conditional testing using jest's native APIs than to work with nodeunitshim. Nevertheless, we should be using native jest APIs everywhere. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../aws-codepipeline/test/pipeline.test.ts | 89 +++++++++---------- 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/packages/@aws-cdk/aws-codepipeline/test/pipeline.test.ts b/packages/@aws-cdk/aws-codepipeline/test/pipeline.test.ts index 880c45b1f8a05..3b091ac8ef339 100644 --- a/packages/@aws-cdk/aws-codepipeline/test/pipeline.test.ts +++ b/packages/@aws-cdk/aws-codepipeline/test/pipeline.test.ts @@ -5,16 +5,15 @@ import * as kms from '@aws-cdk/aws-kms'; import * as s3 from '@aws-cdk/aws-s3'; import * as cdk from '@aws-cdk/core'; import * as cxapi from '@aws-cdk/cx-api'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as codepipeline from '../lib'; import { FakeBuildAction } from './fake-build-action'; import { FakeSourceAction } from './fake-source-action'; /* eslint-disable quote-props */ -nodeunitShim({ - 'Pipeline': { - 'can be passed an IAM role during pipeline creation'(test: Test) { +describe('', () => { + describe('Pipeline', () => { + test('can be passed an IAM role during pipeline creation', () => { const stack = new cdk.Stack(); const role = new iam.Role(stack, 'Role', { assumedBy: new iam.ServicePrincipal('codepipeline.amazonaws.com'), @@ -32,23 +31,23 @@ nodeunitShim({ }, })); - test.done(); - }, - 'can be imported by ARN'(test: Test) { + }); + + test('can be imported by ARN', () => { const stack = new cdk.Stack(); const pipeline = codepipeline.Pipeline.fromPipelineArn(stack, 'Pipeline', 'arn:aws:codepipeline:us-east-1:123456789012:MyPipeline'); - test.equal(pipeline.pipelineArn, 'arn:aws:codepipeline:us-east-1:123456789012:MyPipeline'); - test.equal(pipeline.pipelineName, 'MyPipeline'); + expect(pipeline.pipelineArn).toEqual('arn:aws:codepipeline:us-east-1:123456789012:MyPipeline'); + expect(pipeline.pipelineName).toEqual('MyPipeline'); + - test.done(); - }, + }); - 'that is cross-region': { - 'validates that source actions are in the same region as the pipeline'(test: Test) { + describe('that is cross-region', () => { + test('validates that source actions are in the same region as the pipeline', () => { const app = new cdk.App(); const stack = new cdk.Stack(app, 'PipelineStack', { env: { region: 'us-west-1', account: '123456789012' } }); const pipeline = new codepipeline.Pipeline(stack, 'Pipeline'); @@ -61,14 +60,14 @@ nodeunitShim({ region: 'ap-southeast-1', }); - test.throws(() => { + expect(() => { sourceStage.addAction(sourceAction); - }, /Source action 'FakeSource' must be in the same region as the pipeline/); + }).toThrow(/Source action 'FakeSource' must be in the same region as the pipeline/); + - test.done(); - }, + }); - 'allows passing an Alias in place of the KMS Key in the replication Bucket'(test: Test) { + test('allows passing an Alias in place of the KMS Key in the replication Bucket', () => { const app = new cdk.App(); const replicationRegion = 'us-west-1'; @@ -173,10 +172,10 @@ nodeunitShim({ }, }); - test.done(); - }, - "generates ArtifactStores with the alias' ARN as the KeyID"(test: Test) { + }); + + test('generates ArtifactStores with the alias ARN as the KeyID', () => { const app = new cdk.App(); const replicationRegion = 'us-west-1'; @@ -239,10 +238,10 @@ nodeunitShim({ 'UpdateReplacePolicy': 'Delete', }, ResourcePart.CompleteDefinition); - test.done(); - }, - 'allows passing an imported Bucket and Key for the replication Bucket'(test: Test) { + }); + + test('allows passing an imported Bucket and Key for the replication Bucket', () => { const replicationRegion = 'us-west-1'; const pipelineRegion = 'us-west-2'; @@ -296,10 +295,10 @@ nodeunitShim({ ], }); - test.done(); - }, - 'generates the support stack containing the replication Bucket without the need to bootstrap in that environment'(test: Test) { + }); + + test('generates the support stack containing the replication Bucket without the need to bootstrap in that environment', () => { const app = new cdk.App({ treeMetadata: false, // we can't set the context otherwise, because App will have a child }); @@ -331,17 +330,17 @@ nodeunitShim({ const assembly = app.synth(); const supportStackArtifact = assembly.getStackByName('PipelineStack-support-eu-south-1'); - test.equal(supportStackArtifact.assumeRoleArn, + expect(supportStackArtifact.assumeRoleArn).toEqual( 'arn:${AWS::Partition}:iam::123456789012:role/cdk-hnb659fds-deploy-role-123456789012-us-west-2'); - test.equal(supportStackArtifact.cloudFormationExecutionRoleArn, + expect(supportStackArtifact.cloudFormationExecutionRoleArn).toEqual( 'arn:${AWS::Partition}:iam::123456789012:role/cdk-hnb659fds-cfn-exec-role-123456789012-us-west-2'); - test.done(); - }, - }, - 'that is cross-account': { - 'does not allow passing a dynamic value in the Action account property'(test: Test) { + }); + }); + + describe('that is cross-account', () => { + test('does not allow passing a dynamic value in the Action account property', () => { const app = new cdk.App(); const stack = new cdk.Stack(app, 'PipelineStack', { env: { account: '123456789012' } }); const sourceOutput = new codepipeline.Artifact(); @@ -355,18 +354,18 @@ nodeunitShim({ }); const buildStage = pipeline.addStage({ stageName: 'Build' }); - test.throws(() => { + expect(() => { buildStage.addAction(new FakeBuildAction({ actionName: 'FakeBuild', input: sourceOutput, account: cdk.Aws.ACCOUNT_ID, })); - }, /The 'account' property must be a concrete value \(action: 'FakeBuild'\)/); + }).toThrow(/The 'account' property must be a concrete value \(action: 'FakeBuild'\)/); + - test.done(); - }, + }); - 'does not allow an env-agnostic Pipeline Stack if an Action account has been provided'(test: Test) { + test('does not allow an env-agnostic Pipeline Stack if an Action account has been provided', () => { const app = new cdk.App(); const stack = new cdk.Stack(app, 'PipelineStack'); const sourceOutput = new codepipeline.Artifact(); @@ -380,18 +379,18 @@ nodeunitShim({ }); const buildStage = pipeline.addStage({ stageName: 'Build' }); - test.throws(() => { + expect(() => { buildStage.addAction(new FakeBuildAction({ actionName: 'FakeBuild', input: sourceOutput, account: '123456789012', })); - }, /Pipeline stack which uses cross-environment actions must have an explicitly set account/); + }).toThrow(/Pipeline stack which uses cross-environment actions must have an explicitly set account/); + - test.done(); - }, - }, - }, + }); + }); + }); }); describe('test with shared setup', () => {