Skip to content

Commit

Permalink
Write the test!
Browse files Browse the repository at this point in the history
  • Loading branch information
skinny85 committed Nov 23, 2020
1 parent 2465852 commit 1484e61
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/monocdk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ dist
# Ignore barrel import entry points
/*.ts

junit.xml
junit.xml

.nyc_output
coverage
nyc.config.js
!jest.config.js
!jest.setup.local.js
4 changes: 3 additions & 1 deletion packages/monocdk/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ tsconfig.json
# exclude cdk artifacts
**/cdk.out
junit.xml
test/
test/
jest.config.js
jest.setup.local.js
5 changes: 5 additions & 0 deletions packages/monocdk/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const baseConfig = require('cdk-build-tools/config/jest.config');
// no point in collecting coverage for monocdk
baseConfig.collectCoverage = false;
baseConfig.setupFiles = ['./jest.setup.local.js'];
module.exports = baseConfig;
6 changes: 6 additions & 0 deletions packages/monocdk/jest.setup.local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// disallow tests (and production code) in monocdk from including the @aws-cdk/core module,
// which effectively bans using any @aws-cdk/* module,
// as they all depend on @aws-cdk/core
jest.mock('@aws-cdk/core', () => {
throw new Error('@aws-cdk/core is not available in monocdk tests!')
});
3 changes: 2 additions & 1 deletion packages/monocdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"gen": "ubergen",
"build": "cdk-build",
"lint": "cdk-lint",
"test": "echo done",
"test": "cdk-test",
"package": "cdk-package",
"pkglint": "pkglint -f",
"build+test": "npm run build && npm test",
Expand All @@ -29,6 +29,7 @@
]
},
"cdk-build": {
"jest": true,
"eslint": {
"disable": true
}
Expand Down
13 changes: 13 additions & 0 deletions packages/monocdk/test/cfn-include/cfn-include.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as cfn_inc from '../../cloudformation-include';
import * as s3 from '../../aws-s3';
import { Stack } from '../../lib';

test('cloudformation-include works in monocdk', () => {
const stack = new Stack();
const cfnInclude = new cfn_inc.CfnInclude(stack, 'Template', {
templateFile: `${__dirname}/minimal-template.json`
});
const cfnBucket = cfnInclude.getResource('Bucket') as s3.CfnBucket;

expect(cfnBucket.bucketName).toEqual('my-bucket');
});
10 changes: 10 additions & 0 deletions packages/monocdk/test/cfn-include/minimal-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Resources": {
"Bucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": "my-bucket"
}
}
}
}

0 comments on commit 1484e61

Please sign in to comment.