Skip to content

Commit

Permalink
chore(cloudfront): convert tests to Jest (#8939)
Browse files Browse the repository at this point in the history
Following in the example of #8811 and the aws-ec2 conversion, converting the
aws-cloudfront tests to Jest in preparation for adding new tests.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
njlynch authored Jul 8, 2020
1 parent d2609bd commit a6bffa1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 38 deletions.
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-cloudfront/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ nyc.config.js
.LAST_PACKAGE
*.snk
!.eslintrc.js
!jest.config.js
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-cloudfront/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ tsconfig.json
.eslintrc.js

# exclude cdk artifacts
**/cdk.out
**/cdk.out
jest.config.js
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-cloudfront/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/jest.config');
module.exports = baseConfig;
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-cloudfront/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"compat": "cdk-compat"
},
"cdk-build": {
"cloudformation": "AWS::CloudFront"
"cloudformation": "AWS::CloudFront",
"jest": true
},
"keywords": [
"aws",
Expand All @@ -63,12 +64,11 @@
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@types/nodeunit": "^0.0.31",
"aws-sdk": "^2.711.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
"nodeunit": "^0.11.3",
"nodeunit-shim": "0.0.0",
"pkglint": "0.0.0"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { expect } from '@aws-cdk/assert';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import { OriginAccessIdentity } from '../lib';

// tslint:disable:object-literal-key-quotes

export = {
nodeunitShim({
'Origin Access Identity with automatic comment'(test: Test) {
const stack = new cdk.Stack();

Expand Down Expand Up @@ -66,4 +66,4 @@ export = {

test.done();
},
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as certificatemanager from '@aws-cdk/aws-certificatemanager';
import * as lambda from '@aws-cdk/aws-lambda';
import * as s3 from '@aws-cdk/aws-s3';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import {
CfnDistribution,
CloudFrontWebDistribution,
Expand All @@ -17,7 +17,7 @@ import {

// tslint:disable:object-literal-key-quotes

export = {
nodeunitShim({

'distribution with custom origin adds custom origin'(test: Test) {
const stack = new cdk.Stack();
Expand Down Expand Up @@ -1046,22 +1046,22 @@ export = {
'throws if locations is empty array'(test: Test) {
test.throws(() => {
GeoRestriction.whitelist();
}, 'Should provide at least 1 location');
}, /Should provide at least 1 location/);

test.throws(() => {
GeoRestriction.blacklist();
}, 'Should provide at least 1 location');
}, /Should provide at least 1 location/);

test.done();
},
'throws if locations format is wrong'(test: Test) {
test.throws(() => {
GeoRestriction.whitelist('us');
}, 'Invalid location format for location: us, location should be two-letter and uppercase country ISO 3166-1-alpha-2 code');
}, /Invalid location format for location: us, location should be two-letter and uppercase country ISO 3166-1-alpha-2 code/);

test.throws(() => {
GeoRestriction.blacklist('us');
}, 'Invalid location format for location: us, location should be two-letter and uppercase country ISO 3166-1-alpha-2 code');
}, /Invalid location format for location: us, location should be two-letter and uppercase country ISO 3166-1-alpha-2 code/);

test.done();
},
Expand All @@ -1080,7 +1080,7 @@ export = {
customOriginSource: { domainName: 'myorigin.com' },
}],
});
}, 'connectionAttempts: You can specify 1, 2, or 3 as the number of attempts.');
}, /connectionAttempts: You can specify 1, 2, or 3 as the number of attempts./);
test.done();
},
'3 = connectionAttempts'(test: Test) {
Expand All @@ -1093,7 +1093,7 @@ export = {
customOriginSource: { domainName: 'myorigin.com' },
}],
});
}, 'connectionAttempts: You can specify 1, 2, or 3 as the number of attempts.');
}, /connectionAttempts: You can specify 1, 2, or 3 as the number of attempts./);
test.done();
},
'connectionTimeout = 1'(test: Test) {
Expand All @@ -1106,7 +1106,7 @@ export = {
customOriginSource: { domainName: 'myorigin.com' },
}],
});
}, 'connectionTimeout: You can specify a number of seconds between 1 and 10 (inclusive).');
}, /connectionTimeout: You can specify a number of seconds between 1 and 10 (inclusive)./);
test.done();
},
'10 = connectionTimeout'(test: Test) {
Expand All @@ -1119,7 +1119,7 @@ export = {
customOriginSource: { domainName: 'myorigin.com' },
}],
});
}, 'connectionTimeout: You can specify a number of seconds between 1 and 10 (inclusive).');
}, /connectionTimeout: You can specify a number of seconds between 1 and 10 (inclusive)./);
test.done();
},
},
Expand All @@ -1134,7 +1134,7 @@ export = {
customOriginSource: { domainName: 'myorigin.com' },
}],
});
}, 'connectionAttempts: You can specify 1, 2, or 3 as the number of attempts.');
}, /connectionAttempts: You can specify 1, 2, or 3 as the number of attempts./);
test.done();
},
'connectionAttempts = -1'(test: Test) {
Expand All @@ -1147,7 +1147,7 @@ export = {
customOriginSource: { domainName: 'myorigin.com' },
}],
});
}, 'connectionAttempts: You can specify 1, 2, or 3 as the number of attempts.');
}, /connectionAttempts: You can specify 1, 2, or 3 as the number of attempts./);
test.done();
},
'connectionAttempts < 1'(test: Test) {
Expand All @@ -1160,7 +1160,7 @@ export = {
customOriginSource: { domainName: 'myorigin.com' },
}],
});
}, 'connectionAttempts: You can specify 1, 2, or 3 as the number of attempts.');
}, /connectionAttempts: You can specify 1, 2, or 3 as the number of attempts./);
test.done();
},
'3 < connectionAttempts'(test: Test) {
Expand All @@ -1173,7 +1173,7 @@ export = {
customOriginSource: { domainName: 'myorigin.com' },
}],
});
}, 'connectionAttempts: You can specify 1, 2, or 3 as the number of attempts.');
}, /connectionAttempts: You can specify 1, 2, or 3 as the number of attempts./);
test.done();
},
'connectionTimeout = 1.1'(test: Test) {
Expand All @@ -1186,20 +1186,7 @@ export = {
customOriginSource: { domainName: 'myorigin.com' },
}],
});
}, 'connectionTimeout: You can specify a number of seconds between 1 and 10 (inclusive).');
test.done();
},
'connectionTimeout = -1'(test: Test) {
const stack = new cdk.Stack();
test.throws(() => {
new CloudFrontWebDistribution(stack, 'Distribution', {
originConfigs: [{
behaviors: [{ isDefaultBehavior: true }],
connectionTimeout: cdk.Duration.seconds(-1),
customOriginSource: { domainName: 'myorigin.com' },
}],
});
}, 'connectionTimeout: You can specify a number of seconds between 1 and 10 (inclusive).');
}, /connectionTimeout: You can specify a number of seconds between 1 and 10 \(inclusive\)./);
test.done();
},
'connectionTimeout < 1'(test: Test) {
Expand All @@ -1212,7 +1199,7 @@ export = {
customOriginSource: { domainName: 'myorigin.com' },
}],
});
}, 'connectionTimeout: You can specify a number of seconds between 1 and 10 (inclusive).');
}, /connectionTimeout: You can specify a number of seconds between 1 and 10 \(inclusive\)./);
test.done();
},
'10 < connectionTimeout'(test: Test) {
Expand All @@ -1225,9 +1212,9 @@ export = {
customOriginSource: { domainName: 'myorigin.com' },
}],
});
}, 'connectionTimeout: You can specify a number of seconds between 1 and 10 (inclusive).');
}, /connectionTimeout: You can specify a number of seconds between 1 and 10 \(inclusive\)./);
test.done();
},
},
},
};
});

0 comments on commit a6bffa1

Please sign in to comment.