diff --git a/packages/@aws-cdk/aws-autoscaling/package.json b/packages/@aws-cdk/aws-autoscaling/package.json index c2ece82fdb8b0..67fb9d4e1dd7e 100644 --- a/packages/@aws-cdk/aws-autoscaling/package.json +++ b/packages/@aws-cdk/aws-autoscaling/package.json @@ -78,7 +78,7 @@ "cdk-build-tools": "0.0.0", "cdk-integ-tools": "0.0.0", "cfn2ts": "0.0.0", - "nodeunit-shim": "0.0.0", + "jest": "^26.6.3", "pkglint": "0.0.0", "@aws-cdk/cloud-assembly-schema": "0.0.0", "@aws-cdk/assert-internal": "0.0.0" diff --git a/packages/@aws-cdk/aws-autoscaling/test/auto-scaling-group.test.ts b/packages/@aws-cdk/aws-autoscaling/test/auto-scaling-group.test.ts index 9fb5da7b46ce8..64795593e8ec4 100644 --- a/packages/@aws-cdk/aws-autoscaling/test/auto-scaling-group.test.ts +++ b/packages/@aws-cdk/aws-autoscaling/test/auto-scaling-group.test.ts @@ -1,17 +1,17 @@ -import { ABSENT, expect, haveResource, haveResourceLike, InspectionFailure, ResourcePart } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; +import { ABSENT, InspectionFailure, ResourcePart } from '@aws-cdk/assert-internal'; import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as iam from '@aws-cdk/aws-iam'; import * as sns from '@aws-cdk/aws-sns'; import * as cxschema from '@aws-cdk/cloud-assembly-schema'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as autoscaling from '../lib'; /* eslint-disable quote-props */ -nodeunitShim({ - 'default fleet'(test: Test) { +describe('auto scaling group', () => { + test('default fleet', () => { const stack = getTestStack(); const vpc = mockVpc(stack); @@ -21,7 +21,7 @@ nodeunitShim({ vpc, }); - expect(stack).toMatch({ + expect(stack).toMatchTemplate({ 'Parameters': { 'SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter': { 'Type': 'AWS::SSM::Parameter::Value', @@ -136,10 +136,10 @@ nodeunitShim({ }, }); - test.done(); - }, - 'can set minCapacity, maxCapacity, desiredCapacity to 0'(test: Test) { + }); + + test('can set minCapacity, maxCapacity, desiredCapacity to 0', () => { const stack = new cdk.Stack(undefined, 'MyStack', { env: { region: 'us-east-1', account: '1234' } }); const vpc = mockVpc(stack); @@ -152,17 +152,17 @@ nodeunitShim({ desiredCapacity: 0, }); - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { MinSize: '0', MaxSize: '0', DesiredCapacity: '0', }, - )); + ); - test.done(); - }, - 'validation is not performed when using Tokens'(test: Test) { + }); + + test('validation is not performed when using Tokens', () => { const stack = new cdk.Stack(undefined, 'MyStack', { env: { region: 'us-east-1', account: '1234' } }); const vpc = mockVpc(stack); @@ -176,17 +176,17 @@ nodeunitShim({ }); // THEN: no exception - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { MinSize: '5', MaxSize: '1', DesiredCapacity: '20', }, - )); + ); - test.done(); - }, - 'userdata can be overridden by image'(test: Test) { + }); + + test('userdata can be overridden by image', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -204,12 +204,12 @@ nodeunitShim({ }); // THEN - test.equals(asg.userData.render(), '#!/bin/bash\nit me!'); + expect(asg.userData.render()).toEqual('#!/bin/bash\nit me!'); + - test.done(); - }, + }); - 'userdata can be overridden at ASG directly'(test: Test) { + test('userdata can be overridden at ASG directly', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -231,12 +231,12 @@ nodeunitShim({ }); // THEN - test.equals(asg.userData.render(), '#!/bin/bash\nno me!'); + expect(asg.userData.render()).toEqual('#!/bin/bash\nno me!'); - test.done(); - }, - 'can specify only min capacity'(test: Test) { + }); + + test('can specify only min capacity', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -250,16 +250,16 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { MinSize: '10', MaxSize: '10', }, - )); + ); + - test.done(); - }, + }); - 'can specify only max capacity'(test: Test) { + test('can specify only max capacity', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -273,16 +273,16 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { MinSize: '1', MaxSize: '10', }, - )); + ); + - test.done(); - }, + }); - 'can specify only desiredCount'(test: Test) { + test('can specify only desiredCount', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -296,17 +296,17 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { MinSize: '1', MaxSize: '10', DesiredCapacity: '10', }, - )); + ); + - test.done(); - }, + }); - 'addToRolePolicy can be used to add statements to the role policy'(test: Test) { + test('addToRolePolicy can be used to add statements to the role policy', () => { const stack = new cdk.Stack(undefined, 'MyStack', { env: { region: 'us-east-1', account: '1234' } }); const vpc = mockVpc(stack); @@ -321,7 +321,7 @@ nodeunitShim({ resources: ['*'], })); - expect(stack).to(haveResource('AWS::IAM::Policy', { + expect(stack).toHaveResource('AWS::IAM::Policy', { PolicyDocument: { Version: '2012-10-17', Statement: [ @@ -332,11 +332,11 @@ nodeunitShim({ }, ], }, - })); - test.done(); - }, + }); + + }); - 'can configure replacing update'(test: Test) { + test('can configure replacing update', () => { // GIVEN const stack = new cdk.Stack(undefined, 'MyStack', { env: { region: 'us-east-1', account: '1234' } }); const vpc = mockVpc(stack); @@ -351,7 +351,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResourceLike('AWS::AutoScaling::AutoScalingGroup', { UpdatePolicy: { AutoScalingReplacingUpdate: { WillReplace: true, @@ -362,12 +362,12 @@ nodeunitShim({ MinSuccessfulInstancesPercent: 50, }, }, - }, ResourcePart.CompleteDefinition)); + }, ResourcePart.CompleteDefinition); - test.done(); - }, - 'can configure rolling update'(test: Test) { + }); + + test('can configure rolling update', () => { // GIVEN const stack = new cdk.Stack(undefined, 'MyStack', { env: { region: 'us-east-1', account: '1234' } }); const vpc = mockVpc(stack); @@ -385,7 +385,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResourceLike('AWS::AutoScaling::AutoScalingGroup', { UpdatePolicy: { 'AutoScalingRollingUpdate': { 'MinSuccessfulInstancesPercent': 50, @@ -394,12 +394,12 @@ nodeunitShim({ 'SuspendProcesses': ['HealthCheck', 'ReplaceUnhealthy', 'AZRebalance', 'AlarmNotification', 'ScheduledActions'], }, }, - }, ResourcePart.CompleteDefinition)); + }, ResourcePart.CompleteDefinition); - test.done(); - }, - 'can configure resource signals'(test: Test) { + }); + + test('can configure resource signals', () => { // GIVEN const stack = new cdk.Stack(undefined, 'MyStack', { env: { region: 'us-east-1', account: '1234' } }); const vpc = mockVpc(stack); @@ -414,19 +414,19 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResourceLike('AWS::AutoScaling::AutoScalingGroup', { CreationPolicy: { ResourceSignal: { Count: 5, Timeout: 'PT11M6S', }, }, - }, ResourcePart.CompleteDefinition)); + }, ResourcePart.CompleteDefinition); - test.done(); - }, - 'can configure EC2 health check'(test: Test) { + }); + + test('can configure EC2 health check', () => { // GIVEN const stack = new cdk.Stack(undefined, 'MyStack', { env: { region: 'us-east-1', account: '1234' } }); const vpc = mockVpc(stack); @@ -440,14 +440,14 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResourceLike('AWS::AutoScaling::AutoScalingGroup', { HealthCheckType: 'EC2', - })); + }); - test.done(); - }, - 'can configure EBS health check'(test: Test) { + }); + + test('can configure EBS health check', () => { // GIVEN const stack = new cdk.Stack(undefined, 'MyStack', { env: { region: 'us-east-1', account: '1234' } }); const vpc = mockVpc(stack); @@ -461,15 +461,15 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResourceLike('AWS::AutoScaling::AutoScalingGroup', { HealthCheckType: 'ELB', HealthCheckGracePeriod: 900, - })); + }); - test.done(); - }, - 'can add Security Group to Fleet'(test: Test) { + }); + + test('can add Security Group to Fleet', () => { // GIVEN const stack = new cdk.Stack(undefined, 'MyStack', { env: { region: 'us-east-1', account: '1234' } }); const vpc = mockVpc(stack); @@ -481,7 +481,7 @@ nodeunitShim({ vpc, }); asg.addSecurityGroup(mockSecurityGroup(stack)); - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { SecurityGroups: [ { 'Fn::GetAtt': [ @@ -491,11 +491,11 @@ nodeunitShim({ }, 'most-secure', ], - })); - test.done(); - }, + }); - 'can set tags'(test: Test) { + }); + + test('can set tags', () => { // GIVEN const stack = getTestStack(); // new cdk.Stack(undefined, 'MyStack', { env: { region: 'us-east-1', account: '1234' }}); @@ -517,7 +517,7 @@ nodeunitShim({ cdk.Tags.of(asg).add('notsuper', 'caramel', { applyToLaunchedInstances: false }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { Tags: [ { Key: 'Name', @@ -535,11 +535,11 @@ nodeunitShim({ Value: 'acai', }, ], - })); - test.done(); - }, + }); + + }); - 'allows setting spot price'(test: Test) { + test('allows setting spot price', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -554,15 +554,15 @@ nodeunitShim({ }); // THEN - test.deepEqual(asg.spotPrice, '0.05'); - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(asg.spotPrice).toEqual('0.05'); + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { SpotPrice: '0.05', - })); + }); + - test.done(); - }, + }); - 'allows association of public IP address'(test: Test) { + test('allows association of public IP address', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -581,20 +581,20 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { AssociatePublicIpAddress: true, }, - )); - test.done(); - }, + ); + + }); - 'association of public IP address requires public subnet'(test: Test) { + test('association of public IP address requires public subnet', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); // WHEN - test.throws(() => { + expect(() => { new autoscaling.AutoScalingGroup(stack, 'MyStack', { instanceType: ec2.InstanceType.of(ec2.InstanceClass.M4, ec2.InstanceSize.MICRO), machineImage: new ec2.AmazonLinuxImage(), @@ -604,11 +604,11 @@ nodeunitShim({ desiredCapacity: 0, associatePublicIpAddress: true, }); - }); - test.done(); - }, + }).toThrow(); + + }); - 'allows disassociation of public IP address'(test: Test) { + test('allows disassociation of public IP address', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -625,14 +625,14 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { AssociatePublicIpAddress: false, }, - )); - test.done(); - }, + ); - 'does not specify public IP address association by default'(test: Test) { + }); + + test('does not specify public IP address association by default', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -648,7 +648,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', (resource: any, errors: InspectionFailure) => { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', (resource: any, errors: InspectionFailure) => { for (const key of Object.keys(resource)) { if (key === 'AssociatePublicIpAddress') { errors.failureReason = 'Has AssociatePublicIpAddress'; @@ -656,11 +656,11 @@ nodeunitShim({ } } return true; - })); - test.done(); - }, + }); - 'an existing security group can be specified instead of auto-created'(test: Test) { + }); + + test('an existing security group can be specified instead of auto-created', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -675,14 +675,14 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { SecurityGroups: ['most-secure'], }, - )); - test.done(); - }, + ); + + }); - 'an existing role can be specified instead of auto-created'(test: Test) { + test('an existing role can be specified instead of auto-created', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -697,14 +697,14 @@ nodeunitShim({ }); // THEN - test.equal(asg.role, importedRole); - expect(stack).to(haveResource('AWS::IAM::InstanceProfile', { + expect(asg.role).toEqual(importedRole); + expect(stack).toHaveResource('AWS::IAM::InstanceProfile', { 'Roles': ['HelloDude'], - })); - test.done(); - }, + }); + + }); - 'defaultChild is available on an ASG'(test: Test) { + test('defaultChild is available on an ASG', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -715,12 +715,12 @@ nodeunitShim({ }); // THEN - test.ok(asg.node.defaultChild instanceof autoscaling.CfnAutoScalingGroup); + expect(asg.node.defaultChild instanceof autoscaling.CfnAutoScalingGroup).toEqual(true); + - test.done(); - }, + }); - 'can set blockDeviceMappings'(test: Test) { + test('can set blockDeviceMappings', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -758,7 +758,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { BlockDeviceMappings: [ { DeviceName: 'ebs', @@ -795,12 +795,12 @@ nodeunitShim({ NoDevice: true, }, ], - })); + }); - test.done(); - }, - 'can configure maxInstanceLifetime'(test: Test) { + }); + + test('can configure maxInstanceLifetime', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -812,50 +812,50 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { 'MaxInstanceLifetime': 604800, - })); + }); - test.done(); - }, - 'throws if maxInstanceLifetime < 7 days'(test: Test) { + }); + + test('throws if maxInstanceLifetime < 7 days', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); // THEN - test.throws(() => { + expect(() => { new autoscaling.AutoScalingGroup(stack, 'MyStack', { instanceType: ec2.InstanceType.of(ec2.InstanceClass.M4, ec2.InstanceSize.MICRO), machineImage: new ec2.AmazonLinuxImage(), vpc, maxInstanceLifetime: cdk.Duration.days(6), }); - }, /maxInstanceLifetime must be between 7 and 365 days \(inclusive\)/); + }).toThrow(/maxInstanceLifetime must be between 7 and 365 days \(inclusive\)/); - test.done(); - }, - 'throws if maxInstanceLifetime > 365 days'(test: Test) { + }); + + test('throws if maxInstanceLifetime > 365 days', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); // THEN - test.throws(() => { + expect(() => { new autoscaling.AutoScalingGroup(stack, 'MyStack', { instanceType: ec2.InstanceType.of(ec2.InstanceClass.M4, ec2.InstanceSize.MICRO), machineImage: new ec2.AmazonLinuxImage(), vpc, maxInstanceLifetime: cdk.Duration.days(366), }); - }, /maxInstanceLifetime must be between 7 and 365 days \(inclusive\)/); + }).toThrow(/maxInstanceLifetime must be between 7 and 365 days \(inclusive\)/); - test.done(); - }, - 'can configure instance monitoring'(test: Test) { + }); + + test('can configure instance monitoring', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -869,13 +869,13 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { InstanceMonitoring: false, - })); - test.done(); - }, + }); + + }); - 'instance monitoring defaults to absent'(test: Test) { + test('instance monitoring defaults to absent', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -888,19 +888,19 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { InstanceMonitoring: ABSENT, - })); - test.done(); - }, + }); + + }); - 'throws if ephemeral volumeIndex < 0'(test: Test) { + test('throws if ephemeral volumeIndex < 0', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); // THEN - test.throws(() => { + expect(() => { new autoscaling.AutoScalingGroup(stack, 'MyStack', { instanceType: ec2.InstanceType.of(ec2.InstanceClass.M4, ec2.InstanceSize.MICRO), machineImage: new ec2.AmazonLinuxImage(), @@ -910,18 +910,18 @@ nodeunitShim({ volume: autoscaling.BlockDeviceVolume.ephemeral(-1), }], }); - }, /volumeIndex must be a number starting from 0/); + }).toThrow(/volumeIndex must be a number starting from 0/); - test.done(); - }, - 'throws if volumeType === IO1 without iops'(test: Test) { + }); + + test('throws if volumeType === IO1 without iops', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); // THEN - test.throws(() => { + expect(() => { new autoscaling.AutoScalingGroup(stack, 'MyStack', { instanceType: ec2.InstanceType.of(ec2.InstanceClass.M4, ec2.InstanceSize.MICRO), machineImage: new ec2.AmazonLinuxImage(), @@ -935,12 +935,12 @@ nodeunitShim({ }), }], }); - }, /ops property is required with volumeType: EbsDeviceVolumeType.IO1/); + }).toThrow(/ops property is required with volumeType: EbsDeviceVolumeType.IO1/); - test.done(); - }, - 'warning if iops without volumeType'(test: Test) { + }); + + test('warning if iops without volumeType', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -960,13 +960,13 @@ nodeunitShim({ }); // THEN - test.deepEqual(asg.node.metadata[0].type, cxschema.ArtifactMetadataEntryType.WARN); - test.deepEqual(asg.node.metadata[0].data, 'iops will be ignored without volumeType: EbsDeviceVolumeType.IO1'); + expect(asg.node.metadata[0].type).toEqual(cxschema.ArtifactMetadataEntryType.WARN); + expect(asg.node.metadata[0].data).toEqual('iops will be ignored without volumeType: EbsDeviceVolumeType.IO1'); - test.done(); - }, - 'warning if iops and volumeType !== IO1'(test: Test) { + }); + + test('warning if iops and volumeType !== IO1', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -987,13 +987,13 @@ nodeunitShim({ }); // THEN - test.deepEqual(asg.node.metadata[0].type, cxschema.ArtifactMetadataEntryType.WARN); - test.deepEqual(asg.node.metadata[0].data, 'iops will be ignored without volumeType: EbsDeviceVolumeType.IO1'); + expect(asg.node.metadata[0].type).toEqual(cxschema.ArtifactMetadataEntryType.WARN); + expect(asg.node.metadata[0].data).toEqual('iops will be ignored without volumeType: EbsDeviceVolumeType.IO1'); + - test.done(); - }, + }); - 'step scaling on metric'(test: Test) { + test('step scaling on metric', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -1018,18 +1018,18 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::CloudWatch::Alarm', { + expect(stack).toHaveResource('AWS::CloudWatch::Alarm', { ComparisonOperator: 'LessThanOrEqualToThreshold', EvaluationPeriods: 1, MetricName: 'Metric', Namespace: 'Test', Period: 300, - })); + }); + - test.done(); - }, + }); - 'step scaling on MathExpression'(test: Test) { + test('step scaling on MathExpression', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -1059,11 +1059,11 @@ nodeunitShim({ }); // THEN - expect(stack).notTo(haveResource('AWS::CloudWatch::Alarm', { + expect(stack).not.toHaveResource('AWS::CloudWatch::Alarm', { Period: 60, - })); + }); - expect(stack).to(haveResource('AWS::CloudWatch::Alarm', { + expect(stack).toHaveResource('AWS::CloudWatch::Alarm', { 'ComparisonOperator': 'LessThanOrEqualToThreshold', 'EvaluationPeriods': 1, 'Metrics': [ @@ -1085,12 +1085,12 @@ nodeunitShim({ }, ], 'Threshold': 49, - })); + }); - test.done(); - }, - 'test GroupMetrics.all(), adds a single MetricsCollection with no Metrics specified'(test: Test) { + }); + + test('test GroupMetrics.all(), adds a single MetricsCollection with no Metrics specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -1103,18 +1103,18 @@ nodeunitShim({ }); // Then - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { MetricsCollection: [ { Granularity: '1Minute', Metrics: ABSENT, }, ], - })); - test.done(); - }, + }); + + }); - 'test can specify a subset of group metrics'(test: Test) { + test('test can specify a subset of group metrics', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -1138,7 +1138,7 @@ nodeunitShim({ }); // Then - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { MetricsCollection: [ { Granularity: '1Minute', @@ -1148,11 +1148,11 @@ nodeunitShim({ Metrics: ['GroupPendingInstances', 'GroupStandbyInstances', 'GroupTotalInstances', 'GroupTerminatingInstances'], }, ], - })); - test.done(); - }, + }); + + }); - 'test deduplication of group metrics '(test: Test) { + test('test deduplication of group metrics ', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -1168,18 +1168,18 @@ nodeunitShim({ }); // Then - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { MetricsCollection: [ { Granularity: '1Minute', Metrics: ['GroupMinSize', 'GroupMaxSize'], }, ], - })); - test.done(); - }, + }); + + }); - 'allow configuring notifications'(test: Test) { + test('allow configuring notifications', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -1203,7 +1203,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { NotificationConfigurations: [ { TopicARN: { Ref: 'MyTopic86869434' }, @@ -1220,19 +1220,19 @@ nodeunitShim({ }, ], }, - )); + ); - test.done(); - }, - 'throw if notification and notificationsTopics are both configured'(test: Test) { + }); + + test('throw if notification and notificationsTopics are both configured', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); const topic = new sns.Topic(stack, 'MyTopic'); // THEN - test.throws(() => { + expect(() => { new autoscaling.AutoScalingGroup(stack, 'MyASG', { instanceType: ec2.InstanceType.of(ec2.InstanceClass.M4, ec2.InstanceSize.MICRO), machineImage: new ec2.AmazonLinuxImage(), @@ -1242,11 +1242,11 @@ nodeunitShim({ topic, }], }); - }, 'Cannot set \'notificationsTopic\' and \'notifications\', \'notificationsTopic\' is deprecated use \'notifications\' instead'); - test.done(); - }, + }).toThrow('Cannot set \'notificationsTopic\' and \'notifications\', \'notificationsTopic\' is deprecated use \'notifications\' instead'); + + }); - 'notificationTypes default includes all non test NotificationType'(test: Test) { + test('notificationTypes default includes all non test NotificationType', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -1265,7 +1265,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { NotificationConfigurations: [ { TopicARN: { Ref: 'MyTopic86869434' }, @@ -1278,12 +1278,12 @@ nodeunitShim({ }, ], }, - )); + ); - test.done(); - }, - 'setting notificationTopic configures all non test NotificationType'(test: Test) { + }); + + test('setting notificationTopic configures all non test NotificationType', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -1298,7 +1298,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { NotificationConfigurations: [ { TopicARN: { Ref: 'MyTopic86869434' }, @@ -1311,17 +1311,17 @@ nodeunitShim({ }, ], }, - )); + ); + + + }); - test.done(); - }, + test('NotificationTypes.ALL includes all non test NotificationType', () => { + expect(Object.values(autoscaling.ScalingEvent).length - 1).toEqual(autoscaling.ScalingEvents.ALL._types.length); - 'NotificationTypes.ALL includes all non test NotificationType'(test: Test) { - test.deepEqual(Object.values(autoscaling.ScalingEvent).length - 1, autoscaling.ScalingEvents.ALL._types.length); - test.done(); - }, + }); - 'Can protect new instances from scale-in via constructor property'(test: Test) { + test('Can protect new instances from scale-in via constructor property', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -1335,15 +1335,15 @@ nodeunitShim({ }); // THEN - test.strictEqual(asg.areNewInstancesProtectedFromScaleIn(), true); - expect(stack).to(haveResourceLike('AWS::AutoScaling::AutoScalingGroup', { + expect(asg.areNewInstancesProtectedFromScaleIn()).toEqual(true); + expect(stack).toHaveResourceLike('AWS::AutoScaling::AutoScalingGroup', { NewInstancesProtectedFromScaleIn: true, - })); + }); - test.done(); - }, - 'Can protect new instances from scale-in via setter'(test: Test) { + }); + + test('Can protect new instances from scale-in via setter', () => { // GIVEN const stack = new cdk.Stack(); const vpc = mockVpc(stack); @@ -1357,13 +1357,13 @@ nodeunitShim({ asg.protectNewInstancesFromScaleIn(); // THEN - test.strictEqual(asg.areNewInstancesProtectedFromScaleIn(), true); - expect(stack).to(haveResourceLike('AWS::AutoScaling::AutoScalingGroup', { + expect(asg.areNewInstancesProtectedFromScaleIn()).toEqual(true); + expect(stack).toHaveResourceLike('AWS::AutoScaling::AutoScalingGroup', { NewInstancesProtectedFromScaleIn: true, - })); + }); - test.done(); - }, + + }); }); function mockVpc(stack: cdk.Stack) { @@ -1390,9 +1390,9 @@ test('Can set autoScalingGroupName', () => { }); // THEN - expect(stack).to(haveResourceLike('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResourceLike('AWS::AutoScaling::AutoScalingGroup', { AutoScalingGroupName: 'MyAsg', - })); + }); }); test('can use Vpc imported from unparseable list tokens', () => { @@ -1427,11 +1427,11 @@ test('can use Vpc imported from unparseable list tokens', () => { }); // THEN - expect(stack).to(haveResourceLike('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResourceLike('AWS::AutoScaling::AutoScalingGroup', { VPCZoneIdentifier: { 'Fn::Split': [',', { 'Fn::ImportValue': 'myPrivateSubnetIds' }], }, - })); + }); }); function mockSecurityGroup(stack: cdk.Stack) { diff --git a/packages/@aws-cdk/aws-autoscaling/test/cfn-init.test.ts b/packages/@aws-cdk/aws-autoscaling/test/cfn-init.test.ts index 58d9bc6ec152c..2fd252e5e459d 100644 --- a/packages/@aws-cdk/aws-autoscaling/test/cfn-init.test.ts +++ b/packages/@aws-cdk/aws-autoscaling/test/cfn-init.test.ts @@ -1,3 +1,4 @@ +import '@aws-cdk/assert-internal/jest'; import { anything, arrayWith, expect, haveResourceLike, ResourcePart } from '@aws-cdk/assert-internal'; import * as ec2 from '@aws-cdk/aws-ec2'; import { Duration, Stack } from '@aws-cdk/core'; diff --git a/packages/@aws-cdk/aws-autoscaling/test/lifecyclehooks.test.ts b/packages/@aws-cdk/aws-autoscaling/test/lifecyclehooks.test.ts index 24bebc1a605d0..7ebf6d18cbe6e 100644 --- a/packages/@aws-cdk/aws-autoscaling/test/lifecyclehooks.test.ts +++ b/packages/@aws-cdk/aws-autoscaling/test/lifecyclehooks.test.ts @@ -1,13 +1,13 @@ +import '@aws-cdk/assert-internal/jest'; import { expect, haveResource, ResourcePart } from '@aws-cdk/assert-internal'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as iam from '@aws-cdk/aws-iam'; import * as cdk from '@aws-cdk/core'; import * as constructs from 'constructs'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as autoscaling from '../lib'; -nodeunitShim({ - 'we can add a lifecycle hook to an ASG'(test: Test) { +describe('lifecycle hooks', () => { + test('we can add a lifecycle hook to an ASG', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'VPC'); @@ -67,8 +67,8 @@ nodeunitShim({ }, })); - test.done(); - }, + + }); }); class FakeNotificationTarget implements autoscaling.ILifecycleHookTarget { diff --git a/packages/@aws-cdk/aws-autoscaling/test/scaling.test.ts b/packages/@aws-cdk/aws-autoscaling/test/scaling.test.ts index 89b137dd5267f..8216968f406c1 100644 --- a/packages/@aws-cdk/aws-autoscaling/test/scaling.test.ts +++ b/packages/@aws-cdk/aws-autoscaling/test/scaling.test.ts @@ -1,19 +1,19 @@ +import '@aws-cdk/assert-internal/jest'; import { expect, haveResource, haveResourceLike } from '@aws-cdk/assert-internal'; import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2'; import * as cdk from '@aws-cdk/core'; import * as constructs from 'constructs'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as autoscaling from '../lib'; // keep this import separate from other imports to reduce chance for merge conflicts with v2-main // eslint-disable-next-line no-duplicate-imports, import/order import { Construct } from '@aws-cdk/core'; -nodeunitShim({ - 'target tracking policies': { - 'cpu utilization'(test: Test) { +describe('scaling', () => { + describe('target tracking policies', () => { + test('cpu utilization', () => { // GIVEN const stack = new cdk.Stack(); const fixture = new ASGFixture(stack, 'Fixture'); @@ -32,10 +32,10 @@ nodeunitShim({ }, })); - test.done(); - }, - 'network ingress'(test: Test) { + }); + + test('network ingress', () => { // GIVEN const stack = new cdk.Stack(); const fixture = new ASGFixture(stack, 'Fixture'); @@ -54,10 +54,10 @@ nodeunitShim({ }, })); - test.done(); - }, - 'network egress'(test: Test) { + }); + + test('network egress', () => { // GIVEN const stack = new cdk.Stack(); const fixture = new ASGFixture(stack, 'Fixture'); @@ -76,10 +76,10 @@ nodeunitShim({ }, })); - test.done(); - }, - 'request count per second'(test: Test) { + }); + + test('request count per second', () => { // GIVEN const stack = new cdk.Stack(); const fixture = new ASGFixture(stack, 'Fixture'); @@ -124,10 +124,10 @@ nodeunitShim({ }, })); - test.done(); - }, - 'request count per minute'(test: Test) { + }); + + test('request count per minute', () => { // GIVEN const stack = new cdk.Stack(); const fixture = new ASGFixture(stack, 'Fixture'); @@ -172,10 +172,10 @@ nodeunitShim({ }, })); - test.done(); - }, - 'custom metric'(test: Test) { + }); + + test('custom metric', () => { // GIVEN const stack = new cdk.Stack(); const fixture = new ASGFixture(stack, 'Fixture'); @@ -206,11 +206,11 @@ nodeunitShim({ }, })); - test.done(); - }, - }, - 'step scaling'(test: Test) { + }); + }); + + test('step scaling', () => { // GIVEN const stack = new cdk.Stack(); const fixture = new ASGFixture(stack, 'Fixture'); @@ -273,8 +273,8 @@ nodeunitShim({ AlarmDescription: 'Lower threshold scaling alarm', })); - test.done(); - }, + + }); }); test('step scaling from percentile metric', () => { diff --git a/packages/@aws-cdk/aws-autoscaling/test/scheduled-action.test.ts b/packages/@aws-cdk/aws-autoscaling/test/scheduled-action.test.ts index e5044af33543e..3afbd887b45ae 100644 --- a/packages/@aws-cdk/aws-autoscaling/test/scheduled-action.test.ts +++ b/packages/@aws-cdk/aws-autoscaling/test/scheduled-action.test.ts @@ -1,12 +1,12 @@ +import '@aws-cdk/assert-internal/jest'; import { expect, haveResource, MatchStyle } from '@aws-cdk/assert-internal'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as cdk from '@aws-cdk/core'; import * as constructs from 'constructs'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as autoscaling from '../lib'; -nodeunitShim({ - 'can schedule an action'(test: Test) { +describe('scheduled action', () => { + test('can schedule an action', () => { // GIVEN const stack = new cdk.Stack(); const asg = makeAutoScalingGroup(stack); @@ -23,10 +23,10 @@ nodeunitShim({ MinSize: 10, })); - test.done(); - }, - 'correctly formats date objects'(test: Test) { + }); + + test('correctly formats date objects', () => { // GIVEN const stack = new cdk.Stack(); const asg = makeAutoScalingGroup(stack); @@ -43,10 +43,10 @@ nodeunitShim({ StartTime: '2033-09-10T12:00:00Z', })); - test.done(); - }, - 'autoscaling group has recommended updatepolicy for scheduled actions'(test: Test) { + }); + + test('autoscaling group has recommended updatepolicy for scheduled actions', () => { // GIVEN const stack = new cdk.Stack(); const asg = makeAutoScalingGroup(stack); @@ -104,8 +104,8 @@ nodeunitShim({ }, }, MatchStyle.SUPERSET); - test.done(); - }, + + }); }); function makeAutoScalingGroup(scope: constructs.Construct) { diff --git a/packages/@aws-cdk/aws-codepipeline-actions/package.json b/packages/@aws-cdk/aws-codepipeline-actions/package.json index fafc221e72351..e2409aa86db6a 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/package.json +++ b/packages/@aws-cdk/aws-codepipeline-actions/package.json @@ -75,8 +75,8 @@ "@types/lodash": "^4.14.171", "cdk-build-tools": "0.0.0", "cdk-integ-tools": "0.0.0", + "jest": "^26.6.3", "lodash": "^4.17.21", - "nodeunit-shim": "0.0.0", "pkglint": "0.0.0", "@aws-cdk/assert-internal": "0.0.0" }, diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/bitbucket/bitbucket-source-action.test.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/bitbucket/bitbucket-source-action.test.ts index 74df86e395548..a4767fa1a61bc 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/bitbucket/bitbucket-source-action.test.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/bitbucket/bitbucket-source-action.test.ts @@ -1,22 +1,22 @@ -import { arrayWith, expect, haveResourceLike, objectLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; +import { arrayWith, objectLike } from '@aws-cdk/assert-internal'; import * as codebuild from '@aws-cdk/aws-codebuild'; import * as codepipeline from '@aws-cdk/aws-codepipeline'; import { Stack } from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as cpactions from '../../lib'; /* eslint-disable quote-props */ -nodeunitShim({ - 'BitBucket source Action': { - 'produces the correct configuration when added to a pipeline'(test: Test) { +describe('BitBucket source Action', () => { + describe('BitBucket source Action', () => { + test('produces the correct configuration when added to a pipeline', () => { const stack = new Stack(); createBitBucketAndCodeBuildPipeline(stack, { codeBuildCloneOutput: false, }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', @@ -44,20 +44,20 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, - }, + }); + }); - 'setting codeBuildCloneOutput=true adds permission to use the connection to the following CodeBuild Project'(test: Test) { + test('setting codeBuildCloneOutput=true adds permission to use the connection to the following CodeBuild Project', () => { const stack = new Stack(); createBitBucketAndCodeBuildPipeline(stack, { codeBuildCloneOutput: true, }); - expect(stack).to(haveResourceLike('AWS::IAM::Policy', { + expect(stack).toHaveResourceLike('AWS::IAM::Policy', { 'PolicyDocument': { 'Statement': [ { @@ -78,16 +78,16 @@ nodeunitShim({ }, ], }, - })); + }); + - test.done(); - }, - 'grant s3 putObjectACL to the following CodeBuild Project'(test: Test) { + }); + test('grant s3 putObjectACL to the following CodeBuild Project', () => { const stack = new Stack(); createBitBucketAndCodeBuildPipeline(stack, { codeBuildCloneOutput: true, }); - expect(stack).to(haveResourceLike('AWS::IAM::Policy', { + expect(stack).toHaveResourceLike('AWS::IAM::Policy', { 'PolicyDocument': { 'Statement': arrayWith( objectLike({ @@ -110,17 +110,17 @@ nodeunitShim({ }), ), }, - })); - test.done(); - }, - 'setting triggerOnPush=false reflects in the configuration'(test: Test) { + }); + + }); + test('setting triggerOnPush=false reflects in the configuration', () => { const stack = new Stack(); createBitBucketAndCodeBuildPipeline(stack, { triggerOnPush: false, }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', @@ -149,10 +149,10 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, + }); }); function createBitBucketAndCodeBuildPipeline(stack: Stack, props: Partial): void { diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/cloudformation-pipeline-actions.test.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/cloudformation-pipeline-actions.test.ts index e478ad7a97d21..955e54107789a 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/cloudformation-pipeline-actions.test.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/cloudformation-pipeline-actions.test.ts @@ -1,16 +1,15 @@ -import { expect, haveResourceLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as codebuild from '@aws-cdk/aws-codebuild'; import * as codecommit from '@aws-cdk/aws-codecommit'; import * as codepipeline from '@aws-cdk/aws-codepipeline'; import { PolicyStatement, Role, ServicePrincipal } from '@aws-cdk/aws-iam'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as cpactions from '../../lib'; /* eslint-disable quote-props */ -nodeunitShim({ - 'CreateChangeSetAction can be used to make a change set from a CodePipeline'(test: Test) { +describe('CloudFormation Pipeline Actions', () => { + test('CreateChangeSetAction can be used to make a change set from a CodePipeline', () => { const stack = new cdk.Stack(); const pipeline = new codepipeline.Pipeline(stack, 'MagicPipeline'); @@ -79,7 +78,7 @@ nodeunitShim({ ], }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'ArtifactStore': { 'Location': { 'Ref': 'MagicPipelineArtifactsBucket212FE7BF', @@ -193,13 +192,12 @@ nodeunitShim({ ], 'Name': 'prod', }], - })); + }); - test.done(); - }, + }); - 'fullPermissions leads to admin role and full IAM capabilities with pipeline bucket+key read permissions'(test: Test) { + test('fullPermissions leads to admin role and full IAM capabilities with pipeline bucket+key read permissions', () => { // GIVEN const stack = new TestFixture(); @@ -214,7 +212,7 @@ nodeunitShim({ const roleId = 'PipelineDeployCreateUpdateRole515CB7D4'; // THEN: Action in Pipeline has named IAM capabilities - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source' /* don't care about the rest */ }, { @@ -234,10 +232,10 @@ nodeunitShim({ ], }, ], - })); + }); // THEN: Role is created with full permissions - expect(stack).to(haveResourceLike('AWS::IAM::Policy', { + expect(stack).toHaveResourceLike('AWS::IAM::Policy', { PolicyDocument: { Version: '2012-10-17', Statement: [ @@ -264,12 +262,12 @@ nodeunitShim({ ], }, Roles: [{ Ref: roleId }], - })); + }); + - test.done(); - }, + }); - 'outputFileName leads to creation of output artifact'(test: Test) { + test('outputFileName leads to creation of output artifact', () => { // GIVEN const stack = new TestFixture(); @@ -283,7 +281,7 @@ nodeunitShim({ })); // THEN: Action has output artifacts - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source' /* don't care about the rest */ }, { @@ -296,12 +294,12 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, + }); - 'replaceOnFailure switches action type'(test: Test) { + test('replaceOnFailure switches action type', () => { // GIVEN const stack = new TestFixture(); @@ -315,7 +313,7 @@ nodeunitShim({ })); // THEN: Action has output artifacts - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source' /* don't care about the rest */ }, { @@ -330,12 +328,12 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, + }); - 'parameterOverrides are serialized as a string'(test: Test) { + test('parameterOverrides are serialized as a string', () => { // GIVEN const stack = new TestFixture(); @@ -351,7 +349,7 @@ nodeunitShim({ })); // THEN - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source' /* don't care about the rest */ }, { @@ -372,12 +370,12 @@ nodeunitShim({ ], }, ], - })); + }); - test.done(); - }, - 'Action service role is passed to template'(test: Test) { + }); + + test('Action service role is passed to template', () => { const stack = new TestFixture(); const importedRole = Role.fromRoleArn(stack, 'ImportedRole', 'arn:aws:iam::000000000000:role/action-role'); @@ -399,7 +397,7 @@ nodeunitShim({ stackName: 'magicStack', })); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', /* don't care about the rest */ @@ -423,12 +421,12 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, + }); - 'Single capability is passed to template'(test: Test) { + test('Single capability is passed to template', () => { // GIVEN const stack = new TestFixture(); @@ -446,7 +444,7 @@ nodeunitShim({ const roleId = 'PipelineDeployCreateUpdateRole515CB7D4'; // THEN: Action in Pipeline has named IAM capabilities - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source' /* don't care about the rest */ }, { @@ -466,12 +464,12 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, + }); - 'Multiple capabilities are passed to template'(test: Test) { + test('Multiple capabilities are passed to template', () => { // GIVEN const stack = new TestFixture(); @@ -490,7 +488,7 @@ nodeunitShim({ const roleId = 'PipelineDeployCreateUpdateRole515CB7D4'; // THEN: Action in Pipeline has named IAM and AUTOEXPAND capabilities - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source' /* don't care about the rest */ }, { @@ -510,12 +508,12 @@ nodeunitShim({ ], }, ], - })); + }); - test.done(); - }, - 'Empty capabilities is not passed to template'(test: Test) { + }); + + test('Empty capabilities is not passed to template', () => { // GIVEN const stack = new TestFixture(); @@ -533,7 +531,7 @@ nodeunitShim({ const roleId = 'PipelineDeployCreateUpdateRole515CB7D4'; // THEN: Action in Pipeline has no capabilities - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source' /* don't care about the rest */ }, { @@ -552,12 +550,12 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, + }); - 'can use CfnCapabilities from the core module'(test: Test) { + test('can use CfnCapabilities from the core module', () => { // GIVEN const stack = new TestFixture(); @@ -574,7 +572,7 @@ nodeunitShim({ })); // THEN: Action in Pipeline has named IAM and AUTOEXPAND capabilities - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source' /* don't care about the rest */ }, { @@ -594,13 +592,13 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, + }); - 'cross-account CFN Pipeline': { - 'correctly creates the deployment Role in the other account'(test: Test) { + describe('cross-account CFN Pipeline', () => { + test('correctly creates the deployment Role in the other account', () => { const app = new cdk.App(); const pipelineStack = new cdk.Stack(app, 'PipelineStack', { @@ -638,7 +636,7 @@ nodeunitShim({ ], }); - expect(pipelineStack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(pipelineStack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', @@ -662,10 +660,10 @@ nodeunitShim({ ], }, ], - })); + }); // the pipeline's BucketPolicy should trust both CFN roles - expect(pipelineStack).to(haveResourceLike('AWS::S3::BucketPolicy', { + expect(pipelineStack).toHaveResourceLike('AWS::S3::BucketPolicy', { 'PolicyDocument': { 'Statement': [ { @@ -698,19 +696,19 @@ nodeunitShim({ }, ], }, - })); + }); const otherStack = app.node.findChild('cross-account-support-stack-123456789012') as cdk.Stack; - expect(otherStack).to(haveResourceLike('AWS::IAM::Role', { + expect(otherStack).toHaveResourceLike('AWS::IAM::Role', { 'RoleName': 'pipelinestack-support-123loycfnactionrole56af64af3590f311bc50', - })); - expect(otherStack).to(haveResourceLike('AWS::IAM::Role', { + }); + expect(otherStack).toHaveResourceLike('AWS::IAM::Role', { 'RoleName': 'pipelinestack-support-123fndeploymentrole4668d9b5a30ce3dc4508', - })); + }); - test.done(); - }, - }, + + }); + }); }); /** diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/pipeline-actions.test.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/pipeline-actions.test.ts index 2e94273f6924c..3d9594a9ddfbd 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/pipeline-actions.test.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/pipeline-actions.test.ts @@ -1,3 +1,4 @@ +import '@aws-cdk/assert-internal/jest'; import * as codepipeline from '@aws-cdk/aws-codepipeline'; import * as notifications from '@aws-cdk/aws-codestarnotifications'; import * as events from '@aws-cdk/aws-events'; @@ -6,12 +7,11 @@ import * as s3 from '@aws-cdk/aws-s3'; import * as cdk from '@aws-cdk/core'; import * as constructs from 'constructs'; import * as _ from 'lodash'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as cpactions from '../../lib'; -nodeunitShim({ - CreateReplaceChangeSet: { - 'works'(test: Test) { +describe('Pipeline Actions', () => { + describe('CreateReplaceChangeSet', () => { + test('works', (done) => { const app = new cdk.App(); const stack = new cdk.Stack(app, 'Stack'); const pipelineRole = new RoleDouble(stack, 'PipelineRole'); @@ -30,29 +30,29 @@ nodeunitShim({ app.synth(); - _assertPermissionGranted(test, stack, pipelineRole.statements, 'iam:PassRole', action.deploymentRole.roleArn); + _assertPermissionGranted(done, stack, pipelineRole.statements, 'iam:PassRole', action.deploymentRole.roleArn); const stackArn = _stackArn('MyStack', stack); const changeSetCondition = { StringEqualsIfExists: { 'cloudformation:ChangeSetName': 'MyChangeSet' } }; - _assertPermissionGranted(test, stack, pipelineRole.statements, 'cloudformation:DescribeStacks', stackArn, changeSetCondition); - _assertPermissionGranted(test, stack, pipelineRole.statements, 'cloudformation:DescribeChangeSet', stackArn, changeSetCondition); - _assertPermissionGranted(test, stack, pipelineRole.statements, 'cloudformation:CreateChangeSet', stackArn, changeSetCondition); - _assertPermissionGranted(test, stack, pipelineRole.statements, 'cloudformation:DeleteChangeSet', stackArn, changeSetCondition); + _assertPermissionGranted(done, stack, pipelineRole.statements, 'cloudformation:DescribeStacks', stackArn, changeSetCondition); + _assertPermissionGranted(done, stack, pipelineRole.statements, 'cloudformation:DescribeChangeSet', stackArn, changeSetCondition); + _assertPermissionGranted(done, stack, pipelineRole.statements, 'cloudformation:CreateChangeSet', stackArn, changeSetCondition); + _assertPermissionGranted(done, stack, pipelineRole.statements, 'cloudformation:DeleteChangeSet', stackArn, changeSetCondition); // TODO: revert "as any" once we move all actions into a single package. - test.deepEqual(stage.fullActions[0].actionProperties.inputs, [artifact], - 'The input was correctly registered'); + expect(stage.fullActions[0].actionProperties.inputs).toEqual([artifact]); - _assertActionMatches(test, stack, stage.fullActions, 'CloudFormation', 'Deploy', { + _assertActionMatches(done, stack, stage.fullActions, 'CloudFormation', 'Deploy', { ActionMode: 'CHANGE_SET_CREATE_REPLACE', StackName: 'MyStack', ChangeSetName: 'MyChangeSet', }); - test.done(); - }, + done(); - 'uses a single permission statement if the same ChangeSet name is used'(test: Test) { + }); + + test('uses a single permission statement if the same ChangeSet name is used', () => { const stack = new cdk.Stack(); const pipelineRole = new RoleDouble(stack, 'PipelineRole'); const artifact = new codepipeline.Artifact('TestArtifact'); @@ -76,8 +76,9 @@ nodeunitShim({ ], }); - test.deepEqual( + expect( stack.resolve(pipelineRole.statements.map(s => s.toStatementJson())), + ).toEqual( [ { Action: 'iam:PassRole', @@ -106,12 +107,12 @@ nodeunitShim({ ], ); - test.done(); - }, - }, - ExecuteChangeSet: { - 'works'(test: Test) { + }); + }); + + describe('ExecuteChangeSet', () => { + test('works', (done) => { const stack = new cdk.Stack(); const pipelineRole = new RoleDouble(stack, 'PipelineRole'); const stage = new StageDouble({ @@ -126,19 +127,19 @@ nodeunitShim({ }); const stackArn = _stackArn('MyStack', stack); - _assertPermissionGranted(test, stack, pipelineRole.statements, 'cloudformation:ExecuteChangeSet', stackArn, + _assertPermissionGranted(done, stack, pipelineRole.statements, 'cloudformation:ExecuteChangeSet', stackArn, { StringEqualsIfExists: { 'cloudformation:ChangeSetName': 'MyChangeSet' } }); - _assertActionMatches(test, stack, stage.fullActions, 'CloudFormation', 'Deploy', { + _assertActionMatches(done, stack, stage.fullActions, 'CloudFormation', 'Deploy', { ActionMode: 'CHANGE_SET_EXECUTE', StackName: 'MyStack', ChangeSetName: 'MyChangeSet', }); - test.done(); - }, + done(); + }); - 'uses a single permission statement if the same ChangeSet name is used'(test: Test) { + test('uses a single permission statement if the same ChangeSet name is used', () => { const stack = new cdk.Stack(); const pipelineRole = new RoleDouble(stack, 'PipelineRole'); new StageDouble({ @@ -157,8 +158,9 @@ nodeunitShim({ ], }); - test.deepEqual( + expect( stack.resolve(pipelineRole.statements.map(s => s.toStatementJson())), + ).toEqual( [ { Action: [ @@ -178,11 +180,11 @@ nodeunitShim({ ], ); - test.done(); - }, - }, - 'the CreateUpdateStack Action sets the DescribeStack*, Create/Update/DeleteStack & PassRole permissions'(test: Test) { + }); + }); + + test('the CreateUpdateStack Action sets the DescribeStack*, Create/Update/DeleteStack & PassRole permissions', (done) => { const stack = new cdk.Stack(); const pipelineRole = new RoleDouble(stack, 'PipelineRole'); const action = new cpactions.CloudFormationCreateUpdateStackAction({ @@ -198,17 +200,17 @@ nodeunitShim({ }); const stackArn = _stackArn('MyStack', stack); - _assertPermissionGranted(test, stack, pipelineRole.statements, 'cloudformation:DescribeStack*', stackArn); - _assertPermissionGranted(test, stack, pipelineRole.statements, 'cloudformation:CreateStack', stackArn); - _assertPermissionGranted(test, stack, pipelineRole.statements, 'cloudformation:UpdateStack', stackArn); - _assertPermissionGranted(test, stack, pipelineRole.statements, 'cloudformation:DeleteStack', stackArn); + _assertPermissionGranted(done, stack, pipelineRole.statements, 'cloudformation:DescribeStack*', stackArn); + _assertPermissionGranted(done, stack, pipelineRole.statements, 'cloudformation:CreateStack', stackArn); + _assertPermissionGranted(done, stack, pipelineRole.statements, 'cloudformation:UpdateStack', stackArn); + _assertPermissionGranted(done, stack, pipelineRole.statements, 'cloudformation:DeleteStack', stackArn); - _assertPermissionGranted(test, stack, pipelineRole.statements, 'iam:PassRole', action.deploymentRole.roleArn); + _assertPermissionGranted(done, stack, pipelineRole.statements, 'iam:PassRole', action.deploymentRole.roleArn); - test.done(); - }, + done(); + }); - 'the DeleteStack Action sets the DescribeStack*, DeleteStack & PassRole permissions'(test: Test) { + test('the DeleteStack Action sets the DescribeStack*, DeleteStack & PassRole permissions', (done) => { const stack = new cdk.Stack(); const pipelineRole = new RoleDouble(stack, 'PipelineRole'); const action = new cpactions.CloudFormationDeleteStackAction({ @@ -222,13 +224,13 @@ nodeunitShim({ }); const stackArn = _stackArn('MyStack', stack); - _assertPermissionGranted(test, stack, pipelineRole.statements, 'cloudformation:DescribeStack*', stackArn); - _assertPermissionGranted(test, stack, pipelineRole.statements, 'cloudformation:DeleteStack', stackArn); + _assertPermissionGranted(done, stack, pipelineRole.statements, 'cloudformation:DescribeStack*', stackArn); + _assertPermissionGranted(done, stack, pipelineRole.statements, 'cloudformation:DeleteStack', stackArn); - _assertPermissionGranted(test, stack, pipelineRole.statements, 'iam:PassRole', action.deploymentRole.roleArn); + _assertPermissionGranted(done, stack, pipelineRole.statements, 'iam:PassRole', action.deploymentRole.roleArn); - test.done(); - }, + done(); + }); }); interface PolicyStatementJson { @@ -239,7 +241,7 @@ interface PolicyStatementJson { } function _assertActionMatches( - test: Test, + done: jest.DoneCallback, stack: cdk.Stack, actions: FullAction[], provider: string, @@ -256,8 +258,9 @@ function _assertActionMatches( configuration: stack.resolve(a.actionConfig.configuration), }), ), null, 2); - test.ok(_hasAction(stack, actions, provider, category, configuration), - `Expected to find an action with provider ${provider}, category ${category}${configurationStr}, but found ${actionsStr}`); + if (!_hasAction(stack, actions, provider, category, configuration)) { + done.fail(`Expected to find an action with provider ${provider}, category ${category}${configurationStr}, but found ${actionsStr}`); + } } function _hasAction( @@ -280,7 +283,7 @@ function _hasAction( } function _assertPermissionGranted( - test: Test, + done: jest.DoneCallback, stack: cdk.Stack, statements: iam.PolicyStatement[], action: string, @@ -291,8 +294,9 @@ function _assertPermissionGranted( : ''; const resolvedStatements = stack.resolve(statements.map(s => s.toStatementJson())); const statementsStr = JSON.stringify(resolvedStatements, null, 2); - test.ok(_grantsPermission(stack, resolvedStatements, action, resource, conditions), - `Expected to find a statement granting ${action} on ${JSON.stringify(stack.resolve(resource))}${conditionStr}, found:\n${statementsStr}`); + if (!_grantsPermission(stack, resolvedStatements, action, resource, conditions)) { + done.fail(`Expected to find a statement granting ${action} on ${JSON.stringify(stack.resolve(resource))}${conditionStr}, found:\n${statementsStr}`); + } } function _grantsPermission(stack: cdk.Stack, statements: PolicyStatementJson[], action: string, resource: string, conditions?: any) { diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/codebuild/codebuild-action.test.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/codebuild/codebuild-action.test.ts index 09b583c011513..c8ddc211a813d 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/codebuild/codebuild-action.test.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/codebuild/codebuild-action.test.ts @@ -1,19 +1,18 @@ -import { expect, haveResourceLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as codebuild from '@aws-cdk/aws-codebuild'; import * as codecommit from '@aws-cdk/aws-codecommit'; import * as codepipeline from '@aws-cdk/aws-codepipeline'; import * as s3 from '@aws-cdk/aws-s3'; import * as sns from '@aws-cdk/aws-sns'; import { App, SecretValue, Stack } from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as cpactions from '../../lib'; /* eslint-disable quote-props */ -nodeunitShim({ - 'CodeBuild action': { - 'that is cross-account and has outputs': { - 'causes an error'(test: Test) { +describe('CodeBuild Action', () => { + describe('CodeBuild action', () => { + describe('that is cross-account and has outputs', () => { + test('causes an error', () => { const app = new App(); const projectStack = new Stack(app, 'ProjectStack', { @@ -61,15 +60,15 @@ nodeunitShim({ outputs: [new codepipeline.Artifact()], }); - test.throws(() => { + expect(() => { buildStage.addAction(buildAction2); - }, /https:\/\/github\.com\/aws\/aws-cdk\/issues\/4169/); + }).toThrow(/https:\/\/github\.com\/aws\/aws-cdk\/issues\/4169/); - test.done(); - }, - }, - 'can be backed by an imported project'(test: Test) { + }); + }); + + test('can be backed by an imported project', () => { const stack = new Stack(); const codeBuildProject = codebuild.PipelineProject.fromProjectName(stack, 'CodeBuild', @@ -102,7 +101,7 @@ nodeunitShim({ ], }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', @@ -119,12 +118,12 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, + }); - 'exposes variables for other actions to consume'(test: Test) { + test('exposes variables for other actions to consume', () => { const stack = new Stack(); const sourceOutput = new codepipeline.Artifact(); @@ -177,7 +176,7 @@ nodeunitShim({ ], }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', @@ -198,12 +197,12 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, + }); - 'sets the BatchEnabled configuration'(test: Test) { + test('sets the BatchEnabled configuration', () => { const stack = new Stack(); const codeBuildProject = new codebuild.PipelineProject(stack, 'CodeBuild'); @@ -236,7 +235,7 @@ nodeunitShim({ ], }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', @@ -253,12 +252,12 @@ nodeunitShim({ ], }, ], - })); + }); - test.done(); - }, - 'sets the CombineArtifacts configuration'(test: Test) { + }); + + test('sets the CombineArtifacts configuration', () => { const stack = new Stack(); const codeBuildProject = new codebuild.PipelineProject(stack, 'CodeBuild'); @@ -292,7 +291,7 @@ nodeunitShim({ ], }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', @@ -310,13 +309,13 @@ nodeunitShim({ ], }, ], - })); + }); - test.done(); - }, - 'environment variables': { - 'should fail by default when added to a Pipeline while using a secret value in a plaintext variable'(test: Test) { + }); + + describe('environment variables', () => { + test('should fail by default when added to a Pipeline while using a secret value in a plaintext variable', () => { const stack = new Stack(); const sourceOutput = new codepipeline.Artifact(); @@ -350,14 +349,14 @@ nodeunitShim({ }, }); - test.throws(() => { + expect(() => { buildStage.addAction(buildAction); - }, /Plaintext environment variable 'X' contains a secret value!/); + }).toThrow(/Plaintext environment variable 'X' contains a secret value!/); - test.done(); - }, - "should allow opting out of the 'secret value in a plaintext variable' validation"(test: Test) { + }); + + test("should allow opting out of the 'secret value in a plaintext variable' validation", () => { const stack = new Stack(); const sourceOutput = new codepipeline.Artifact(); @@ -390,8 +389,8 @@ nodeunitShim({ ], }); - test.done(); - }, - }, - }, + + }); + }); + }); }); diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/codecommit/codecommit-source-action.test.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/codecommit/codecommit-source-action.test.ts index da226dd37a74d..648c113ce2155 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/codecommit/codecommit-source-action.test.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/codecommit/codecommit-source-action.test.ts @@ -1,4 +1,5 @@ -import { ABSENT, arrayWith, countResources, expect, haveResourceLike, not, objectLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; +import { ABSENT, arrayWith, objectLike } from '@aws-cdk/assert-internal'; import * as codebuild from '@aws-cdk/aws-codebuild'; import * as codecommit from '@aws-cdk/aws-codecommit'; import * as codepipeline from '@aws-cdk/aws-codepipeline'; @@ -6,19 +7,18 @@ import * as iam from '@aws-cdk/aws-iam'; import * as kms from '@aws-cdk/aws-kms'; import * as s3 from '@aws-cdk/aws-s3'; import { Stack, Lazy, App } from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as cpactions from '../../lib'; /* eslint-disable quote-props */ -nodeunitShim({ - 'CodeCommit Source Action': { - 'by default does not poll for source changes and uses Events'(test: Test) { +describe('CodeCommit Source Action', () => { + describe('CodeCommit Source Action', () => { + test('by default does not poll for source changes and uses Events', () => { const stack = new Stack(); minimalPipeline(stack, undefined); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Actions': [ @@ -31,14 +31,14 @@ nodeunitShim({ }, {}, ], - })); + }); + + expect(stack).toCountResources('AWS::Events::Rule', 1); - expect(stack).to(countResources('AWS::Events::Rule', 1)); - test.done(); - }, + }); - 'cross-account CodeCommit Repository Source does not use target role in source stack'(test: Test) { + test('cross-account CodeCommit Repository Source does not use target role in source stack', () => { // Test for https://github.com/aws/aws-cdk/issues/15639 const app = new App(); const sourceStack = new Stack(app, 'SourceStack', { env: { account: '1234', region: 'north-pole' } }); @@ -67,7 +67,7 @@ nodeunitShim({ }); // THEN - creates a Rule in the source stack targeting the pipeline stack's event bus using a generated role - expect(sourceStack).to(haveResourceLike('AWS::Events::Rule', { + expect(sourceStack).toHaveResourceLike('AWS::Events::Rule', { EventPattern: { source: ['aws.codecommit'], resources: [ @@ -84,10 +84,10 @@ nodeunitShim({ ]], }, }], - })); + }); // THEN - creates a Rule in the pipeline stack using the role to start the pipeline - expect(targetStack).to(haveResourceLike('AWS::Events::Rule', { + expect(targetStack).toHaveResourceLike('AWS::Events::Rule', { 'EventPattern': { 'source': [ 'aws.codecommit', @@ -118,17 +118,17 @@ nodeunitShim({ 'RoleArn': { 'Fn::GetAtt': ['MyPipelineEventsRoleFAB99F32', 'Arn'] }, }, ], - })); + }); + - test.done(); - }, + }); - 'does not poll for source changes and uses Events for CodeCommitTrigger.EVENTS'(test: Test) { + test('does not poll for source changes and uses Events for CodeCommitTrigger.EVENTS', () => { const stack = new Stack(); minimalPipeline(stack, cpactions.CodeCommitTrigger.EVENTS); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Actions': [ @@ -141,19 +141,19 @@ nodeunitShim({ }, {}, ], - })); + }); - expect(stack).to(countResources('AWS::Events::Rule', 1)); + expect(stack).toCountResources('AWS::Events::Rule', 1); - test.done(); - }, - 'polls for source changes and does not use Events for CodeCommitTrigger.POLL'(test: Test) { + }); + + test('polls for source changes and does not use Events for CodeCommitTrigger.POLL', () => { const stack = new Stack(); minimalPipeline(stack, cpactions.CodeCommitTrigger.POLL); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Actions': [ @@ -166,19 +166,19 @@ nodeunitShim({ }, {}, ], - })); + }); - expect(stack).to(not(haveResourceLike('AWS::Events::Rule'))); + expect(stack).not.toHaveResourceLike('AWS::Events::Rule'); - test.done(); - }, - 'does not poll for source changes and does not use Events for CodeCommitTrigger.NONE'(test: Test) { + }); + + test('does not poll for source changes and does not use Events for CodeCommitTrigger.NONE', () => { const stack = new Stack(); minimalPipeline(stack, cpactions.CodeCommitTrigger.NONE); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Actions': [ @@ -191,32 +191,32 @@ nodeunitShim({ }, {}, ], - })); + }); + + expect(stack).not.toHaveResourceLike('AWS::Events::Rule'); - expect(stack).to(not(haveResourceLike('AWS::Events::Rule'))); - test.done(); - }, + }); - 'cannot be created with an empty branch'(test: Test) { + test('cannot be created with an empty branch', () => { const stack = new Stack(); const repo = new codecommit.Repository(stack, 'MyRepo', { repositoryName: 'my-repo', }); - test.throws(() => { + expect(() => { new cpactions.CodeCommitSourceAction({ actionName: 'Source2', repository: repo, output: new codepipeline.Artifact(), branch: '', }); - }, /'branch' parameter cannot be an empty string/); + }).toThrow(/'branch' parameter cannot be an empty string/); + - test.done(); - }, + }); - 'allows using the same repository multiple times with different branches when trigger=EVENTS'(test: Test) { + test('allows using the same repository multiple times with different branches when trigger=EVENTS', () => { const stack = new Stack(); const repo = new codecommit.Repository(stack, 'MyRepo', { @@ -255,10 +255,10 @@ nodeunitShim({ ], }); - test.done(); - }, - 'exposes variables for other actions to consume'(test: Test) { + }); + + test('exposes variables for other actions to consume', () => { const stack = new Stack(); const sourceOutput = new codepipeline.Artifact(); @@ -291,7 +291,7 @@ nodeunitShim({ ], }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', @@ -308,12 +308,12 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, + }); - 'allows using a Token for the branch name'(test: Test) { + test('allows using a Token for the branch name', () => { const stack = new Stack(); const sourceOutput = new codepipeline.Artifact(); @@ -345,18 +345,18 @@ nodeunitShim({ ], }); - expect(stack).to(haveResourceLike('AWS::Events::Rule', { + expect(stack).toHaveResourceLike('AWS::Events::Rule', { EventPattern: { detail: { referenceName: ['my-branch'], }, }, - })); + }); + - test.done(); - }, + }); - 'allows to enable full clone'(test: Test) { + test('allows to enable full clone', () => { const stack = new Stack(); const sourceOutput = new codepipeline.Artifact(); @@ -389,7 +389,7 @@ nodeunitShim({ ], }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', @@ -408,9 +408,9 @@ nodeunitShim({ ], }, ], - })); + }); - expect(stack).to(haveResourceLike('AWS::IAM::Policy', { + expect(stack).toHaveResourceLike('AWS::IAM::Policy', { 'PolicyDocument': { 'Statement': arrayWith( objectLike({ @@ -432,9 +432,9 @@ nodeunitShim({ }), ), }, - })); + }); - expect(stack).to(haveResourceLike('AWS::IAM::Policy', { + expect(stack).toHaveResourceLike('AWS::IAM::Policy', { 'PolicyDocument': { 'Statement': arrayWith( objectLike({ @@ -456,12 +456,12 @@ nodeunitShim({ }), ), }, - })); + }); + - test.done(); - }, + }); - 'uses the role when passed'(test: Test) { + test('uses the role when passed', () => { const stack = new Stack(); const pipeline = new codepipeline.Pipeline(stack, 'P', { @@ -504,7 +504,7 @@ nodeunitShim({ actions: [buildAction], }); - expect(stack).to(haveResourceLike('AWS::Events::Rule', { + expect(stack).toHaveResourceLike('AWS::Events::Rule', { Targets: [ { Arn: stack.resolve(pipeline.pipelineArn), @@ -512,12 +512,12 @@ nodeunitShim({ RoleArn: stack.resolve(triggerEventTestRole.roleArn), }, ], - })); + }); + - test.done(); - }, + }); - 'grants explicit s3:PutObjectAcl permissions when the Actions is cross-account'(test: Test) { + test('grants explicit s3:PutObjectAcl permissions when the Actions is cross-account', () => { const app = new App(); const repoStack = new Stack(app, 'RepoStack', { @@ -552,7 +552,7 @@ nodeunitShim({ ], }); - expect(repoStack).to(haveResourceLike('AWS::IAM::Policy', { + expect(repoStack).toHaveResourceLike('AWS::IAM::Policy', { PolicyDocument: { Statement: arrayWith({ 'Action': 's3:PutObjectAcl', @@ -566,11 +566,11 @@ nodeunitShim({ }, }), }, - })); + }); - test.done(); - }, - }, + + }); + }); }); function minimalPipeline(stack: Stack, trigger: cpactions.CodeCommitTrigger | undefined): codepipeline.Pipeline { diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/codedeploy/ecs-deploy-action.test.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/codedeploy/ecs-deploy-action.test.ts index 30a1d4827b091..18a0c714f4d5b 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/codedeploy/ecs-deploy-action.test.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/codedeploy/ecs-deploy-action.test.ts @@ -1,13 +1,12 @@ -import { expect, haveResourceLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as codedeploy from '@aws-cdk/aws-codedeploy'; import * as codepipeline from '@aws-cdk/aws-codepipeline'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as cpactions from '../../lib'; -nodeunitShim({ - 'CodeDeploy ECS Deploy Action': { - 'throws an exception if more than 4 container image inputs are provided'(test: Test) { +describe('CodeDeploy ECS Deploy Action', () => { + describe('CodeDeploy ECS Deploy Action', () => { + test('throws an exception if more than 4 container image inputs are provided', () => { const stack = new cdk.Stack(); const deploymentGroup = addEcsDeploymentGroup(stack); const artifact = new codepipeline.Artifact('Artifact'); @@ -19,7 +18,7 @@ nodeunitShim({ }); } - test.throws(() => { + expect(() => { new cpactions.CodeDeployEcsDeployAction({ actionName: 'DeployToECS', deploymentGroup, @@ -27,18 +26,18 @@ nodeunitShim({ appSpecTemplateInput: artifact, containerImageInputs, }); - }, /Action cannot have more than 4 container image inputs, got: 5/); + }).toThrow(/Action cannot have more than 4 container image inputs, got: 5/); - test.done(); - }, - 'throws an exception if both appspec artifact input and file are specified'(test: Test) { + }); + + test('throws an exception if both appspec artifact input and file are specified', () => { const stack = new cdk.Stack(); const deploymentGroup = addEcsDeploymentGroup(stack); const artifact = new codepipeline.Artifact('Artifact'); const artifactPath = new codepipeline.ArtifactPath(artifact, 'hello'); - test.throws(() => { + expect(() => { new cpactions.CodeDeployEcsDeployAction({ actionName: 'DeployToECS', deploymentGroup, @@ -46,34 +45,34 @@ nodeunitShim({ appSpecTemplateInput: artifact, appSpecTemplateFile: artifactPath, }); - }, /Exactly one of 'appSpecTemplateInput' or 'appSpecTemplateFile' can be provided in the ECS CodeDeploy Action/); + }).toThrow(/Exactly one of 'appSpecTemplateInput' or 'appSpecTemplateFile' can be provided in the ECS CodeDeploy Action/); - test.done(); - }, - 'throws an exception if neither appspec artifact input nor file are specified'(test: Test) { + }); + + test('throws an exception if neither appspec artifact input nor file are specified', () => { const stack = new cdk.Stack(); const deploymentGroup = addEcsDeploymentGroup(stack); const artifact = new codepipeline.Artifact('Artifact'); - test.throws(() => { + expect(() => { new cpactions.CodeDeployEcsDeployAction({ actionName: 'DeployToECS', deploymentGroup, taskDefinitionTemplateInput: artifact, }); - }, /Specifying one of 'appSpecTemplateInput' or 'appSpecTemplateFile' is required for the ECS CodeDeploy Action/); + }).toThrow(/Specifying one of 'appSpecTemplateInput' or 'appSpecTemplateFile' is required for the ECS CodeDeploy Action/); - test.done(); - }, - 'throws an exception if both task definition artifact input and file are specified'(test: Test) { + }); + + test('throws an exception if both task definition artifact input and file are specified', () => { const stack = new cdk.Stack(); const deploymentGroup = addEcsDeploymentGroup(stack); const artifact = new codepipeline.Artifact('Artifact'); const artifactPath = new codepipeline.ArtifactPath(artifact, 'hello'); - test.throws(() => { + expect(() => { new cpactions.CodeDeployEcsDeployAction({ actionName: 'DeployToECS', deploymentGroup, @@ -81,28 +80,28 @@ nodeunitShim({ taskDefinitionTemplateFile: artifactPath, appSpecTemplateInput: artifact, }); - }, /Exactly one of 'taskDefinitionTemplateInput' or 'taskDefinitionTemplateFile' can be provided in the ECS CodeDeploy Action/); + }).toThrow(/Exactly one of 'taskDefinitionTemplateInput' or 'taskDefinitionTemplateFile' can be provided in the ECS CodeDeploy Action/); + - test.done(); - }, + }); - 'throws an exception if neither task definition artifact input nor file are specified'(test: Test) { + test('throws an exception if neither task definition artifact input nor file are specified', () => { const stack = new cdk.Stack(); const deploymentGroup = addEcsDeploymentGroup(stack); const artifact = new codepipeline.Artifact('Artifact'); - test.throws(() => { + expect(() => { new cpactions.CodeDeployEcsDeployAction({ actionName: 'DeployToECS', deploymentGroup, appSpecTemplateInput: artifact, }); - }, /Specifying one of 'taskDefinitionTemplateInput' or 'taskDefinitionTemplateFile' is required for the ECS CodeDeploy Action/); + }).toThrow(/Specifying one of 'taskDefinitionTemplateInput' or 'taskDefinitionTemplateFile' is required for the ECS CodeDeploy Action/); - test.done(); - }, - 'defaults task definition and appspec template paths'(test: Test) { + }); + + test('defaults task definition and appspec template paths', () => { const stack = new cdk.Stack(); const deploymentGroup = addEcsDeploymentGroup(stack); addCodeDeployECSCodePipeline(stack, { @@ -112,7 +111,7 @@ nodeunitShim({ appSpecTemplateInput: new codepipeline.Artifact('AppSpecArtifact'), }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { Stages: [ {}, { @@ -138,12 +137,12 @@ nodeunitShim({ ], }, ], - })); + }); - test.done(); - }, - 'defaults task definition placeholder string'(test: Test) { + }); + + test('defaults task definition placeholder string', () => { const stack = new cdk.Stack(); const deploymentGroup = addEcsDeploymentGroup(stack); const artifact1 = new codepipeline.Artifact(); @@ -163,7 +162,7 @@ nodeunitShim({ ], }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { Stages: [ {}, { @@ -193,11 +192,11 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, - }, + }); + }); }); function addEcsDeploymentGroup(stack: cdk.Stack): codedeploy.IEcsDeploymentGroup { diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/codestar-connections/codestar-connections-source-action.test.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/codestar-connections/codestar-connections-source-action.test.ts index 367da1e11ed3f..75fe764109b25 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/codestar-connections/codestar-connections-source-action.test.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/codestar-connections/codestar-connections-source-action.test.ts @@ -1,22 +1,22 @@ -import { arrayWith, expect, haveResourceLike, objectLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; +import { arrayWith, objectLike } from '@aws-cdk/assert-internal'; import * as codebuild from '@aws-cdk/aws-codebuild'; import * as codepipeline from '@aws-cdk/aws-codepipeline'; import { Stack } from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as cpactions from '../../lib'; /* eslint-disable quote-props */ -nodeunitShim({ - 'CodeStar Connections source Action': { - 'produces the correct configuration when added to a pipeline'(test: Test) { +describe('CodeStar Connections source Action', () => { + describe('CodeStar Connections source Action', () => { + test('produces the correct configuration when added to a pipeline', () => { const stack = new Stack(); createBitBucketAndCodeBuildPipeline(stack, { codeBuildCloneOutput: false, }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', @@ -44,20 +44,20 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, - }, + }); + }); - 'setting codeBuildCloneOutput=true adds permission to use the connection to the following CodeBuild Project'(test: Test) { + test('setting codeBuildCloneOutput=true adds permission to use the connection to the following CodeBuild Project', () => { const stack = new Stack(); createBitBucketAndCodeBuildPipeline(stack, { codeBuildCloneOutput: true, }); - expect(stack).to(haveResourceLike('AWS::IAM::Policy', { + expect(stack).toHaveResourceLike('AWS::IAM::Policy', { 'PolicyDocument': { 'Statement': [ { @@ -78,19 +78,19 @@ nodeunitShim({ }, ], }, - })); + }); + - test.done(); - }, + }); - 'grant s3 putObjectACL to the following CodeBuild Project'(test: Test) { + test('grant s3 putObjectACL to the following CodeBuild Project', () => { const stack = new Stack(); createBitBucketAndCodeBuildPipeline(stack, { codeBuildCloneOutput: true, }); - expect(stack).to(haveResourceLike('AWS::IAM::Policy', { + expect(stack).toHaveResourceLike('AWS::IAM::Policy', { 'PolicyDocument': { 'Statement': arrayWith( objectLike({ @@ -105,19 +105,19 @@ nodeunitShim({ }), ), }, - })); + }); + - test.done(); - }, + }); - 'setting triggerOnPush=false reflects in the configuration'(test: Test) { + test('setting triggerOnPush=false reflects in the configuration', () => { const stack = new Stack(); createBitBucketAndCodeBuildPipeline(stack, { triggerOnPush: false, }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', @@ -146,10 +146,10 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, + }); }); function createBitBucketAndCodeBuildPipeline(stack: Stack, props: Partial): void { diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/ecr/ecr-source-action.test.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/ecr/ecr-source-action.test.ts index aecf6cb915f04..b51a566d4ef14 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/ecr/ecr-source-action.test.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/ecr/ecr-source-action.test.ts @@ -1,16 +1,15 @@ -import { expect, haveResourceLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as codebuild from '@aws-cdk/aws-codebuild'; import * as codepipeline from '@aws-cdk/aws-codepipeline'; import * as ecr from '@aws-cdk/aws-ecr'; import { Stack } from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as cpactions from '../../lib'; /* eslint-disable quote-props */ -nodeunitShim({ - 'ECR source Action': { - 'exposes variables for other actions to consume'(test: Test) { +describe('ecr source action', () => { + describe('ECR source Action', () => { + test('exposes variables for other actions to consume', () => { const stack = new Stack(); const sourceOutput = new codepipeline.Artifact(); @@ -41,7 +40,7 @@ nodeunitShim({ ], }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', @@ -58,9 +57,9 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, - }, + }); + }); }); diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/ecs/ecs-deploy-action.test.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/ecs/ecs-deploy-action.test.ts index 3cdc12554d501..63927d5832ec8 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/ecs/ecs-deploy-action.test.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/ecs/ecs-deploy-action.test.ts @@ -1,124 +1,123 @@ -import { expect, haveResourceLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as codepipeline from '@aws-cdk/aws-codepipeline'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as ecs from '@aws-cdk/aws-ecs'; import * as s3 from '@aws-cdk/aws-s3'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as cpactions from '../../lib'; -nodeunitShim({ - 'ECS deploy Action': { - 'throws an exception if neither inputArtifact nor imageFile were provided'(test: Test) { +describe('ecs deploy action', () => { + describe('ECS deploy Action', () => { + test('throws an exception if neither inputArtifact nor imageFile were provided', () => { const service = anyEcsService(); - test.throws(() => { + expect(() => { new cpactions.EcsDeployAction({ actionName: 'ECS', service, }); - }, /one of 'input' or 'imageFile' is required/); + }).toThrow(/one of 'input' or 'imageFile' is required/); - test.done(); - }, - 'can be created just by specifying the inputArtifact'(test: Test) { + }); + + test('can be created just by specifying the inputArtifact', () => { const service = anyEcsService(); const artifact = new codepipeline.Artifact('Artifact'); - test.doesNotThrow(() => { + expect(() => { new cpactions.EcsDeployAction({ actionName: 'ECS', service, input: artifact, }); - }); + }).not.toThrow(); - test.done(); - }, - 'can be created just by specifying the imageFile'(test: Test) { + }); + + test('can be created just by specifying the imageFile', () => { const service = anyEcsService(); const artifact = new codepipeline.Artifact('Artifact'); - test.doesNotThrow(() => { + expect(() => { new cpactions.EcsDeployAction({ actionName: 'ECS', service, imageFile: artifact.atPath('imageFile.json'), }); - }); + }).not.toThrow(); - test.done(); - }, - 'throws an exception if both inputArtifact and imageFile were provided'(test: Test) { + }); + + test('throws an exception if both inputArtifact and imageFile were provided', () => { const service = anyEcsService(); const artifact = new codepipeline.Artifact('Artifact'); - test.throws(() => { + expect(() => { new cpactions.EcsDeployAction({ actionName: 'ECS', service, input: artifact, imageFile: artifact.atPath('file.json'), }); - }, /one of 'input' or 'imageFile' can be provided/); + }).toThrow(/one of 'input' or 'imageFile' can be provided/); + - test.done(); - }, + }); - 'can be created with deploymentTimeout between 1-60 minutes'(test: Test) { + test('can be created with deploymentTimeout between 1-60 minutes', () => { const service = anyEcsService(); const artifact = new codepipeline.Artifact('Artifact'); - test.doesNotThrow(() => { + expect(() => { new cpactions.EcsDeployAction({ actionName: 'ECS', service, input: artifact, deploymentTimeout: cdk.Duration.minutes(30), }); - }); + }).not.toThrow(); - test.done(); - }, - 'throws an exception if deploymentTimeout is out of bounds'(test: Test) { + }); + + test('throws an exception if deploymentTimeout is out of bounds', () => { const service = anyEcsService(); const artifact = new codepipeline.Artifact('Artifact'); - test.throws(() => { + expect(() => { new cpactions.EcsDeployAction({ actionName: 'ECS', service, input: artifact, deploymentTimeout: cdk.Duration.minutes(61), }); - }, /timeout must be between 1 and 60 minutes/); + }).toThrow(/timeout must be between 1 and 60 minutes/); - test.throws(() => { + expect(() => { new cpactions.EcsDeployAction({ actionName: 'ECS', service, input: artifact, deploymentTimeout: cdk.Duration.minutes(0), }); - }, /timeout must be between 1 and 60 minutes/); + }).toThrow(/timeout must be between 1 and 60 minutes/); - test.throws(() => { + expect(() => { new cpactions.EcsDeployAction({ actionName: 'ECS', service, input: artifact, deploymentTimeout: cdk.Duration.seconds(30), }); - }, /cannot be converted into a whole number/); + }).toThrow(/cannot be converted into a whole number/); + - test.done(); - }, + }); - "sets the target service as the action's backing resource"(test: Test) { + test("sets the target service as the action's backing resource", () => { const service = anyEcsService(); const artifact = new codepipeline.Artifact('Artifact'); @@ -128,12 +127,12 @@ nodeunitShim({ input: artifact, }); - test.equal(action.actionProperties.resource, service); + expect(action.actionProperties.resource).toEqual(service); + - test.done(); - }, + }); - 'can be created by existing service'(test: Test) { + test('can be created by existing service', () => { const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'Vpc'); const service = ecs.FargateService.fromFargateServiceAttributes(stack, 'FargateService', { @@ -173,7 +172,7 @@ nodeunitShim({ ], }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { Stages: [ {}, { @@ -193,11 +192,11 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, - }, + }); + }); }); function anyEcsService(): ecs.FargateService { diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/github/github-source-action.test.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/github/github-source-action.test.ts index 635f7ac67780f..6a1342888042e 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/github/github-source-action.test.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/github/github-source-action.test.ts @@ -1,15 +1,15 @@ -import { expect, haveResourceLike, SynthUtils } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; +import { SynthUtils } from '@aws-cdk/assert-internal'; import * as codebuild from '@aws-cdk/aws-codebuild'; import * as codepipeline from '@aws-cdk/aws-codepipeline'; import { SecretValue, Stack } from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as cpactions from '../../lib'; /* eslint-disable quote-props */ -nodeunitShim({ - 'GitHub source Action': { - 'exposes variables for other actions to consume'(test: Test) { +describe('Github source action', () => { + describe('GitHub source Action', () => { + test('exposes variables for other actions to consume', () => { const stack = new Stack(); const sourceOutput = new codepipeline.Artifact(); @@ -42,7 +42,7 @@ nodeunitShim({ ], }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', @@ -59,12 +59,12 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, + }); - 'always renders the customer-supplied namespace, even if none of the variables are used'(test: Test) { + test('always renders the customer-supplied namespace, even if none of the variables are used', () => { const stack = new Stack(); const sourceOutput = new codepipeline.Artifact(); @@ -96,7 +96,7 @@ nodeunitShim({ ], }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', @@ -110,12 +110,12 @@ nodeunitShim({ { }, ], - })); + }); - test.done(); - }, - 'fails if a variable from an action without a namespace set that is not part of a pipeline is referenced'(test: Test) { + }); + + test('fails if a variable from an action without a namespace set that is not part of a pipeline is referenced', () => { const stack = new Stack(); const unusedSourceAction = new cpactions.GitHubSourceAction({ @@ -154,14 +154,14 @@ nodeunitShim({ ], }); - test.throws(() => { + expect(() => { SynthUtils.synthesize(stack); - }, /Cannot reference variables of action 'Source2', as that action was never added to a pipeline/); + }).toThrow(/Cannot reference variables of action 'Source2', as that action was never added to a pipeline/); + - test.done(); - }, + }); - 'fails if a variable from an action with a namespace set that is not part of a pipeline is referenced'(test: Test) { + test('fails if a variable from an action with a namespace set that is not part of a pipeline is referenced', () => { const stack = new Stack(); const unusedSourceAction = new cpactions.GitHubSourceAction({ @@ -201,11 +201,11 @@ nodeunitShim({ ], }); - test.throws(() => { + expect(() => { SynthUtils.synthesize(stack); - }, /Cannot reference variables of action 'Source2', as that action was never added to a pipeline/); + }).toThrow(/Cannot reference variables of action 'Source2', as that action was never added to a pipeline/); + - test.done(); - }, - }, + }); + }); }); diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/manual-approval.test.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/manual-approval.test.ts index 93b4dc1134160..bf894a5db1c88 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/manual-approval.test.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/manual-approval.test.ts @@ -1,16 +1,15 @@ -import { expect, haveResourceLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as codepipeline from '@aws-cdk/aws-codepipeline'; import * as iam from '@aws-cdk/aws-iam'; import * as sns from '@aws-cdk/aws-sns'; import { SecretValue, Stack } from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as cpactions from '../lib'; /* eslint-disable quote-props */ -nodeunitShim({ - 'manual approval Action': { - 'allows passing an SNS Topic when constructing it'(test: Test) { +describe('manual approval', () => { + describe('manual approval Action', () => { + test('allows passing an SNS Topic when constructing it', () => { const stack = new Stack(); const topic = new sns.Topic(stack, 'Topic'); const manualApprovalAction = new cpactions.ManualApprovalAction({ @@ -21,12 +20,12 @@ nodeunitShim({ const stage = pipeline.addStage({ stageName: 'stage' }); stage.addAction(manualApprovalAction); - test.equal(manualApprovalAction.notificationTopic, topic); + expect(manualApprovalAction.notificationTopic).toEqual(topic); - test.done(); - }, - 'allows granting manual approval permissions to role'(test: Test) { + }); + + test('allows granting manual approval permissions to role', () => { const stack = new Stack(); const role = new iam.Role(stack, 'Human', { assumedBy: new iam.AnyPrincipal() }); const pipeline = new codepipeline.Pipeline(stack, 'pipeline'); @@ -49,7 +48,7 @@ nodeunitShim({ manualApprovalAction.grantManualApproval(role); - expect(stack).to(haveResourceLike('AWS::IAM::Policy', { + expect(stack).toHaveResourceLike('AWS::IAM::Policy', { 'PolicyDocument': { 'Statement': [ { @@ -109,26 +108,26 @@ nodeunitShim({ 'Ref': 'HumanD337C84C', }, ], - })); + }); + - test.done(); - }, + }); - 'rejects granting manual approval permissions before binding action to stage'(test: Test) { + test('rejects granting manual approval permissions before binding action to stage', () => { const stack = new Stack(); const role = new iam.Role(stack, 'Human', { assumedBy: new iam.AnyPrincipal() }); const manualApprovalAction = new cpactions.ManualApprovalAction({ actionName: 'Approve', }); - test.throws(() => { + expect(() => { manualApprovalAction.grantManualApproval(role); - }, 'Cannot grant permissions before binding action to a stage'); + }).toThrow('Cannot grant permissions before binding action to a stage'); - test.done(); - }, - 'renders CustomData and ExternalEntityLink even if notificationTopic was not passed'(test: Test) { + }); + + test('renders CustomData and ExternalEntityLink even if notificationTopic was not passed', () => { const stack = new Stack(); new codepipeline.Pipeline(stack, 'pipeline', { stages: [ @@ -155,7 +154,7 @@ nodeunitShim({ ], }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', @@ -173,9 +172,9 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, - }, + }); + }); }); diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/pipeline.test.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/pipeline.test.ts index 331bae0db4b9e..1c680e0c7e95d 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/pipeline.test.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/pipeline.test.ts @@ -1,4 +1,5 @@ -import { countResources, expect, haveResource, haveResourceLike, not, SynthUtils } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; +import { SynthUtils } from '@aws-cdk/assert-internal'; import * as codebuild from '@aws-cdk/aws-codebuild'; import * as codecommit from '@aws-cdk/aws-codecommit'; import * as codepipeline from '@aws-cdk/aws-codepipeline'; @@ -8,13 +9,12 @@ import * as lambda from '@aws-cdk/aws-lambda'; import * as s3 from '@aws-cdk/aws-s3'; import * as sns from '@aws-cdk/aws-sns'; import { App, Aws, CfnParameter, ConstructNode, SecretValue, Stack } from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as cpactions from '../lib'; /* eslint-disable quote-props */ -nodeunitShim({ - 'basic pipeline'(test: Test) { +describe('pipeline', () => { + test('basic pipeline', () => { const stack = new Stack(); const repository = new codecommit.Repository(stack, 'MyRepo', { @@ -45,28 +45,50 @@ nodeunitShim({ ], }); - test.notDeepEqual(SynthUtils.toCloudFormation(stack), {}); - test.deepEqual([], ConstructNode.validate(pipeline.node)); - test.done(); - }, + expect(SynthUtils.toCloudFormation(stack)).not.toEqual({}); + expect([]).toEqual(ConstructNode.validate(pipeline.node)); - 'Tokens can be used as physical names of the Pipeline'(test: Test) { + }); + + test('Tokens can be used as physical names of the Pipeline', () => { const stack = new Stack(undefined, 'StackName'); - new codepipeline.Pipeline(stack, 'Pipeline', { + const p = new codepipeline.Pipeline(stack, 'Pipeline', { pipelineName: Aws.STACK_NAME, }); + p.addStage({ + stageName: 'Source', + actions: [ + new cpactions.GitHubSourceAction({ + actionName: 'GH', + runOrder: 8, + output: new codepipeline.Artifact('A'), + branch: 'branch', + oauthToken: SecretValue.plainText('secret'), + owner: 'foo', + repo: 'bar', + trigger: cpactions.GitHubTrigger.POLL, + }), + ], + }); - expect(stack, true).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + p.addStage({ + stageName: 'Two', + actions: [ + new cpactions.ManualApprovalAction({ actionName: 'Boo' }), + ], + }); + + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Name': { 'Ref': 'AWS::StackName', }, - })); + }); + - test.done(); - }, + }); - 'pipeline with GitHub source with poll trigger'(test: Test) { + test('pipeline with GitHub source with poll trigger', () => { const stack = new Stack(); const secret = new CfnParameter(stack, 'GitHubToken', { type: 'String', default: 'my-token' }); @@ -96,9 +118,9 @@ nodeunitShim({ ], }); - expect(stack).to(not(haveResourceLike('AWS::CodePipeline::Webhook'))); + expect(stack).not.toHaveResourceLike('AWS::CodePipeline::Webhook'); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Actions': [ @@ -120,12 +142,12 @@ nodeunitShim({ 'Name': 'Two', }, ], - })); + }); + - test.done(); - }, + }); - 'pipeline with GitHub source without triggers'(test: Test) { + test('pipeline with GitHub source without triggers', () => { const stack = new Stack(); const secret = new CfnParameter(stack, 'GitHubToken', { type: 'String', default: 'my-token' }); @@ -155,9 +177,9 @@ nodeunitShim({ ], }); - expect(stack).to(not(haveResourceLike('AWS::CodePipeline::Webhook'))); + expect(stack).not.toHaveResourceLike('AWS::CodePipeline::Webhook'); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Actions': [ @@ -179,12 +201,12 @@ nodeunitShim({ 'Name': 'Two', }, ], - })); + }); + - test.done(); - }, + }); - 'github action uses ThirdParty owner'(test: Test) { + test('github action uses ThirdParty owner', () => { const stack = new Stack(); const secret = new CfnParameter(stack, 'GitHubToken', { type: 'String', default: 'my-token' }); @@ -213,9 +235,9 @@ nodeunitShim({ ], }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Webhook')); + expect(stack).toHaveResourceLike('AWS::CodePipeline::Webhook'); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'ArtifactStore': { 'Location': { 'Ref': 'PArtifactsBucket5E711C12', @@ -274,13 +296,13 @@ nodeunitShim({ 'Name': 'Two', }, ], - })); + }); + + expect([]).toEqual(ConstructNode.validate(p.node)); - test.deepEqual([], ConstructNode.validate(p.node)); - test.done(); - }, + }); - 'onStateChange'(test: Test) { + test('onStateChange', () => { const stack = new Stack(); const topic = new sns.Topic(stack, 'Topic'); @@ -316,7 +338,7 @@ nodeunitShim({ }, }); - expect(stack).to(haveResource('AWS::Events::Rule', { + expect(stack).toHaveResource('AWS::Events::Rule', { 'Description': 'desc', 'EventPattern': { 'detail': { @@ -365,22 +387,22 @@ nodeunitShim({ 'Id': 'Target0', }, ], - })); + }); - test.deepEqual([], ConstructNode.validate(pipeline.node)); - test.done(); - }, + expect([]).toEqual(ConstructNode.validate(pipeline.node)); - 'PipelineProject': { - 'with a custom Project Name': { - 'sets the source and artifacts to CodePipeline'(test: Test) { + }); + + describe('PipelineProject', () => { + describe('with a custom Project Name', () => { + test('sets the source and artifacts to CodePipeline', () => { const stack = new Stack(); new codebuild.PipelineProject(stack, 'MyProject', { projectName: 'MyProject', }); - expect(stack).to(haveResourceLike('AWS::CodeBuild::Project', { + expect(stack).toHaveResourceLike('AWS::CodeBuild::Project', { 'Name': 'MyProject', 'Source': { 'Type': 'CODEPIPELINE', @@ -400,14 +422,14 @@ nodeunitShim({ 'Image': 'aws/codebuild/standard:1.0', 'ComputeType': 'BUILD_GENERAL1_SMALL', }, - })); + }); - test.done(); - }, - }, - }, - 'Lambda PipelineInvokeAction can be used to invoke Lambda functions from a CodePipeline'(test: Test) { + }); + }); + }); + + test('Lambda PipelineInvokeAction can be used to invoke Lambda functions from a CodePipeline', () => { const stack = new Stack(); const lambdaFun = new lambda.Function(stack, 'Function', { @@ -459,7 +481,7 @@ nodeunitShim({ actions: [lambdaAction], }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'ArtifactStore': { 'Location': { 'Ref': 'PipelineArtifactsBucket22248F97', @@ -506,11 +528,11 @@ nodeunitShim({ 'Name': 'Stage', }, ], - })); + }); - test.equal((lambdaAction.actionProperties.outputs || []).length, 3); + expect((lambdaAction.actionProperties.outputs || []).length).toEqual(3); - expect(stack, /* skip validation */ true).to(haveResource('AWS::IAM::Policy', { + expect(stack).toHaveResource('AWS::IAM::Policy', { 'PolicyDocument': { 'Statement': [ { @@ -530,13 +552,13 @@ nodeunitShim({ 'Ref': 'FunctionServiceRole675BB04A', }, ], - })); + }); - test.done(); - }, - 'cross-region Pipeline': { - 'generates the required Action & ArtifactStores properties in the template'(test: Test) { + }); + + describe('cross-region Pipeline', () => { + test('generates the required Action & ArtifactStores properties in the template', () => { const pipelineRegion = 'us-west-2'; const pipelineAccount = '123'; @@ -594,7 +616,7 @@ nodeunitShim({ ], }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'ArtifactStores': [ { 'Region': 'us-west-1', @@ -644,36 +666,35 @@ nodeunitShim({ ], }, ], - })); + }); - test.notEqual(pipeline.crossRegionSupport[pipelineRegion], undefined); - test.notEqual(pipeline.crossRegionSupport['us-west-1'], undefined); + expect(pipeline.crossRegionSupport[pipelineRegion]).toBeDefined(); + expect(pipeline.crossRegionSupport['us-west-1']).toBeDefined(); const usEast1Support = pipeline.crossRegionSupport['us-east-1']; - test.notEqual(usEast1Support, undefined); - test.equal(usEast1Support.stack.region, 'us-east-1'); - test.equal(usEast1Support.stack.account, pipelineAccount); - test.ok(usEast1Support.stack.node.id.indexOf('us-east-1') !== -1, - `expected '${usEast1Support.stack.node.id}' to contain 'us-east-1'`); + expect(usEast1Support).toBeDefined(); + expect(usEast1Support.stack.region).toEqual('us-east-1'); + expect(usEast1Support.stack.account).toEqual(pipelineAccount); + expect(usEast1Support.stack.node.id.indexOf('us-east-1')).not.toEqual(-1); - test.done(); - }, - 'allows specifying only one of artifactBucket and crossRegionReplicationBuckets'(test: Test) { + }); + + test('allows specifying only one of artifactBucket and crossRegionReplicationBuckets', () => { const stack = new Stack(); - test.throws(() => { + expect(() => { new codepipeline.Pipeline(stack, 'Pipeline', { artifactBucket: new s3.Bucket(stack, 'Bucket'), crossRegionReplicationBuckets: { // even an empty map should trigger this validation... }, }); - }, /Only one of artifactBucket and crossRegionReplicationBuckets can be specified!/); - test.done(); - }, + }).toThrow(/Only one of artifactBucket and crossRegionReplicationBuckets can be specified!/); - 'does not create a new artifact Bucket if one was provided in the cross-region Buckets for the Pipeline region'(test: Test) { + }); + + test('does not create a new artifact Bucket if one was provided in the cross-region Buckets for the Pipeline region', () => { const pipelineRegion = 'us-west-2'; const stack = new Stack(undefined, undefined, { @@ -712,9 +733,9 @@ nodeunitShim({ ], }); - expect(stack).to(countResources('AWS::S3::Bucket', 1)); + expect(stack).toCountResources('AWS::S3::Bucket', 1); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'ArtifactStores': [ { 'Region': pipelineRegion, @@ -726,12 +747,12 @@ nodeunitShim({ }, }, ], - })); + }); - test.done(); - }, - 'allows providing a resource-backed action from a different region directly'(test: Test) { + }); + + test('allows providing a resource-backed action from a different region directly', () => { const account = '123456789012'; const app = new App(); @@ -765,7 +786,7 @@ nodeunitShim({ ], }); - expect(pipelineStack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(pipelineStack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'ArtifactStores': [ { 'Region': replicationRegion, @@ -810,18 +831,18 @@ nodeunitShim({ ], }, ], - })); + }); - expect(replicationStack).to(haveResourceLike('AWS::S3::Bucket', { + expect(replicationStack).toHaveResourceLike('AWS::S3::Bucket', { 'BucketName': 'replicationstackeplicationbucket2464cd5c33b386483b66', - })); + }); + - test.done(); - }, - }, + }); + }); - 'cross-account Pipeline': { - 'with a CodeBuild Project in a different account works correctly'(test: Test) { + describe('cross-account Pipeline', () => { + test('with a CodeBuild Project in a different account works correctly', () => { const app = new App(); const buildAccount = '901234567890'; @@ -874,7 +895,7 @@ nodeunitShim({ ], }); - expect(pipelineStack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(pipelineStack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', @@ -903,9 +924,9 @@ nodeunitShim({ ], }, ], - })); + }); - expect(buildStack).to(haveResourceLike('AWS::IAM::Policy', { + expect(buildStack).toHaveResourceLike('AWS::IAM::Policy', { 'PolicyDocument': { 'Statement': [ { @@ -958,12 +979,12 @@ nodeunitShim({ }, ], }, - })); + }); - test.done(); - }, - 'adds a dependency on the Stack containing a new action Role'(test: Test) { + }); + + test('adds a dependency on the Stack containing a new action Role', () => { const region = 'us-west-2'; const pipelineAccount = '123456789012'; const buildAccount = '901234567890'; @@ -1017,7 +1038,7 @@ nodeunitShim({ ], }); - expect(pipelineStack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(pipelineStack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', @@ -1041,14 +1062,14 @@ nodeunitShim({ ], }, ], - })); + }); - test.equal(pipelineStack.dependencies.length, 1); + expect(pipelineStack.dependencies.length).toEqual(1); - test.done(); - }, - 'does not add a dependency on the Stack containing an imported action Role'(test: Test) { + }); + + test('does not add a dependency on the Stack containing an imported action Role', () => { const region = 'us-west-2'; const pipelineAccount = '123456789012'; const buildAccount = '901234567890'; @@ -1101,7 +1122,7 @@ nodeunitShim({ ], }); - expect(pipelineStack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(pipelineStack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', @@ -1119,11 +1140,11 @@ nodeunitShim({ ], }, ], - })); + }); + + expect(pipelineStack.dependencies.length).toEqual(0); - test.equal(pipelineStack.dependencies.length, 0); - test.done(); - }, - }, + }); + }); }); diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/s3/s3-source-action.test.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/s3/s3-source-action.test.ts index 0fb227a9246e8..65553aee81be5 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/s3/s3-source-action.test.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/s3/s3-source-action.test.ts @@ -1,21 +1,20 @@ -import { countResources, expect, haveResourceLike, not } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as codebuild from '@aws-cdk/aws-codebuild'; import * as codepipeline from '@aws-cdk/aws-codepipeline'; import * as s3 from '@aws-cdk/aws-s3'; import { Lazy, Stack } from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as cpactions from '../../lib'; /* eslint-disable quote-props */ -nodeunitShim({ - 'S3 Source Action': { - 'by default polls for source changes and does not use Events'(test: Test) { +describe('S3 source Action', () => { + describe('S3 Source Action', () => { + test('by default polls for source changes and does not use Events', () => { const stack = new Stack(); minimalPipeline(stack, undefined); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Actions': [ @@ -27,19 +26,19 @@ nodeunitShim({ }, {}, ], - })); + }); + + expect(stack).not.toHaveResourceLike('AWS::Events::Rule'); - expect(stack).to(not(haveResourceLike('AWS::Events::Rule'))); - test.done(); - }, + }); - 'does not poll for source changes and uses Events for S3Trigger.EVENTS'(test: Test) { + test('does not poll for source changes and uses Events for S3Trigger.EVENTS', () => { const stack = new Stack(); minimalPipeline(stack, { trigger: cpactions.S3Trigger.EVENTS }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Actions': [ @@ -52,19 +51,19 @@ nodeunitShim({ }, {}, ], - })); + }); + + expect(stack).toCountResources('AWS::Events::Rule', 1); - expect(stack).to(countResources('AWS::Events::Rule', 1)); - test.done(); - }, + }); - 'polls for source changes and does not use Events for S3Trigger.POLL'(test: Test) { + test('polls for source changes and does not use Events for S3Trigger.POLL', () => { const stack = new Stack(); minimalPipeline(stack, { trigger: cpactions.S3Trigger.POLL }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Actions': [ @@ -77,19 +76,19 @@ nodeunitShim({ }, {}, ], - })); + }); + + expect(stack).not.toHaveResourceLike('AWS::Events::Rule'); - expect(stack).to(not(haveResourceLike('AWS::Events::Rule'))); - test.done(); - }, + }); - 'does not poll for source changes and does not use Events for S3Trigger.NONE'(test: Test) { + test('does not poll for source changes and does not use Events for S3Trigger.NONE', () => { const stack = new Stack(); minimalPipeline(stack, { trigger: cpactions.S3Trigger.NONE }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Actions': [ @@ -102,29 +101,29 @@ nodeunitShim({ }, {}, ], - })); + }); - expect(stack).to(not(haveResourceLike('AWS::Events::Rule'))); + expect(stack).not.toHaveResourceLike('AWS::Events::Rule'); - test.done(); - }, - 'does not allow passing an empty string for the bucketKey property'(test: Test) { + }); + + test('does not allow passing an empty string for the bucketKey property', () => { const stack = new Stack(); - test.throws(() => { + expect(() => { new cpactions.S3SourceAction({ actionName: 'Source', bucket: new s3.Bucket(stack, 'MyBucket'), bucketKey: '', output: new codepipeline.Artifact(), }); - }, /Property bucketKey cannot be an empty string/); + }).toThrow(/Property bucketKey cannot be an empty string/); + - test.done(); - }, + }); - 'allows using the same bucket with events trigger mutliple times with different bucket paths'(test: Test) { + test('allows using the same bucket with events trigger mutliple times with different bucket paths', () => { const stack = new Stack(); const bucket = new s3.Bucket(stack, 'MyBucket'); @@ -141,10 +140,10 @@ nodeunitShim({ output: new codepipeline.Artifact(), })); - test.done(); - }, - 'throws an error if the same bucket and path with trigger = Events are added to the same pipeline twice'(test: Test) { + }); + + test('throws an error if the same bucket and path with trigger = Events are added to the same pipeline twice', () => { const stack = new Stack(); const bucket = new s3.Bucket(stack, 'MyBucket'); @@ -169,14 +168,14 @@ nodeunitShim({ output: new codepipeline.Artifact(), }); - test.throws(() => { + expect(() => { sourceStage.addAction(duplicateBucketAndPath); - }, /S3 source action with path 'my\/other\/path' is already present in the pipeline for this source bucket/); + }).toThrow(/S3 source action with path 'my\/other\/path' is already present in the pipeline for this source bucket/); - test.done(); - }, - 'allows using a Token bucketKey with trigger = Events, multiple times'(test: Test) { + }); + + test('allows using a Token bucketKey with trigger = Events, multiple times', () => { const stack = new Stack(); const bucket = new s3.Bucket(stack, 'MyBucket'); @@ -193,7 +192,7 @@ nodeunitShim({ output: new codepipeline.Artifact(), })); - expect(stack, /* skipValidation = */ true).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Actions': [ @@ -210,12 +209,12 @@ nodeunitShim({ ], }, ], - })); + }); - test.done(); - }, - 'exposes variables for other actions to consume'(test: Test) { + }); + + test('exposes variables for other actions to consume', () => { const stack = new Stack(); const sourceOutput = new codepipeline.Artifact(); @@ -247,7 +246,7 @@ nodeunitShim({ ], }); - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source', @@ -264,11 +263,11 @@ nodeunitShim({ ], }, ], - })); + }); - test.done(); - }, - }, + + }); + }); }); interface MinimalPipelineOptions { diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/servicecatalog/servicecatalog-deploy-action-beta1.test.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/servicecatalog/servicecatalog-deploy-action-beta1.test.ts index ef96441ca585e..cf490f21fc206 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/servicecatalog/servicecatalog-deploy-action-beta1.test.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/servicecatalog/servicecatalog-deploy-action-beta1.test.ts @@ -1,14 +1,13 @@ -import { expect, haveResourceLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as codecommit from '@aws-cdk/aws-codecommit'; import * as codepipeline from '@aws-cdk/aws-codepipeline'; import { Stack } from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as cpactions from '../../lib'; /* eslint-disable quote-props */ -nodeunitShim({ - 'addAction succesfully leads to creation of codepipeline service catalog action with properly formatted TemplateFilePath'(test: Test) { +describe('ServiceCatalog Deploy Action', () => { + test('addAction succesfully leads to creation of codepipeline service catalog action with properly formatted TemplateFilePath', () => { // GIVEN const stack = new TestFixture(); // WHEN @@ -20,7 +19,7 @@ nodeunitShim({ productId: 'prod-xxxxxxxxx', })); // THEN - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source' /* don't care about the rest */ }, { @@ -50,11 +49,11 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, - 'deployment without a description works successfully'(test: Test) { + }); + test('deployment without a description works successfully', () => { // GIVEN const stack = new TestFixture(); // WHEN @@ -65,7 +64,7 @@ nodeunitShim({ productId: 'prod-xxxxxxxxx', })); // THEN - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { 'Stages': [ { 'Name': 'Source' /* don't care about the rest */ }, { @@ -94,10 +93,10 @@ nodeunitShim({ ], }, ], - })); + }); + - test.done(); - }, + }); }); /** diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/stepfunctions/stepfunctions-invoke-actions.test.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/stepfunctions/stepfunctions-invoke-actions.test.ts index 50f8788e8823c..0ad5d8b2213a1 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/stepfunctions/stepfunctions-invoke-actions.test.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/stepfunctions/stepfunctions-invoke-actions.test.ts @@ -1,21 +1,20 @@ -import { expect, haveResourceLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as codepipeline from '@aws-cdk/aws-codepipeline'; import * as s3 from '@aws-cdk/aws-s3'; import * as stepfunction from '@aws-cdk/aws-stepfunctions'; import { Stack } from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as cpactions from '../../lib'; -nodeunitShim({ - 'StepFunctions Invoke Action': { - 'Verify stepfunction configuration properties are set to specific values'(test: Test) { +describe('StepFunctions Invoke Action', () => { + describe('StepFunctions Invoke Action', () => { + test('Verify stepfunction configuration properties are set to specific values', () => { const stack = new Stack(); // when minimalPipeline(stack); // then - expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + expect(stack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { Stages: [ // Must have a source stage { @@ -58,17 +57,17 @@ nodeunitShim({ ], }, ], - })); + }); - test.done(); - }, - 'Allows the pipeline to invoke this stepfunction'(test: Test) { + }); + + test('Allows the pipeline to invoke this stepfunction', () => { const stack = new Stack(); minimalPipeline(stack); - expect(stack).to(haveResourceLike('AWS::IAM::Policy', { + expect(stack).toHaveResourceLike('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -80,19 +79,19 @@ nodeunitShim({ }, ], }, - })); + }); + + expect(stack).toHaveResourceLike('AWS::IAM::Role'); - expect(stack).to(haveResourceLike('AWS::IAM::Role')); - test.done(); - }, + }); - 'Allows the pipeline to describe this stepfunction execution'(test: Test) { + test('Allows the pipeline to describe this stepfunction execution', () => { const stack = new Stack(); minimalPipeline(stack); - expect(stack).to(haveResourceLike('AWS::IAM::Policy', { + expect(stack).toHaveResourceLike('AWS::IAM::Policy', { PolicyDocument: { Statement: [ {}, @@ -136,14 +135,14 @@ nodeunitShim({ }, ], }, - })); + }); - expect(stack).to(haveResourceLike('AWS::IAM::Role')); + expect(stack).toHaveResourceLike('AWS::IAM::Role'); - test.done(); - }, - }, + }); + + }); }); function minimalPipeline(stack: Stack): codepipeline.IStage { diff --git a/packages/@aws-cdk/aws-ecs/package.json b/packages/@aws-cdk/aws-ecs/package.json index 1348aef9b9d62..f050efe94d045 100644 --- a/packages/@aws-cdk/aws-ecs/package.json +++ b/packages/@aws-cdk/aws-ecs/package.json @@ -81,7 +81,7 @@ "cdk-build-tools": "0.0.0", "cdk-integ-tools": "0.0.0", "cfn2ts": "0.0.0", - "nodeunit-shim": "0.0.0", + "jest": "^26.6.3", "pkglint": "0.0.0", "proxyquire": "^2.1.3", "@aws-cdk/assert-internal": "0.0.0" diff --git a/packages/@aws-cdk/aws-ecs/test/app-mesh-proxy-configuration.test.ts b/packages/@aws-cdk/aws-ecs/test/app-mesh-proxy-configuration.test.ts index 7865809011a32..7c8bd5f880f77 100644 --- a/packages/@aws-cdk/aws-ecs/test/app-mesh-proxy-configuration.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/app-mesh-proxy-configuration.test.ts @@ -1,10 +1,9 @@ -import { expect, haveResourceLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as ecs from '../lib'; -nodeunitShim({ - 'correctly sets all appMeshProxyConfiguration'(test: Test) { +describe('app mesh proxy configuration', () => { + test('correctly sets all appMeshProxyConfiguration', () => { // GIVEN const stack = new cdk.Stack(); @@ -34,7 +33,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ProxyConfiguration: { ContainerName: 'envoy', ProxyConfigurationProperties: [ @@ -69,11 +68,11 @@ nodeunitShim({ ], Type: 'APPMESH', }, - })); - test.done(); - }, + }); + + }); - 'correctly sets appMeshProxyConfiguration with default properties set'(test: Test) { + test('correctly sets appMeshProxyConfiguration with default properties set', () => { // GIVEN const stack = new cdk.Stack(); @@ -100,7 +99,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ProxyConfiguration: { ContainerName: 'envoy', ProxyConfigurationProperties: [ @@ -123,11 +122,11 @@ nodeunitShim({ ], Type: 'APPMESH', }, - })); - test.done(); - }, + }); + + }); - 'correctly sets appMeshProxyConfiguration with empty egressIgnoredPorts and egressIgnoredIPs'(test: Test) { + test('correctly sets appMeshProxyConfiguration with empty egressIgnoredPorts and egressIgnoredIPs', () => { // GIVEN const stack = new cdk.Stack(); @@ -156,7 +155,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ProxyConfiguration: { ContainerName: 'envoy', ProxyConfigurationProperties: [ @@ -179,16 +178,16 @@ nodeunitShim({ ], Type: 'APPMESH', }, - })); - test.done(); - }, + }); + + }); - 'throws when neither of IgnoredUID and IgnoredGID is set'(test: Test) { + test('throws when neither of IgnoredUID and IgnoredGID is set', () => { // GIVEN const stack = new cdk.Stack(); // THEN - test.throws(() => { + expect(() => { new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef', { networkMode: ecs.NetworkMode.AWS_VPC, proxyConfiguration: ecs.ProxyConfigurations.appMeshProxyConfiguration({ @@ -200,8 +199,8 @@ nodeunitShim({ }, }), }); - }, /At least one of ignoredUID or ignoredGID should be specified./); + }).toThrow(/At least one of ignoredUID or ignoredGID should be specified./); + - test.done(); - }, + }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/aws-log-driver.test.ts b/packages/@aws-cdk/aws-ecs/test/aws-log-driver.test.ts index 8a802ac72014b..5e570a7d39eeb 100644 --- a/packages/@aws-cdk/aws-ecs/test/aws-log-driver.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/aws-log-driver.test.ts @@ -1,22 +1,21 @@ -import { expect, haveResource, haveResourceLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as logs from '@aws-cdk/aws-logs'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as ecs from '../lib'; let stack: cdk.Stack; let td: ecs.TaskDefinition; const image = ecs.ContainerImage.fromRegistry('test-image'); -nodeunitShim({ - 'setUp'(cb: () => void) { +describe('aws log driver', () => { + beforeEach(() => { stack = new cdk.Stack(); td = new ecs.FargateTaskDefinition(stack, 'TaskDefinition'); - cb(); - }, - 'create an aws log driver'(test: Test) { + }); + + test('create an aws log driver', () => { // WHEN td.addContainer('Container', { image, @@ -30,11 +29,11 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Logs::LogGroup', { + expect(stack).toHaveResource('AWS::Logs::LogGroup', { RetentionInDays: logs.RetentionDays.ONE_MONTH, - })); + }); - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -50,12 +49,12 @@ nodeunitShim({ }, }, ], - })); + }); - test.done(); - }, - 'create an aws log driver using awsLogs'(test: Test) { + }); + + test('create an aws log driver using awsLogs', () => { // WHEN td.addContainer('Container', { image, @@ -68,11 +67,11 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Logs::LogGroup', { + expect(stack).toHaveResource('AWS::Logs::LogGroup', { RetentionInDays: logs.RetentionDays.ONE_MONTH, - })); + }); - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -87,12 +86,12 @@ nodeunitShim({ }, }, ], - })); + }); - test.done(); - }, - 'with a defined log group'(test: Test) { + }); + + test('with a defined log group', () => { // GIVEN const logGroup = new logs.LogGroup(stack, 'LogGroup'); @@ -106,11 +105,11 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Logs::LogGroup', { + expect(stack).toHaveResource('AWS::Logs::LogGroup', { RetentionInDays: logs.RetentionDays.TWO_YEARS, - })); + }); - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -123,12 +122,12 @@ nodeunitShim({ }, }, ], - })); + }); - test.done(); - }, - 'without a defined log group: creates one anyway'(test: Test) { + }); + + test('without a defined log group: creates one anyway', () => { // GIVEN td.addContainer('Container', { image, @@ -138,22 +137,22 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Logs::LogGroup', {})); + expect(stack).toHaveResource('AWS::Logs::LogGroup', {}); + - test.done(); - }, + }); - 'throws when specifying log retention and log group'(test: Test) { + test('throws when specifying log retention and log group', () => { // GIVEN const logGroup = new logs.LogGroup(stack, 'LogGroup'); // THEN - test.throws(() => new ecs.AwsLogDriver({ + expect(() => new ecs.AwsLogDriver({ logGroup, logRetention: logs.RetentionDays.FIVE_DAYS, streamPrefix: 'hello', - }), /`logGroup`.*`logRetentionDays`/); + })).toThrow(/`logGroup`.*`logRetentionDays`/); + - test.done(); - }, + }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/cluster.test.ts b/packages/@aws-cdk/aws-ecs/test/cluster.test.ts index 40c74a08257f2..cfe65183d1c02 100644 --- a/packages/@aws-cdk/aws-ecs/test/cluster.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/cluster.test.ts @@ -1,11 +1,5 @@ -import { - countResources, - expect, - haveResource, - haveResourceLike, - ResourcePart, - ABSENT, -} from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; +import { ABSENT } from '@aws-cdk/assert-internal'; import * as autoscaling from '@aws-cdk/aws-autoscaling'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as kms from '@aws-cdk/aws-kms'; @@ -13,12 +7,11 @@ import * as logs from '@aws-cdk/aws-logs'; import * as s3 from '@aws-cdk/aws-s3'; import * as cloudmap from '@aws-cdk/aws-servicediscovery'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as ecs from '../lib'; -nodeunitShim({ - 'When creating an ECS Cluster': { - 'with no properties set, it correctly sets default properties'(test: Test) { +describe('cluster', () => { + describe('When creating an ECS Cluster', () => { + test('with no properties set, it correctly sets default properties', () => { // GIVEN const stack = new cdk.Stack(); const cluster = new ecs.Cluster(stack, 'EcsCluster'); @@ -27,9 +20,9 @@ nodeunitShim({ instanceType: new ec2.InstanceType('t2.micro'), }); - expect(stack).to(haveResource('AWS::ECS::Cluster')); + expect(stack).toHaveResource('AWS::ECS::Cluster'); - expect(stack).to(haveResource('AWS::EC2::VPC', { + expect(stack).toHaveResource('AWS::EC2::VPC', { CidrBlock: '10.0.0.0/16', EnableDnsHostnames: true, EnableDnsSupport: true, @@ -40,9 +33,9 @@ nodeunitShim({ Value: 'Default/EcsCluster/Vpc', }, ], - })); + }); - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsserviceecsoptimizedamiamazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, @@ -73,9 +66,9 @@ nodeunitShim({ ], }, }, - })); + }); - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { MaxSize: '1', MinSize: '1', LaunchConfigurationName: { @@ -96,9 +89,9 @@ nodeunitShim({ Ref: 'EcsClusterVpcPrivateSubnet2SubnetC2B7B1BA', }, ], - })); + }); - expect(stack).to(haveResource('AWS::EC2::SecurityGroup', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { GroupDescription: 'Default/EcsCluster/DefaultAutoScalingGroup/InstanceSecurityGroup', SecurityGroupEgress: [ { @@ -116,9 +109,9 @@ nodeunitShim({ VpcId: { Ref: 'EcsClusterVpc779914AB', }, - })); + }); - expect(stack).to(haveResource('AWS::IAM::Role', { + expect(stack).toHaveResource('AWS::IAM::Role', { AssumeRolePolicyDocument: { Statement: [ { @@ -131,9 +124,9 @@ nodeunitShim({ ], Version: '2012-10-17', }, - })); + }); - expect(stack).to(haveResource('AWS::IAM::Policy', { + expect(stack).toHaveResource('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -181,12 +174,12 @@ nodeunitShim({ ], Version: '2012-10-17', }, - })); + }); - test.done(); - }, - 'with only vpc set, it correctly sets default properties'(test: Test) { + }); + + test('with only vpc set, it correctly sets default properties', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -198,9 +191,9 @@ nodeunitShim({ instanceType: new ec2.InstanceType('t2.micro'), }); - expect(stack).to(haveResource('AWS::ECS::Cluster')); + expect(stack).toHaveResource('AWS::ECS::Cluster'); - expect(stack).to(haveResource('AWS::EC2::VPC', { + expect(stack).toHaveResource('AWS::EC2::VPC', { CidrBlock: '10.0.0.0/16', EnableDnsHostnames: true, EnableDnsSupport: true, @@ -211,9 +204,9 @@ nodeunitShim({ Value: 'Default/MyVpc', }, ], - })); + }); - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsserviceecsoptimizedamiamazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, @@ -244,9 +237,9 @@ nodeunitShim({ ], }, }, - })); + }); - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { MaxSize: '1', MinSize: '1', LaunchConfigurationName: { @@ -267,9 +260,9 @@ nodeunitShim({ Ref: 'MyVpcPrivateSubnet2Subnet0040C983', }, ], - })); + }); - expect(stack).to(haveResource('AWS::EC2::SecurityGroup', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { GroupDescription: 'Default/EcsCluster/DefaultAutoScalingGroup/InstanceSecurityGroup', SecurityGroupEgress: [ { @@ -287,9 +280,9 @@ nodeunitShim({ VpcId: { Ref: 'MyVpcF9F0CA6F', }, - })); + }); - expect(stack).to(haveResource('AWS::IAM::Role', { + expect(stack).toHaveResource('AWS::IAM::Role', { AssumeRolePolicyDocument: { Statement: [ { @@ -302,9 +295,9 @@ nodeunitShim({ ], Version: '2012-10-17', }, - })); + }); - expect(stack).to(haveResource('AWS::IAM::Policy', { + expect(stack).toHaveResource('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -352,12 +345,12 @@ nodeunitShim({ ], Version: '2012-10-17', }, - })); + }); - test.done(); - }, - 'multiple clusters with default capacity'(test: Test) { + }); + + test('multiple clusters with default capacity', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -370,10 +363,10 @@ nodeunitShim({ }); } - test.done(); - }, - 'lifecycle hook is automatically added'(test: Test) { + }); + + test('lifecycle hook is automatically added', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -387,16 +380,16 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::LifecycleHook', { + expect(stack).toHaveResource('AWS::AutoScaling::LifecycleHook', { AutoScalingGroupName: { Ref: 'EcsClusterDefaultAutoScalingGroupASGC1A785DB' }, LifecycleTransition: 'autoscaling:EC2_INSTANCE_TERMINATING', DefaultResult: 'CONTINUE', HeartbeatTimeout: 300, NotificationTargetARN: { Ref: 'EcsClusterDefaultAutoScalingGroupLifecycleHookDrainHookTopicACD2D4A4' }, RoleARN: { 'Fn::GetAtt': ['EcsClusterDefaultAutoScalingGroupLifecycleHookDrainHookRoleA38EC83B', 'Arn'] }, - })); + }); - expect(stack).to(haveResource('AWS::Lambda::Function', { + expect(stack).toHaveResource('AWS::Lambda::Function', { Timeout: 310, Environment: { Variables: { @@ -406,9 +399,9 @@ nodeunitShim({ }, }, Handler: 'index.lambda_handler', - })); + }); - expect(stack).to(haveResource('AWS::IAM::Policy', { + expect(stack).toHaveResource('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -507,12 +500,12 @@ nodeunitShim({ Ref: 'EcsClusterDefaultAutoScalingGroupDrainECSHookFunctionServiceRole94543EDA', }, ], - })); + }); + - test.done(); - }, + }); - 'lifecycle hook with encrypted SNS is added correctly'(test: Test) { + test('lifecycle hook with encrypted SNS is added correctly', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -528,19 +521,19 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::SNS::Topic', { + expect(stack).toHaveResourceLike('AWS::SNS::Topic', { KmsMasterKeyId: { 'Fn::GetAtt': [ 'Key961B73FD', 'Arn', ], }, - })); + }); - test.done(); - }, - 'with capacity and cloudmap namespace properties set'(test: Test) { + }); + + test('with capacity and cloudmap namespace properties set', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -555,16 +548,16 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ServiceDiscovery::PrivateDnsNamespace', { + expect(stack).toHaveResource('AWS::ServiceDiscovery::PrivateDnsNamespace', { Name: 'foo.com', Vpc: { Ref: 'MyVpcF9F0CA6F', }, - })); + }); - expect(stack).to(haveResource('AWS::ECS::Cluster')); + expect(stack).toHaveResource('AWS::ECS::Cluster'); - expect(stack).to(haveResource('AWS::EC2::VPC', { + expect(stack).toHaveResource('AWS::EC2::VPC', { CidrBlock: '10.0.0.0/16', EnableDnsHostnames: true, EnableDnsSupport: true, @@ -575,9 +568,9 @@ nodeunitShim({ Value: 'Default/MyVpc', }, ], - })); + }); - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsserviceecsoptimizedamiamazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, @@ -608,9 +601,9 @@ nodeunitShim({ ], }, }, - })); + }); - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { MaxSize: '1', MinSize: '1', LaunchConfigurationName: { @@ -631,9 +624,9 @@ nodeunitShim({ Ref: 'MyVpcPrivateSubnet2Subnet0040C983', }, ], - })); + }); - expect(stack).to(haveResource('AWS::EC2::SecurityGroup', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { GroupDescription: 'Default/EcsCluster/DefaultAutoScalingGroup/InstanceSecurityGroup', SecurityGroupEgress: [ { @@ -651,9 +644,9 @@ nodeunitShim({ VpcId: { Ref: 'MyVpcF9F0CA6F', }, - })); + }); - expect(stack).to(haveResource('AWS::IAM::Role', { + expect(stack).toHaveResource('AWS::IAM::Role', { AssumeRolePolicyDocument: { Statement: [ { @@ -666,9 +659,9 @@ nodeunitShim({ ], Version: '2012-10-17', }, - })); + }); - expect(stack).to(haveResource('AWS::IAM::Policy', { + expect(stack).toHaveResource('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -716,13 +709,13 @@ nodeunitShim({ ], Version: '2012-10-17', }, - })); + }); + - test.done(); - }, - }, + }); + }); - 'allows specifying instance type'(test: Test) { + test('allows specifying instance type', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -733,14 +726,14 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { InstanceType: 'm3.large', - })); + }); - test.done(); - }, - 'allows specifying cluster size'(test: Test) { + }); + + test('allows specifying cluster size', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -752,14 +745,14 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { MaxSize: '3', - })); + }); - test.done(); - }, - 'configures userdata with powershell if windows machine image is specified'(test: Test) { + }); + + test('configures userdata with powershell if windows machine image is specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -773,7 +766,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsserviceecsoptimizedamiwindowsserver2019englishfullrecommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, @@ -807,15 +800,15 @@ nodeunitShim({ ], }, }, - })); + }); - test.done(); - }, + + }); /* * TODO:v2.0.0 BEGINNING OF OBSOLETE BLOCK */ - 'allows specifying special HW AMI Type'(test: Test) { + test('allows specifying special HW AMI Type', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -832,23 +825,23 @@ nodeunitShim({ // THEN const assembly = app.synth(); const template = assembly.getStackByName(stack.stackName).template; - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsserviceecsoptimizedamiamazonlinux2gpurecommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, - })); + }); - test.deepEqual(template.Parameters, { + expect(template.Parameters).toEqual({ SsmParameterValueawsserviceecsoptimizedamiamazonlinux2gpurecommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter: { Type: 'AWS::SSM::Parameter::Value', Default: '/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_id', }, }); - test.done(); - }, - 'errors if amazon linux given with special HW type'(test: Test) { + }); + + test('errors if amazon linux given with special HW type', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -856,7 +849,7 @@ nodeunitShim({ const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); // THEN - test.throws(() => { + expect(() => { cluster.addCapacity('GpuAutoScalingGroup', { instanceType: new ec2.InstanceType('t2.micro'), machineImage: new ecs.EcsOptimizedAmi({ @@ -864,12 +857,12 @@ nodeunitShim({ hardwareType: ecs.AmiHardwareType.GPU, }), }); - }, /Amazon Linux does not support special hardware type/); + }).toThrow(/Amazon Linux does not support special hardware type/); + - test.done(); - }, + }); - 'allows specifying windows image'(test: Test) { + test('allows specifying windows image', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -886,17 +879,17 @@ nodeunitShim({ // THEN const assembly = app.synth(); const template = assembly.getStackByName(stack.stackName).template; - test.deepEqual(template.Parameters, { + expect(template.Parameters).toEqual({ SsmParameterValueawsserviceecsoptimizedamiwindowsserver2019englishfullrecommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter: { Type: 'AWS::SSM::Parameter::Value', Default: '/aws/service/ecs/optimized-ami/windows_server/2019/english/full/recommended/image_id', }, }); - test.done(); - }, - 'errors if windows given with special HW type'(test: Test) { + }); + + test('errors if windows given with special HW type', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -904,7 +897,7 @@ nodeunitShim({ const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); // THEN - test.throws(() => { + expect(() => { cluster.addCapacity('WindowsGpuAutoScalingGroup', { instanceType: new ec2.InstanceType('t2.micro'), machineImage: new ecs.EcsOptimizedAmi({ @@ -912,12 +905,12 @@ nodeunitShim({ hardwareType: ecs.AmiHardwareType.GPU, }), }); - }, /Windows Server does not support special hardware type/); + }).toThrow(/Windows Server does not support special hardware type/); + - test.done(); - }, + }); - 'errors if windowsVersion and linux generation are set'(test: Test) { + test('errors if windowsVersion and linux generation are set', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -925,7 +918,7 @@ nodeunitShim({ const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); // THEN - test.throws(() => { + expect(() => { cluster.addCapacity('WindowsScalingGroup', { instanceType: new ec2.InstanceType('t2.micro'), machineImage: new ecs.EcsOptimizedAmi({ @@ -933,93 +926,93 @@ nodeunitShim({ generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX, }), }); - }, /"windowsVersion" and Linux image "generation" cannot be both set/); + }).toThrow(/"windowsVersion" and Linux image "generation" cannot be both set/); - test.done(); - }, - 'allows returning the correct image for windows for EcsOptimizedAmi'(test: Test) { + }); + + test('allows returning the correct image for windows for EcsOptimizedAmi', () => { // GIVEN const stack = new cdk.Stack(); const ami = new ecs.EcsOptimizedAmi({ windowsVersion: ecs.WindowsOptimizedVersion.SERVER_2019, }); - test.equal(ami.getImage(stack).osType, ec2.OperatingSystemType.WINDOWS); + expect(ami.getImage(stack).osType).toEqual(ec2.OperatingSystemType.WINDOWS); + - test.done(); - }, + }); - 'allows returning the correct image for linux for EcsOptimizedAmi'(test: Test) { + test('allows returning the correct image for linux for EcsOptimizedAmi', () => { // GIVEN const stack = new cdk.Stack(); const ami = new ecs.EcsOptimizedAmi({ generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX, }); - test.equal(ami.getImage(stack).osType, ec2.OperatingSystemType.LINUX); + expect(ami.getImage(stack).osType).toEqual(ec2.OperatingSystemType.LINUX); - test.done(); - }, - 'allows returning the correct image for linux 2 for EcsOptimizedAmi'(test: Test) { + }); + + test('allows returning the correct image for linux 2 for EcsOptimizedAmi', () => { // GIVEN const stack = new cdk.Stack(); const ami = new ecs.EcsOptimizedAmi({ generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2, }); - test.equal(ami.getImage(stack).osType, ec2.OperatingSystemType.LINUX); + expect(ami.getImage(stack).osType).toEqual(ec2.OperatingSystemType.LINUX); + - test.done(); - }, + }); - 'allows returning the correct image for linux for EcsOptimizedImage'(test: Test) { + test('allows returning the correct image for linux for EcsOptimizedImage', () => { // GIVEN const stack = new cdk.Stack(); - test.equal(ecs.EcsOptimizedImage.amazonLinux().getImage(stack).osType, + expect(ecs.EcsOptimizedImage.amazonLinux().getImage(stack).osType).toEqual( ec2.OperatingSystemType.LINUX); - test.done(); - }, - 'allows returning the correct image for linux 2 for EcsOptimizedImage'(test: Test) { + }); + + test('allows returning the correct image for linux 2 for EcsOptimizedImage', () => { // GIVEN const stack = new cdk.Stack(); - test.equal(ecs.EcsOptimizedImage.amazonLinux2().getImage(stack).osType, + expect(ecs.EcsOptimizedImage.amazonLinux2().getImage(stack).osType).toEqual( ec2.OperatingSystemType.LINUX); - test.done(); - }, - 'allows returning the correct image for linux 2 for EcsOptimizedImage with ARM hardware'(test: Test) { + }); + + test('allows returning the correct image for linux 2 for EcsOptimizedImage with ARM hardware', () => { // GIVEN const stack = new cdk.Stack(); - test.equal(ecs.EcsOptimizedImage.amazonLinux2(ecs.AmiHardwareType.ARM).getImage(stack).osType, + expect(ecs.EcsOptimizedImage.amazonLinux2(ecs.AmiHardwareType.ARM).getImage(stack).osType).toEqual( ec2.OperatingSystemType.LINUX); - test.done(); - }, + }); - 'allows returning the correct image for windows for EcsOptimizedImage'(test: Test) { + + test('allows returning the correct image for windows for EcsOptimizedImage', () => { // GIVEN const stack = new cdk.Stack(); - test.equal(ecs.EcsOptimizedImage.windows(ecs.WindowsOptimizedVersion.SERVER_2019).getImage(stack).osType, + expect(ecs.EcsOptimizedImage.windows(ecs.WindowsOptimizedVersion.SERVER_2019).getImage(stack).osType).toEqual( ec2.OperatingSystemType.WINDOWS); - test.done(); - }, + + }); /* * TODO:v2.0.0 END OF OBSOLETE BLOCK */ - 'allows specifying special HW AMI Type v2'(test: Test) { + test('allows specifying special HW AMI Type v2', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1034,23 +1027,23 @@ nodeunitShim({ // THEN const assembly = app.synth(); const template = assembly.getStackByName(stack.stackName).template; - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsserviceecsoptimizedamiamazonlinux2gpurecommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, - })); + }); - test.deepEqual(template.Parameters, { + expect(template.Parameters).toEqual({ SsmParameterValueawsserviceecsoptimizedamiamazonlinux2gpurecommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter: { Type: 'AWS::SSM::Parameter::Value', Default: '/aws/service/ecs/optimized-ami/amazon-linux-2/gpu/recommended/image_id', }, }); - test.done(); - }, - 'allows specifying Amazon Linux v1 AMI'(test: Test) { + }); + + test('allows specifying Amazon Linux v1 AMI', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1065,23 +1058,23 @@ nodeunitShim({ // THEN const assembly = app.synth(); const template = assembly.getStackByName(stack.stackName).template; - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsserviceecsoptimizedamiamazonlinuxrecommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, - })); + }); - test.deepEqual(template.Parameters, { + expect(template.Parameters).toEqual({ SsmParameterValueawsserviceecsoptimizedamiamazonlinuxrecommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter: { Type: 'AWS::SSM::Parameter::Value', Default: '/aws/service/ecs/optimized-ami/amazon-linux/recommended/image_id', }, }); - test.done(); - }, - 'allows specifying windows image v2'(test: Test) { + }); + + test('allows specifying windows image v2', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1096,17 +1089,17 @@ nodeunitShim({ // THEN const assembly = app.synth(); const template = assembly.getStackByName(stack.stackName).template; - test.deepEqual(template.Parameters, { + expect(template.Parameters).toEqual({ SsmParameterValueawsserviceecsoptimizedamiwindowsserver2019englishfullrecommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter: { Type: 'AWS::SSM::Parameter::Value', Default: '/aws/service/ecs/optimized-ami/windows_server/2019/english/full/recommended/image_id', }, }); - test.done(); - }, - 'allows specifying spot fleet'(test: Test) { + }); + + test('allows specifying spot fleet', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1118,14 +1111,14 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { SpotPrice: '0.31', - })); + }); - test.done(); - }, - 'allows specifying drain time'(test: Test) { + }); + + test('allows specifying drain time', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1137,14 +1130,14 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::LifecycleHook', { + expect(stack).toHaveResource('AWS::AutoScaling::LifecycleHook', { HeartbeatTimeout: 60, - })); + }); + - test.done(); - }, + }); - 'allows specifying automated spot draining'(test: Test) { + test('allows specifying automated spot draining', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1157,7 +1150,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { UserData: { 'Fn::Base64': { 'Fn::Join': [ @@ -1172,12 +1165,12 @@ nodeunitShim({ ], }, }, - })); + }); + - test.done(); - }, + }); - 'allows containers access to instance metadata service'(test: Test) { + test('allows containers access to instance metadata service', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1189,7 +1182,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { UserData: { 'Fn::Base64': { 'Fn::Join': [ @@ -1204,12 +1197,12 @@ nodeunitShim({ ], }, }, - })); + }); + - test.done(); - }, + }); - 'allows adding default service discovery namespace'(test: Test) { + test('allows adding default service discovery namespace', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1225,17 +1218,17 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ServiceDiscovery::PrivateDnsNamespace', { + expect(stack).toHaveResource('AWS::ServiceDiscovery::PrivateDnsNamespace', { Name: 'foo.com', Vpc: { Ref: 'MyVpcF9F0CA6F', }, - })); + }); + - test.done(); - }, + }); - 'allows adding public service discovery namespace'(test: Test) { + test('allows adding public service discovery namespace', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1252,16 +1245,16 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ServiceDiscovery::PublicDnsNamespace', { + expect(stack).toHaveResource('AWS::ServiceDiscovery::PublicDnsNamespace', { Name: 'foo.com', - })); + }); + + expect(cluster.defaultCloudMapNamespace!.type).toEqual(cloudmap.NamespaceType.DNS_PUBLIC); - test.equal(cluster.defaultCloudMapNamespace!.type, cloudmap.NamespaceType.DNS_PUBLIC); - test.done(); - }, + }); - 'throws if default service discovery namespace added more than once'(test: Test) { + test('throws if default service discovery namespace added more than once', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1277,16 +1270,16 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { cluster.addDefaultCloudMapNamespace({ name: 'foo.com', }); - }, /Can only add default namespace once./); + }).toThrow(/Can only add default namespace once./); - test.done(); - }, - 'export/import of a cluster with a namespace'(test: Test) { + }); + + test('export/import of a cluster with a namespace', () => { // GIVEN const stack1 = new cdk.Stack(); const vpc1 = new ec2.Vpc(stack1, 'Vpc'); @@ -1310,16 +1303,16 @@ nodeunitShim({ }); // THEN - test.equal(cluster2.defaultCloudMapNamespace!.type, cloudmap.NamespaceType.DNS_PRIVATE); - test.deepEqual(stack2.resolve(cluster2.defaultCloudMapNamespace!.namespaceId), 'import-namespace-id'); + expect(cluster2.defaultCloudMapNamespace!.type).toEqual(cloudmap.NamespaceType.DNS_PRIVATE); + expect(stack2.resolve(cluster2.defaultCloudMapNamespace!.namespaceId)).toEqual('import-namespace-id'); // Can retrieve subnets from VPC - will throw 'There are no 'Private' subnets in this VPC. Use a different VPC subnet selection.' if broken. cluster2.vpc.selectSubnets(); - test.done(); - }, - 'imported cluster with imported security groups honors allowAllOutbound'(test: Test) { + }); + + test('imported cluster with imported security groups honors allowAllOutbound', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'Vpc'); @@ -1337,16 +1330,16 @@ nodeunitShim({ cluster.connections.allowToAnyIpv4(ec2.Port.tcp(443)); // THEN - expect(stack).to(haveResource('AWS::EC2::SecurityGroupEgress', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroupEgress', { GroupId: 'sg-1', - })); + }); + + expect(stack).toCountResources('AWS::EC2::SecurityGroupEgress', 1); - expect(stack).to(countResources('AWS::EC2::SecurityGroupEgress', 1)); - test.done(); - }, + }); - 'Metric'(test: Test) { + test('Metric', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1354,7 +1347,7 @@ nodeunitShim({ const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); // THEN - test.deepEqual(stack.resolve(cluster.metricCpuReservation()), { + expect(stack.resolve(cluster.metricCpuReservation())).toEqual({ dimensions: { ClusterName: { Ref: 'EcsCluster97242B84' }, }, @@ -1364,7 +1357,7 @@ nodeunitShim({ statistic: 'Average', }); - test.deepEqual(stack.resolve(cluster.metricMemoryReservation()), { + expect(stack.resolve(cluster.metricMemoryReservation())).toEqual({ dimensions: { ClusterName: { Ref: 'EcsCluster97242B84' }, }, @@ -1374,7 +1367,7 @@ nodeunitShim({ statistic: 'Average', }); - test.deepEqual(stack.resolve(cluster.metric('myMetric')), { + expect(stack.resolve(cluster.metric('myMetric'))).toEqual({ dimensions: { ClusterName: { Ref: 'EcsCluster97242B84' }, }, @@ -1384,10 +1377,10 @@ nodeunitShim({ statistic: 'Average', }); - test.done(); - }, - 'ASG with a public VPC without NAT Gateways'(test: Test) { + }); + + test('ASG with a public VPC without NAT Gateways', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyPublicVpc', { @@ -1409,9 +1402,9 @@ nodeunitShim({ }, }); - expect(stack).to(haveResource('AWS::ECS::Cluster')); + expect(stack).toHaveResource('AWS::ECS::Cluster'); - expect(stack).to(haveResource('AWS::EC2::VPC', { + expect(stack).toHaveResource('AWS::EC2::VPC', { CidrBlock: '10.0.0.0/16', EnableDnsHostnames: true, EnableDnsSupport: true, @@ -1422,9 +1415,9 @@ nodeunitShim({ Value: 'Default/MyPublicVpc', }, ], - })); + }); - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsserviceecsoptimizedamiamazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, @@ -1456,9 +1449,9 @@ nodeunitShim({ ], }, }, - })); + }); - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { MaxSize: '1', MinSize: '1', LaunchConfigurationName: { @@ -1479,9 +1472,9 @@ nodeunitShim({ Ref: 'MyPublicVpcingressSubnet2SubnetD2F2E034', }, ], - })); + }); - expect(stack).to(haveResource('AWS::EC2::SecurityGroup', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { GroupDescription: 'Default/EcsCluster/DefaultAutoScalingGroup/InstanceSecurityGroup', SecurityGroupEgress: [ { @@ -1499,13 +1492,13 @@ nodeunitShim({ VpcId: { Ref: 'MyPublicVpcA2BF6CDA', }, - })); + }); // THEN - test.done(); - }, - 'enable container insights'(test: Test) { + }); + + test('enable container insights', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1513,19 +1506,19 @@ nodeunitShim({ new ecs.Cluster(stack, 'EcsCluster', { containerInsights: true }); // THEN - expect(stack).to(haveResource('AWS::ECS::Cluster', { + expect(stack).toHaveResource('AWS::ECS::Cluster', { ClusterSettings: [ { Name: 'containerInsights', Value: 'enabled', }, ], - }, ResourcePart.Properties)); + }); + - test.done(); - }, + }); - 'disable container insights'(test: Test) { + test('disable container insights', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1533,19 +1526,19 @@ nodeunitShim({ new ecs.Cluster(stack, 'EcsCluster', { containerInsights: false }); // THEN - expect(stack).to(haveResource('AWS::ECS::Cluster', { + expect(stack).toHaveResource('AWS::ECS::Cluster', { ClusterSettings: [ { Name: 'containerInsights', Value: 'disabled', }, ], - }, ResourcePart.Properties)); + }); + - test.done(); - }, + }); - 'default container insights is undefined'(test: Test) { + test('default container insights is undefined', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1557,17 +1550,15 @@ nodeunitShim({ const stackAssembly = assembly.getStackByName(stack.stackName); const template = stackAssembly.template; - test.equal( + expect( template.Resources.EcsCluster97242B84.Properties === undefined || template.Resources.EcsCluster97242B84.Properties.ClusterSettings === undefined, - true, - 'ClusterSettings should not be defined', - ); + ).toEqual(true); - test.done(); - }, - 'BottleRocketImage() returns correct AMI'(test: Test) { + }); + + test('BottleRocketImage() returns correct AMI', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1578,18 +1569,18 @@ nodeunitShim({ // THEN const assembly = app.synth(); const parameters = assembly.getStackByName(stack.stackName).template.Parameters; - test.ok(Object.entries(parameters).some( + expect(Object.entries(parameters).some( ([k, v]) => k.startsWith('SsmParameterValueawsservicebottlerocketawsecs') && (v as any).Default.includes('/bottlerocket/'), - ), 'Bottlerocket AMI should be in ssm parameters'); - test.ok(Object.entries(parameters).some( + )).toEqual(true); + expect(Object.entries(parameters).some( ([k, v]) => k.startsWith('SsmParameterValueawsservicebottlerocketawsecs') && (v as any).Default.includes('/aws-ecs-1/'), - ), 'ecs variant should be in ssm parameters'); - test.done(); - }, + )).toEqual(true); + + }); - 'cluster capacity with bottlerocket AMI, by setting machineImageType'(test: Test) { + test('cluster capacity with bottlerocket AMI, by setting machineImageType', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1601,9 +1592,9 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Cluster')); - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup')); - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::ECS::Cluster'); + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup'); + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsservicebottlerocketawsecs1x8664latestimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, @@ -1621,8 +1612,8 @@ nodeunitShim({ ], }, }, - })); - expect(stack).to(haveResourceLike('AWS::IAM::Role', { + }); + expect(stack).toHaveResourceLike('AWS::IAM::Role', { AssumeRolePolicyDocument: { Statement: [ { @@ -1677,12 +1668,11 @@ nodeunitShim({ Value: 'test/EcsCluster/bottlerocket-asg', }, ], - }), - ); - test.done(); - }, + }); - 'correct bottlerocket AMI for ARM64 architecture'(test: Test) { + }); + + test('correct bottlerocket AMI for ARM64 architecture', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1694,24 +1684,24 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { ImageId: { Ref: 'SsmParameterValueawsservicebottlerocketawsecs1arm64latestimageidC96584B6F00A464EAD1953AFF4B05118Parameter', }, - })); + }); const assembly = app.synth(); const template = assembly.getStackByName(stack.stackName).template; - test.deepEqual(template.Parameters, { + expect(template.Parameters).toEqual({ SsmParameterValueawsservicebottlerocketawsecs1arm64latestimageidC96584B6F00A464EAD1953AFF4B05118Parameter: { Type: 'AWS::SSM::Parameter::Value', Default: '/aws/service/bottlerocket/aws-ecs-1/arm64/latest/image_id', }, }); - test.done(); - }, - 'throws when machineImage and machineImageType both specified'(test: Test) { + }); + + test('throws when machineImage and machineImageType both specified', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1723,7 +1713,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::AutoScaling::LaunchConfiguration', { + expect(stack).toHaveResourceLike('AWS::AutoScaling::LaunchConfiguration', { UserData: { 'Fn::Base64': { 'Fn::Join': [ @@ -1738,11 +1728,11 @@ nodeunitShim({ ], }, }, - })); - test.done(); - }, + }); - 'allows specifying capacityProviders (deprecated)'(test: Test) { + }); + + test('allows specifying capacityProviders (deprecated)', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1751,18 +1741,18 @@ nodeunitShim({ new ecs.Cluster(stack, 'EcsCluster', { capacityProviders: ['FARGATE_SPOT'] }); // THEN - expect(stack).to(haveResource('AWS::ECS::Cluster', { + expect(stack).toHaveResource('AWS::ECS::Cluster', { CapacityProviders: ABSENT, - })); + }); - expect(stack).to(haveResource('AWS::ECS::ClusterCapacityProviderAssociations', { + expect(stack).toHaveResource('AWS::ECS::ClusterCapacityProviderAssociations', { CapacityProviders: ['FARGATE_SPOT'], - })); + }); + - test.done(); - }, + }); - 'allows specifying Fargate capacityProviders'(test: Test) { + test('allows specifying Fargate capacityProviders', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1773,18 +1763,18 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Cluster', { + expect(stack).toHaveResource('AWS::ECS::Cluster', { CapacityProviders: ABSENT, - })); + }); - expect(stack).to(haveResource('AWS::ECS::ClusterCapacityProviderAssociations', { + expect(stack).toHaveResource('AWS::ECS::ClusterCapacityProviderAssociations', { CapacityProviders: ['FARGATE', 'FARGATE_SPOT'], - })); + }); - test.done(); - }, - 'allows specifying capacityProviders (alternate method)'(test: Test) { + }); + + test('allows specifying capacityProviders (alternate method)', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1794,18 +1784,18 @@ nodeunitShim({ cluster.enableFargateCapacityProviders(); // THEN - expect(stack).to(haveResource('AWS::ECS::Cluster', { + expect(stack).toHaveResource('AWS::ECS::Cluster', { CapacityProviders: ABSENT, - })); + }); - expect(stack).to(haveResource('AWS::ECS::ClusterCapacityProviderAssociations', { + expect(stack).toHaveResource('AWS::ECS::ClusterCapacityProviderAssociations', { CapacityProviders: ['FARGATE', 'FARGATE_SPOT'], - })); + }); + - test.done(); - }, + }); - 'allows adding capacityProviders post-construction (deprecated)'(test: Test) { + test('allows adding capacityProviders post-construction (deprecated)', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1816,18 +1806,18 @@ nodeunitShim({ cluster.addCapacityProvider('FARGATE'); // does not add twice // THEN - expect(stack).to(haveResource('AWS::ECS::Cluster', { + expect(stack).toHaveResource('AWS::ECS::Cluster', { CapacityProviders: ABSENT, - })); + }); - expect(stack).to(haveResource('AWS::ECS::ClusterCapacityProviderAssociations', { + expect(stack).toHaveResource('AWS::ECS::ClusterCapacityProviderAssociations', { CapacityProviders: ['FARGATE'], - })); + }); - test.done(); - }, - 'allows adding capacityProviders post-construction'(test: Test) { + }); + + test('allows adding capacityProviders post-construction', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1838,32 +1828,32 @@ nodeunitShim({ cluster.addCapacityProvider('FARGATE'); // does not add twice // THEN - expect(stack).to(haveResource('AWS::ECS::Cluster', { + expect(stack).toHaveResource('AWS::ECS::Cluster', { CapacityProviders: ABSENT, - })); + }); - expect(stack).to(haveResource('AWS::ECS::ClusterCapacityProviderAssociations', { + expect(stack).toHaveResource('AWS::ECS::ClusterCapacityProviderAssociations', { CapacityProviders: ['FARGATE'], - })); + }); + - test.done(); - }, + }); - 'throws for unsupported capacity providers'(test: Test) { + test('throws for unsupported capacity providers', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); const cluster = new ecs.Cluster(stack, 'EcsCluster'); // THEN - test.throws(() => { + expect(() => { cluster.addCapacityProvider('HONK'); - }, /CapacityProvider not supported/); + }).toThrow(/CapacityProvider not supported/); - test.done(); - }, - 'creates ASG capacity providers with expected defaults'(test: Test) { + }); + + test('creates ASG capacity providers with expected defaults', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1880,7 +1870,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::CapacityProvider', { + expect(stack).toHaveResource('AWS::ECS::CapacityProvider', { AutoScalingGroupProvider: { AutoScalingGroupArn: { Ref: 'asgASG4D014670', @@ -1891,11 +1881,11 @@ nodeunitShim({ }, ManagedTerminationProtection: 'ENABLED', }, - })); - test.done(); - }, + }); - 'can disable managed scaling for ASG capacity provider'(test: Test) { + }); + + test('can disable managed scaling for ASG capacity provider', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1913,7 +1903,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::CapacityProvider', { + expect(stack).toHaveResource('AWS::ECS::CapacityProvider', { AutoScalingGroupProvider: { AutoScalingGroupArn: { Ref: 'asgASG4D014670', @@ -1921,11 +1911,11 @@ nodeunitShim({ ManagedScaling: ABSENT, ManagedTerminationProtection: 'ENABLED', }, - })); - test.done(); - }, + }); - 'capacity provider enables ASG new instance scale-in protection by default'(test: Test) { + }); + + test('capacity provider enables ASG new instance scale-in protection by default', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1942,13 +1932,13 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { NewInstancesProtectedFromScaleIn: true, - })); - test.done(); - }, + }); - 'capacity provider disables ASG new instance scale-in protection'(test: Test) { + }); + + test('capacity provider disables ASG new instance scale-in protection', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1966,13 +1956,13 @@ nodeunitShim({ }); // THEN - expect(stack).notTo(haveResource('AWS::AutoScaling::AutoScalingGroup', { + expect(stack).not.toHaveResource('AWS::AutoScaling::AutoScalingGroup', { NewInstancesProtectedFromScaleIn: true, - })); - test.done(); - }, + }); - 'can add ASG capacity via Capacity Provider'(test: Test) { + }); + + test('can add ASG capacity via Capacity Provider', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -1998,7 +1988,7 @@ nodeunitShim({ cluster.addAsgCapacityProvider(capacityProvider); // THEN - expect(stack).to(haveResource('AWS::ECS::ClusterCapacityProviderAssociations', { + expect(stack).toHaveResource('AWS::ECS::ClusterCapacityProviderAssociations', { Cluster: { Ref: 'EcsCluster97242B84', }, @@ -2010,11 +2000,11 @@ nodeunitShim({ }, ], DefaultCapacityProviderStrategy: [], - })); - test.done(); - }, + }); - 'correctly sets log configuration for execute command'(test: Test) { + }); + + test('correctly sets log configuration for execute command', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -2045,7 +2035,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Cluster', { + expect(stack).toHaveResource('AWS::ECS::Cluster', { Configuration: { ExecuteCommandConfiguration: { KmsKeyId: { @@ -2068,29 +2058,29 @@ nodeunitShim({ Logging: 'OVERRIDE', }, }, - })); + }); - test.done(); - }, - 'throws when no log configuration is provided when logging is set to OVERRIDE'(test: Test) { + }); + + test('throws when no log configuration is provided when logging is set to OVERRIDE', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); // THEN - test.throws(() => { + expect(() => { new ecs.Cluster(stack, 'EcsCluster', { executeCommandConfiguration: { logging: ecs.ExecuteCommandLogging.OVERRIDE, }, }); - }, /Execute command log configuration must only be specified when logging is OVERRIDE./); + }).toThrow(/Execute command log configuration must only be specified when logging is OVERRIDE./); + - test.done(); - }, + }); - 'throws when log configuration provided but logging is set to DEFAULT'(test: Test) { + test('throws when log configuration provided but logging is set to DEFAULT', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); @@ -2098,7 +2088,7 @@ nodeunitShim({ const logGroup = new logs.LogGroup(stack, 'LogGroup'); // THEN - test.throws(() => { + expect(() => { new ecs.Cluster(stack, 'EcsCluster', { executeCommandConfiguration: { logConfiguration: { @@ -2107,18 +2097,18 @@ nodeunitShim({ logging: ecs.ExecuteCommandLogging.DEFAULT, }, }); - }, /Execute command log configuration must only be specified when logging is OVERRIDE./); + }).toThrow(/Execute command log configuration must only be specified when logging is OVERRIDE./); - test.done(); - }, - 'throws when CloudWatchEncryptionEnabled without providing CloudWatch Logs log group name'(test: Test) { + }); + + test('throws when CloudWatchEncryptionEnabled without providing CloudWatch Logs log group name', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); // THEN - test.throws(() => { + expect(() => { new ecs.Cluster(stack, 'EcsCluster', { executeCommandConfiguration: { logConfiguration: { @@ -2127,18 +2117,18 @@ nodeunitShim({ logging: ecs.ExecuteCommandLogging.OVERRIDE, }, }); - }, /You must specify a CloudWatch log group in the execute command log configuration to enable CloudWatch encryption./); + }).toThrow(/You must specify a CloudWatch log group in the execute command log configuration to enable CloudWatch encryption./); + - test.done(); - }, + }); - 'throws when S3EncryptionEnabled without providing S3 Bucket name'(test: Test) { + test('throws when S3EncryptionEnabled without providing S3 Bucket name', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app, 'test'); // THEN - test.throws(() => { + expect(() => { new ecs.Cluster(stack, 'EcsCluster', { executeCommandConfiguration: { logConfiguration: { @@ -2147,8 +2137,8 @@ nodeunitShim({ logging: ecs.ExecuteCommandLogging.OVERRIDE, }, }); - }, /You must specify an S3 bucket name in the execute command log configuration to enable S3 encryption./); + }).toThrow(/You must specify an S3 bucket name in the execute command log configuration to enable S3 encryption./); + - test.done(); - }, + }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/ec2/cross-stack.test.ts b/packages/@aws-cdk/aws-ecs/test/ec2/cross-stack.test.ts index 7e6fce7a4f301..7decd0047975e 100644 --- a/packages/@aws-cdk/aws-ecs/test/ec2/cross-stack.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/ec2/cross-stack.test.ts @@ -1,8 +1,7 @@ -import { expect, haveResource } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2'; import { App, Stack } from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as ecs from '../../lib'; // Test various cross-stack Cluster/Service/ALB scenario's @@ -13,8 +12,8 @@ let stack2: Stack; let cluster: ecs.Cluster; let service: ecs.Ec2Service; -nodeunitShim({ - 'setUp'(cb: () => void) { +describe('cross stack', () => { + beforeEach(() => { app = new App(); stack1 = new Stack(app, 'Stack1'); @@ -37,10 +36,10 @@ nodeunitShim({ taskDefinition, }); - cb(); - }, - 'ALB next to Service'(test: Test) { + }); + + test('ALB next to Service', () => { // WHEN const lb = new elbv2.ApplicationLoadBalancer(stack2, 'ALB', { vpc: cluster.vpc }); const listener = lb.addListener('listener', { port: 80 }); @@ -50,14 +49,14 @@ nodeunitShim({ }); // THEN: it shouldn't throw due to cyclic dependencies - expect(stack2).to(haveResource('AWS::ECS::Service')); + expect(stack2).toHaveResource('AWS::ECS::Service'); expectIngress(stack2); - test.done(); - }, - 'ALB next to Cluster'(test: Test) { + }); + + test('ALB next to Cluster', () => { // WHEN const lb = new elbv2.ApplicationLoadBalancer(stack1, 'ALB', { vpc: cluster.vpc }); const listener = lb.addListener('listener', { port: 80 }); @@ -67,13 +66,13 @@ nodeunitShim({ }); // THEN: it shouldn't throw due to cyclic dependencies - expect(stack2).to(haveResource('AWS::ECS::Service')); + expect(stack2).toHaveResource('AWS::ECS::Service'); expectIngress(stack2); - test.done(); - }, - 'ALB in its own stack'(test: Test) { + }); + + test('ALB in its own stack', () => { // WHEN const stack3 = new Stack(app, 'Stack3'); const lb = new elbv2.ApplicationLoadBalancer(stack3, 'ALB', { vpc: cluster.vpc }); @@ -84,17 +83,17 @@ nodeunitShim({ }); // THEN: it shouldn't throw due to cyclic dependencies - expect(stack2).to(haveResource('AWS::ECS::Service')); + expect(stack2).toHaveResource('AWS::ECS::Service'); expectIngress(stack2); - test.done(); - }, + + }); }); function expectIngress(stack: Stack) { - expect(stack).to(haveResource('AWS::EC2::SecurityGroupIngress', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroupIngress', { FromPort: 32768, ToPort: 65535, GroupId: { 'Fn::ImportValue': 'Stack1:ExportsOutputFnGetAttClusterDefaultAutoScalingGroupInstanceSecurityGroup1D15236AGroupIdEAB9C5E1' }, - })); + }); } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ecs/test/ec2/ec2-service.test.ts b/packages/@aws-cdk/aws-ecs/test/ec2/ec2-service.test.ts index 7e942c866b213..48da04142ff3c 100644 --- a/packages/@aws-cdk/aws-ecs/test/ec2/ec2-service.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/ec2/ec2-service.test.ts @@ -1,4 +1,5 @@ -import { expect, haveResource, haveResourceLike } from '@aws-cdk/assert-internal'; +import { SynthUtils } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as autoscaling from '@aws-cdk/aws-autoscaling'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as elb from '@aws-cdk/aws-elasticloadbalancing'; @@ -8,14 +9,13 @@ import * as logs from '@aws-cdk/aws-logs'; import * as s3 from '@aws-cdk/aws-s3'; import * as cloudmap from '@aws-cdk/aws-servicediscovery'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as ecs from '../../lib'; import { DeploymentControllerType, LaunchType, PropagatedTagSource } from '../../lib/base/base-service'; import { PlacementConstraint, PlacementStrategy } from '../../lib/placement'; -nodeunitShim({ - 'When creating an EC2 Service': { - 'with only required properties set, it correctly sets default properties'(test: Test) { +describe('ec2 service', () => { + describe('When creating an EC2 Service', () => { + test('with only required properties set, it correctly sets default properties', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -34,7 +34,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { TaskDefinition: { Ref: 'Ec2TaskDef0226F28C', }, @@ -48,14 +48,14 @@ nodeunitShim({ LaunchType: LaunchType.EC2, SchedulingStrategy: 'REPLICA', EnableECSManagedTags: false, - })); + }); - test.notEqual(service.node.defaultChild, undefined); + expect(service.node.defaultChild).toBeDefined(); - test.done(); - }, - 'allows setting enable execute command'(test: Test) { + }); + + test('allows setting enable execute command', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -75,7 +75,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { TaskDefinition: { Ref: 'Ec2TaskDef0226F28C', }, @@ -90,9 +90,9 @@ nodeunitShim({ SchedulingStrategy: 'REPLICA', EnableECSManagedTags: false, EnableExecuteCommand: true, - })); + }); - expect(stack).to(haveResource('AWS::IAM::Policy', { + expect(stack).toHaveResource('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -128,12 +128,12 @@ nodeunitShim({ Ref: 'Ec2TaskDefTaskRole400FA349', }, ], - })); + }); - test.done(); - }, - 'no logging enabled when logging field is set to NONE'(test: Test) { + }); + + test('no logging enabled when logging field is set to NONE', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -166,7 +166,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::IAM::Policy', { + expect(stack).toHaveResource('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -188,12 +188,12 @@ nodeunitShim({ Ref: 'Ec2TaskDefTaskRole400FA349', }, ], - })); + }); + - test.done(); - }, + }); - 'enables execute command logging when logging field is set to OVERRIDE'(test: Test) { + test('enables execute command logging when logging field is set to OVERRIDE', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -229,7 +229,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::IAM::Policy', { + expect(stack).toHaveResource('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -305,12 +305,12 @@ nodeunitShim({ Ref: 'Ec2TaskDefTaskRole400FA349', }, ], - })); + }); - test.done(); - }, - 'enables only execute command session encryption'(test: Test) { + }); + + test('enables only execute command session encryption', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -349,7 +349,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::IAM::Policy', { + expect(stack).toHaveResource('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -438,9 +438,9 @@ nodeunitShim({ Ref: 'Ec2TaskDefTaskRole400FA349', }, ], - })); + }); - expect(stack).to(haveResource('AWS::KMS::Key', { + expect(stack).toHaveResource('AWS::KMS::Key', { KeyPolicy: { Statement: [ { @@ -504,12 +504,12 @@ nodeunitShim({ ], Version: '2012-10-17', }, - })); + }); + - test.done(); - }, + }); - 'enables encryption for execute command logging'(test: Test) { + test('enables encryption for execute command logging', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -555,7 +555,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::IAM::Policy', { + expect(stack).toHaveResource('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -659,9 +659,9 @@ nodeunitShim({ Ref: 'Ec2TaskDefTaskRole400FA349', }, ], - })); + }); - expect(stack).to(haveResource('AWS::KMS::Key', { + expect(stack).toHaveResource('AWS::KMS::Key', { KeyPolicy: { Statement: [ { @@ -770,12 +770,12 @@ nodeunitShim({ ], Version: '2012-10-17', }, - })); + }); + - test.done(); - }, + }); - 'with custom cloudmap namespace'(test: Test) { + test('with custom cloudmap namespace', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -805,7 +805,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ServiceDiscovery::Service', { + expect(stack).toHaveResource('AWS::ServiceDiscovery::Service', { DnsConfig: { DnsRecords: [ { @@ -831,19 +831,19 @@ nodeunitShim({ 'Id', ], }, - })); + }); - expect(stack).to(haveResource('AWS::ServiceDiscovery::PrivateDnsNamespace', { + expect(stack).toHaveResource('AWS::ServiceDiscovery::PrivateDnsNamespace', { Name: 'scorekeep.com', Vpc: { Ref: 'MyVpcF9F0CA6F', }, - })); + }); + - test.done(); - }, + }); - 'with all properties set'(test: Test) { + test('with all properties set', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -896,7 +896,7 @@ nodeunitShim({ service.addPlacementStrategies(PlacementStrategy.spreadAcross(ecs.BuiltInAttributes.AVAILABILITY_ZONE)); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { TaskDefinition: { Ref: 'Ec2TaskDef0226F28C', }, @@ -957,12 +957,12 @@ nodeunitShim({ }, }, ], - })); + }); - test.done(); - }, - 'with autoscaling group capacity provider'(test: Test) { + }); + + test('with autoscaling group capacity provider', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'Vpc'); @@ -1002,7 +1002,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { CapacityProviderStrategy: [ { CapacityProvider: { @@ -1010,11 +1010,11 @@ nodeunitShim({ }, }, ], - })); - test.done(); - }, + }); - 'with multiple security groups, it correctly updates the cfn template'(test: Test) { + }); + + test('with multiple security groups, it correctly updates the cfn template', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1053,7 +1053,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { TaskDefinition: { Ref: 'Ec2TaskDef0226F28C', }, @@ -1091,9 +1091,9 @@ nodeunitShim({ }, SchedulingStrategy: 'REPLICA', ServiceName: 'bonjour', - })); + }); - expect(stack).to(haveResource('AWS::EC2::SecurityGroup', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { GroupDescription: 'Example', GroupName: 'Bingo', SecurityGroupEgress: [ @@ -1106,9 +1106,9 @@ nodeunitShim({ VpcId: { Ref: 'MyVpcF9F0CA6F', }, - })); + }); - expect(stack).to(haveResource('AWS::EC2::SecurityGroup', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { GroupDescription: 'Example', GroupName: 'Rolly', SecurityGroupEgress: [ @@ -1123,12 +1123,12 @@ nodeunitShim({ VpcId: { Ref: 'MyVpcF9F0CA6F', }, - })); + }); - test.done(); - }, - 'throws when both securityGroup and securityGroups are supplied'(test: Test) { + }); + + test('throws when both securityGroup and securityGroups are supplied', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1155,7 +1155,7 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { new ecs.Ec2Service(stack, 'Ec2Service', { cluster, taskDefinition, @@ -1168,12 +1168,12 @@ nodeunitShim({ serviceName: 'bonjour', vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC }, }); - }, /Only one of SecurityGroup or SecurityGroups can be populated./); + }).toThrow(/Only one of SecurityGroup or SecurityGroups can be populated./); - test.done(); - }, - 'throws when task definition is not EC2 compatible'(test: Test) { + }); + + test('throws when task definition is not EC2 compatible', () => { const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); @@ -1188,17 +1188,17 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { new ecs.Ec2Service(stack, 'Ec2Service', { cluster, taskDefinition, }); - }, /Supplied TaskDefinition is not configured for compatibility with EC2/); + }).toThrow(/Supplied TaskDefinition is not configured for compatibility with EC2/); - test.done(); - }, - 'ignore task definition and launch type if deployment controller is set to be EXTERNAL'(test: Test) { + }); + + test('ignore task definition and launch type if deployment controller is set to be EXTERNAL', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1220,8 +1220,8 @@ nodeunitShim({ }); // THEN - test.deepEqual(service.node.metadata[0].data, 'taskDefinition and launchType are blanked out when using external deployment controller.'); - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(service.node.metadata[0].data).toEqual('taskDefinition and launchType are blanked out when using external deployment controller.'); + expect(stack).toHaveResource('AWS::ECS::Service', { Cluster: { Ref: 'EcsCluster97242B84', }, @@ -1231,12 +1231,12 @@ nodeunitShim({ }, SchedulingStrategy: 'REPLICA', EnableECSManagedTags: false, - })); + }); - test.done(); - }, - 'errors if daemon and desiredCount both specified'(test: Test) { + }); + + test('errors if daemon and desiredCount both specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1249,19 +1249,19 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { new ecs.Ec2Service(stack, 'Ec2Service', { cluster, taskDefinition, daemon: true, desiredCount: 2, }); - }, /Don't supply desiredCount/); + }).toThrow(/Don't supply desiredCount/); - test.done(); - }, - 'errors if daemon and maximumPercent not 100'(test: Test) { + }); + + test('errors if daemon and maximumPercent not 100', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1274,19 +1274,19 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { new ecs.Ec2Service(stack, 'Ec2Service', { cluster, taskDefinition, daemon: true, maxHealthyPercent: 300, }); - }, /Maximum percent must be 100 for daemon mode./); + }).toThrow(/Maximum percent must be 100 for daemon mode./); - test.done(); - }, - 'errors if minimum not less than maximum'(test: Test) { + }); + + test('errors if minimum not less than maximum', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1299,7 +1299,7 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { new ecs.Ec2Service(stack, 'Ec2Service', { cluster, taskDefinition, @@ -1307,12 +1307,12 @@ nodeunitShim({ minHealthyPercent: 100, maxHealthyPercent: 100, }); - }, /Minimum healthy percent must be less than maximum healthy percent./); + }).toThrow(/Minimum healthy percent must be less than maximum healthy percent./); - test.done(); - }, - 'errors if no container definitions'(test: Test) { + }); + + test('errors if no container definitions', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1326,14 +1326,14 @@ nodeunitShim({ }); // THEN - test.throws(() => { - expect(stack); - }, /one essential container/); + expect(() => { + SynthUtils.synthesize(stack); + }).toThrow(/one essential container/); - test.done(); - }, - 'allows adding the default container after creating the service'(test: Test) { + }); + + test('allows adding the default container after creating the service', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1353,18 +1353,18 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { Name: 'main', }, ], - })); + }); - test.done(); - }, - 'sets daemon scheduling strategy'(test: Test) { + }); + + test('sets daemon scheduling strategy', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1384,19 +1384,19 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { SchedulingStrategy: 'DAEMON', DeploymentConfiguration: { MaximumPercent: 100, MinimumHealthyPercent: 0, }, - })); + }); - test.done(); - }, - 'with a TaskDefinition with Bridge network mode': { - 'it errors if vpcSubnets is specified'(test: Test) { + }); + + describe('with a TaskDefinition with Bridge network mode', () => { + test('it errors if vpcSubnets is specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1412,7 +1412,7 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { new ecs.Ec2Service(stack, 'Ec2Service', { cluster, taskDefinition, @@ -1423,10 +1423,10 @@ nodeunitShim({ }); // THEN - test.done(); - }, - 'it errors if assignPublicIp is true'(test: Test) { + }); + + test('it errors if assignPublicIp is true', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1442,19 +1442,19 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { new ecs.Ec2Service(stack, 'Ec2Service', { cluster, taskDefinition, assignPublicIp: true, }); - }, /vpcSubnets, securityGroup\(s\) and assignPublicIp can only be used in AwsVpc networking mode/); + }).toThrow(/vpcSubnets, securityGroup\(s\) and assignPublicIp can only be used in AwsVpc networking mode/); // THEN - test.done(); - }, - 'it errors if vpc subnets is provided'(test: Test) { + }); + + test('it errors if vpc subnets is provided', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1474,7 +1474,7 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { new ecs.Ec2Service(stack, 'Ec2Service', { cluster, taskDefinition, @@ -1482,13 +1482,13 @@ nodeunitShim({ subnets: [subnet], }, }); - }, /vpcSubnets, securityGroup\(s\) and assignPublicIp can only be used in AwsVpc networking mode/); + }).toThrow(/vpcSubnets, securityGroup\(s\) and assignPublicIp can only be used in AwsVpc networking mode/); // THEN - test.done(); - }, - 'it errors if security group is provided'(test: Test) { + }); + + test('it errors if security group is provided', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1504,19 +1504,19 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { new ecs.Ec2Service(stack, 'Ec2Service', { cluster, taskDefinition, securityGroup, }); - }, /vpcSubnets, securityGroup\(s\) and assignPublicIp can only be used in AwsVpc networking mode/); + }).toThrow(/vpcSubnets, securityGroup\(s\) and assignPublicIp can only be used in AwsVpc networking mode/); // THEN - test.done(); - }, - 'it errors if multiple security groups is provided'(test: Test) { + }); + + test('it errors if multiple security groups is provided', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1535,21 +1535,21 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { new ecs.Ec2Service(stack, 'Ec2Service', { cluster, taskDefinition, securityGroups, }); - }, /vpcSubnets, securityGroup\(s\) and assignPublicIp can only be used in AwsVpc networking mode/); + }).toThrow(/vpcSubnets, securityGroup\(s\) and assignPublicIp can only be used in AwsVpc networking mode/); // THEN - test.done(); - }, - }, - 'with a TaskDefinition with AwsVpc network mode': { - 'it creates a security group for the service'(test: Test) { + }); + }); + + describe('with a TaskDefinition with AwsVpc network mode', () => { + test('it creates a security group for the service', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1570,7 +1570,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { NetworkConfiguration: { AwsvpcConfiguration: { AssignPublicIp: 'DISABLED', @@ -1592,12 +1592,12 @@ nodeunitShim({ ], }, }, - })); + }); - test.done(); - }, - 'it allows vpcSubnets'(test: Test) { + }); + + test('it allows vpcSubnets', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1621,11 +1621,11 @@ nodeunitShim({ }); // THEN - test.done(); - }, - }, - 'with distinctInstance placement constraint'(test: Test) { + }); + }); + + test('with distinctInstance placement constraint', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1645,16 +1645,16 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { PlacementConstraints: [{ Type: 'distinctInstance', }], - })); + }); + - test.done(); - }, + }); - 'with memberOf placement constraints'(test: Test) { + test('with memberOf placement constraints', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1675,17 +1675,17 @@ nodeunitShim({ service.addPlacementConstraints(PlacementConstraint.memberOf('attribute:ecs.instance-type =~ t2.*')); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { PlacementConstraints: [{ Expression: 'attribute:ecs.instance-type =~ t2.*', Type: 'memberOf', }], - })); + }); + - test.done(); - }, + }); - 'with spreadAcross container instances strategy'(test: Test) { + test('with spreadAcross container instances strategy', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1707,17 +1707,17 @@ nodeunitShim({ service.addPlacementStrategies(PlacementStrategy.spreadAcrossInstances()); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { PlacementStrategies: [{ Field: 'instanceId', Type: 'spread', }], - })); + }); + - test.done(); - }, + }); - 'with spreadAcross placement strategy'(test: Test) { + test('with spreadAcross placement strategy', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1738,36 +1738,36 @@ nodeunitShim({ service.addPlacementStrategies(PlacementStrategy.spreadAcross(ecs.BuiltInAttributes.AVAILABILITY_ZONE)); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { PlacementStrategies: [{ Field: 'attribute:ecs.availability-zone', Type: 'spread', }], - })); + }); + - test.done(); - }, + }); - 'can turn PlacementStrategy into json format'(test: Test) { + test('can turn PlacementStrategy into json format', () => { // THEN - test.deepEqual(PlacementStrategy.spreadAcross(ecs.BuiltInAttributes.AVAILABILITY_ZONE).toJson(), [{ + expect(PlacementStrategy.spreadAcross(ecs.BuiltInAttributes.AVAILABILITY_ZONE).toJson()).toEqual([{ type: 'spread', field: 'attribute:ecs.availability-zone', }]); - test.done(); - }, - 'can turn PlacementConstraints into json format'(test: Test) { + }); + + test('can turn PlacementConstraints into json format', () => { // THEN - test.deepEqual(PlacementConstraint.distinctInstances().toJson(), [{ + expect(PlacementConstraint.distinctInstances().toJson()).toEqual([{ type: 'distinctInstance', }]); - test.done(); - }, - 'errors when spreadAcross with no input'(test: Test) { + }); + + test('errors when spreadAcross with no input', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1786,14 +1786,14 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { service.addPlacementStrategies(PlacementStrategy.spreadAcross()); - }, 'spreadAcross: give at least one field to spread by'); + }).toThrow('spreadAcross: give at least one field to spread by'); + - test.done(); - }, + }); - 'errors with spreadAcross placement strategy if daemon specified'(test: Test) { + test('errors with spreadAcross placement strategy if daemon specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1813,14 +1813,14 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { service.addPlacementStrategies(PlacementStrategy.spreadAcross(ecs.BuiltInAttributes.AVAILABILITY_ZONE)); }); - test.done(); - }, - 'with no placement constraints'(test: Test) { + }); + + test('with no placement constraints', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1839,14 +1839,14 @@ nodeunitShim({ }); // THEN - expect(stack).notTo(haveResource('AWS::ECS::Service', { + expect(stack).not.toHaveResource('AWS::ECS::Service', { PlacementConstraints: undefined, - })); + }); + - test.done(); - }, + }); - 'with both propagateTags and propagateTaskTagsFrom defined'(test: Test) { + test('with both propagateTags and propagateTaskTagsFrom defined', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1859,18 +1859,18 @@ nodeunitShim({ memoryLimitMiB: 512, }); - test.throws(() => { + expect(() => { new ecs.Ec2Service(stack, 'Ec2Service', { cluster, taskDefinition, propagateTags: PropagatedTagSource.SERVICE, propagateTaskTagsFrom: PropagatedTagSource.SERVICE, }); - }, /You can only specify either propagateTags or propagateTaskTagsFrom. Alternatively, you can leave both blank/); - test.done(); - }, + }).toThrow(/You can only specify either propagateTags or propagateTaskTagsFrom. Alternatively, you can leave both blank/); + + }); - 'with no placement strategy if daemon specified'(test: Test) { + test('with no placement strategy if daemon specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1890,14 +1890,14 @@ nodeunitShim({ }); // THEN - expect(stack).notTo(haveResource('AWS::ECS::Service', { + expect(stack).not.toHaveResource('AWS::ECS::Service', { PlacementStrategies: undefined, - })); + }); + - test.done(); - }, + }); - 'with random placement strategy'(test: Test) { + test('with random placement strategy', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc'); @@ -1918,16 +1918,16 @@ nodeunitShim({ service.addPlacementStrategies(PlacementStrategy.randomly()); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { PlacementStrategies: [{ Type: 'random', }], - })); + }); - test.done(); - }, - 'errors with random placement strategy if daemon specified'(test: Test) { + }); + + test('errors with random placement strategy if daemon specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc'); @@ -1947,14 +1947,14 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { service.addPlacementStrategies(PlacementStrategy.randomly()); - }); + }).toThrow(); - test.done(); - }, - 'with packedbyCpu placement strategy'(test: Test) { + }); + + test('with packedbyCpu placement strategy', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1975,17 +1975,17 @@ nodeunitShim({ service.addPlacementStrategies(PlacementStrategy.packedByCpu()); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { PlacementStrategies: [{ Field: 'cpu', Type: 'binpack', }], - })); + }); + - test.done(); - }, + }); - 'with packedbyMemory placement strategy'(test: Test) { + test('with packedbyMemory placement strategy', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2006,17 +2006,17 @@ nodeunitShim({ service.addPlacementStrategies(PlacementStrategy.packedByMemory()); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { PlacementStrategies: [{ Field: 'memory', Type: 'binpack', }], - })); + }); - test.done(); - }, - 'with packedBy placement strategy'(test: Test) { + }); + + test('with packedBy placement strategy', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2037,17 +2037,17 @@ nodeunitShim({ service.addPlacementStrategies(PlacementStrategy.packedBy(ecs.BinPackResource.MEMORY)); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { PlacementStrategies: [{ Field: 'memory', Type: 'binpack', }], - })); + }); + - test.done(); - }, + }); - 'errors with packedBy placement strategy if daemon specified'(test: Test) { + test('errors with packedBy placement strategy if daemon specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2067,16 +2067,16 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { service.addPlacementStrategies(PlacementStrategy.packedBy(ecs.BinPackResource.MEMORY)); - }); + }).toThrow(); - test.done(); - }, - }, - 'attachToClassicLB': { - 'allows network mode of task definition to be host'(test: Test) { + }); + }); + + describe('attachToClassicLB', () => { + test('allows network mode of task definition to be host', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'VPC'); @@ -2097,10 +2097,10 @@ nodeunitShim({ const lb = new elb.LoadBalancer(stack, 'LB', { vpc }); service.attachToClassicLB(lb); - test.done(); - }, - 'allows network mode of task definition to be bridge'(test: Test) { + }); + + test('allows network mode of task definition to be bridge', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'VPC'); @@ -2121,10 +2121,10 @@ nodeunitShim({ const lb = new elb.LoadBalancer(stack, 'LB', { vpc }); service.attachToClassicLB(lb); - test.done(); - }, - 'throws when network mode of task definition is AwsVpc'(test: Test) { + }); + + test('throws when network mode of task definition is AwsVpc', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'VPC'); @@ -2143,14 +2143,14 @@ nodeunitShim({ // THEN const lb = new elb.LoadBalancer(stack, 'LB', { vpc }); - test.throws(() => { + expect(() => { service.attachToClassicLB(lb); - }, /Cannot use a Classic Load Balancer if NetworkMode is AwsVpc. Use Host or Bridge instead./); + }).toThrow(/Cannot use a Classic Load Balancer if NetworkMode is AwsVpc. Use Host or Bridge instead./); - test.done(); - }, - 'throws when network mode of task definition is none'(test: Test) { + }); + + test('throws when network mode of task definition is none', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'VPC'); @@ -2169,16 +2169,16 @@ nodeunitShim({ // THEN const lb = new elb.LoadBalancer(stack, 'LB', { vpc }); - test.throws(() => { + expect(() => { service.attachToClassicLB(lb); - }, /Cannot use a Classic Load Balancer if NetworkMode is None. Use Host or Bridge instead./); + }).toThrow(/Cannot use a Classic Load Balancer if NetworkMode is None. Use Host or Bridge instead./); - test.done(); - }, - }, - 'attachToApplicationTargetGroup': { - 'allows network mode of task definition to be other than none'(test: Test) { + }); + }); + + describe('attachToApplicationTargetGroup', () => { + test('allows network mode of task definition to be other than none', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2203,10 +2203,10 @@ nodeunitShim({ // THEN service.attachToApplicationTargetGroup(targetGroup); - test.done(); - }, - 'throws when network mode of task definition is none'(test: Test) { + }); + + test('throws when network mode of task definition is none', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2229,15 +2229,15 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { service.attachToApplicationTargetGroup(targetGroup); - }, /Cannot use a load balancer if NetworkMode is None. Use Bridge, Host or AwsVpc instead./); + }).toThrow(/Cannot use a load balancer if NetworkMode is None. Use Bridge, Host or AwsVpc instead./); - test.done(); - }, - 'correctly setting ingress and egress port': { - 'with bridge/NAT network mode and 0 host port'(test: Test) { + }); + + describe('correctly setting ingress and egress port', () => { + test('with bridge/NAT network mode and 0 host port', () => { [ecs.NetworkMode.BRIDGE, ecs.NetworkMode.NAT].forEach((networkMode: ecs.NetworkMode) => { // GIVEN const stack = new cdk.Stack(); @@ -2269,23 +2269,23 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::EC2::SecurityGroupIngress', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroupIngress', { Description: 'Load balancer to target', FromPort: 32768, ToPort: 65535, - })); + }); - expect(stack).to(haveResource('AWS::EC2::SecurityGroupEgress', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroupEgress', { Description: 'Load balancer to target', FromPort: 32768, ToPort: 65535, - })); + }); }); - test.done(); - }, - 'with bridge/NAT network mode and host port other than 0'(test: Test) { + }); + + test('with bridge/NAT network mode and host port other than 0', () => { [ecs.NetworkMode.BRIDGE, ecs.NetworkMode.NAT].forEach((networkMode: ecs.NetworkMode) => { // GIVEN const stack = new cdk.Stack(); @@ -2317,23 +2317,23 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::EC2::SecurityGroupIngress', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroupIngress', { Description: 'Load balancer to target', FromPort: 80, ToPort: 80, - })); + }); - expect(stack).to(haveResource('AWS::EC2::SecurityGroupEgress', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroupEgress', { Description: 'Load balancer to target', FromPort: 80, ToPort: 80, - })); + }); }); - test.done(); - }, - 'with host network mode'(test: Test) { + }); + + test('with host network mode', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2364,22 +2364,22 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::EC2::SecurityGroupIngress', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroupIngress', { Description: 'Load balancer to target', FromPort: 8001, ToPort: 8001, - })); + }); - expect(stack).to(haveResource('AWS::EC2::SecurityGroupEgress', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroupEgress', { Description: 'Load balancer to target', FromPort: 8001, ToPort: 8001, - })); + }); - test.done(); - }, - 'with aws_vpc network mode'(test: Test) { + }); + + test('with aws_vpc network mode', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2410,25 +2410,25 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::EC2::SecurityGroupIngress', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroupIngress', { Description: 'Load balancer to target', FromPort: 8001, ToPort: 8001, - })); + }); - expect(stack).to(haveResource('AWS::EC2::SecurityGroupEgress', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroupEgress', { Description: 'Load balancer to target', FromPort: 8001, ToPort: 8001, - })); + }); - test.done(); - }, - }, - }, - 'attachToNetworkTargetGroup': { - 'allows network mode of task definition to be other than none'(test: Test) { + }); + }); + }); + + describe('attachToNetworkTargetGroup', () => { + test('allows network mode of task definition to be other than none', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2453,10 +2453,10 @@ nodeunitShim({ // THEN service.attachToNetworkTargetGroup(targetGroup); - test.done(); - }, - 'throws when network mode of task definition is none'(test: Test) { + }); + + test('throws when network mode of task definition is none', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2479,16 +2479,16 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { service.attachToNetworkTargetGroup(targetGroup); - }, /Cannot use a load balancer if NetworkMode is None. Use Bridge, Host or AwsVpc instead./); + }).toThrow(/Cannot use a load balancer if NetworkMode is None. Use Bridge, Host or AwsVpc instead./); - test.done(); - }, - }, - 'classic ELB': { - 'can attach to classic ELB'(test: Test) { + }); + }); + + describe('classic ELB', () => { + test('can attach to classic ELB', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'VPC'); @@ -2510,7 +2510,7 @@ nodeunitShim({ lb.addTarget(service); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { LoadBalancers: [ { ContainerName: 'web', @@ -2518,18 +2518,18 @@ nodeunitShim({ LoadBalancerName: { Ref: 'LB8A12904C' }, }, ], - })); + }); - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { // if any load balancer is configured and healthCheckGracePeriodSeconds is not // set, then it should default to 60 seconds. HealthCheckGracePeriodSeconds: 60, - })); + }); - test.done(); - }, - 'can attach any container and port as a target'(test: Test) { + }); + + test('can attach any container and port as a target', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'VPC'); @@ -2555,7 +2555,7 @@ nodeunitShim({ })); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { LoadBalancers: [ { ContainerName: 'web', @@ -2563,14 +2563,14 @@ nodeunitShim({ LoadBalancerName: { Ref: 'LB8A12904C' }, }, ], - })); + }); - test.done(); - }, - }, - 'When enabling service discovery': { - 'throws if namespace has not been added to cluster'(test: Test) { + }); + }); + + describe('When enabling service discovery', () => { + test('throws if namespace has not been added to cluster', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2586,7 +2586,7 @@ nodeunitShim({ container.addPortMappings({ containerPort: 8000 }); // THEN - test.throws(() => { + expect(() => { new ecs.Ec2Service(stack, 'Service', { cluster, taskDefinition, @@ -2594,12 +2594,12 @@ nodeunitShim({ name: 'myApp', }, }); - }, /Cannot enable service discovery if a Cloudmap Namespace has not been created in the cluster./); + }).toThrow(/Cannot enable service discovery if a Cloudmap Namespace has not been created in the cluster./); + - test.done(); - }, + }); - 'throws if network mode is none'(test: Test) { + test('throws if network mode is none', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2617,7 +2617,7 @@ nodeunitShim({ cluster.addDefaultCloudMapNamespace({ name: 'foo.com' }); // THEN - test.throws(() => { + expect(() => { new ecs.Ec2Service(stack, 'Service', { cluster, taskDefinition, @@ -2625,12 +2625,12 @@ nodeunitShim({ name: 'myApp', }, }); - }, /Cannot use a service discovery if NetworkMode is None. Use Bridge, Host or AwsVpc instead./); + }).toThrow(/Cannot use a service discovery if NetworkMode is None. Use Bridge, Host or AwsVpc instead./); - test.done(); - }, - 'creates AWS Cloud Map service for Private DNS namespace with bridge network mode'(test: Test) { + }); + + test('creates AWS Cloud Map service for Private DNS namespace with bridge network mode', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2660,7 +2660,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { ServiceRegistries: [ { ContainerName: 'MainContainer', @@ -2673,9 +2673,9 @@ nodeunitShim({ }, }, ], - })); + }); - expect(stack).to(haveResource('AWS::ServiceDiscovery::Service', { + expect(stack).toHaveResource('AWS::ServiceDiscovery::Service', { DnsConfig: { DnsRecords: [ { @@ -2701,12 +2701,12 @@ nodeunitShim({ 'Id', ], }, - })); + }); + - test.done(); - }, + }); - 'creates AWS Cloud Map service for Private DNS namespace with host network mode'(test: Test) { + test('creates AWS Cloud Map service for Private DNS namespace with host network mode', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2737,7 +2737,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { ServiceRegistries: [ { ContainerName: 'MainContainer', @@ -2750,9 +2750,9 @@ nodeunitShim({ }, }, ], - })); + }); - expect(stack).to(haveResource('AWS::ServiceDiscovery::Service', { + expect(stack).toHaveResource('AWS::ServiceDiscovery::Service', { DnsConfig: { DnsRecords: [ { @@ -2778,12 +2778,12 @@ nodeunitShim({ 'Id', ], }, - })); + }); + - test.done(); - }, + }); - 'throws if wrong DNS record type specified with bridge network mode'(test: Test) { + test('throws if wrong DNS record type specified with bridge network mode', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2803,7 +2803,7 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { new ecs.Ec2Service(stack, 'Service', { cluster, taskDefinition, @@ -2812,12 +2812,12 @@ nodeunitShim({ dnsRecordType: cloudmap.DnsRecordType.A, }, }); - }, /SRV records must be used when network mode is Bridge or Host./); + }).toThrow(/SRV records must be used when network mode is Bridge or Host./); + - test.done(); - }, + }); - 'creates AWS Cloud Map service for Private DNS namespace with AwsVpc network mode'(test: Test) { + test('creates AWS Cloud Map service for Private DNS namespace with AwsVpc network mode', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2848,7 +2848,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { ServiceRegistries: [ { RegistryArn: { @@ -2859,9 +2859,9 @@ nodeunitShim({ }, }, ], - })); + }); - expect(stack).to(haveResource('AWS::ServiceDiscovery::Service', { + expect(stack).toHaveResource('AWS::ServiceDiscovery::Service', { DnsConfig: { DnsRecords: [ { @@ -2887,12 +2887,12 @@ nodeunitShim({ 'Id', ], }, - })); + }); + - test.done(); - }, + }); - 'creates AWS Cloud Map service for Private DNS namespace with AwsVpc network mode with SRV records'(test: Test) { + test('creates AWS Cloud Map service for Private DNS namespace with AwsVpc network mode with SRV records', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2924,7 +2924,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { ServiceRegistries: [ { ContainerName: 'MainContainer', @@ -2937,9 +2937,9 @@ nodeunitShim({ }, }, ], - })); + }); - expect(stack).to(haveResource('AWS::ServiceDiscovery::Service', { + expect(stack).toHaveResource('AWS::ServiceDiscovery::Service', { DnsConfig: { DnsRecords: [ { @@ -2965,12 +2965,12 @@ nodeunitShim({ 'Id', ], }, - })); + }); + - test.done(); - }, + }); - 'user can select any container and port'(test: Test) { + test('user can select any container and port', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -3008,7 +3008,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::Service', { + expect(stack).toHaveResourceLike('AWS::ECS::Service', { ServiceRegistries: [ { RegistryArn: { 'Fn::GetAtt': ['ServiceCloudmapService046058A4', 'Arn'] }, @@ -3016,12 +3016,12 @@ nodeunitShim({ ContainerPort: 8001, }, ], - })); + }); + - test.done(); - }, + }); - 'By default, the container name is the default'(test: Test) { + test('By default, the container name is the default', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -3053,17 +3053,17 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::Service', { + expect(stack).toHaveResourceLike('AWS::ECS::Service', { ServiceRegistries: [{ ContainerName: 'main', ContainerPort: undefined, }], - })); + }); + - test.done(); - }, + }); - 'For SRV, by default, container name is default container and port is the default container port'(test: Test) { + test('For SRV, by default, container name is default container and port is the default container port', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -3097,17 +3097,17 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::Service', { + expect(stack).toHaveResourceLike('AWS::ECS::Service', { ServiceRegistries: [{ ContainerName: 'main', ContainerPort: 1234, }], - })); + }); + - test.done(); - }, + }); - 'allows SRV service discovery to select the container and port'(test: Test) { + test('allows SRV service discovery to select the container and port', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -3144,17 +3144,17 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::Service', { + expect(stack).toHaveResourceLike('AWS::ECS::Service', { ServiceRegistries: [{ ContainerName: 'second', ContainerPort: 4321, }], - })); + }); + - test.done(); - }, + }); - 'throws if SRV and container is not part of task definition'(test: Test) { + test('throws if SRV and container is not part of task definition', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -3182,7 +3182,7 @@ nodeunitShim({ }); // WHEN - test.throws(() => { + expect(() => { new ecs.Ec2Service(stack, 'Service', { cluster, taskDefinition, @@ -3192,12 +3192,12 @@ nodeunitShim({ containerPort: 4321, }, }); - }, /another task definition/i); + }).toThrow(/another task definition/i); + - test.done(); - }, + }); - 'throws if SRV and the container port is not mapped'(test: Test) { + test('throws if SRV and the container port is not mapped', () => { const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); @@ -3217,7 +3217,7 @@ nodeunitShim({ container.addPortMappings({ containerPort: 8000 }); - test.throws(() => { + expect(() => { new ecs.Ec2Service(stack, 'Service', { cluster, taskDefinition, @@ -3227,13 +3227,13 @@ nodeunitShim({ containerPort: 4321, }, }); - }, /container port.*not.*mapped/i); + }).toThrow(/container port.*not.*mapped/i); + - test.done(); - }, - }, + }); + }); - 'Metric'(test: Test) { + test('Metric', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -3251,7 +3251,7 @@ nodeunitShim({ }); // THEN - test.deepEqual(stack.resolve(service.metricMemoryUtilization()), { + expect(stack.resolve(service.metricMemoryUtilization())).toEqual({ dimensions: { ClusterName: { Ref: 'EcsCluster97242B84' }, ServiceName: { 'Fn::GetAtt': ['ServiceD69D759B', 'Name'] }, @@ -3262,7 +3262,7 @@ nodeunitShim({ statistic: 'Average', }); - test.deepEqual(stack.resolve(service.metricCpuUtilization()), { + expect(stack.resolve(service.metricCpuUtilization())).toEqual({ dimensions: { ClusterName: { Ref: 'EcsCluster97242B84' }, ServiceName: { 'Fn::GetAtt': ['ServiceD69D759B', 'Name'] }, @@ -3273,11 +3273,11 @@ nodeunitShim({ statistic: 'Average', }); - test.done(); - }, - 'When import an EC2 Service': { - 'with serviceArn'(test: Test) { + }); + + describe('When import an EC2 Service', () => { + test('with serviceArn', () => { // GIVEN const stack = new cdk.Stack(); const cluster = new ecs.Cluster(stack, 'EcsCluster'); @@ -3289,13 +3289,13 @@ nodeunitShim({ }); // THEN - test.equal(service.serviceArn, 'arn:aws:ecs:us-west-2:123456789012:service/my-http-service'); - test.equal(service.serviceName, 'my-http-service'); + expect(service.serviceArn).toEqual('arn:aws:ecs:us-west-2:123456789012:service/my-http-service'); + expect(service.serviceName).toEqual('my-http-service'); - test.done(); - }, - 'with serviceName'(test: Test) { + }); + + test('with serviceName', () => { // GIVEN const stack = new cdk.Stack(); const pseudo = new cdk.ScopedAws(stack); @@ -3308,40 +3308,40 @@ nodeunitShim({ }); // THEN - test.deepEqual(stack.resolve(service.serviceArn), stack.resolve(`arn:${pseudo.partition}:ecs:${pseudo.region}:${pseudo.accountId}:service/my-http-service`)); - test.equal(service.serviceName, 'my-http-service'); + expect(stack.resolve(service.serviceArn)).toEqual(stack.resolve(`arn:${pseudo.partition}:ecs:${pseudo.region}:${pseudo.accountId}:service/my-http-service`)); + expect(service.serviceName).toEqual('my-http-service'); - test.done(); - }, - 'throws an exception if both serviceArn and serviceName were provided for fromEc2ServiceAttributes'(test: Test) { + }); + + test('throws an exception if both serviceArn and serviceName were provided for fromEc2ServiceAttributes', () => { // GIVEN const stack = new cdk.Stack(); const cluster = new ecs.Cluster(stack, 'EcsCluster'); - test.throws(() => { + expect(() => { ecs.Ec2Service.fromEc2ServiceAttributes(stack, 'EcsService', { serviceArn: 'arn:aws:ecs:us-west-2:123456789012:service/my-http-service', serviceName: 'my-http-service', cluster, }); - }, /only specify either serviceArn or serviceName/); + }).toThrow(/only specify either serviceArn or serviceName/); - test.done(); - }, - 'throws an exception if neither serviceArn nor serviceName were provided for fromEc2ServiceAttributes'(test: Test) { + }); + + test('throws an exception if neither serviceArn nor serviceName were provided for fromEc2ServiceAttributes', () => { // GIVEN const stack = new cdk.Stack(); const cluster = new ecs.Cluster(stack, 'EcsCluster'); - test.throws(() => { + expect(() => { ecs.Ec2Service.fromEc2ServiceAttributes(stack, 'EcsService', { cluster, }); - }, /only specify either serviceArn or serviceName/); + }).toThrow(/only specify either serviceArn or serviceName/); - test.done(); - }, - }, + + }); + }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/environment-file.test.ts b/packages/@aws-cdk/aws-ecs/test/environment-file.test.ts index e80651cbbd65b..815973a80e602 100644 --- a/packages/@aws-cdk/aws-ecs/test/environment-file.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/environment-file.test.ts @@ -1,23 +1,23 @@ +import '@aws-cdk/assert-internal/jest'; import * as path from 'path'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as ecs from '../lib'; /* eslint-disable dot-notation */ -nodeunitShim({ - 'ecs.EnvironmentFile.fromAsset': { - 'fails if asset is not a single file'(test: Test) { +describe('environment file', () => { + describe('ecs.EnvironmentFile.fromAsset', () => { + test('fails if asset is not a single file', () => { // GIVEN const stack = new cdk.Stack(); const fileAsset = ecs.EnvironmentFile.fromAsset(path.join(__dirname, 'demo-envfiles')); // THEN - test.throws(() => defineContainerDefinition(stack, fileAsset), /Asset must be a single file/); - test.done(); - }, + expect(() => defineContainerDefinition(stack, fileAsset)).toThrow(/Asset must be a single file/); - 'only one environment file asset object is created even if multiple container definitions use the same file'(test: Test) { + }); + + test('only one environment file asset object is created even if multiple container definitions use the same file', () => { // GIVEN const app = new cdk.App(); const stack = new cdk.Stack(app); @@ -41,10 +41,10 @@ nodeunitShim({ const synthesized = assembly.stacks[0]; // container one has an asset, container two does not - test.deepEqual(synthesized.assets.length, 1); - test.done(); - }, - }, + expect(synthesized.assets.length).toEqual(1); + + }); + }); }); function defineContainerDefinition(stack: cdk.Stack, environmentFile: ecs.EnvironmentFile) { diff --git a/packages/@aws-cdk/aws-ecs/test/external/external-service.test.ts b/packages/@aws-cdk/aws-ecs/test/external/external-service.test.ts index d01eaa14f11b9..94384a464bb47 100644 --- a/packages/@aws-cdk/aws-ecs/test/external/external-service.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/external/external-service.test.ts @@ -4,13 +4,12 @@ import * as ec2 from '@aws-cdk/aws-ec2'; import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2'; import * as cloudmap from '@aws-cdk/aws-servicediscovery'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as ecs from '../../lib'; import { LaunchType } from '../../lib/base/base-service'; -nodeunitShim({ - 'When creating an External Service': { - 'with only required properties set, it correctly sets default properties'(test: Test) { +describe('external service', () => { + describe('When creating an External Service', () => { + test('with only required properties set, it correctly sets default properties', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -44,13 +43,13 @@ nodeunitShim({ LaunchType: LaunchType.EXTERNAL, }); - test.notEqual(service.node.defaultChild, undefined); + expect(service.node.defaultChild).toBeDefined(); - test.done(); - }, - }, - 'with all properties set'(test: Test) { + }); + }); + + test('with all properties set', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -97,10 +96,10 @@ nodeunitShim({ ServiceName: 'bonjour', }); - test.done(); - }, - 'with cloudmap set on cluster, throw error'(test: Test) { + }); + + test('with cloudmap set on cluster, throw error', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -130,10 +129,10 @@ nodeunitShim({ serviceName: 'bonjour', })).toThrow('Cloud map integration is not supported for External service' ); - test.done(); - }, - 'with multiple security groups, it correctly updates the cfn template'(test: Test) { + }); + + test('with multiple security groups, it correctly updates the cfn template', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -205,10 +204,10 @@ nodeunitShim({ ], }); - test.done(); - }, - 'throws when task definition is not External compatible'(test: Test) { + }); + + test('throws when task definition is not External compatible', () => { const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); @@ -227,10 +226,10 @@ nodeunitShim({ taskDefinition, })).toThrow('Supplied TaskDefinition is not configured for compatibility with ECS Anywhere cluster'); - test.done(); - }, - 'errors if minimum not less than maximum'(test: Test) { + }); + + test('errors if minimum not less than maximum', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -250,10 +249,10 @@ nodeunitShim({ maxHealthyPercent: 100, })).toThrow('Minimum healthy percent must be less than maximum healthy percent.'); - test.done(); - }, - 'error if cloudmap options provided with external service'(test: Test) { + }); + + test('error if cloudmap options provided with external service', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -276,10 +275,10 @@ nodeunitShim({ })).toThrow('Cloud map options are not supported for External service'); // THEN - test.done(); - }, - 'error if enableExecuteCommand options provided with external service'(test: Test) { + }); + + test('error if enableExecuteCommand options provided with external service', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -300,10 +299,10 @@ nodeunitShim({ })).toThrow('Enable Execute Command options are not supported for External service'); // THEN - test.done(); - }, - 'error if capacityProviderStrategies options provided with external service'(test: Test) { + }); + + test('error if capacityProviderStrategies options provided with external service', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -338,10 +337,10 @@ nodeunitShim({ })).toThrow('Capacity Providers are not supported for External service'); // THEN - test.done(); - }, - 'error when performing attachToApplicationTargetGroup to an external service'(test: Test) { + }); + + test('error when performing attachToApplicationTargetGroup to an external service', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -369,10 +368,10 @@ nodeunitShim({ expect(() => service.attachToApplicationTargetGroup(targetGroup)).toThrow('Application load balancer cannot be attached to an external service'); // THEN - test.done(); - }, - 'error when performing loadBalancerTarget to an external service'(test: Test) { + }); + + test('error when performing loadBalancerTarget to an external service', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -396,10 +395,10 @@ nodeunitShim({ })).toThrow('External service cannot be attached as load balancer targets'); // THEN - test.done(); - }, - 'error when performing registerLoadBalancerTargets to an external service'(test: Test) { + }); + + test('error when performing registerLoadBalancerTargets to an external service', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -430,10 +429,10 @@ nodeunitShim({ )).toThrow('External service cannot be registered as load balancer targets'); // THEN - test.done(); - }, - 'error when performing autoScaleTaskCount to an external service'(test: Test) { + }); + + test('error when performing autoScaleTaskCount to an external service', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -458,10 +457,10 @@ nodeunitShim({ })).toThrow('Autoscaling not supported for external service'); // THEN - test.done(); - }, - 'error when performing enableCloudMap to an external service'(test: Test) { + }); + + test('error when performing enableCloudMap to an external service', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -483,10 +482,10 @@ nodeunitShim({ expect(() => service.enableCloudMap({})).toThrow('Cloud map integration not supported for an external service'); // THEN - test.done(); - }, - 'error when performing associateCloudMapService to an external service'(test: Test) { + }); + + test('error when performing associateCloudMapService to an external service', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -523,6 +522,6 @@ nodeunitShim({ })).toThrow('Cloud map service association is not supported for an external service'); // THEN - test.done(); - }, + + }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/external/external-task-definition.test.ts b/packages/@aws-cdk/aws-ecs/test/external/external-task-definition.test.ts index c5fd8f942f1f0..c4e296b2c6831 100644 --- a/packages/@aws-cdk/aws-ecs/test/external/external-task-definition.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/external/external-task-definition.test.ts @@ -6,12 +6,11 @@ import * as iam from '@aws-cdk/aws-iam'; import * as secretsmanager from '@aws-cdk/aws-secretsmanager'; import * as ssm from '@aws-cdk/aws-ssm'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as ecs from '../../lib'; -nodeunitShim({ - 'When creating an External TaskDefinition': { - 'with only required properties set, it correctly sets default properties'(test: Test) { +describe('external task definition', () => { + describe('When creating an External TaskDefinition', () => { + test('with only required properties set, it correctly sets default properties', () => { // GIVEN const stack = new cdk.Stack(); new ecs.ExternalTaskDefinition(stack, 'ExternalTaskDef'); @@ -23,10 +22,10 @@ nodeunitShim({ RequiresCompatibilities: ['EXTERNAL'], }); - test.done(); - }, - 'with all properties set'(test: Test) { + }); + + test('with all properties set', () => { // GIVEN const stack = new cdk.Stack(); new ecs.ExternalTaskDefinition(stack, 'ExternalTaskDef', { @@ -64,10 +63,10 @@ nodeunitShim({ }, }); - test.done(); - }, - 'correctly sets containers'(test: Test) { + }); + + test('correctly sets containers', () => { // GIVEN const stack = new cdk.Stack(); @@ -131,10 +130,10 @@ nodeunitShim({ }, }); - test.done(); - }, - 'all container definition options defined'(test: Test) { + }); + + test('all container definition options defined', () => { const stack = new cdk.Stack(); const taskDefinition = new ecs.ExternalTaskDefinition(stack, 'ExternalTaskDef'); @@ -330,10 +329,10 @@ nodeunitShim({ ], }); - test.done(); - }, - 'correctly sets containers from ECR repository using all props'(test: Test) { + }); + + test('correctly sets containers from ECR repository using all props', () => { // GIVEN const stack = new cdk.Stack(); @@ -423,11 +422,11 @@ nodeunitShim({ }], }); - test.done(); - }, - }, - 'correctly sets containers from ECR repository using an image tag'(test: Test) { + }); + }); + + test('correctly sets containers from ECR repository using an image tag', () => { // GIVEN const stack = new cdk.Stack(); @@ -498,10 +497,10 @@ nodeunitShim({ }], }); - test.done(); - }, - 'correctly sets containers from ECR repository using an image digest'(test: Test) { + }); + + test('correctly sets containers from ECR repository using an image digest', () => { // GIVEN const stack = new cdk.Stack(); const taskDefinition = new ecs.ExternalTaskDefinition(stack, 'ExternalTaskDef'); @@ -571,10 +570,10 @@ nodeunitShim({ }], }); - test.done(); - }, - 'correctly sets containers from ECR repository using default props'(test: Test) { + }); + + test('correctly sets containers from ECR repository using default props', () => { // GIVEN const stack = new cdk.Stack(); const taskDefinition = new ecs.ExternalTaskDefinition(stack, 'ExternalTaskDef'); @@ -588,10 +587,10 @@ nodeunitShim({ // THEN expect(stack).toHaveResource('AWS::ECR::Repository', {}); - test.done(); - }, - 'warns when setting containers from ECR repository using fromRegistry method'(test: Test) { + }); + + test('warns when setting containers from ECR repository using fromRegistry method', () => { // GIVEN const stack = new cdk.Stack(); @@ -605,10 +604,10 @@ nodeunitShim({ // THEN expect(container.node.metadata[0].data).toEqual("Proper policies need to be attached before pulling from ECR repository, or use 'fromEcrRepository'."); - test.done(); - }, - 'correctly sets volumes from'(test: Test) { + }); + + test('correctly sets volumes from', () => { const stack = new cdk.Stack(); const taskDefinition = new ecs.ExternalTaskDefinition(stack, 'ExternalTaskDef', {}); @@ -620,10 +619,10 @@ nodeunitShim({ name: 'scratch', })).toThrow('External task definitions doesnt support volumes' ); - test.done(); - }, - 'error when interferenceAccelerators set'(test: Test) { + }); + + test('error when interferenceAccelerators set', () => { const stack = new cdk.Stack(); const taskDefinition = new ecs.ExternalTaskDefinition(stack, 'ExternalTaskDef', {}); @@ -633,6 +632,6 @@ nodeunitShim({ deviceType: 'eia2.medium', })).toThrow('Cannot use inference accelerators on tasks that run on External service'); - test.done(); - }, + + }); }); \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ecs/test/fargate/fargate-service.test.ts b/packages/@aws-cdk/aws-ecs/test/fargate/fargate-service.test.ts index f7c33eb7b8af9..ef4ceae4ccedc 100644 --- a/packages/@aws-cdk/aws-ecs/test/fargate/fargate-service.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/fargate/fargate-service.test.ts @@ -1,4 +1,5 @@ -import { expect, haveResource, haveResourceLike, ABSENT } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; +import { ABSENT, SynthUtils } from '@aws-cdk/assert-internal'; import * as appscaling from '@aws-cdk/aws-applicationautoscaling'; import * as cloudwatch from '@aws-cdk/aws-cloudwatch'; import * as ec2 from '@aws-cdk/aws-ec2'; @@ -9,13 +10,12 @@ import * as s3 from '@aws-cdk/aws-s3'; import * as secretsmanager from '@aws-cdk/aws-secretsmanager'; import * as cloudmap from '@aws-cdk/aws-servicediscovery'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as ecs from '../../lib'; import { DeploymentControllerType, LaunchType, PropagatedTagSource } from '../../lib/base/base-service'; -nodeunitShim({ - 'When creating a Fargate Service': { - 'with only required properties set, it correctly sets default properties'(test: Test) { +describe('fargate service', () => { + describe('When creating a Fargate Service', () => { + test('with only required properties set, it correctly sets default properties', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -32,7 +32,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { TaskDefinition: { Ref: 'FargateTaskDefC6FB60B4', }, @@ -66,9 +66,9 @@ nodeunitShim({ ], }, }, - })); + }); - expect(stack).to(haveResource('AWS::EC2::SecurityGroup', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { GroupDescription: 'Default/FargateService/SecurityGroup', SecurityGroupEgress: [ { @@ -80,14 +80,14 @@ nodeunitShim({ VpcId: { Ref: 'MyVpcF9F0CA6F', }, - })); + }); + + expect(service.node.defaultChild).toBeDefined(); - test.notEqual(service.node.defaultChild, undefined); - test.done(); - }, + }); - 'can create service with default settings if VPC only has public subnets'(test: Test) { + test('can create service with default settings if VPC only has public subnets', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', { @@ -112,10 +112,10 @@ nodeunitShim({ }); // THEN -- did not throw - test.done(); - }, - 'does not set launchType when capacity provider strategies specified (deprecated)'(test: Test) { + }); + + test('does not set launchType when capacity provider strategies specified (deprecated)', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -147,15 +147,15 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Cluster', { + expect(stack).toHaveResource('AWS::ECS::Cluster', { CapacityProviders: ABSENT, - })); + }); - expect(stack).to(haveResource('AWS::ECS::ClusterCapacityProviderAssociations', { + expect(stack).toHaveResource('AWS::ECS::ClusterCapacityProviderAssociations', { CapacityProviders: ['FARGATE', 'FARGATE_SPOT'], - })); + }); - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { TaskDefinition: { Ref: 'FargateTaskDefC6FB60B4', }, @@ -199,12 +199,12 @@ nodeunitShim({ ], }, }, - })); + }); - test.done(); - }, - 'does not set launchType when capacity provider strategies specified'(test: Test) { + }); + + test('does not set launchType when capacity provider strategies specified', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -237,15 +237,15 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Cluster', { + expect(stack).toHaveResource('AWS::ECS::Cluster', { CapacityProviders: ABSENT, - })); + }); - expect(stack).to(haveResource('AWS::ECS::ClusterCapacityProviderAssociations', { + expect(stack).toHaveResource('AWS::ECS::ClusterCapacityProviderAssociations', { CapacityProviders: ['FARGATE', 'FARGATE_SPOT'], - })); + }); - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { TaskDefinition: { Ref: 'FargateTaskDefC6FB60B4', }, @@ -290,12 +290,12 @@ nodeunitShim({ ], }, }, - })); + }); + - test.done(); - }, + }); - 'with custom cloudmap namespace'(test: Test) { + test('with custom cloudmap namespace', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -324,7 +324,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ServiceDiscovery::Service', { + expect(stack).toHaveResource('AWS::ServiceDiscovery::Service', { DnsConfig: { DnsRecords: [ { @@ -350,19 +350,19 @@ nodeunitShim({ 'Id', ], }, - })); + }); - expect(stack).to(haveResource('AWS::ServiceDiscovery::PrivateDnsNamespace', { + expect(stack).toHaveResource('AWS::ServiceDiscovery::PrivateDnsNamespace', { Name: 'scorekeep.com', Vpc: { Ref: 'MyVpcF9F0CA6F', }, - })); + }); - test.done(); - }, - 'with user-provided cloudmap service'(test: Test) { + }); + + test('with user-provided cloudmap service', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -399,7 +399,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { ServiceRegistries: [ { ContainerName: 'web', @@ -407,12 +407,12 @@ nodeunitShim({ RegistryArn: { 'Fn::GetAtt': ['ServiceDBC79909', 'Arn'] }, }, ], - })); + }); - test.done(); - }, - 'errors when more than one service registry used'(test: Test) { + }); + + test('errors when more than one service registry used', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -446,18 +446,18 @@ nodeunitShim({ }); // WHEN / THEN - test.throws(() => { + expect(() => { ecsService.associateCloudMapService({ service: cloudMapService, container: container, containerPort: 8000, }); - }, /at most one service registry/i); + }).toThrow(/at most one service registry/i); - test.done(); - }, - 'with all properties set'(test: Test) { + }); + + test('with all properties set', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -503,9 +503,9 @@ nodeunitShim({ }); // THEN - test.ok(svc.cloudMapService !== undefined); + expect(svc.cloudMapService).toBeDefined(); - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { TaskDefinition: { Ref: 'FargateTaskDefC6FB60B4', }, @@ -558,12 +558,12 @@ nodeunitShim({ }, }, ], - })); + }); - test.done(); - }, - 'throws when task definition is not Fargate compatible'(test: Test) { + }); + + test('throws when task definition is not Fargate compatible', () => { const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); @@ -576,17 +576,17 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { new ecs.FargateService(stack, 'FargateService', { cluster, taskDefinition, }); - }, /Supplied TaskDefinition is not configured for compatibility with Fargate/); + }).toThrow(/Supplied TaskDefinition is not configured for compatibility with Fargate/); - test.done(); - }, - 'throws whith secret json field on unsupported platform version'(test: Test) { + }); + + test('throws whith secret json field on unsupported platform version', () => { const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); @@ -600,18 +600,18 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { new ecs.FargateService(stack, 'FargateService', { cluster, taskDefinition, platformVersion: ecs.FargatePlatformVersion.VERSION1_3, }); - }, new RegExp(`uses at least one container that references a secret JSON field.+platform version ${ecs.FargatePlatformVersion.VERSION1_4} or later`)); + }).toThrow(new RegExp(`uses at least one container that references a secret JSON field.+platform version ${ecs.FargatePlatformVersion.VERSION1_4} or later`)); + - test.done(); - }, + }); - 'ignore task definition and launch type if deployment controller is set to be EXTERNAL'(test: Test) { + test('ignore task definition and launch type if deployment controller is set to be EXTERNAL', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -631,8 +631,8 @@ nodeunitShim({ }); // THEN - test.deepEqual(service.node.metadata[0].data, 'taskDefinition and launchType are blanked out when using external deployment controller.'); - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(service.node.metadata[0].data).toEqual('taskDefinition and launchType are blanked out when using external deployment controller.'); + expect(stack).toHaveResource('AWS::ECS::Service', { Cluster: { Ref: 'EcsCluster97242B84', }, @@ -665,12 +665,12 @@ nodeunitShim({ ], }, }, - })); + }); + - test.done(); - }, + }); - 'errors when no container specified on task definition'(test: Test) { + test('errors when no container specified on task definition', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -684,14 +684,14 @@ nodeunitShim({ }); // THEN - test.throws(() => { - expect(stack); - }, /one essential container/); + expect(() => { + SynthUtils.synthesize(stack); + }).toThrow(/one essential container/); + - test.done(); - }, + }); - 'allows adding the default container after creating the service'(test: Test) { + test('allows adding the default container after creating the service', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -709,18 +709,18 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { Name: 'main', }, ], - })); + }); + - test.done(); - }, + }); - 'allows specifying assignPublicIP as enabled'(test: Test) { + test('allows specifying assignPublicIP as enabled', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -738,18 +738,18 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::Service', { + expect(stack).toHaveResourceLike('AWS::ECS::Service', { NetworkConfiguration: { AwsvpcConfiguration: { AssignPublicIp: 'ENABLED', }, }, - })); + }); + - test.done(); - }, + }); - 'allows specifying 0 for minimumHealthyPercent'(test: Test) { + test('allows specifying 0 for minimumHealthyPercent', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -767,16 +767,16 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::Service', { + expect(stack).toHaveResourceLike('AWS::ECS::Service', { DeploymentConfiguration: { MinimumHealthyPercent: 0, }, - })); + }); - test.done(); - }, - 'throws when securityGroup and securityGroups are supplied'(test: Test) { + }); + + test('throws when securityGroup and securityGroups are supplied', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -800,19 +800,19 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { new ecs.FargateService(stack, 'FargateService', { cluster, taskDefinition, securityGroup: securityGroup1, securityGroups: [securityGroup2], }); - }, /Only one of SecurityGroup or SecurityGroups can be populated./); + }).toThrow(/Only one of SecurityGroup or SecurityGroups can be populated./); + - test.done(); - }, + }); - 'with multiple securty groups, it correctly updates cloudformation template'(test: Test) { + test('with multiple securty groups, it correctly updates cloudformation template', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -842,7 +842,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { TaskDefinition: { Ref: 'FargateTaskDefC6FB60B4', }, @@ -882,9 +882,9 @@ nodeunitShim({ ], }, }, - })); + }); - expect(stack).to(haveResource('AWS::EC2::SecurityGroup', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { GroupDescription: 'Example', GroupName: 'Bingo', SecurityGroupEgress: [ @@ -897,9 +897,9 @@ nodeunitShim({ VpcId: { Ref: 'MyVpcF9F0CA6F', }, - })); + }); - expect(stack).to(haveResource('AWS::EC2::SecurityGroup', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroup', { GroupDescription: 'Example', GroupName: 'Rolly', SecurityGroupEgress: [ @@ -914,15 +914,15 @@ nodeunitShim({ VpcId: { Ref: 'MyVpcF9F0CA6F', }, - })); + }); - test.done(); - }, - }, + }); + + }); - 'When setting up a health check': { - 'grace period is respected'(test: Test) { + describe('When setting up a health check', () => { + test('grace period is respected', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -940,16 +940,16 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { HealthCheckGracePeriodSeconds: 10, - })); + }); - test.done(); - }, - }, - 'When adding an app load balancer': { - 'allows auto scaling by ALB request per target'(test: Test) { + }); + }); + + describe('When adding an app load balancer', () => { + test('allows auto scaling by ALB request per target', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -976,7 +976,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ApplicationAutoScaling::ScalableTarget', { + expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalableTarget', { MaxCapacity: 10, MinCapacity: 1, ResourceId: { @@ -997,9 +997,9 @@ nodeunitShim({ ], ], }, - })); + }); - expect(stack).to(haveResource('AWS::ApplicationAutoScaling::ScalingPolicy', { + expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalingPolicy', { TargetTrackingScalingPolicyConfiguration: { PredefinedMetricSpecification: { PredefinedMetricType: 'ALBRequestCountPerTarget', @@ -1014,18 +1014,18 @@ nodeunitShim({ }, TargetValue: 1000, }, - })); + }); - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { // if any load balancer is configured and healthCheckGracePeriodSeconds is not // set, then it should default to 60 seconds. HealthCheckGracePeriodSeconds: 60, - })); + }); - test.done(); - }, - 'allows auto scaling by ALB with new service arn format'(test: Test) { + }); + + test('allows auto scaling by ALB with new service arn format', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1056,7 +1056,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ApplicationAutoScaling::ScalableTarget', { + expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalableTarget', { MaxCapacity: 10, MinCapacity: 1, ResourceId: { @@ -1077,13 +1077,13 @@ nodeunitShim({ ], ], }, - })); + }); - test.done(); - }, - 'allows specify any existing container name and port in a service': { - 'with default setting'(test: Test) { + }); + + describe('allows specify any existing container name and port in a service', () => { + test('with default setting', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1111,7 +1111,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { LoadBalancers: [ { ContainerName: 'MainContainer', @@ -1121,24 +1121,24 @@ nodeunitShim({ }, }, ], - })); + }); - expect(stack).to(haveResource('AWS::EC2::SecurityGroupIngress', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroupIngress', { Description: 'Load balancer to target', FromPort: 8000, ToPort: 8000, - })); + }); - expect(stack).to(haveResource('AWS::EC2::SecurityGroupEgress', { + expect(stack).toHaveResource('AWS::EC2::SecurityGroupEgress', { Description: 'Load balancer to target', FromPort: 8000, ToPort: 8000, - })); + }); - test.done(); - }, - 'with TCP protocol'(test: Test) { + }); + + test('with TCP protocol', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1169,10 +1169,10 @@ nodeunitShim({ })], }); - test.done(); - }, - 'with UDP protocol'(test: Test) { + }); + + test('with UDP protocol', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1203,10 +1203,10 @@ nodeunitShim({ })], }); - test.done(); - }, - 'throws when protocol does not match'(test: Test) { + }); + + test('throws when protocol does not match', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1228,7 +1228,7 @@ nodeunitShim({ const listener = lb.addListener('listener', { port: 80 }); // THEN - test.throws(() => { + expect(() => { listener.addTargets('target', { port: 80, targets: [service.loadBalancerTarget({ @@ -1237,12 +1237,12 @@ nodeunitShim({ protocol: ecs.Protocol.TCP, })], }); - }, /Container 'Default\/FargateTaskDef\/MainContainer' has no mapping for port 8001 and protocol tcp. Did you call "container.addPortMappings\(\)"\?/); + }).toThrow(/Container 'Default\/FargateTaskDef\/MainContainer' has no mapping for port 8001 and protocol tcp. Did you call "container.addPortMappings\(\)"\?/); - test.done(); - }, - 'throws when port does not match'(test: Test) { + }); + + test('throws when port does not match', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1264,7 +1264,7 @@ nodeunitShim({ const listener = lb.addListener('listener', { port: 80 }); // THEN - test.throws(() => { + expect(() => { listener.addTargets('target', { port: 80, targets: [service.loadBalancerTarget({ @@ -1272,12 +1272,12 @@ nodeunitShim({ containerPort: 8002, })], }); - }, /Container 'Default\/FargateTaskDef\/MainContainer' has no mapping for port 8002 and protocol tcp. Did you call "container.addPortMappings\(\)"\?/); + }).toThrow(/Container 'Default\/FargateTaskDef\/MainContainer' has no mapping for port 8002 and protocol tcp. Did you call "container.addPortMappings\(\)"\?/); - test.done(); - }, - 'throws when container does not exist'(test: Test) { + }); + + test('throws when container does not exist', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1299,7 +1299,7 @@ nodeunitShim({ const listener = lb.addListener('listener', { port: 80 }); // THEN - test.throws(() => { + expect(() => { listener.addTargets('target', { port: 80, targets: [service.loadBalancerTarget({ @@ -1307,15 +1307,15 @@ nodeunitShim({ containerPort: 8001, })], }); - }, /No container named 'SideContainer'. Did you call "addContainer()"?/); + }).toThrow(/No container named 'SideContainer'. Did you call "addContainer()"?/); - test.done(); - }, - }, - 'allows load balancing to any container and port of service': { - 'with application load balancers': { - 'with default target group port and protocol'(test: Test) { + }); + }); + + describe('allows load balancing to any container and port of service', () => { + describe('with application load balancers', () => { + test('with default target group port and protocol', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1345,7 +1345,7 @@ nodeunitShim({ ); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { LoadBalancers: [ { ContainerName: 'MainContainer', @@ -1355,17 +1355,17 @@ nodeunitShim({ }, }, ], - })); + }); - expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { + expect(stack).toHaveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { Port: 80, Protocol: 'HTTP', - })); + }); - test.done(); - }, - 'with default target group port and HTTP protocol'(test: Test) { + }); + + test('with default target group port and HTTP protocol', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1397,7 +1397,7 @@ nodeunitShim({ ); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { LoadBalancers: [ { ContainerName: 'MainContainer', @@ -1407,17 +1407,17 @@ nodeunitShim({ }, }, ], - })); + }); - expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { + expect(stack).toHaveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { Port: 80, Protocol: 'HTTP', - })); + }); - test.done(); - }, - 'with default target group port and HTTPS protocol'(test: Test) { + }); + + test('with default target group port and HTTPS protocol', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1449,7 +1449,7 @@ nodeunitShim({ ); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { LoadBalancers: [ { ContainerName: 'MainContainer', @@ -1459,17 +1459,17 @@ nodeunitShim({ }, }, ], - })); + }); - expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { + expect(stack).toHaveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { Port: 443, Protocol: 'HTTPS', - })); + }); - test.done(); - }, - 'with any target group port and protocol'(test: Test) { + }); + + test('with any target group port and protocol', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1502,7 +1502,7 @@ nodeunitShim({ ); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { LoadBalancers: [ { ContainerName: 'MainContainer', @@ -1512,19 +1512,19 @@ nodeunitShim({ }, }, ], - })); + }); - expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { + expect(stack).toHaveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { Port: 83, Protocol: 'HTTP', - })); + }); - test.done(); - }, - }, - 'with network load balancers': { - 'with default target group port'(test: Test) { + }); + }); + + describe('with network load balancers', () => { + test('with default target group port', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1554,7 +1554,7 @@ nodeunitShim({ ); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { LoadBalancers: [ { ContainerName: 'MainContainer', @@ -1564,17 +1564,17 @@ nodeunitShim({ }, }, ], - })); + }); - expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { + expect(stack).toHaveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { Port: 80, Protocol: 'TCP', - })); + }); - test.done(); - }, - 'with any target group port'(test: Test) { + }); + + test('with any target group port', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1606,7 +1606,7 @@ nodeunitShim({ ); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { LoadBalancers: [ { ContainerName: 'MainContainer', @@ -1616,20 +1616,20 @@ nodeunitShim({ }, }, ], - })); + }); - expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { + expect(stack).toHaveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { Port: 81, Protocol: 'TCP', - })); + }); - test.done(); - }, - }, - }, - }, - 'allows scaling on a specified scheduled time'(test: Test) { + }); + }); + }); + }); + + test('allows scaling on a specified scheduled time', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1653,7 +1653,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ApplicationAutoScaling::ScalableTarget', { + expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalableTarget', { ScheduledActions: [ { ScalableTargetAction: { @@ -1663,12 +1663,12 @@ nodeunitShim({ ScheduledActionName: 'ScaleOnSchedule', }, ], - })); + }); - test.done(); - }, - 'allows scaling on a specified metric value'(test: Test) { + }); + + test('allows scaling on a specified metric value', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1696,7 +1696,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ApplicationAutoScaling::ScalingPolicy', { + expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalingPolicy', { PolicyType: 'StepScaling', ScalingTargetId: { Ref: 'ServiceTaskCountTarget23E25614', @@ -1711,12 +1711,12 @@ nodeunitShim({ }, ], }, - })); + }); + - test.done(); - }, + }); - 'allows scaling on a target CPU utilization'(test: Test) { + test('allows scaling on a target CPU utilization', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1739,18 +1739,18 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ApplicationAutoScaling::ScalingPolicy', { + expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalingPolicy', { PolicyType: 'TargetTrackingScaling', TargetTrackingScalingPolicyConfiguration: { PredefinedMetricSpecification: { PredefinedMetricType: 'ECSServiceAverageCPUUtilization' }, TargetValue: 30, }, - })); + }); + - test.done(); - }, + }); - 'allows scaling on memory utilization'(test: Test) { + test('allows scaling on memory utilization', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1773,18 +1773,18 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ApplicationAutoScaling::ScalingPolicy', { + expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalingPolicy', { PolicyType: 'TargetTrackingScaling', TargetTrackingScalingPolicyConfiguration: { PredefinedMetricSpecification: { PredefinedMetricType: 'ECSServiceAverageMemoryUtilization' }, TargetValue: 30, }, - })); + }); - test.done(); - }, - 'allows scaling on custom CloudWatch metric'(test: Test) { + }); + + test('allows scaling on custom CloudWatch metric', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1808,7 +1808,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ApplicationAutoScaling::ScalingPolicy', { + expect(stack).toHaveResource('AWS::ApplicationAutoScaling::ScalingPolicy', { PolicyType: 'TargetTrackingScaling', TargetTrackingScalingPolicyConfiguration: { CustomizedMetricSpecification: { @@ -1818,13 +1818,13 @@ nodeunitShim({ }, TargetValue: 5, }, - })); + }); + - test.done(); - }, + }); - 'When enabling service discovery': { - 'throws if namespace has not been added to cluster'(test: Test) { + describe('When enabling service discovery', () => { + test('throws if namespace has not been added to cluster', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1837,7 +1837,7 @@ nodeunitShim({ container.addPortMappings({ containerPort: 8000 }); // THEN - test.throws(() => { + expect(() => { new ecs.FargateService(stack, 'Service', { cluster, taskDefinition, @@ -1845,12 +1845,12 @@ nodeunitShim({ name: 'myApp', }, }); - }, /Cannot enable service discovery if a Cloudmap Namespace has not been created in the cluster./); + }).toThrow(/Cannot enable service discovery if a Cloudmap Namespace has not been created in the cluster./); - test.done(); - }, - 'creates cloud map service for Private DNS namespace'(test: Test) { + }); + + test('creates cloud map service for Private DNS namespace', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1876,7 +1876,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ServiceDiscovery::Service', { + expect(stack).toHaveResource('AWS::ServiceDiscovery::Service', { DnsConfig: { DnsRecords: [ { @@ -1902,12 +1902,12 @@ nodeunitShim({ 'Id', ], }, - })); + }); + - test.done(); - }, + }); - 'creates AWS Cloud Map service for Private DNS namespace with SRV records with proper defaults'(test: Test) { + test('creates AWS Cloud Map service for Private DNS namespace with SRV records with proper defaults', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1937,7 +1937,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ServiceDiscovery::Service', { + expect(stack).toHaveResource('AWS::ServiceDiscovery::Service', { DnsConfig: { DnsRecords: [ { @@ -1963,12 +1963,12 @@ nodeunitShim({ 'Id', ], }, - })); + }); + - test.done(); - }, + }); - 'creates AWS Cloud Map service for Private DNS namespace with SRV records with overriden defaults'(test: Test) { + test('creates AWS Cloud Map service for Private DNS namespace with SRV records with overriden defaults', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1999,7 +1999,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ServiceDiscovery::Service', { + expect(stack).toHaveResource('AWS::ServiceDiscovery::Service', { DnsConfig: { DnsRecords: [ { @@ -2025,12 +2025,12 @@ nodeunitShim({ 'Id', ], }, - })); + }); + - test.done(); - }, + }); - 'user can select any container and port'(test: Test) { + test('user can select any container and port', () => { const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); @@ -2063,7 +2063,7 @@ nodeunitShim({ }, }); - expect(stack).to(haveResourceLike('AWS::ECS::Service', { + expect(stack).toHaveResourceLike('AWS::ECS::Service', { ServiceRegistries: [ { RegistryArn: { 'Fn::GetAtt': ['ServiceCloudmapService046058A4', 'Arn'] }, @@ -2071,13 +2071,13 @@ nodeunitShim({ ContainerPort: 8001, }, ], - })); + }); + - test.done(); - }, - }, + }); + }); - 'Metric'(test: Test) { + test('Metric', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2094,7 +2094,7 @@ nodeunitShim({ }); // THEN - test.deepEqual(stack.resolve(service.metricCpuUtilization()), { + expect(stack.resolve(service.metricCpuUtilization())).toEqual({ dimensions: { ClusterName: { Ref: 'EcsCluster97242B84' }, ServiceName: { 'Fn::GetAtt': ['ServiceD69D759B', 'Name'] }, @@ -2105,11 +2105,11 @@ nodeunitShim({ statistic: 'Average', }); - test.done(); - }, - 'When import a Fargate Service': { - 'with serviceArn'(test: Test) { + }); + + describe('When import a Fargate Service', () => { + test('with serviceArn', () => { // GIVEN const stack = new cdk.Stack(); const cluster = new ecs.Cluster(stack, 'EcsCluster'); @@ -2121,13 +2121,13 @@ nodeunitShim({ }); // THEN - test.equal(service.serviceArn, 'arn:aws:ecs:us-west-2:123456789012:service/my-http-service'); - test.equal(service.serviceName, 'my-http-service'); + expect(service.serviceArn).toEqual('arn:aws:ecs:us-west-2:123456789012:service/my-http-service'); + expect(service.serviceName).toEqual('my-http-service'); + - test.done(); - }, + }); - 'with serviceName'(test: Test) { + test('with serviceName', () => { // GIVEN const stack = new cdk.Stack(); const pseudo = new cdk.ScopedAws(stack); @@ -2140,13 +2140,13 @@ nodeunitShim({ }); // THEN - test.deepEqual(stack.resolve(service.serviceArn), stack.resolve(`arn:${pseudo.partition}:ecs:${pseudo.region}:${pseudo.accountId}:service/my-http-service`)); - test.equal(service.serviceName, 'my-http-service'); + expect(stack.resolve(service.serviceArn)).toEqual(stack.resolve(`arn:${pseudo.partition}:ecs:${pseudo.region}:${pseudo.accountId}:service/my-http-service`)); + expect(service.serviceName).toEqual('my-http-service'); + - test.done(); - }, + }); - 'with circuit breaker'(test: Test) { + test('with circuit breaker', () => { // GIVEN const stack = new cdk.Stack(); const cluster = new ecs.Cluster(stack, 'EcsCluster'); @@ -2164,7 +2164,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { DeploymentConfiguration: { MaximumPercent: 200, MinimumHealthyPercent: 50, @@ -2176,42 +2176,42 @@ nodeunitShim({ DeploymentController: { Type: ecs.DeploymentControllerType.ECS, }, - })); + }); + - test.done(); - }, + }); - 'throws an exception if both serviceArn and serviceName were provided for fromEc2ServiceAttributes'(test: Test) { + test('throws an exception if both serviceArn and serviceName were provided for fromEc2ServiceAttributes', () => { // GIVEN const stack = new cdk.Stack(); const cluster = new ecs.Cluster(stack, 'EcsCluster'); - test.throws(() => { + expect(() => { ecs.FargateService.fromFargateServiceAttributes(stack, 'EcsService', { serviceArn: 'arn:aws:ecs:us-west-2:123456789012:service/my-http-service', serviceName: 'my-http-service', cluster, }); - }, /only specify either serviceArn or serviceName/); + }).toThrow(/only specify either serviceArn or serviceName/); - test.done(); - }, - 'throws an exception if neither serviceArn nor serviceName were provided for fromEc2ServiceAttributes'(test: Test) { + }); + + test('throws an exception if neither serviceArn nor serviceName were provided for fromEc2ServiceAttributes', () => { // GIVEN const stack = new cdk.Stack(); const cluster = new ecs.Cluster(stack, 'EcsCluster'); - test.throws(() => { + expect(() => { ecs.FargateService.fromFargateServiceAttributes(stack, 'EcsService', { cluster, }); - }, /only specify either serviceArn or serviceName/); + }).toThrow(/only specify either serviceArn or serviceName/); - test.done(); - }, - 'allows setting enable execute command'(test: Test) { + }); + + test('allows setting enable execute command', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2229,7 +2229,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::Service', { + expect(stack).toHaveResource('AWS::ECS::Service', { TaskDefinition: { Ref: 'FargateTaskDefC6FB60B4', }, @@ -2264,9 +2264,9 @@ nodeunitShim({ ], }, }, - })); + }); - expect(stack).to(haveResource('AWS::IAM::Policy', { + expect(stack).toHaveResource('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -2302,12 +2302,12 @@ nodeunitShim({ Ref: 'FargateTaskDefTaskRole0B257552', }, ], - })); + }); + - test.done(); - }, + }); - 'no logging enabled when logging field is set to NONE'(test: Test) { + test('no logging enabled when logging field is set to NONE', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2340,7 +2340,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::IAM::Policy', { + expect(stack).toHaveResource('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -2362,12 +2362,12 @@ nodeunitShim({ Ref: 'FargateTaskDefTaskRole0B257552', }, ], - })); + }); + - test.done(); - }, + }); - 'enables execute command logging with logging field set to OVERRIDE'(test: Test) { + test('enables execute command logging with logging field set to OVERRIDE', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2403,7 +2403,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::IAM::Policy', { + expect(stack).toHaveResource('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -2479,12 +2479,12 @@ nodeunitShim({ Ref: 'FargateTaskDefTaskRole0B257552', }, ], - })); + }); + - test.done(); - }, + }); - 'enables only execute command session encryption'(test: Test) { + test('enables only execute command session encryption', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2523,7 +2523,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::IAM::Policy', { + expect(stack).toHaveResource('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -2612,9 +2612,9 @@ nodeunitShim({ Ref: 'FargateTaskDefTaskRole0B257552', }, ], - })); + }); - expect(stack).to(haveResource('AWS::KMS::Key', { + expect(stack).toHaveResource('AWS::KMS::Key', { KeyPolicy: { Statement: [ { @@ -2678,12 +2678,12 @@ nodeunitShim({ ], Version: '2012-10-17', }, - })); + }); - test.done(); - }, - 'enables encryption for execute command logging'(test: Test) { + }); + + test('enables encryption for execute command logging', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2729,7 +2729,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::IAM::Policy', { + expect(stack).toHaveResource('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -2833,9 +2833,9 @@ nodeunitShim({ Ref: 'FargateTaskDefTaskRole0B257552', }, ], - })); + }); - expect(stack).to(haveResource('AWS::KMS::Key', { + expect(stack).toHaveResource('AWS::KMS::Key', { KeyPolicy: { Statement: [ { @@ -2944,12 +2944,12 @@ nodeunitShim({ ], Version: '2012-10-17', }, - })); + }); + - test.done(); - }, + }); - 'with both propagateTags and propagateTaskTagsFrom defined'(test: Test) { + test('with both propagateTags and propagateTaskTagsFrom defined', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -2962,15 +2962,15 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { new ecs.FargateService(stack, 'FargateService', { cluster, taskDefinition, propagateTags: PropagatedTagSource.SERVICE, propagateTaskTagsFrom: PropagatedTagSource.SERVICE, }); - }, /You can only specify either propagateTags or propagateTaskTagsFrom. Alternatively, you can leave both blank/); - test.done(); - }, - }, + }).toThrow(/You can only specify either propagateTags or propagateTaskTagsFrom. Alternatively, you can leave both blank/); + + }); + }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/fargate/fargate-task-definition.test.ts b/packages/@aws-cdk/aws-ecs/test/fargate/fargate-task-definition.test.ts index 294ae3001aa64..3ff15ac22057e 100644 --- a/packages/@aws-cdk/aws-ecs/test/fargate/fargate-task-definition.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/fargate/fargate-task-definition.test.ts @@ -1,29 +1,28 @@ -import { expect, haveResourceLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as iam from '@aws-cdk/aws-iam'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as ecs from '../../lib'; -nodeunitShim({ - 'When creating a Fargate TaskDefinition': { - 'with only required properties set, it correctly sets default properties'(test: Test) { +describe('fargate task definition', () => { + describe('When creating a Fargate TaskDefinition', () => { + test('with only required properties set, it correctly sets default properties', () => { // GIVEN const stack = new cdk.Stack(); new ecs.FargateTaskDefinition(stack, 'FargateTaskDef'); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { Family: 'FargateTaskDef', NetworkMode: ecs.NetworkMode.AWS_VPC, RequiresCompatibilities: ['FARGATE'], Cpu: '256', Memory: '512', - })); + }); + - test.done(); - }, + }); - 'support lazy cpu and memory values'(test: Test) { + test('support lazy cpu and memory values', () => { // GIVEN const stack = new cdk.Stack(); @@ -33,15 +32,15 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { Cpu: '128', Memory: '1024', - })); + }); - test.done(); - }, - 'with all properties set'(test: Test) { + }); + + test('with all properties set', () => { // GIVEN const stack = new cdk.Stack(); const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef', { @@ -69,7 +68,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { Cpu: '128', ExecutionRoleArn: { 'Fn::GetAtt': [ @@ -100,25 +99,25 @@ nodeunitShim({ Name: 'scratch', }, ], - })); + }); + - test.done(); - }, + }); - 'throws when adding placement constraint'(test: Test) { + test('throws when adding placement constraint', () => { // GIVEN const stack = new cdk.Stack(); const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef'); // THEN - test.throws(() => { + expect(() => { taskDefinition.addPlacementConstraint(ecs.PlacementConstraint.memberOf('attribute:ecs.instance-type =~ t2.*')); - }, /Cannot set placement constraints on tasks that run on Fargate/); + }).toThrow(/Cannot set placement constraints on tasks that run on Fargate/); - test.done(); - }, - 'throws when adding inference accelerators'(test: Test) { + }); + + test('throws when adding inference accelerators', () => { // GIVEN const stack = new cdk.Stack(); const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef'); @@ -129,42 +128,40 @@ nodeunitShim({ }; // THEN - test.throws(() => { + expect(() => { taskDefinition.addInferenceAccelerator(inferenceAccelerator); - }, /Cannot use inference accelerators on tasks that run on Fargate/); + }).toThrow(/Cannot use inference accelerators on tasks that run on Fargate/); + - test.done(); - }, + }); - 'throws when ephemeral storage request is too high'(test: Test) { + test('throws when ephemeral storage request is too high', () => { // GIVEN const stack = new cdk.Stack(); - test.throws(() => { + expect(() => { new ecs.FargateTaskDefinition(stack, 'FargateTaskDef', { ephemeralStorageGiB: 201, }); - }, /Ephemeral storage size must be between 21GiB and 200GiB/); + }).toThrow(/Ephemeral storage size must be between 21GiB and 200GiB/); // THEN - test.done(); - }, + }); - 'throws when ephemeral storage request is too low'(test: Test) { + test('throws when ephemeral storage request is too low', () => { // GIVEN const stack = new cdk.Stack(); - test.throws(() => { + expect(() => { new ecs.FargateTaskDefinition(stack, 'FargateTaskDef', { ephemeralStorageGiB: 20, }); - }, /Ephemeral storage size must be between 21GiB and 200GiB/); + }).toThrow(/Ephemeral storage size must be between 21GiB and 200GiB/); // THEN - test.done(); - }, - }, + }); + }); - 'When importing from an existing Fargate TaskDefinition': { - 'can succeed using TaskDefinition Arn'(test: Test) { + describe('When importing from an existing Fargate TaskDefinition', () => { + test('can succeed using TaskDefinition Arn', () => { // GIVEN const stack = new cdk.Stack(); const expectTaskDefinitionArn = 'TD_ARN'; @@ -173,11 +170,11 @@ nodeunitShim({ const taskDefinition = ecs.FargateTaskDefinition.fromFargateTaskDefinitionArn(stack, 'FARGATE_TD_ID', expectTaskDefinitionArn); // THEN - test.equal(taskDefinition.taskDefinitionArn, expectTaskDefinitionArn); - test.done(); - }, + expect(taskDefinition.taskDefinitionArn).toEqual(expectTaskDefinitionArn); + + }); - 'can succeed using attributes'(test: Test) { + test('can succeed using attributes', () => { // GIVEN const stack = new cdk.Stack(); const expectTaskDefinitionArn = 'TD_ARN'; @@ -194,17 +191,17 @@ nodeunitShim({ }); // THEN - test.equal(taskDefinition.taskDefinitionArn, expectTaskDefinitionArn); - test.equal(taskDefinition.compatibility, ecs.Compatibility.FARGATE); - test.ok(taskDefinition.isFargateCompatible); - test.equal(taskDefinition.isEc2Compatible, false); - test.equal(taskDefinition.networkMode, expectNetworkMode); - test.equal(taskDefinition.taskRole, expectTaskRole); + expect(taskDefinition.taskDefinitionArn).toEqual(expectTaskDefinitionArn); + expect(taskDefinition.compatibility).toEqual(ecs.Compatibility.FARGATE); + expect(taskDefinition.isFargateCompatible).toEqual(true); + expect(taskDefinition.isEc2Compatible).toEqual(false); + expect(taskDefinition.networkMode).toEqual(expectNetworkMode); + expect(taskDefinition.taskRole).toEqual(expectTaskRole); - test.done(); - }, - 'returns a Fargate TaskDefinition that will throw an error when trying to access its networkMode but its networkMode is undefined'(test: Test) { + }); + + test('returns a Fargate TaskDefinition that will throw an error when trying to access its networkMode but its networkMode is undefined', () => { // GIVEN const stack = new cdk.Stack(); const expectTaskDefinitionArn = 'TD_ARN'; @@ -219,15 +216,15 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { taskDefinition.networkMode; - }, 'This operation requires the networkMode in ImportedTaskDefinition to be defined. ' + + }).toThrow('This operation requires the networkMode in ImportedTaskDefinition to be defined. ' + 'Add the \'networkMode\' in ImportedTaskDefinitionProps to instantiate ImportedTaskDefinition'); - test.done(); - }, - 'returns a Fargate TaskDefinition that will throw an error when trying to access its taskRole but its taskRole is undefined'(test: Test) { + }); + + test('returns a Fargate TaskDefinition that will throw an error when trying to access its taskRole but its taskRole is undefined', () => { // GIVEN const stack = new cdk.Stack(); const expectTaskDefinitionArn = 'TD_ARN'; @@ -240,12 +237,12 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { taskDefinition.taskRole; - }, 'This operation requires the taskRole in ImportedTaskDefinition to be defined. ' + + }).toThrow('This operation requires the taskRole in ImportedTaskDefinition to be defined. ' + 'Add the \'taskRole\' in ImportedTaskDefinitionProps to instantiate ImportedTaskDefinition'); - test.done(); - }, - }, + + }); + }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/firelens-log-driver.test.ts b/packages/@aws-cdk/aws-ecs/test/firelens-log-driver.test.ts index aff395c8598d2..6ab96b05df364 100644 --- a/packages/@aws-cdk/aws-ecs/test/firelens-log-driver.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/firelens-log-driver.test.ts @@ -1,22 +1,21 @@ -import { expect, haveResourceLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as secretsmanager from '@aws-cdk/aws-secretsmanager'; import * as ssm from '@aws-cdk/aws-ssm'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as ecs from '../lib'; let stack: cdk.Stack; let td: ecs.TaskDefinition; const image = ecs.ContainerImage.fromRegistry('test-image'); -nodeunitShim({ - 'setUp'(cb: () => void) { +describe('firelens log driver', () => { + beforeEach(() => { stack = new cdk.Stack(); td = new ecs.Ec2TaskDefinition(stack, 'TaskDefinition'); - cb(); - }, - 'create a firelens log driver with default options'(test: Test) { + + }); + test('create a firelens log driver with default options', () => { // WHEN td.addContainer('Container', { image, @@ -25,7 +24,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -39,12 +38,12 @@ nodeunitShim({ }, }, ], - })); + }); + - test.done(); - }, + }); - 'create a firelens log driver with secret options'(test: Test) { + test('create a firelens log driver with secret options', () => { const secret = new secretsmanager.Secret(stack, 'Secret'); const parameter = ssm.StringParameter.fromSecureStringParameterAttributes(stack, 'Parameter', { parameterName: '/host', @@ -72,7 +71,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -125,9 +124,9 @@ nodeunitShim({ }, }, ], - })); + }); - expect(stack).to(haveResourceLike('AWS::IAM::Policy', { + expect(stack).toHaveResourceLike('AWS::IAM::Policy', { PolicyDocument: { Statement: [ { @@ -172,12 +171,12 @@ nodeunitShim({ ], Version: '2012-10-17', }, - })); + }); - test.done(); - }, - 'create a firelens log driver to route logs to CloudWatch Logs with Fluent Bit'(test: Test) { + }); + + test('create a firelens log driver to route logs to CloudWatch Logs with Fluent Bit', () => { // WHEN td.addContainer('Container', { image, @@ -194,7 +193,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -215,12 +214,12 @@ nodeunitShim({ }, }, ], - })); + }); + - test.done(); - }, + }); - 'create a firelens log driver to route logs to kinesis firehose Logs with Fluent Bit'(test: Test) { + test('create a firelens log driver to route logs to kinesis firehose Logs with Fluent Bit', () => { // WHEN td.addContainer('Container', { image, @@ -235,7 +234,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -254,13 +253,13 @@ nodeunitShim({ }, }, ], - })); + }); + - test.done(); - }, + }); - 'Firelens Configuration': { - 'fluentd log router container'(test: Test) { + describe('Firelens Configuration', () => { + test('fluentd log router container', () => { // GIVEN td.addFirelensLogRouter('log_router', { image: ecs.ContainerImage.fromRegistry('fluent/fluentd'), @@ -271,7 +270,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { Essential: true, @@ -283,11 +282,11 @@ nodeunitShim({ }, }, ], - })); - test.done(); - }, + }); + + }); - 'fluent-bit log router container with options'(test: Test) { + test('fluent-bit log router container with options', () => { // GIVEN const stack2 = new cdk.Stack(undefined, 'Stack2', { env: { region: 'us-east-1' } }); const td2 = new ecs.Ec2TaskDefinition(stack2, 'TaskDefinition'); @@ -305,7 +304,7 @@ nodeunitShim({ }); // THEN - expect(stack2).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack2).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { Essential: true, @@ -321,12 +320,12 @@ nodeunitShim({ }, }, ], - })); + }); - test.done(); - }, - 'fluent-bit log router with file config type'(test: Test) { + }); + + test('fluent-bit log router with file config type', () => { // GIVEN td.addFirelensLogRouter('log_router', { image: ecs.obtainDefaultFluentBitECRImage(td, undefined, '2.1.0'), @@ -343,7 +342,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { Essential: true, @@ -359,9 +358,9 @@ nodeunitShim({ }, }, ], - })); + }); - test.done(); - }, - }, + + }); + }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/fluentd-log-driver.test.ts b/packages/@aws-cdk/aws-ecs/test/fluentd-log-driver.test.ts index 54ac824fb6c47..81c17b8c0b76f 100644 --- a/packages/@aws-cdk/aws-ecs/test/fluentd-log-driver.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/fluentd-log-driver.test.ts @@ -1,21 +1,20 @@ -import { expect, haveResourceLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as ecs from '../lib'; let stack: cdk.Stack; let td: ecs.TaskDefinition; const image = ecs.ContainerImage.fromRegistry('test-image'); -nodeunitShim({ - 'setUp'(cb: () => void) { +describe('fluentd log driver', () => { + beforeEach(() => { stack = new cdk.Stack(); td = new ecs.Ec2TaskDefinition(stack, 'TaskDefinition'); - cb(); - }, - 'create a fluentd log driver with options'(test: Test) { + }); + + test('create a fluentd log driver with options', () => { // WHEN td.addContainer('Container', { image, @@ -26,7 +25,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -37,12 +36,12 @@ nodeunitShim({ }, }, ], - })); + }); + - test.done(); - }, + }); - 'create a fluentd log driver without options'(test: Test) { + test('create a fluentd log driver without options', () => { // WHEN td.addContainer('Container', { image, @@ -51,7 +50,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -59,12 +58,12 @@ nodeunitShim({ }, }, ], - })); + }); + - test.done(); - }, + }); - 'create a fluentd log driver with all possible options'(test: Test) { + test('create a fluentd log driver with all possible options', () => { // WHEN td.addContainer('Container', { image, @@ -92,7 +91,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -112,12 +111,12 @@ nodeunitShim({ }, }, ], - })); + }); + - test.done(); - }, + }); - 'create a fluentd log driver using fluentd'(test: Test) { + test('create a fluentd log driver using fluentd', () => { // WHEN td.addContainer('Container', { image, @@ -126,7 +125,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -134,8 +133,8 @@ nodeunitShim({ }, }, ], - })); + }); + - test.done(); - }, + }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/gelf-log-driver.test.ts b/packages/@aws-cdk/aws-ecs/test/gelf-log-driver.test.ts index 9f6663304d353..e8cdce10736e1 100644 --- a/packages/@aws-cdk/aws-ecs/test/gelf-log-driver.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/gelf-log-driver.test.ts @@ -1,21 +1,20 @@ -import { expect, haveResourceLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as ecs from '../lib'; let stack: cdk.Stack; let td: ecs.TaskDefinition; const image = ecs.ContainerImage.fromRegistry('test-image'); -nodeunitShim({ - 'setUp'(cb: () => void) { +describe('gelf log driver', () => { + beforeEach(() => { stack = new cdk.Stack(); td = new ecs.Ec2TaskDefinition(stack, 'TaskDefinition'); - cb(); - }, - 'create a gelf log driver with minimum options'(test: Test) { + }); + + test('create a gelf log driver with minimum options', () => { // WHEN td.addContainer('Container', { image, @@ -26,7 +25,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -37,12 +36,12 @@ nodeunitShim({ }, }, ], - })); + }); + - test.done(); - }, + }); - 'create a gelf log driver using gelf with minimum options'(test: Test) { + test('create a gelf log driver using gelf with minimum options', () => { // WHEN td.addContainer('Container', { image, @@ -53,7 +52,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -64,8 +63,8 @@ nodeunitShim({ }, }, ], - })); + }); + - test.done(); - }, + }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/images/tag-parameter-container-image.test.ts b/packages/@aws-cdk/aws-ecs/test/images/tag-parameter-container-image.test.ts index d782d39d874cb..3f409739d76ed 100644 --- a/packages/@aws-cdk/aws-ecs/test/images/tag-parameter-container-image.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/images/tag-parameter-container-image.test.ts @@ -1,12 +1,12 @@ -import { expect, haveResourceLike, SynthUtils } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; +import { SynthUtils } from '@aws-cdk/assert-internal'; import * as ecr from '@aws-cdk/aws-ecr'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as ecs from '../../lib'; -nodeunitShim({ - 'TagParameter container image': { - 'throws an error when tagParameterName() is used without binding the image'(test: Test) { +describe('tag parameter container image', () => { + describe('TagParameter container image', () => { + test('throws an error when tagParameterName() is used without binding the image', () => { // GIVEN const stack = new cdk.Stack(); const repository = new ecr.Repository(stack, 'Repository'); @@ -15,14 +15,14 @@ nodeunitShim({ value: tagParameterContainerImage.tagParameterName, }); - test.throws(() => { + expect(() => { SynthUtils.synthesize(stack); - }, /TagParameterContainerImage must be used in a container definition when using tagParameterName/); + }).toThrow(/TagParameterContainerImage must be used in a container definition when using tagParameterName/); - test.done(); - }, - 'throws an error when tagParameterValue() is used without binding the image'(test: Test) { + }); + + test('throws an error when tagParameterValue() is used without binding the image', () => { // GIVEN const stack = new cdk.Stack(); const repository = new ecr.Repository(stack, 'Repository'); @@ -31,14 +31,14 @@ nodeunitShim({ value: tagParameterContainerImage.tagParameterValue, }); - test.throws(() => { + expect(() => { SynthUtils.synthesize(stack); - }, /TagParameterContainerImage must be used in a container definition when using tagParameterValue/); + }).toThrow(/TagParameterContainerImage must be used in a container definition when using tagParameterValue/); + - test.done(); - }, + }); - 'can be used in a cross-account manner'(test: Test) { + test('can be used in a cross-account manner', () => { // GIVEN const app = new cdk.App(); const pipelineStack = new cdk.Stack(app, 'PipelineStack', { @@ -67,7 +67,7 @@ nodeunitShim({ }); // THEN - expect(pipelineStack).to(haveResourceLike('AWS::ECR::Repository', { + expect(pipelineStack).toHaveResourceLike('AWS::ECR::Repository', { RepositoryName: repositoryName, RepositoryPolicyText: { Statement: [{ @@ -88,11 +88,11 @@ nodeunitShim({ }, }], }, - })); - expect(serviceStack).to(haveResourceLike('AWS::IAM::Role', { + }); + expect(serviceStack).toHaveResourceLike('AWS::IAM::Role', { RoleName: 'servicestackionexecutionrolee7e2d9a783a54eb795f4', - })); - expect(serviceStack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + }); + expect(serviceStack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { Image: { @@ -128,9 +128,9 @@ nodeunitShim({ }, }, ], - })); + }); + - test.done(); - }, - }, + }); + }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/journald-log-driver.test.ts b/packages/@aws-cdk/aws-ecs/test/journald-log-driver.test.ts index aeffbc2073629..fdf67efc3bb4f 100644 --- a/packages/@aws-cdk/aws-ecs/test/journald-log-driver.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/journald-log-driver.test.ts @@ -1,21 +1,20 @@ -import { expect, haveResourceLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as ecs from '../lib'; let stack: cdk.Stack; let td: ecs.TaskDefinition; const image = ecs.ContainerImage.fromRegistry('test-image'); -nodeunitShim({ - 'setUp'(cb: () => void) { +describe('journald log driver', () => { + beforeEach(() => { stack = new cdk.Stack(); td = new ecs.Ec2TaskDefinition(stack, 'TaskDefinition'); - cb(); - }, - 'create a journald log driver with options'(test: Test) { + }); + + test('create a journald log driver with options', () => { // WHEN td.addContainer('Container', { image, @@ -26,7 +25,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -37,12 +36,12 @@ nodeunitShim({ }, }, ], - })); + }); - test.done(); - }, - 'create a journald log driver without options'(test: Test) { + }); + + test('create a journald log driver without options', () => { // WHEN td.addContainer('Container', { image, @@ -51,7 +50,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -59,12 +58,12 @@ nodeunitShim({ }, }, ], - })); + }); - test.done(); - }, - 'create a journald log driver using journald'(test: Test) { + }); + + test('create a journald log driver using journald', () => { // WHEN td.addContainer('Container', { image, @@ -73,7 +72,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -82,8 +81,8 @@ nodeunitShim({ }, }, ], - })); + }); + - test.done(); - }, + }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/json-file-log-driver.test.ts b/packages/@aws-cdk/aws-ecs/test/json-file-log-driver.test.ts index b282a61c29f88..0c21ff2d0b5f1 100644 --- a/packages/@aws-cdk/aws-ecs/test/json-file-log-driver.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/json-file-log-driver.test.ts @@ -1,21 +1,20 @@ -import { expect, haveResourceLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as ecs from '../lib'; let stack: cdk.Stack; let td: ecs.TaskDefinition; const image = ecs.ContainerImage.fromRegistry('test-image'); -nodeunitShim({ - 'setUp'(cb: () => void) { +describe('json file log driver', () => { + beforeEach(() => { stack = new cdk.Stack(); td = new ecs.Ec2TaskDefinition(stack, 'TaskDefinition'); - cb(); - }, - 'create a json-file log driver with options'(test: Test) { + }); + + test('create a json-file log driver with options', () => { // WHEN td.addContainer('Container', { image, @@ -26,7 +25,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -37,12 +36,12 @@ nodeunitShim({ }, }, ], - })); + }); - test.done(); - }, - 'create a json-file log driver without options'(test: Test) { + }); + + test('create a json-file log driver without options', () => { // WHEN td.addContainer('Container', { image, @@ -51,7 +50,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -59,12 +58,12 @@ nodeunitShim({ }, }, ], - })); + }); - test.done(); - }, - 'create a json-file log driver using json-file'(test: Test) { + }); + + test('create a json-file log driver using json-file', () => { // WHEN td.addContainer('Container', { image, @@ -73,7 +72,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -82,8 +81,8 @@ nodeunitShim({ }, }, ], - })); + }); + - test.done(); - }, + }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/splunk-log-driver.test.ts b/packages/@aws-cdk/aws-ecs/test/splunk-log-driver.test.ts index ee7d3f4b68ee8..d9902cb9728e3 100644 --- a/packages/@aws-cdk/aws-ecs/test/splunk-log-driver.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/splunk-log-driver.test.ts @@ -1,23 +1,22 @@ -import { expect, haveResourceLike } from '@aws-cdk/assert-internal'; -import * as cdk from '@aws-cdk/core'; +import '@aws-cdk/assert-internal/jest'; import * as secretsmanager from '@aws-cdk/aws-secretsmanager'; import * as ssm from '@aws-cdk/aws-ssm'; -import { nodeunitShim, Test } from 'nodeunit-shim'; +import * as cdk from '@aws-cdk/core'; import * as ecs from '../lib'; let stack: cdk.Stack; let td: ecs.TaskDefinition; const image = ecs.ContainerImage.fromRegistry('test-image'); -nodeunitShim({ - 'setUp'(cb: () => void) { +describe('splunk log driver', () => { + beforeEach(() => { stack = new cdk.Stack(); td = new ecs.Ec2TaskDefinition(stack, 'TaskDefinition'); - cb(); - }, - 'create a splunk log driver with minimum options'(test: Test) { + }); + + test('create a splunk log driver with minimum options', () => { // WHEN td.addContainer('Container', { image, @@ -29,7 +28,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -41,12 +40,12 @@ nodeunitShim({ }, }, ], - })); + }); - test.done(); - }, - 'create a splunk log driver using splunk with minimum options'(test: Test) { + }); + + test('create a splunk log driver using splunk with minimum options', () => { // WHEN td.addContainer('Container', { image, @@ -58,7 +57,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -70,12 +69,12 @@ nodeunitShim({ }, }, ], - })); + }); + - test.done(); - }, + }); - 'create a splunk log driver using splunk with sourcetype defined'(test: Test) { + test('create a splunk log driver using splunk with sourcetype defined', () => { // WHEN td.addContainer('Container', { image, @@ -88,7 +87,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -101,12 +100,12 @@ nodeunitShim({ }, }, ], - })); + }); + - test.done(); - }, + }); - 'create a splunk log driver using secret splunk token from secrets manager'(test: Test) { + test('create a splunk log driver using secret splunk token from secrets manager', () => { const secret = new secretsmanager.Secret(stack, 'Secret'); // WHEN td.addContainer('Container', { @@ -119,7 +118,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -138,12 +137,12 @@ nodeunitShim({ }, }, ], - })); + }); + - test.done(); - }, + }); - 'create a splunk log driver using secret splunk token from systems manager parameter store'(test: Test) { + test('create a splunk log driver using secret splunk token from systems manager parameter store', () => { const parameter = ssm.StringParameter.fromSecureStringParameterAttributes(stack, 'Parameter', { parameterName: '/token', version: 1, @@ -159,7 +158,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -195,13 +194,13 @@ nodeunitShim({ }, }, ], - })); + }); + - test.done(); - }, + }); - 'throws when neither token nor secret token are provided'(test: Test) { - test.throws(() => { + test('throws when neither token nor secret token are provided', () => { + expect(() => { td.addContainer('Container', { image, logging: ecs.LogDrivers.splunk({ @@ -209,8 +208,8 @@ nodeunitShim({ }), memoryLimitMiB: 128, }); - }, 'Please provide either token or secretToken.'); + }).toThrow('Please provide either token or secretToken.'); + - test.done(); - }, + }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/syslog-log-driver.test.ts b/packages/@aws-cdk/aws-ecs/test/syslog-log-driver.test.ts index db328772d7548..ae32f55ecd863 100644 --- a/packages/@aws-cdk/aws-ecs/test/syslog-log-driver.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/syslog-log-driver.test.ts @@ -1,21 +1,20 @@ -import { expect, haveResourceLike } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as ecs from '../lib'; let stack: cdk.Stack; let td: ecs.TaskDefinition; const image = ecs.ContainerImage.fromRegistry('test-image'); -nodeunitShim({ - 'setUp'(cb: () => void) { +describe('syslog log driver', () => { + beforeEach(() => { stack = new cdk.Stack(); td = new ecs.Ec2TaskDefinition(stack, 'TaskDefinition'); - cb(); - }, - 'create a syslog log driver with options'(test: Test) { + }); + + test('create a syslog log driver with options', () => { // WHEN td.addContainer('Container', { image, @@ -26,7 +25,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -37,12 +36,12 @@ nodeunitShim({ }, }, ], - })); + }); - test.done(); - }, - 'create a syslog log driver without options'(test: Test) { + }); + + test('create a syslog log driver without options', () => { // WHEN td.addContainer('Container', { image, @@ -51,7 +50,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -59,12 +58,12 @@ nodeunitShim({ }, }, ], - })); + }); - test.done(); - }, - 'create a syslog log driver using syslog'(test: Test) { + }); + + test('create a syslog log driver using syslog', () => { // WHEN td.addContainer('Container', { image, @@ -73,7 +72,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResourceLike('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ { LogConfiguration: { @@ -82,8 +81,8 @@ nodeunitShim({ }, }, ], - })); + }); + - test.done(); - }, + }); }); diff --git a/packages/@aws-cdk/aws-ecs/test/task-definition.test.ts b/packages/@aws-cdk/aws-ecs/test/task-definition.test.ts index 6e578952a5765..07b3a8211da06 100644 --- a/packages/@aws-cdk/aws-ecs/test/task-definition.test.ts +++ b/packages/@aws-cdk/aws-ecs/test/task-definition.test.ts @@ -1,12 +1,11 @@ -import { expect, haveResource } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as iam from '@aws-cdk/aws-iam'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as ecs from '../lib'; -nodeunitShim({ - 'When creating a new TaskDefinition': { - 'A task definition with both compatibilities defaults to networkmode AwsVpc'(test: Test) { +describe('task definition', () => { + describe('When creating a new TaskDefinition', () => { + test('A task definition with both compatibilities defaults to networkmode AwsVpc', () => { // GIVEN const stack = new cdk.Stack(); @@ -18,16 +17,16 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::ECS::TaskDefinition', { + expect(stack).toHaveResource('AWS::ECS::TaskDefinition', { NetworkMode: 'awsvpc', - })); + }); + - test.done(); - }, - }, + }); + }); - 'When importing from an existing Task definition': { - 'can import using a task definition arn'(test: Test) { + describe('When importing from an existing Task definition', () => { + test('can import using a task definition arn', () => { // GIVEN const stack = new cdk.Stack(); const taskDefinitionArn = 'TDArn'; @@ -36,14 +35,14 @@ nodeunitShim({ const taskDefinition = ecs.TaskDefinition.fromTaskDefinitionArn(stack, 'TD_ID', taskDefinitionArn); // THEN - test.equal(taskDefinition.taskDefinitionArn, taskDefinitionArn); - test.equal(taskDefinition.compatibility, ecs.Compatibility.EC2_AND_FARGATE); - test.equal(taskDefinition.executionRole, undefined); + expect(taskDefinition.taskDefinitionArn).toEqual(taskDefinitionArn); + expect(taskDefinition.compatibility).toEqual(ecs.Compatibility.EC2_AND_FARGATE); + expect(taskDefinition.executionRole).toEqual(undefined); + - test.done(); - }, + }); - 'can import a Task Definition using attributes'(test: Test) { + test('can import a Task Definition using attributes', () => { // GIVEN const stack = new cdk.Stack(); const expectTaskDefinitionArn = 'TD_ARN'; @@ -62,16 +61,16 @@ nodeunitShim({ }); // THEN - test.equal(taskDefinition.taskDefinitionArn, expectTaskDefinitionArn); - test.equal(taskDefinition.compatibility, expectCompatibility); - test.equal(taskDefinition.executionRole, undefined); - test.equal(taskDefinition.networkMode, expectNetworkMode); - test.equal(taskDefinition.taskRole, expectTaskRole); + expect(taskDefinition.taskDefinitionArn).toEqual(expectTaskDefinitionArn); + expect(taskDefinition.compatibility).toEqual(expectCompatibility); + expect(taskDefinition.executionRole).toEqual(undefined); + expect(taskDefinition.networkMode).toEqual(expectNetworkMode); + expect(taskDefinition.taskRole).toEqual(expectTaskRole); - test.done(); - }, - 'returns an imported TaskDefinition that will throw an error when trying to access its yet to defined networkMode'(test: Test) { + }); + + test('returns an imported TaskDefinition that will throw an error when trying to access its yet to defined networkMode', () => { // GIVEN const stack = new cdk.Stack(); const expectTaskDefinitionArn = 'TD_ARN'; @@ -88,15 +87,15 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { taskDefinition.networkMode; - }, 'This operation requires the networkMode in ImportedTaskDefinition to be defined. ' + + }).toThrow('This operation requires the networkMode in ImportedTaskDefinition to be defined. ' + 'Add the \'networkMode\' in ImportedTaskDefinitionProps to instantiate ImportedTaskDefinition'); - test.done(); - }, - 'returns an imported TaskDefinition that will throw an error when trying to access its yet to defined taskRole'(test: Test) { + }); + + test('returns an imported TaskDefinition that will throw an error when trying to access its yet to defined taskRole', () => { // GIVEN const stack = new cdk.Stack(); const expectTaskDefinitionArn = 'TD_ARN'; @@ -111,12 +110,12 @@ nodeunitShim({ }); // THEN - test.throws(() => { + expect(() => { taskDefinition.taskRole; - }, 'This operation requires the taskRole in ImportedTaskDefinition to be defined. ' + + }).toThrow('This operation requires the taskRole in ImportedTaskDefinition to be defined. ' + 'Add the \'taskRole\' in ImportedTaskDefinitionProps to instantiate ImportedTaskDefinition'); - test.done(); - }, - }, + + }); + }); }); diff --git a/packages/@aws-cdk/aws-route53/package.json b/packages/@aws-cdk/aws-route53/package.json index 90608982f090b..24e72e9300c93 100644 --- a/packages/@aws-cdk/aws-route53/package.json +++ b/packages/@aws-cdk/aws-route53/package.json @@ -81,7 +81,6 @@ "cdk-integ-tools": "0.0.0", "cfn2ts": "0.0.0", "jest": "^26.6.3", - "nodeunit-shim": "0.0.0", "pkglint": "0.0.0", "@aws-cdk/assert-internal": "0.0.0" }, diff --git a/packages/@aws-cdk/aws-route53/test/hosted-zone-provider.test.ts b/packages/@aws-cdk/aws-route53/test/hosted-zone-provider.test.ts index bf4fba67df048..0b66c9589cd50 100644 --- a/packages/@aws-cdk/aws-route53/test/hosted-zone-provider.test.ts +++ b/packages/@aws-cdk/aws-route53/test/hosted-zone-provider.test.ts @@ -1,11 +1,11 @@ +import '@aws-cdk/assert-internal/jest'; import { SynthUtils } from '@aws-cdk/assert-internal'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import { HostedZone } from '../lib'; -nodeunitShim({ - 'Hosted Zone Provider': { - 'HostedZoneProvider will return context values if available'(test: Test) { +describe('hosted zone provider', () => { + describe('Hosted Zone Provider', () => { + test('HostedZoneProvider will return context values if available', () => { // GIVEN const stack = new cdk.Stack(undefined, 'TestStack', { env: { account: '12345', region: 'us-east-1' }, @@ -15,7 +15,7 @@ nodeunitShim({ HostedZone.fromLookup(stack, 'Ref', filter); const missing = SynthUtils.synthesize(stack).assembly.manifest.missing!; - test.ok(missing && missing.length === 1); + expect(missing && missing.length === 1).toEqual(true); const fakeZoneId = '11111111111111'; const fakeZone = { @@ -38,12 +38,10 @@ nodeunitShim({ const zoneRef = HostedZone.fromLookup(stack2, 'MyZoneProvider', filter); // THEN - test.deepEqual(zoneRef.hostedZoneId, fakeZoneId); - test.done(); - }, - 'HostedZoneProvider will return context values if available when using plain hosted zone id'( - test: Test, - ) { + expect(zoneRef.hostedZoneId).toEqual(fakeZoneId); + + }); + test('HostedZoneProvider will return context values if available when using plain hosted zone id', () => { // GIVEN const stack = new cdk.Stack(undefined, 'TestStack', { env: { account: '12345', region: 'us-east-1' }, @@ -53,7 +51,7 @@ nodeunitShim({ HostedZone.fromLookup(stack, 'Ref', filter); const missing = SynthUtils.synthesize(stack).assembly.manifest.missing!; - test.ok(missing && missing.length === 1); + expect(missing && missing.length === 1).toEqual(true); const fakeZoneId = '11111111111111'; const fakeZone = { @@ -78,8 +76,8 @@ nodeunitShim({ const zoneId = zone.hostedZoneId; // THEN - test.deepEqual(fakeZoneId, zoneId); - test.done(); - }, - }, + expect(fakeZoneId).toEqual(zoneId); + + }); + }); }); diff --git a/packages/@aws-cdk/aws-route53/test/hosted-zone.test.ts b/packages/@aws-cdk/aws-route53/test/hosted-zone.test.ts index a11b3308641d2..7939452fd3421 100644 --- a/packages/@aws-cdk/aws-route53/test/hosted-zone.test.ts +++ b/packages/@aws-cdk/aws-route53/test/hosted-zone.test.ts @@ -1,12 +1,11 @@ -import { expect } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import * as iam from '@aws-cdk/aws-iam'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import { HostedZone, PublicHostedZone } from '../lib'; -nodeunitShim({ - 'Hosted Zone': { - 'Hosted Zone constructs the ARN'(test: Test) { +describe('hosted zone', () => { + describe('Hosted Zone', () => { + test('Hosted Zone constructs the ARN', () => { // GIVEN const stack = new cdk.Stack(undefined, 'TestStack', { env: { account: '123456789012', region: 'us-east-1' }, @@ -16,7 +15,7 @@ nodeunitShim({ zoneName: 'testZone', }); - test.deepEqual(stack.resolve(testZone.hostedZoneArn), { + expect(stack.resolve(testZone.hostedZoneArn)).toEqual({ 'Fn::Join': [ '', [ @@ -28,11 +27,11 @@ nodeunitShim({ ], }); - test.done(); - }, - }, - 'Supports tags'(test: Test) { + }); + }); + + test('Supports tags', () => { // GIVEN const stack = new cdk.Stack(); @@ -43,7 +42,7 @@ nodeunitShim({ cdk.Tags.of(hostedZone).add('zoneTag', 'inMyZone'); // THEN - expect(stack).toMatch({ + expect(stack).toMatchTemplate({ Resources: { HostedZoneDB99F866: { Type: 'AWS::Route53::HostedZone', @@ -60,10 +59,10 @@ nodeunitShim({ }, }); - test.done(); - }, - 'with crossAccountZoneDelegationPrincipal'(test: Test) { + }); + + test('with crossAccountZoneDelegationPrincipal', () => { // GIVEN const stack = new cdk.Stack(undefined, 'TestStack', { env: { account: '123456789012', region: 'us-east-1' }, @@ -77,7 +76,7 @@ nodeunitShim({ }); // THEN - expect(stack).toMatch({ + expect(stack).toMatchTemplate({ Resources: { HostedZoneDB99F866: { Type: 'AWS::Route53::HostedZone', @@ -151,23 +150,23 @@ nodeunitShim({ }, }); - test.done(); - }, - 'with crossAccountZoneDelegationPrincipal, throws if name provided without principal'(test: Test) { + }); + + test('with crossAccountZoneDelegationPrincipal, throws if name provided without principal', () => { // GIVEN const stack = new cdk.Stack(undefined, 'TestStack', { env: { account: '123456789012', region: 'us-east-1' }, }); // THEN - test.throws(() => { + expect(() => { new PublicHostedZone(stack, 'HostedZone', { zoneName: 'testZone', crossAccountZoneDelegationRoleName: 'myrole', }); - }, /crossAccountZoneDelegationRoleName property is not supported without crossAccountZoneDelegationPrincipal/); + }).toThrow(/crossAccountZoneDelegationRoleName property is not supported without crossAccountZoneDelegationPrincipal/); + - test.done(); - }, + }); }); diff --git a/packages/@aws-cdk/aws-route53/test/record-set.test.ts b/packages/@aws-cdk/aws-route53/test/record-set.test.ts index a071ad2a1aeea..8e380e3dfcd81 100644 --- a/packages/@aws-cdk/aws-route53/test/record-set.test.ts +++ b/packages/@aws-cdk/aws-route53/test/record-set.test.ts @@ -1,11 +1,11 @@ -import { expect, haveResource, ResourcePart } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; +import { ResourcePart } from '@aws-cdk/assert-internal'; import * as iam from '@aws-cdk/aws-iam'; import { Duration, RemovalPolicy, Stack } from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as route53 from '../lib'; -nodeunitShim({ - 'with default ttl'(test: Test) { +describe('record set', () => { + test('with default ttl', () => { // GIVEN const stack = new Stack(); @@ -22,7 +22,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Name: 'www.myzone.', Type: 'CNAME', HostedZoneId: { @@ -32,11 +32,11 @@ nodeunitShim({ 'zzz', ], TTL: '1800', - })); - test.done(); - }, + }); + + }); - 'with custom ttl'(test: Test) { + test('with custom ttl', () => { // GIVEN const stack = new Stack(); @@ -54,7 +54,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Name: 'aa.myzone.', Type: 'CNAME', HostedZoneId: { @@ -64,11 +64,11 @@ nodeunitShim({ 'bbb', ], TTL: '6077', - })); - test.done(); - }, + }); - 'with ttl of 0'(test: Test) { + }); + + test('with ttl of 0', () => { // GIVEN const stack = new Stack(); @@ -86,13 +86,13 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { TTL: '0', - })); - test.done(); - }, + }); + + }); - 'defaults to zone root'(test: Test) { + test('defaults to zone root', () => { // GIVEN const stack = new Stack(); @@ -108,7 +108,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Name: 'myzone.', Type: 'A', HostedZoneId: { @@ -117,11 +117,11 @@ nodeunitShim({ ResourceRecords: [ '1.2.3.4', ], - })); - test.done(); - }, + }); + + }); - 'A record with ip addresses'(test: Test) { + test('A record with ip addresses', () => { // GIVEN const stack = new Stack(); @@ -137,7 +137,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Name: 'www.myzone.', Type: 'A', HostedZoneId: { @@ -148,11 +148,11 @@ nodeunitShim({ '5.6.7.8', ], TTL: '1800', - })); - test.done(); - }, + }); - 'A record with alias'(test: Test) { + }); + + test('A record with alias', () => { // GIVEN const stack = new Stack(); @@ -177,7 +177,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Name: '_foo.myzone.', HostedZoneId: { Ref: 'HostedZoneDB99F866', @@ -187,12 +187,12 @@ nodeunitShim({ HostedZoneId: 'Z2P70J7EXAMPLE', DNSName: 'foo.example.com', }, - })); + }); - test.done(); - }, - 'AAAA record with ip addresses'(test: Test) { + }); + + test('AAAA record with ip addresses', () => { // GIVEN const stack = new Stack(); @@ -208,7 +208,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Name: 'www.myzone.', Type: 'AAAA', HostedZoneId: { @@ -218,11 +218,11 @@ nodeunitShim({ '2001:0db8:85a3:0000:0000:8a2e:0370:7334', ], TTL: '1800', - })); - test.done(); - }, + }); + + }); - 'AAAA record with alias on zone root'(test: Test) { + test('AAAA record with alias on zone root', () => { // GIVEN const stack = new Stack(); const zone = new route53.HostedZone(stack, 'HostedZone', { @@ -245,7 +245,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Name: 'myzone.', HostedZoneId: { Ref: 'HostedZoneDB99F866', @@ -255,12 +255,12 @@ nodeunitShim({ HostedZoneId: 'Z2P70J7EXAMPLE', DNSName: 'foo.example.com', }, - })); + }); + - test.done(); - }, + }); - 'CNAME record'(test: Test) { + test('CNAME record', () => { // GIVEN const stack = new Stack(); @@ -276,7 +276,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Name: 'www.myzone.', Type: 'CNAME', HostedZoneId: { @@ -286,11 +286,11 @@ nodeunitShim({ 'hello', ], TTL: '1800', - })); - test.done(); - }, + }); - 'TXT record'(test: Test) { + }); + + test('TXT record', () => { // GIVEN const stack = new Stack(); @@ -306,7 +306,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Name: 'www.myzone.', Type: 'TXT', HostedZoneId: { @@ -316,11 +316,11 @@ nodeunitShim({ '"should be enclosed with double quotes"', ], TTL: '1800', - })); - test.done(); - }, + }); + + }); - 'TXT record with value longer than 255 chars'(test: Test) { + test('TXT record with value longer than 255 chars', () => { // GIVEN const stack = new Stack(); @@ -336,7 +336,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Name: 'www.myzone.', Type: 'TXT', HostedZoneId: { @@ -346,11 +346,11 @@ nodeunitShim({ '"hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello""hello"', ], TTL: '1800', - })); - test.done(); - }, + }); + + }); - 'SRV record'(test: Test) { + test('SRV record', () => { // GIVEN const stack = new Stack(); @@ -371,7 +371,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Name: 'www.myzone.', Type: 'SRV', HostedZoneId: { @@ -381,11 +381,11 @@ nodeunitShim({ '10 5 8080 aws.com', ], TTL: '1800', - })); - test.done(); - }, + }); + + }); - 'CAA record'(test: Test) { + test('CAA record', () => { // GIVEN const stack = new Stack(); @@ -405,7 +405,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Name: 'www.myzone.', Type: 'CAA', HostedZoneId: { @@ -415,11 +415,11 @@ nodeunitShim({ '0 issue "ssl.com"', ], TTL: '1800', - })); - test.done(); - }, + }); - 'CAA Amazon record'(test: Test) { + }); + + test('CAA Amazon record', () => { // GIVEN const stack = new Stack(); @@ -433,7 +433,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Name: 'myzone.', Type: 'CAA', HostedZoneId: { @@ -443,11 +443,11 @@ nodeunitShim({ '0 issue "amazon.com"', ], TTL: '1800', - })); - test.done(); - }, + }); + + }); - 'CAA Amazon record with record name'(test: Test) { + test('CAA Amazon record with record name', () => { // GIVEN const stack = new Stack(); @@ -462,7 +462,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Name: 'www.myzone.', Type: 'CAA', HostedZoneId: { @@ -472,11 +472,11 @@ nodeunitShim({ '0 issue "amazon.com"', ], TTL: '1800', - })); - test.done(); - }, + }); + + }); - 'MX record'(test: Test) { + test('MX record', () => { // GIVEN const stack = new Stack(); @@ -495,7 +495,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Name: 'mail.myzone.', Type: 'MX', HostedZoneId: { @@ -505,11 +505,11 @@ nodeunitShim({ '10 workmail.aws', ], TTL: '1800', - })); - test.done(); - }, + }); - 'NS record'(test: Test) { + }); + + test('NS record', () => { // GIVEN const stack = new Stack(); @@ -525,7 +525,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Name: 'www.myzone.', Type: 'NS', HostedZoneId: { @@ -536,11 +536,11 @@ nodeunitShim({ 'ns-2.awsdns.com.', ], TTL: '1800', - })); - test.done(); - }, + }); - 'DS record'(test: Test) { + }); + + test('DS record', () => { // GIVEN const stack = new Stack(); @@ -556,7 +556,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Name: 'www.myzone.', Type: 'DS', HostedZoneId: { @@ -566,11 +566,11 @@ nodeunitShim({ '12345 3 1 123456789abcdef67890123456789abcdef67890', ], TTL: '1800', - })); - test.done(); - }, + }); + + }); - 'Zone delegation record'(test: Test) { + test('Zone delegation record', () => { // GIVEN const stack = new Stack(); @@ -586,7 +586,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Name: 'foo.myzone.', Type: 'NS', HostedZoneId: { @@ -596,11 +596,11 @@ nodeunitShim({ 'ns-1777.awsdns-30.co.uk.', ], TTL: '172800', - })); - test.done(); - }, + }); + + }); - 'Cross account zone delegation record with parentHostedZoneId'(test: Test) { + test('Cross account zone delegation record with parentHostedZoneId', () => { // GIVEN const stack = new Stack(); const parentZone = new route53.PublicHostedZone(stack, 'ParentHostedZone', { @@ -621,7 +621,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('Custom::CrossAccountZoneDelegation', { + expect(stack).toHaveResource('Custom::CrossAccountZoneDelegation', { ServiceToken: { 'Fn::GetAtt': [ 'CustomCrossAccountZoneDelegationCustomResourceProviderHandler44A84265', @@ -645,15 +645,15 @@ nodeunitShim({ ], }, TTL: 60, - })); - expect(stack).to(haveResource('Custom::CrossAccountZoneDelegation', { + }); + expect(stack).toHaveResource('Custom::CrossAccountZoneDelegation', { DeletionPolicy: 'Retain', UpdateReplacePolicy: 'Retain', - }, ResourcePart.CompleteDefinition)); - test.done(); - }, + }, ResourcePart.CompleteDefinition); + + }); - 'Cross account zone delegation record with parentHostedZoneName'(test: Test) { + test('Cross account zone delegation record with parentHostedZoneName', () => { // GIVEN const stack = new Stack(); const parentZone = new route53.PublicHostedZone(stack, 'ParentHostedZone', { @@ -673,7 +673,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('Custom::CrossAccountZoneDelegation', { + expect(stack).toHaveResource('Custom::CrossAccountZoneDelegation', { ServiceToken: { 'Fn::GetAtt': [ 'CustomCrossAccountZoneDelegationCustomResourceProviderHandler44A84265', @@ -695,11 +695,11 @@ nodeunitShim({ ], }, TTL: 60, - })); - test.done(); - }, + }); - 'Cross account zone delegation record throws when parent id and name both/nither are supplied'(test: Test) { + }); + + test('Cross account zone delegation record throws when parent id and name both/nither are supplied', () => { // GIVEN const stack = new Stack(); const parentZone = new route53.PublicHostedZone(stack, 'ParentHostedZone', { @@ -712,15 +712,15 @@ nodeunitShim({ zoneName: 'sub.myzone.com', }); - test.throws(() => { + expect(() => { new route53.CrossAccountZoneDelegationRecord(stack, 'Delegation1', { delegatedZone: childZone, delegationRole: parentZone.crossAccountZoneDelegationRole!, ttl: Duration.seconds(60), }); - }, /At least one of parentHostedZoneName or parentHostedZoneId is required/); + }).toThrow(/At least one of parentHostedZoneName or parentHostedZoneId is required/); - test.throws(() => { + expect(() => { new route53.CrossAccountZoneDelegationRecord(stack, 'Delegation2', { delegatedZone: childZone, parentHostedZoneId: parentZone.hostedZoneId, @@ -728,8 +728,8 @@ nodeunitShim({ delegationRole: parentZone.crossAccountZoneDelegationRole!, ttl: Duration.seconds(60), }); - }, /Only one of parentHostedZoneName and parentHostedZoneId is supported/); + }).toThrow(/Only one of parentHostedZoneName and parentHostedZoneId is supported/); + - test.done(); - }, + }); }); diff --git a/packages/@aws-cdk/aws-route53/test/route53.test.ts b/packages/@aws-cdk/aws-route53/test/route53.test.ts index e5dd624163a9b..f86b155592db7 100644 --- a/packages/@aws-cdk/aws-route53/test/route53.test.ts +++ b/packages/@aws-cdk/aws-route53/test/route53.test.ts @@ -1,15 +1,15 @@ -import { beASupersetOfTemplate, exactlyMatchTemplate, expect, haveResource } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; +import { MatchStyle } from '@aws-cdk/assert-internal'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import { HostedZone, PrivateHostedZone, PublicHostedZone, TxtRecord } from '../lib'; -nodeunitShim({ - 'default properties': { - 'public hosted zone'(test: Test) { +describe('route53', () => { + describe('default properties', () => { + test('public hosted zone', () => { const app = new TestApp(); new PublicHostedZone(app.stack, 'HostedZone', { zoneName: 'test.public' }); - expect(app.stack).to(exactlyMatchTemplate({ + expect(app.stack).toMatchTemplate({ Resources: { HostedZoneDB99F866: { Type: 'AWS::Route53::HostedZone', @@ -18,14 +18,14 @@ nodeunitShim({ }, }, }, - })); - test.done(); - }, - 'private hosted zone'(test: Test) { + }); + + }); + test('private hosted zone', () => { const app = new TestApp(); const vpcNetwork = new ec2.Vpc(app.stack, 'VPC'); new PrivateHostedZone(app.stack, 'HostedZone', { zoneName: 'test.private', vpc: vpcNetwork }); - expect(app.stack).to(beASupersetOfTemplate({ + expect(app.stack).toMatchTemplate({ Resources: { HostedZoneDB99F866: { Type: 'AWS::Route53::HostedZone', @@ -38,16 +38,16 @@ nodeunitShim({ }, }, }, - })); - test.done(); - }, - 'when specifying multiple VPCs'(test: Test) { + }, MatchStyle.SUPERSET); + + }); + test('when specifying multiple VPCs', () => { const app = new TestApp(); const vpcNetworkA = new ec2.Vpc(app.stack, 'VPC1'); const vpcNetworkB = new ec2.Vpc(app.stack, 'VPC2'); new PrivateHostedZone(app.stack, 'HostedZone', { zoneName: 'test.private', vpc: vpcNetworkA }) .addVpc(vpcNetworkB); - expect(app.stack).to(beASupersetOfTemplate({ + expect(app.stack).toMatchTemplate({ Resources: { HostedZoneDB99F866: { Type: 'AWS::Route53::HostedZone', @@ -64,12 +64,12 @@ nodeunitShim({ }, }, }, - })); - test.done(); - }, - }, + }, MatchStyle.SUPERSET); - 'exporting and importing works'(test: Test) { + }); + }); + + test('exporting and importing works', () => { const stack2 = new cdk.Stack(); const importedZone = HostedZone.fromHostedZoneAttributes(stack2, 'Imported', { @@ -83,17 +83,17 @@ nodeunitShim({ values: ['SeeThere'], }); - expect(stack2).to(haveResource('AWS::Route53::RecordSet', { + expect(stack2).toHaveResource('AWS::Route53::RecordSet', { HostedZoneId: 'hosted-zone-id', Name: 'lookHere.cdk.local.', ResourceRecords: ['"SeeThere"'], Type: 'TXT', - })); + }); - test.done(); - }, - 'adds period to name if not provided'(test: Test) { + }); + + test('adds period to name if not provided', () => { // GIVEN const stack = new cdk.Stack(); @@ -103,22 +103,22 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::HostedZone', { + expect(stack).toHaveResource('AWS::Route53::HostedZone', { Name: 'zonename.', - })); - test.done(); - }, + }); - 'fails if zone name ends with a trailing dot'(test: Test) { + }); + + test('fails if zone name ends with a trailing dot', () => { // GIVEN const stack = new cdk.Stack(); // THEN - test.throws(() => new HostedZone(stack, 'MyHostedZone', { zoneName: 'zonename.' }), /zone name must not end with a trailing dot/); - test.done(); - }, + expect(() => new HostedZone(stack, 'MyHostedZone', { zoneName: 'zonename.' })).toThrow(/zone name must not end with a trailing dot/); + + }); - 'a hosted zone can be assiciated with a VPC either upon creation or using "addVpc"'(test: Test) { + test('a hosted zone can be assiciated with a VPC either upon creation or using "addVpc"', () => { // GIVEN const stack = new cdk.Stack(); const vpc1 = new ec2.Vpc(stack, 'VPC1'); @@ -133,7 +133,7 @@ nodeunitShim({ zone.addVpc(vpc3); // THEN - expect(stack).to(haveResource('AWS::Route53::HostedZone', { + expect(stack).toHaveResource('AWS::Route53::HostedZone', { VPCs: [ { VPCId: { @@ -160,22 +160,22 @@ nodeunitShim({ }, }, ], - })); - test.done(); - }, + }); - 'public zone cannot be associated with a vpc (runtime error)'(test: Test) { + }); + + test('public zone cannot be associated with a vpc (runtime error)', () => { // GIVEN const stack = new cdk.Stack(); const zone = new PublicHostedZone(stack, 'MyHostedZone', { zoneName: 'zonename' }); const vpc = new ec2.Vpc(stack, 'VPC'); // THEN - test.throws(() => zone.addVpc(vpc), /Cannot associate public hosted zones with a VPC/); - test.done(); - }, + expect(() => zone.addVpc(vpc)).toThrow(/Cannot associate public hosted zones with a VPC/); + + }); - 'setting up zone delegation'(test: Test) { + test('setting up zone delegation', () => { // GIVEN const stack = new cdk.Stack(); const zone = new PublicHostedZone(stack, 'TopZone', { zoneName: 'top.test' }); @@ -185,17 +185,17 @@ nodeunitShim({ zone.addDelegation(delegate, { ttl: cdk.Duration.seconds(1337) }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Type: 'NS', Name: 'sub.top.test.', HostedZoneId: stack.resolve(zone.hostedZoneId), ResourceRecords: stack.resolve(delegate.hostedZoneNameServers), TTL: '1337', - })); - test.done(); - }, + }); + + }); - 'public hosted zone wiht caaAmazon set to true'(test: Test) { + test('public hosted zone wiht caaAmazon set to true', () => { // GIVEN const stack = new cdk.Stack(); @@ -206,15 +206,15 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::Route53::RecordSet', { + expect(stack).toHaveResource('AWS::Route53::RecordSet', { Type: 'CAA', Name: 'protected.com.', ResourceRecords: [ '0 issue "amazon.com"', ], - })); - test.done(); - }, + }); + + }); }); class TestApp { diff --git a/packages/@aws-cdk/aws-route53/test/util.test.ts b/packages/@aws-cdk/aws-route53/test/util.test.ts index c6ded4e74f7b4..f6ec2b7cd36a6 100644 --- a/packages/@aws-cdk/aws-route53/test/util.test.ts +++ b/packages/@aws-cdk/aws-route53/test/util.test.ts @@ -1,21 +1,20 @@ import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import { HostedZone } from '../lib'; import * as util from '../lib/util'; -nodeunitShim({ - 'throws when zone name ending with a \'.\''(test: Test) { - test.throws(() => util.validateZoneName('zone.name.'), /trailing dot/); - test.done(); - }, +describe('util', () => { + test('throws when zone name ending with a \'.\'', () => { + expect(() => util.validateZoneName('zone.name.')).toThrow(/trailing dot/); - 'accepts a valid domain name'(test: Test) { + }); + + test('accepts a valid domain name', () => { const domainName = 'amazonaws.com'; util.validateZoneName(domainName); - test.done(); - }, - 'providedName ending with a dot returns the name'(test: Test) { + }); + + test('providedName ending with a dot returns the name', () => { // GIVEN const stack = new cdk.Stack(); @@ -27,11 +26,11 @@ nodeunitShim({ })); // THEN - test.equal(qualified, 'test.domain.com.'); - test.done(); - }, + expect(qualified).toEqual('test.domain.com.'); + + }); - 'providedName that matches zoneName returns providedName with a trailing dot'(test: Test) { + test('providedName that matches zoneName returns providedName with a trailing dot', () => { // GIVEN const stack = new cdk.Stack(); @@ -43,11 +42,11 @@ nodeunitShim({ })); // THEN - test.equal(qualified, 'test.domain.com.'); - test.done(); - }, + expect(qualified).toEqual('test.domain.com.'); - 'providedName that ends with zoneName returns providedName with a trailing dot'(test: Test) { + }); + + test('providedName that ends with zoneName returns providedName with a trailing dot', () => { // GIVEN const stack = new cdk.Stack(); @@ -59,11 +58,11 @@ nodeunitShim({ })); // THEN - test.equal(qualified, 'test.domain.com.'); - test.done(); - }, + expect(qualified).toEqual('test.domain.com.'); + + }); - 'providedName that does not match zoneName concatenates providedName and zoneName'(test: Test) { + test('providedName that does not match zoneName concatenates providedName and zoneName', () => { // GIVEN const stack = new cdk.Stack(); @@ -75,7 +74,7 @@ nodeunitShim({ })); // THEN - test.equal(qualified, 'test.domain.com.'); - test.done(); - }, + expect(qualified).toEqual('test.domain.com.'); + + }); }); diff --git a/packages/@aws-cdk/aws-route53/test/vpc-endpoint-service-domain-name.test.ts b/packages/@aws-cdk/aws-route53/test/vpc-endpoint-service-domain-name.test.ts index 82706fe29d0ea..35b7ac9c67596 100644 --- a/packages/@aws-cdk/aws-route53/test/vpc-endpoint-service-domain-name.test.ts +++ b/packages/@aws-cdk/aws-route53/test/vpc-endpoint-service-domain-name.test.ts @@ -1,4 +1,3 @@ -/* eslint-disable jest/no-disabled-tests */ import { expect as cdkExpect, haveResource, haveResourceLike, ResourcePart } from '@aws-cdk/assert-internal'; import '@aws-cdk/assert-internal/jest'; import { IVpcEndpointServiceLoadBalancer, VpcEndpointService } from '@aws-cdk/aws-ec2'; diff --git a/packages/@aws-cdk/aws-s3/package.json b/packages/@aws-cdk/aws-s3/package.json index da9bdd3d05df4..865be5d5232b8 100644 --- a/packages/@aws-cdk/aws-s3/package.json +++ b/packages/@aws-cdk/aws-s3/package.json @@ -78,8 +78,8 @@ "cdk-build-tools": "0.0.0", "cdk-integ-tools": "0.0.0", "cfn2ts": "0.0.0", + "jest": "^26.6.3", "pkglint": "0.0.0", - "nodeunit-shim": "0.0.0", "@aws-cdk/assert-internal": "0.0.0" }, "dependencies": { diff --git a/packages/@aws-cdk/aws-s3/test/aspect.test.ts b/packages/@aws-cdk/aws-s3/test/aspect.test.ts index ef0394a4cf9cb..023ef826c18f8 100644 --- a/packages/@aws-cdk/aws-s3/test/aspect.test.ts +++ b/packages/@aws-cdk/aws-s3/test/aspect.test.ts @@ -1,12 +1,11 @@ -// import { expect, haveResource, haveResourceLike, SynthUtils } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import { SynthUtils } from '@aws-cdk/assert-internal'; import * as cdk from '@aws-cdk/core'; import { IConstruct } from 'constructs'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as s3 from '../lib'; -nodeunitShim({ - 'bucket must have versioning: failure'(test: Test) { +describe('aspect', () => { + test('bucket must have versioning: failure', () => { // GIVEN const stack = new cdk.Stack(); new s3.Bucket(stack, 'MyBucket'); @@ -17,12 +16,12 @@ nodeunitShim({ // THEN const assembly = SynthUtils.synthesize(stack); const errorMessage = assembly.messages.find(m => m.entry.data === 'Bucket versioning is not enabled'); - test.ok(errorMessage, 'Error message not reported'); + expect(errorMessage).toBeDefined(); - test.done(); - }, - 'bucket must have versioning: success'(test: Test) { + }); + + test('bucket must have versioning: success', () => { // GIVEN const stack = new cdk.Stack(); new s3.Bucket(stack, 'MyBucket', { @@ -34,10 +33,10 @@ nodeunitShim({ // THEN const assembly = SynthUtils.synthesize(stack); - test.deepEqual(assembly.messages, []); + expect(assembly.messages.length).toEqual(0); + - test.done(); - }, + }); }); class BucketVersioningChecker implements cdk.IAspect { diff --git a/packages/@aws-cdk/aws-s3/test/bucket-policy.test.ts b/packages/@aws-cdk/aws-s3/test/bucket-policy.test.ts index b64ab3d99df43..13b4b798bbd09 100644 --- a/packages/@aws-cdk/aws-s3/test/bucket-policy.test.ts +++ b/packages/@aws-cdk/aws-s3/test/bucket-policy.test.ts @@ -1,14 +1,13 @@ -import { expect, haveResource } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import { AnyPrincipal, PolicyStatement } from '@aws-cdk/aws-iam'; import { RemovalPolicy, Stack, App } from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as s3 from '../lib'; // to make it easy to copy & paste from output: /* eslint-disable quote-props */ -nodeunitShim({ - 'default properties'(test: Test) { +describe('bucket policy', () => { + test('default properties', () => { const stack = new Stack(); const myBucket = new s3.Bucket(stack, 'MyBucket'); @@ -21,7 +20,7 @@ nodeunitShim({ principals: [new AnyPrincipal()], })); - expect(stack).to(haveResource('AWS::S3::BucketPolicy', { + expect(stack).toHaveResource('AWS::S3::BucketPolicy', { Bucket: { 'Ref': 'MyBucketF68F3FF0', }, @@ -36,12 +35,12 @@ nodeunitShim({ }, ], }, - })); + }); - test.done(); - }, - 'when specifying a removalPolicy at creation'(test: Test) { + }); + + test('when specifying a removalPolicy at creation', () => { const stack = new Stack(); const myBucket = new s3.Bucket(stack, 'MyBucket'); @@ -55,7 +54,7 @@ nodeunitShim({ principals: [new AnyPrincipal()], })); - expect(stack).toMatch({ + expect(stack).toMatchTemplate({ 'Resources': { 'MyBucketF68F3FF0': { 'Type': 'AWS::S3::Bucket', @@ -86,10 +85,10 @@ nodeunitShim({ }, }); - test.done(); - }, - 'when specifying a removalPolicy after creation'(test: Test) { + }); + + test('when specifying a removalPolicy after creation', () => { const stack = new Stack(); const myBucket = new s3.Bucket(stack, 'MyBucket'); @@ -100,7 +99,7 @@ nodeunitShim({ })); myBucket.policy?.applyRemovalPolicy(RemovalPolicy.RETAIN); - expect(stack).toMatch({ + expect(stack).toMatchTemplate({ 'Resources': { 'MyBucketF68F3FF0': { 'Type': 'AWS::S3::Bucket', @@ -131,10 +130,10 @@ nodeunitShim({ }, }); - test.done(); - }, - 'fails if bucket policy has no actions'(test: Test) { + }); + + test('fails if bucket policy has no actions', () => { const app = new App(); const stack = new Stack(app, 'my-stack'); const myBucket = new s3.Bucket(stack, 'MyBucket'); @@ -143,12 +142,12 @@ nodeunitShim({ principals: [new AnyPrincipal()], })); - test.throws(() => app.synth(), /A PolicyStatement must specify at least one \'action\' or \'notAction\'/); + expect(() => app.synth()).toThrow(/A PolicyStatement must specify at least one \'action\' or \'notAction\'/); + - test.done(); - }, + }); - 'fails if bucket policy has no IAM principals'(test: Test) { + test('fails if bucket policy has no IAM principals', () => { const app = new App(); const stack = new Stack(app, 'my-stack'); const myBucket = new s3.Bucket(stack, 'MyBucket'); @@ -157,8 +156,8 @@ nodeunitShim({ actions: ['s3:GetObject*'], })); - test.throws(() => app.synth(), /A PolicyStatement used in a resource-based policy must specify at least one IAM principal/); + expect(() => app.synth()).toThrow(/A PolicyStatement used in a resource-based policy must specify at least one IAM principal/); + - test.done(); - }, + }); }); \ No newline at end of file diff --git a/packages/@aws-cdk/aws-s3/test/cors.test.ts b/packages/@aws-cdk/aws-s3/test/cors.test.ts index 5769c1059640d..feddf0b159669 100644 --- a/packages/@aws-cdk/aws-s3/test/cors.test.ts +++ b/packages/@aws-cdk/aws-s3/test/cors.test.ts @@ -1,10 +1,9 @@ -import { expect, haveResource } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import { Stack } from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import { Bucket, HttpMethods } from '../lib'; -nodeunitShim({ - 'Can use addCors() to add a CORS configuration'(test: Test) { +describe('cors', () => { + test('Can use addCors() to add a CORS configuration', () => { // GIVEN const stack = new Stack(); @@ -16,19 +15,19 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::S3::Bucket', { + expect(stack).toHaveResource('AWS::S3::Bucket', { CorsConfiguration: { CorsRules: [{ AllowedMethods: ['GET', 'HEAD'], AllowedOrigins: ['https://example.com'], }], }, - })); + }); + - test.done(); - }, + }); - 'Bucket with multiple cors configurations'(test: Test) { + test('Bucket with multiple cors configurations', () => { // GIVEN const stack = new Stack(); @@ -74,7 +73,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::S3::Bucket', { + expect(stack).toHaveResource('AWS::S3::Bucket', { CorsConfiguration: { CorsRules: [ { @@ -114,8 +113,8 @@ nodeunitShim({ }, ], }, - })); + }); + - test.done(); - }, + }); }); diff --git a/packages/@aws-cdk/aws-s3/test/metrics.test.ts b/packages/@aws-cdk/aws-s3/test/metrics.test.ts index bf7e57e04b557..9072c33a5fcb6 100644 --- a/packages/@aws-cdk/aws-s3/test/metrics.test.ts +++ b/packages/@aws-cdk/aws-s3/test/metrics.test.ts @@ -1,10 +1,9 @@ -import { expect, haveResource } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import { Stack } from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import { Bucket } from '../lib'; -nodeunitShim({ - 'Can use addMetrics() to add a metric configuration'(test: Test) { +describe('metrics', () => { + test('Can use addMetrics() to add a metric configuration', () => { // GIVEN const stack = new Stack(); @@ -15,16 +14,16 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::S3::Bucket', { + expect(stack).toHaveResource('AWS::S3::Bucket', { MetricsConfigurations: [{ Id: 'test', }], - })); + }); + - test.done(); - }, + }); - 'Bucket with metrics on prefix'(test: Test) { + test('Bucket with metrics on prefix', () => { // GIVEN const stack = new Stack(); @@ -37,17 +36,17 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::S3::Bucket', { + expect(stack).toHaveResource('AWS::S3::Bucket', { MetricsConfigurations: [{ Id: 'test', Prefix: 'prefix', }], - })); + }); + - test.done(); - }, + }); - 'Bucket with metrics on tag filter'(test: Test) { + test('Bucket with metrics on tag filter', () => { // GIVEN const stack = new Stack(); @@ -60,7 +59,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::S3::Bucket', { + expect(stack).toHaveResource('AWS::S3::Bucket', { MetricsConfigurations: [{ Id: 'test', TagFilters: [ @@ -68,12 +67,12 @@ nodeunitShim({ { Key: 'tagname2', Value: 'tagvalue2' }, ], }], - })); + }); + - test.done(); - }, + }); - 'Bucket with multiple metric configurations'(test: Test) { + test('Bucket with multiple metric configurations', () => { // GIVEN const stack = new Stack(); @@ -93,7 +92,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::S3::Bucket', { + expect(stack).toHaveResource('AWS::S3::Bucket', { MetricsConfigurations: [{ Id: 'test', TagFilters: [ @@ -105,8 +104,8 @@ nodeunitShim({ Id: 'test2', Prefix: 'prefix', }], - })); + }); + - test.done(); - }, + }); }); diff --git a/packages/@aws-cdk/aws-s3/test/notification.test.ts b/packages/@aws-cdk/aws-s3/test/notification.test.ts index 75906826ddeff..2f3178fb42af0 100644 --- a/packages/@aws-cdk/aws-s3/test/notification.test.ts +++ b/packages/@aws-cdk/aws-s3/test/notification.test.ts @@ -1,10 +1,10 @@ -import { expect, haveResource, haveResourceLike, ResourcePart } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; +import { ResourcePart } from '@aws-cdk/assert-internal'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import * as s3 from '../lib'; -nodeunitShim({ - 'when notification is added a custom s3 bucket notification resource is provisioned'(test: Test) { +describe('notification', () => { + test('when notification is added a custom s3 bucket notification resource is provisioned', () => { const stack = new cdk.Stack(); const bucket = new s3.Bucket(stack, 'MyBucket'); @@ -16,8 +16,8 @@ nodeunitShim({ }), }); - expect(stack).to(haveResource('AWS::S3::Bucket')); - expect(stack).to(haveResource('Custom::S3BucketNotifications', { + expect(stack).toHaveResource('AWS::S3::Bucket'); + expect(stack).toHaveResource('Custom::S3BucketNotifications', { NotificationConfiguration: { TopicConfigurations: [ { @@ -28,12 +28,12 @@ nodeunitShim({ }, ], }, - })); + }); + - test.done(); - }, + }); - 'can specify prefix and suffix filter rules'(test: Test) { + test('can specify prefix and suffix filter rules', () => { const stack = new cdk.Stack(); const bucket = new s3.Bucket(stack, 'MyBucket'); @@ -45,7 +45,7 @@ nodeunitShim({ }), }, { prefix: 'images/', suffix: '.png' }); - expect(stack).to(haveResource('Custom::S3BucketNotifications', { + expect(stack).toHaveResource('Custom::S3BucketNotifications', { NotificationConfiguration: { TopicConfigurations: [ { @@ -70,12 +70,12 @@ nodeunitShim({ }, ], }, - })); + }); + - test.done(); - }, + }); - 'the notification lambda handler must depend on the role to prevent executing too early'(test: Test) { + test('the notification lambda handler must depend on the role to prevent executing too early', () => { const stack = new cdk.Stack(); const bucket = new s3.Bucket(stack, 'MyBucket'); @@ -87,7 +87,7 @@ nodeunitShim({ }), }); - expect(stack).to(haveResourceLike('AWS::Lambda::Function', { + expect(stack).toHaveResourceLike('AWS::Lambda::Function', { Type: 'AWS::Lambda::Function', Properties: { Role: { @@ -99,38 +99,38 @@ nodeunitShim({ }, DependsOn: ['BucketNotificationsHandler050a0587b7544547bf325f094a3db834RoleDefaultPolicy2CF63D36', 'BucketNotificationsHandler050a0587b7544547bf325f094a3db834RoleB6FB88EC'], - }, ResourcePart.CompleteDefinition ) ); + }, ResourcePart.CompleteDefinition ); - test.done(); - }, - 'throws with multiple prefix rules in a filter'(test: Test) { + }); + + test('throws with multiple prefix rules in a filter', () => { const stack = new cdk.Stack(); const bucket = new s3.Bucket(stack, 'MyBucket'); - test.throws(() => bucket.addEventNotification(s3.EventType.OBJECT_CREATED, { + expect(() => bucket.addEventNotification(s3.EventType.OBJECT_CREATED, { bind: () => ({ arn: 'ARN', type: s3.BucketNotificationDestinationType.TOPIC, }), - }, { prefix: 'images/' }, { prefix: 'archive/' }), /prefix rule/); + }, { prefix: 'images/' }, { prefix: 'archive/' })).toThrow(/prefix rule/); + - test.done(); - }, + }); - 'throws with multiple suffix rules in a filter'(test: Test) { + test('throws with multiple suffix rules in a filter', () => { const stack = new cdk.Stack(); const bucket = new s3.Bucket(stack, 'MyBucket'); - test.throws(() => bucket.addEventNotification(s3.EventType.OBJECT_CREATED, { + expect(() => bucket.addEventNotification(s3.EventType.OBJECT_CREATED, { bind: () => ({ arn: 'ARN', type: s3.BucketNotificationDestinationType.TOPIC, }), - }, { suffix: '.png' }, { suffix: '.zip' }), /suffix rule/); + }, { suffix: '.png' }, { suffix: '.zip' })).toThrow(/suffix rule/); + - test.done(); - }, + }); }); diff --git a/packages/@aws-cdk/aws-s3/test/rules.test.ts b/packages/@aws-cdk/aws-s3/test/rules.test.ts index fb613bcf109e8..818ae7d830439 100644 --- a/packages/@aws-cdk/aws-s3/test/rules.test.ts +++ b/packages/@aws-cdk/aws-s3/test/rules.test.ts @@ -1,10 +1,9 @@ -import { expect, haveResource } from '@aws-cdk/assert-internal'; +import '@aws-cdk/assert-internal/jest'; import { Duration, Stack } from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import { Bucket, StorageClass } from '../lib'; -nodeunitShim({ - 'Bucket with expiration days'(test: Test) { +describe('rules', () => { + test('Bucket with expiration days', () => { // GIVEN const stack = new Stack(); @@ -16,19 +15,19 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::S3::Bucket', { + expect(stack).toHaveResource('AWS::S3::Bucket', { LifecycleConfiguration: { Rules: [{ ExpirationInDays: 30, Status: 'Enabled', }], }, - })); + }); + - test.done(); - }, + }); - 'Can use addLifecycleRule() to add a lifecycle rule'(test: Test) { + test('Can use addLifecycleRule() to add a lifecycle rule', () => { // GIVEN const stack = new Stack(); @@ -39,19 +38,19 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::S3::Bucket', { + expect(stack).toHaveResource('AWS::S3::Bucket', { LifecycleConfiguration: { Rules: [{ ExpirationInDays: 30, Status: 'Enabled', }], }, - })); + }); - test.done(); - }, - 'Bucket with expiration date'(test: Test) { + }); + + test('Bucket with expiration date', () => { // GIVEN const stack = new Stack(); @@ -63,19 +62,19 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::S3::Bucket', { + expect(stack).toHaveResource('AWS::S3::Bucket', { LifecycleConfiguration: { Rules: [{ ExpirationDate: '2018-01-01T00:00:00', Status: 'Enabled', }], }, - })); + }); + - test.done(); - }, + }); - 'Bucket with transition rule'(test: Test) { + test('Bucket with transition rule', () => { // GIVEN const stack = new Stack(); @@ -90,7 +89,7 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::S3::Bucket', { + expect(stack).toHaveResource('AWS::S3::Bucket', { LifecycleConfiguration: { Rules: [{ Transitions: [{ @@ -100,23 +99,23 @@ nodeunitShim({ Status: 'Enabled', }], }, - })); + }); + - test.done(); - }, + }); - 'Noncurrent rule on nonversioned bucket fails'(test: Test) { + test('Noncurrent rule on nonversioned bucket fails', () => { // GIVEN const stack = new Stack(); // WHEN: Fail because of lack of versioning - test.throws(() => { + expect(() => { new Bucket(stack, 'Bucket1', { lifecycleRules: [{ noncurrentVersionExpiration: Duration.days(10), }], }); - }); + }).toThrow(); // WHEN: Succeeds because versioning is enabled new Bucket(stack, 'Bucket2', { @@ -126,10 +125,10 @@ nodeunitShim({ }], }); - test.done(); - }, - 'Bucket with expiredObjectDeleteMarker'(test: Test) { + }); + + test('Bucket with expiredObjectDeleteMarker', () => { // GIVEN const stack = new Stack(); @@ -141,15 +140,15 @@ nodeunitShim({ }); // THEN - expect(stack).to(haveResource('AWS::S3::Bucket', { + expect(stack).toHaveResource('AWS::S3::Bucket', { LifecycleConfiguration: { Rules: [{ ExpiredObjectDeleteMarker: true, Status: 'Enabled', }], }, - })); + }); + - test.done(); - }, + }); }); diff --git a/packages/@aws-cdk/aws-s3/test/util.test.ts b/packages/@aws-cdk/aws-s3/test/util.test.ts index 528b83b10404b..e688932a0f7eb 100644 --- a/packages/@aws-cdk/aws-s3/test/util.test.ts +++ b/packages/@aws-cdk/aws-s3/test/util.test.ts @@ -1,68 +1,69 @@ +import '@aws-cdk/assert-internal/jest'; import * as cdk from '@aws-cdk/core'; -import { nodeunitShim, Test } from 'nodeunit-shim'; import { parseBucketArn, parseBucketName } from '../lib/util'; -nodeunitShim({ - parseBucketArn: { - 'explicit arn'(test: Test) { +describe('utils', () => { + describe('parseBucketArn', () => { + test('explicit arn', () => { const stack = new cdk.Stack(); const bucketArn = 'my:bucket:arn'; - test.deepEqual(parseBucketArn(stack, { bucketArn }), bucketArn); - test.done(); - }, + expect(parseBucketArn(stack, { bucketArn })).toEqual(bucketArn); - 'produce arn from bucket name'(test: Test) { + }); + + test('produce arn from bucket name', () => { const stack = new cdk.Stack(); const bucketName = 'hello'; - test.deepEqual(stack.resolve(parseBucketArn(stack, { bucketName })), { + expect(stack.resolve(parseBucketArn(stack, { bucketName }))).toEqual({ 'Fn::Join': ['', ['arn:', { Ref: 'AWS::Partition' }, ':s3:::hello']], }); - test.done(); - }, - 'fails if neither arn nor name are provided'(test: Test) { + }); + + test('fails if neither arn nor name are provided', () => { const stack = new cdk.Stack(); - test.throws(() => parseBucketArn(stack, {}), /Cannot determine bucket ARN. At least `bucketArn` or `bucketName` is needed/); - test.done(); - }, - }, + expect(() => parseBucketArn(stack, {})).toThrow(/Cannot determine bucket ARN. At least `bucketArn` or `bucketName` is needed/); - parseBucketName: { + }); + }); - 'explicit name'(test: Test) { + describe('parseBucketName', () => { + + test('explicit name', () => { const stack = new cdk.Stack(); const bucketName = 'foo'; - test.deepEqual(stack.resolve(parseBucketName(stack, { bucketName })), 'foo'); - test.done(); - }, + expect(stack.resolve(parseBucketName(stack, { bucketName }))).toEqual('foo'); + + }); - 'extract bucket name from string arn'(test: Test) { + test('extract bucket name from string arn', () => { const stack = new cdk.Stack(); const bucketArn = 'arn:aws:s3:::my-bucket'; - test.deepEqual(stack.resolve(parseBucketName(stack, { bucketArn })), 'my-bucket'); - test.done(); - }, + expect(stack.resolve(parseBucketName(stack, { bucketArn }))).toEqual('my-bucket'); - 'can parse bucket name even if it contains a token'(test: Test) { + }); + + test('can parse bucket name even if it contains a token', () => { const stack = new cdk.Stack(); const bucketArn = `arn:aws:s3:::${cdk.Token.asString({ Ref: 'my-bucket' })}`; - test.deepEqual( + expect( stack.resolve(parseBucketName(stack, { bucketArn })), + ).toEqual( { Ref: 'my-bucket' }, ); - test.done(); - }, - 'fails if ARN has invalid format'(test: Test) { + }); + + test('fails if ARN has invalid format', () => { const stack = new cdk.Stack(); const bucketArn = 'invalid-arn'; - test.throws(() => parseBucketName(stack, { bucketArn }), /ARNs must/); - test.done(); - }, - }, + expect(() => parseBucketName(stack, { bucketArn })).toThrow(/ARNs must/); + + }); + }); });