Skip to content

Commit

Permalink
chore(s3): migrate tests to jest (#10934)
Browse files Browse the repository at this point in the history
One test was modified because the last argument didn't type check against the nodeunit-shim - here:

https://github.com/aws/aws-cdk/blob/2640d9aa06039a6eb539d959d2126749486c7ef3/packages/%40aws-cdk/aws-s3/test/test.bucket.ts#L128-L132

changed to:

```ts
test.throws(() => new s3.Bucket(stack, 'MyBucket', {
  bucketName: bucket,
}), expectedErrors);
```

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
Chriscbr authored Oct 20, 2020
1 parent fe6ec39 commit 585920e
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 33 deletions.
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-s3/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ nyc.config.js
*.snk
!.eslintrc.js

junit.xml
junit.xml
!jest.config.js
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-s3/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ tsconfig.json
# exclude cdk artifacts
**/cdk.out
junit.xml
test/
test/
jest.config.js
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-s3/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('cdk-build-tools/config/jest.config');
module.exports = baseConfig;
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-s3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"cloudformation": "AWS::S3",
"env": {
"AWSLINT_BASE_CONSTRUCT": "true"
}
},
"jest": true
},
"keywords": [
"aws",
Expand All @@ -72,12 +73,11 @@
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@types/nodeunit": "^0.0.31",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
"nodeunit": "^0.11.3",
"pkglint": "0.0.0"
"pkglint": "0.0.0",
"nodeunit-shim": "0.0.0"
},
"dependencies": {
"@aws-cdk/aws-events": "0.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import { SynthUtils } from '@aws-cdk/assert';
import * as cdk from '@aws-cdk/core';
import { IConstruct } from 'constructs';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import * as s3 from '../lib';

export = {
nodeunitShim({
'bucket must have versioning: failure'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down Expand Up @@ -38,7 +38,7 @@ export = {

test.done();
},
};
});

class BucketVersioningChecker implements cdk.IAspect {
public visit(node: IConstruct): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expect, haveResource } from '@aws-cdk/assert';
import { AnyPrincipal, PolicyStatement } from '@aws-cdk/aws-iam';
import { RemovalPolicy, Stack, App } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import * as s3 from '../lib';

// to make it easy to copy & paste from output:
/* eslint-disable quote-props */

export = {
nodeunitShim({
'default properties'(test: Test) {
const stack = new Stack();

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

test.done();
},
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { expect, haveResource, haveResourceLike, SynthUtils, arrayWith, objectLi
import * as iam from '@aws-cdk/aws-iam';
import * as kms from '@aws-cdk/aws-kms';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import * as s3 from '../lib';

// to make it easy to copy & paste from output:
/* eslint-disable quote-props */

export = {
nodeunitShim({
'default bucket'(test: Test) {
const stack = new cdk.Stack();

Expand Down Expand Up @@ -127,9 +127,7 @@ export = {

test.throws(() => new s3.Bucket(stack, 'MyBucket', {
bucketName: bucket,
}), function(err: Error) {
return expectedErrors === err.message;
});
}), expectedErrors);

test.done();
},
Expand Down Expand Up @@ -2250,4 +2248,4 @@ export = {
test.done();
},

};
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect, haveResource } from '@aws-cdk/assert';
import { Stack } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import { Bucket, HttpMethods } from '../lib';

export = {
nodeunitShim({
'Can use addCors() to add a CORS configuration'(test: Test) {
// GIVEN
const stack = new Stack();
Expand Down Expand Up @@ -118,4 +118,4 @@ export = {

test.done();
},
};
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect, haveResource } from '@aws-cdk/assert';
import { Stack } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import { Bucket } from '../lib';

export = {
nodeunitShim({
'Can use addMetrics() to add a metric configuration'(test: Test) {
// GIVEN
const stack = new Stack();
Expand Down Expand Up @@ -109,4 +109,4 @@ export = {

test.done();
},
};
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect, haveResource, haveResourceLike, ResourcePart } from '@aws-cdk/assert';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import * as s3 from '../lib';

export = {
nodeunitShim({
'when notification is added a custom s3 bucket notification resource is provisioned'(test: Test) {
const stack = new cdk.Stack();

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

test.done();
},
};
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect, haveResource } from '@aws-cdk/assert';
import { Duration, Stack } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import { Bucket, StorageClass } from '../lib';

export = {
nodeunitShim({
'Bucket with expiration days'(test: Test) {
// GIVEN
const stack = new Stack();
Expand Down Expand Up @@ -128,4 +128,4 @@ export = {

test.done();
},
};
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import { parseBucketArn, parseBucketName } from '../lib/util';

export = {
nodeunitShim({
parseBucketArn: {
'explicit arn'(test: Test) {
const stack = new cdk.Stack();
Expand Down Expand Up @@ -65,4 +65,4 @@ export = {
test.done();
},
},
};
});

0 comments on commit 585920e

Please sign in to comment.