Skip to content

Commit

Permalink
chore(ecr): migrate tests to jest (aws#12620)
Browse files Browse the repository at this point in the history
* use native jest API like what aws#12596 did
* move `removal policy is "Retain" by default` & `'grant adds appropriate resource-*'` tests out of `events` scope in `repository.test.ts`, which I believe they were misplaced

I'm doing this partially because I would like to implement the feature proposed in aws#12618. It would be easier to mock `aws-sdk` function calls with jest.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
kirintwn authored and john-tipper committed May 10, 2021
1 parent 006e0dc commit 86a9268
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 150 deletions.
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-ecr/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ nyc.config.js
.LAST_PACKAGE
*.snk
!.eslintrc.js
!jest.config.js

junit.xml
junit.xml
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-ecr/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ dist

tsconfig.json
.eslintrc.js
jest.config.js

# exclude cdk artifacts
**/cdk.out
junit.xml
test/
test/
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-ecr/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const baseConfig = require('cdk-build-tools/config/jest.config');
module.exports = {
...baseConfig,
coverageThreshold: {
global: {
...baseConfig.coverageThreshold.global,
branches: 70,
},
},
};
9 changes: 4 additions & 5 deletions packages/@aws-cdk/aws-ecr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"cloudformation": "AWS::ECR",
"env": {
"AWSLINT_BASE_CONSTRUCT": true
}
},
"jest": true
},
"nyc": {
"lines": 78,
Expand All @@ -74,13 +75,11 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@types/nodeunit": "^0.0.31",
"@aws-cdk/assert-internal": "0.0.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
"nodeunit": "^0.11.3",
"pkglint": "0.0.0",
"@aws-cdk/assert-internal": "0.0.0"
"pkglint": "0.0.0"
},
"dependencies": {
"@aws-cdk/aws-events": "0.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { expect, haveResourceLike } from '@aws-cdk/assert-internal';
import { expect as expectCDK, haveResourceLike } from '@aws-cdk/assert-internal';
import * as iam from '@aws-cdk/aws-iam';
import { Stack } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { AuthorizationToken, PublicGalleryAuthorizationToken } from '../lib';

export = {
'AuthorizationToken.grantRead()'(test: Test) {
describe('auth-token', () => {
test('AuthorizationToken.grantRead()', () => {
// GIVEN
const stack = new Stack();
const user = new iam.User(stack, 'User');
Expand All @@ -14,7 +13,7 @@ export = {
AuthorizationToken.grantRead(user);

// THEN
expect(stack).to(haveResourceLike('AWS::IAM::Policy', {
expectCDK(stack).to(haveResourceLike('AWS::IAM::Policy', {
PolicyDocument: {
Statement: [
{
Expand All @@ -25,11 +24,9 @@ export = {
],
},
}));
});

test.done();
},

'PublicGalleryAuthorizationToken.grantRead()'(test: Test) {
test('PublicGalleryAuthorizationToken.grantRead()', () => {
// GIVEN
const stack = new Stack();
const user = new iam.User(stack, 'User');
Expand All @@ -38,7 +35,7 @@ export = {
PublicGalleryAuthorizationToken.grantRead(user);

// THEN
expect(stack).to(haveResourceLike('AWS::IAM::Policy', {
expectCDK(stack).to(haveResourceLike('AWS::IAM::Policy', {
PolicyDocument: {
Statement: [
{
Expand All @@ -52,8 +49,5 @@ export = {
],
},
}));

test.done();
},

};
});
});
Loading

0 comments on commit 86a9268

Please sign in to comment.