Skip to content

Commit

Permalink
feat(cli): Add Jest tests to JavaScript init templates (#4282)
Browse files Browse the repository at this point in the history
The test target in these templates were previously not running tests or failing.

Adresses #4027
  • Loading branch information
shivlaks authored and mergify[bot] committed Sep 30, 2019
1 parent fff798c commit 22a5ada
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 12 deletions.
3 changes: 1 addition & 2 deletions packages/aws-cdk/lib/init-templates/app/javascript/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Useful commands

* `npm run test` check javascript error using the typescript compiler
* `npm run test:watch` watch for changes and check javascript error using the typescript compiler
* `npm run test` perform the jest unit tests
* `cdk deploy` deploy this stack to your default AWS account/region
* `cdk diff` compare deployed stack with current state
* `cdk synth` emits the synthesized CloudFormation template
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
"%name%": "bin/%name%.js"
},
"scripts": {
"cdk": "cdk"
"build": "echo \"The build step is not required when using JavaScript!\" && exit 0",
"cdk": "cdk",
"test": "jest"
},
"devDependencies": {
"aws-cdk": "^%cdk-version%"
"@aws-cdk/assert": "^%cdk-version%",
"@types/jest": "^24.0.18",
"aws-cdk": "^%cdk-version%",
"jest": "^24.9.0"
},
"dependencies": {
"@aws-cdk/core": "^%cdk-version%"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { expect, matchTemplate, MatchStyle } = require('@aws-cdk/assert');
const cdk = require('@aws-cdk/core');
const %name.PascalCased% = require('../lib/%name%-stack');

test('Empty Stack', () => {
const app = new cdk.App();
// WHEN
const stack = new %name.PascalCased%.%name.PascalCased%Stack(app, 'MyTestStack');
// THEN
expect(stack).to(matchTemplate({
"Resources": {}
}, MatchStyle.EXACT))
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Useful commands

* `npm run test` check javascript error using the typescript compiler
* `npm run test:watch` watch for changes and check javascript error using the typescript compiler
* `npm run test` perform the jest unit tests
* `cdk deploy` deploy this stack to your default AWS account/region
* `cdk diff` compare deployed stack with current state
* `cdk synth` emits the synthesized CloudFormation template
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
"%name%": "bin/%name%.js"
},
"scripts": {
"test": "tsc",
"test:watch": "tsc -w",
"cdk": "cdk"
"build": "echo \"The build step is not required when using JavaScript!\" && exit 0",
"cdk": "cdk",
"test": "jest"
},
"devDependencies": {
"@types/node": "8.10.45",
"typescript": "^3.3.3333",
"aws-cdk": "^%cdk-version%"
"@aws-cdk/assert": "^%cdk-version%",
"@types/node": "8.10.54",
"@types/jest": "^24.0.18",
"aws-cdk": "^%cdk-version%",
"jest": "^24.9.0"
},
"dependencies": {
"@aws-cdk/aws-sns": "^%cdk-version%",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { expect, haveResource } = require('@aws-cdk/assert');
const cdk = require('@aws-cdk/core');
const %name.PascalCased% = require('../lib/%name%-stack');

test('SQS Queue Created', () => {
const app = new cdk.App();
// WHEN
const stack = new %name.PascalCased%.%name.PascalCased%Stack(app, 'MyTestStack');
// THEN
expect(stack).to(haveResource("AWS::SQS::Queue",{
VisibilityTimeout: 300
}));
});

test('SNS Topic Created', () => {
const app = new cdk.App();
// WHEN
const stack = new %name.PascalCased%.%name.PascalCased%Stack(app, 'MyTestStack');
// THEN
expect(stack).to(haveResource("AWS::SNS::Topic"));
});

0 comments on commit 22a5ada

Please sign in to comment.