Skip to content

Commit d0d74f2

Browse files
author
Niranjan Jayakar
authored
chore(codepipeline-actions,rds): migrate tests to jest (#13212)
Move codepipeline-actions from nodeunit to jest. Most tests now use `nodeunit-shim` but some tests have been migrated entirely to pure jest. Move `cluster.test.ts` and `instance.test.ts` in the rds module from `nodeunit-shim` to native jest. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent b9cdd52 commit d0d74f2

22 files changed

+723
-715
lines changed

packages/@aws-cdk/aws-codepipeline-actions/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ nyc.config.js
1616
*.snk
1717
!.eslintrc.js
1818

19-
junit.xml
19+
junit.xml
20+
!jest.config.js

packages/@aws-cdk/aws-codepipeline-actions/.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ tsconfig.json
2323
# exclude cdk artifacts
2424
**/cdk.out
2525
junit.xml
26-
test/
26+
test/
27+
jest.config.js
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const baseConfig = require('cdk-build-tools/config/jest.config');
2+
module.exports = baseConfig;

packages/@aws-cdk/aws-codepipeline-actions/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@
6969
"@aws-cdk/assert": "0.0.0",
7070
"@aws-cdk/aws-cloudtrail": "0.0.0",
7171
"@types/lodash": "^4.14.168",
72-
"@types/nodeunit": "^0.0.31",
7372
"cdk-build-tools": "0.0.0",
7473
"cdk-integ-tools": "0.0.0",
7574
"lodash": "^4.17.21",
76-
"nodeunit": "^0.11.3",
75+
"nodeunit-shim": "0.0.0",
7776
"pkglint": "0.0.0"
7877
},
7978
"dependencies": {
@@ -177,6 +176,7 @@
177176
},
178177
"maturity": "stable",
179178
"cdk-build": {
179+
"jest": true,
180180
"env": {
181181
"AWSLINT_BASE_CONSTRUCT": true
182182
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { expect, haveResourceLike } from '@aws-cdk/assert';
22
import * as codebuild from '@aws-cdk/aws-codebuild';
33
import * as codepipeline from '@aws-cdk/aws-codepipeline';
44
import { Stack } from '@aws-cdk/core';
5-
import { Test } from 'nodeunit';
5+
import { nodeunitShim, Test } from 'nodeunit-shim';
66
import * as cpactions from '../../lib';
77

88
/* eslint-disable quote-props */
99

10-
export = {
10+
nodeunitShim({
1111
'BitBucket source Action': {
1212
'produces the correct configuration when added to a pipeline'(test: Test) {
1313
const stack = new Stack();
@@ -82,7 +82,7 @@ export = {
8282

8383
test.done();
8484
},
85-
};
85+
});
8686

8787
function createBitBucketAndCodeBuildPipeline(stack: Stack, props: { codeBuildCloneOutput: boolean }): void {
8888
const sourceOutput = new codepipeline.Artifact();
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import * as codecommit from '@aws-cdk/aws-codecommit';
55
import * as codepipeline from '@aws-cdk/aws-codepipeline';
66
import { PolicyStatement, Role, ServicePrincipal } from '@aws-cdk/aws-iam';
77
import * as cdk from '@aws-cdk/core';
8-
import { Test } from 'nodeunit';
8+
import { nodeunitShim, Test } from 'nodeunit-shim';
99
import * as cpactions from '../../lib';
1010

1111
/* eslint-disable quote-props */
1212

13-
export = {
13+
nodeunitShim({
1414
'CreateChangeSetAction can be used to make a change set from a CodePipeline'(test: Test) {
1515
const stack = new cdk.Stack();
1616

@@ -712,7 +712,7 @@ export = {
712712
test.done();
713713
},
714714
},
715-
};
715+
});
716716

717717
/**
718718
* A test stack with a half-prepared pipeline ready to add CloudFormation actions to

packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/test.pipeline-actions.ts renamed to packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/pipeline-actions.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import * as s3 from '@aws-cdk/aws-s3';
55
import * as cdk from '@aws-cdk/core';
66
import * as constructs from 'constructs';
77
import * as _ from 'lodash';
8-
import * as nodeunit from 'nodeunit';
8+
import { nodeunitShim, Test } from 'nodeunit-shim';
99
import * as cpactions from '../../lib';
1010

11-
export = nodeunit.testCase({
11+
nodeunitShim({
1212
CreateReplaceChangeSet: {
13-
'works'(test: nodeunit.Test) {
13+
'works'(test: Test) {
1414
const app = new cdk.App();
1515
const stack = new cdk.Stack(app, 'Stack');
1616
const pipelineRole = new RoleDouble(stack, 'PipelineRole');
@@ -51,7 +51,7 @@ export = nodeunit.testCase({
5151
test.done();
5252
},
5353

54-
'uses a single permission statement if the same ChangeSet name is used'(test: nodeunit.Test) {
54+
'uses a single permission statement if the same ChangeSet name is used'(test: Test) {
5555
const stack = new cdk.Stack();
5656
const pipelineRole = new RoleDouble(stack, 'PipelineRole');
5757
const artifact = new codepipeline.Artifact('TestArtifact');
@@ -110,7 +110,7 @@ export = nodeunit.testCase({
110110
},
111111

112112
ExecuteChangeSet: {
113-
'works'(test: nodeunit.Test) {
113+
'works'(test: Test) {
114114
const stack = new cdk.Stack();
115115
const pipelineRole = new RoleDouble(stack, 'PipelineRole');
116116
const stage = new StageDouble({
@@ -137,7 +137,7 @@ export = nodeunit.testCase({
137137
test.done();
138138
},
139139

140-
'uses a single permission statement if the same ChangeSet name is used'(test: nodeunit.Test) {
140+
'uses a single permission statement if the same ChangeSet name is used'(test: Test) {
141141
const stack = new cdk.Stack();
142142
const pipelineRole = new RoleDouble(stack, 'PipelineRole');
143143
new StageDouble({
@@ -181,7 +181,7 @@ export = nodeunit.testCase({
181181
},
182182
},
183183

184-
'the CreateUpdateStack Action sets the DescribeStack*, Create/Update/DeleteStack & PassRole permissions'(test: nodeunit.Test) {
184+
'the CreateUpdateStack Action sets the DescribeStack*, Create/Update/DeleteStack & PassRole permissions'(test: Test) {
185185
const stack = new cdk.Stack();
186186
const pipelineRole = new RoleDouble(stack, 'PipelineRole');
187187
const action = new cpactions.CloudFormationCreateUpdateStackAction({
@@ -207,7 +207,7 @@ export = nodeunit.testCase({
207207
test.done();
208208
},
209209

210-
'the DeleteStack Action sets the DescribeStack*, DeleteStack & PassRole permissions'(test: nodeunit.Test) {
210+
'the DeleteStack Action sets the DescribeStack*, DeleteStack & PassRole permissions'(test: Test) {
211211
const stack = new cdk.Stack();
212212
const pipelineRole = new RoleDouble(stack, 'PipelineRole');
213213
const action = new cpactions.CloudFormationDeleteStackAction({
@@ -238,7 +238,7 @@ interface PolicyStatementJson {
238238
}
239239

240240
function _assertActionMatches(
241-
test: nodeunit.Test,
241+
test: Test,
242242
stack: cdk.Stack,
243243
actions: FullAction[],
244244
provider: string,
@@ -279,7 +279,7 @@ function _hasAction(
279279
}
280280

281281
function _assertPermissionGranted(
282-
test: nodeunit.Test,
282+
test: Test,
283283
stack: cdk.Stack,
284284
statements: iam.PolicyStatement[],
285285
action: string,

packages/@aws-cdk/aws-codepipeline-actions/test/codebuild/test.codebuild-action.ts renamed to packages/@aws-cdk/aws-codepipeline-actions/test/codebuild/codebuild-action.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import * as codepipeline from '@aws-cdk/aws-codepipeline';
55
import * as s3 from '@aws-cdk/aws-s3';
66
import * as sns from '@aws-cdk/aws-sns';
77
import { App, SecretValue, Stack } from '@aws-cdk/core';
8-
import { Test } from 'nodeunit';
8+
import { nodeunitShim, Test } from 'nodeunit-shim';
99
import * as cpactions from '../../lib';
1010

1111
/* eslint-disable quote-props */
1212

13-
export = {
13+
nodeunitShim({
1414
'CodeBuild action': {
1515
'that is cross-account and has outputs': {
1616
'causes an error'(test: Test) {
@@ -337,4 +337,4 @@ export = {
337337
},
338338
},
339339
},
340-
};
340+
});
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import * as codecommit from '@aws-cdk/aws-codecommit';
44
import * as codepipeline from '@aws-cdk/aws-codepipeline';
55
import * as iam from '@aws-cdk/aws-iam';
66
import { Stack, Lazy } from '@aws-cdk/core';
7-
import { Test } from 'nodeunit';
7+
import { nodeunitShim, Test } from 'nodeunit-shim';
88
import * as cpactions from '../../lib';
99

1010
/* eslint-disable quote-props */
1111

12-
export = {
12+
nodeunitShim({
1313
'CodeCommit Source Action': {
1414
'by default does not poll for source changes and uses Events'(test: Test) {
1515
const stack = new Stack();
@@ -430,7 +430,7 @@ export = {
430430
test.done();
431431
},
432432
},
433-
};
433+
});
434434

435435
function minimalPipeline(stack: Stack, trigger: cpactions.CodeCommitTrigger | undefined): codepipeline.Pipeline {
436436
const sourceOutput = new codepipeline.Artifact();

packages/@aws-cdk/aws-codepipeline-actions/test/codedeploy/test.ecs-deploy-action.ts renamed to packages/@aws-cdk/aws-codepipeline-actions/test/codedeploy/ecs-deploy-action.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { expect, haveResourceLike } from '@aws-cdk/assert';
22
import * as codedeploy from '@aws-cdk/aws-codedeploy';
33
import * as codepipeline from '@aws-cdk/aws-codepipeline';
44
import * as cdk from '@aws-cdk/core';
5-
import { Test } from 'nodeunit';
5+
import { nodeunitShim, Test } from 'nodeunit-shim';
66
import * as cpactions from '../../lib';
77

8-
export = {
8+
nodeunitShim({
99
'CodeDeploy ECS Deploy Action': {
1010
'throws an exception if more than 4 container image inputs are provided'(test: Test) {
1111
const stack = new cdk.Stack();
@@ -198,7 +198,7 @@ export = {
198198
test.done();
199199
},
200200
},
201-
};
201+
});
202202

203203
function addEcsDeploymentGroup(stack: cdk.Stack): codedeploy.IEcsDeploymentGroup {
204204
return codedeploy.EcsDeploymentGroup.fromEcsDeploymentGroupAttributes(

0 commit comments

Comments
 (0)