From 63088e1ae92d810a3954ae87031c2989e0b04327 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Mon, 5 Oct 2020 10:28:19 +0200 Subject: [PATCH] chore: move 'core' tests to jest via nodeunit-shim (#10661) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/core/.gitignore | 3 +- packages/@aws-cdk/core/.npmignore | 3 +- packages/@aws-cdk/core/jest.config.js | 10 ++++++ packages/@aws-cdk/core/lib/tag-manager.ts | 24 ++++++++++---- packages/@aws-cdk/core/package.json | 4 +-- ...est.annotations.ts => annotations.test.ts} | 6 ++-- .../core/test/{test.app.ts => app.test.ts} | 10 +++--- .../core/test/{test.arn.ts => arn.test.ts} | 6 ++-- .../test/{test.aspect.ts => aspect.test.ts} | 6 ++-- .../test/{test.assets.ts => assets.test.ts} | 6 ++-- .../{test.bundling.ts => bundling.test.ts} | 6 ++-- .../{test.cfn-json.ts => cfn-json.test.ts} | 6 ++-- ...cfn-parameter.ts => cfn-parameter.test.ts} | 6 ++-- ...t.cfn-resource.ts => cfn-resource.test.ts} | 20 ++++++------ ...on-json.ts => cloudformation-json.test.ts} | 6 ++-- .../{test.condition.ts => condition.test.ts} | 6 ++-- .../{test.construct.ts => construct.test.ts} | 6 ++-- .../test/{test.context.ts => context.test.ts} | 6 ++-- ...ken.ts => cross-environment-token.test.ts} | 6 ++-- ...er.ts => custom-resource-provider.test.ts} | 6 ++-- ...ntrypoint.ts => nodejs-entrypoint.test.ts} | 8 ++--- ...om-resource.ts => custom-resource.test.ts} | 6 ++-- .../{test.duration.ts => duration.test.ts} | 32 +++++++++---------- ...reference.ts => dynamic-reference.test.ts} | 6 ++-- ...est.environment.ts => environment.test.ts} | 6 ++-- ...{test.expiration.ts => expiration.test.ts} | 18 +++++------ ...feature-flags.ts => feature-flags.test.ts} | 6 ++-- .../core/test/{test.fn.ts => fn.test.ts} | 24 +++++++------- .../fs/{test.fs-copy.ts => fs-copy.test.ts} | 6 ++-- ...-fingerprint.ts => fs-fingerprint.test.ts} | 6 ++-- .../core/test/fs/{test.fs.ts => fs.test.ts} | 6 ++-- .../test/fs/{test.utils.ts => utils.test.ts} | 6 ++-- .../test/{test.include.ts => include.test.ts} | 6 ++-- ...{test.logical-id.ts => logical-id.test.ts} | 6 ++-- .../{test.mappings.ts => mappings.test.ts} | 10 +++--- .../test/{test.output.ts => output.test.ts} | 6 ++-- .../{test.parameter.ts => parameter.test.ts} | 6 ++-- ...tor.ts => physical-name-generator.test.ts} | 24 +++++++------- ...tree-metadata.ts => tree-metadata.test.ts} | 6 ++-- .../{test.resource.ts => resource.test.ts} | 6 ++-- .../core/test/{test.rule.ts => rule.test.ts} | 6 ++-- ...t.runtime-info.ts => runtime-info.test.ts} | 6 ++-- ...t.secret-value.ts => secret-value.test.ts} | 6 ++-- .../core/test/{test.size.ts => size.test.ts} | 6 ++-- ...nthesis.ts => new-style-synthesis.test.ts} | 8 ++--- .../test/{test.stack.ts => stack.test.ts} | 8 ++--- .../test/{test.stage.ts => stage.test.ts} | 8 ++--- .../test/{test.staging.ts => staging.test.ts} | 6 ++-- .../{test.synthesis.ts => synthesis.test.ts} | 6 ++-- ...{test.tag-aspect.ts => tag-aspect.test.ts} | 6 ++-- ...est.tag-manager.ts => tag-manager.test.ts} | 6 ++-- .../test/{test.tokens.ts => tokens.test.ts} | 8 ++--- .../core/test/{test.util.ts => util.test.ts} | 4 +-- tools/nodeunit-shim/index.ts | 10 +++++- 54 files changed, 238 insertions(+), 208 deletions(-) create mode 100644 packages/@aws-cdk/core/jest.config.js rename packages/@aws-cdk/core/test/{test.annotations.ts => annotations.test.ts} (98%) rename packages/@aws-cdk/core/test/{test.app.ts => app.test.ts} (99%) rename packages/@aws-cdk/core/test/{test.arn.ts => arn.test.ts} (99%) rename packages/@aws-cdk/core/test/{test.aspect.ts => aspect.test.ts} (97%) rename packages/@aws-cdk/core/test/{test.assets.ts => assets.test.ts} (98%) rename packages/@aws-cdk/core/test/{test.bundling.ts => bundling.test.ts} (98%) rename packages/@aws-cdk/core/test/{test.cfn-json.ts => cfn-json.test.ts} (97%) rename packages/@aws-cdk/core/test/{test.cfn-parameter.ts => cfn-parameter.test.ts} (93%) rename packages/@aws-cdk/core/test/{test.cfn-resource.ts => cfn-resource.test.ts} (90%) rename packages/@aws-cdk/core/test/{test.cloudformation-json.ts => cloudformation-json.test.ts} (98%) rename packages/@aws-cdk/core/test/{test.condition.ts => condition.test.ts} (96%) rename packages/@aws-cdk/core/test/{test.construct.ts => construct.test.ts} (99%) rename packages/@aws-cdk/core/test/{test.context.ts => context.test.ts} (98%) rename packages/@aws-cdk/core/test/{test.cross-environment-token.ts => cross-environment-token.test.ts} (98%) rename packages/@aws-cdk/core/test/custom-resource-provider/{test.custom-resource-provider.ts => custom-resource-provider.test.ts} (98%) rename packages/@aws-cdk/core/test/custom-resource-provider/{test.nodejs-entrypoint.ts => nodejs-entrypoint.test.ts} (98%) rename packages/@aws-cdk/core/test/{test.custom-resource.ts => custom-resource.test.ts} (98%) rename packages/@aws-cdk/core/test/{test.duration.ts => duration.test.ts} (88%) rename packages/@aws-cdk/core/test/{test.dynamic-reference.ts => dynamic-reference.test.ts} (84%) rename packages/@aws-cdk/core/test/{test.environment.ts => environment.test.ts} (98%) rename packages/@aws-cdk/core/test/{test.expiration.ts => expiration.test.ts} (80%) rename packages/@aws-cdk/core/test/{test.feature-flags.ts => feature-flags.test.ts} (92%) rename packages/@aws-cdk/core/test/{test.fn.ts => fn.test.ts} (91%) rename packages/@aws-cdk/core/test/fs/{test.fs-copy.ts => fs-copy.test.ts} (98%) rename packages/@aws-cdk/core/test/fs/{test.fs-fingerprint.ts => fs-fingerprint.test.ts} (98%) rename packages/@aws-cdk/core/test/fs/{test.fs.ts => fs.test.ts} (95%) rename packages/@aws-cdk/core/test/fs/{test.utils.ts => utils.test.ts} (99%) rename packages/@aws-cdk/core/test/{test.include.ts => include.test.ts} (97%) rename packages/@aws-cdk/core/test/{test.logical-id.ts => logical-id.test.ts} (99%) rename packages/@aws-cdk/core/test/{test.mappings.ts => mappings.test.ts} (94%) rename packages/@aws-cdk/core/test/{test.output.ts => output.test.ts} (93%) rename packages/@aws-cdk/core/test/{test.parameter.ts => parameter.test.ts} (94%) rename packages/@aws-cdk/core/test/private/{test.physical-name-generator.ts => physical-name-generator.test.ts} (84%) rename packages/@aws-cdk/core/test/private/{test.tree-metadata.ts => tree-metadata.test.ts} (99%) rename packages/@aws-cdk/core/test/{test.resource.ts => resource.test.ts} (99%) rename packages/@aws-cdk/core/test/{test.rule.ts => rule.test.ts} (94%) rename packages/@aws-cdk/core/test/{test.runtime-info.ts => runtime-info.test.ts} (97%) rename packages/@aws-cdk/core/test/{test.secret-value.ts => secret-value.test.ts} (97%) rename packages/@aws-cdk/core/test/{test.size.ts => size.test.ts} (98%) rename packages/@aws-cdk/core/test/stack-synthesis/{test.new-style-synthesis.ts => new-style-synthesis.test.ts} (99%) rename packages/@aws-cdk/core/test/{test.stack.ts => stack.test.ts} (99%) rename packages/@aws-cdk/core/test/{test.stage.ts => stage.test.ts} (99%) rename packages/@aws-cdk/core/test/{test.staging.ts => staging.test.ts} (99%) rename packages/@aws-cdk/core/test/{test.synthesis.ts => synthesis.test.ts} (98%) rename packages/@aws-cdk/core/test/{test.tag-aspect.ts => tag-aspect.test.ts} (99%) rename packages/@aws-cdk/core/test/{test.tag-manager.ts => tag-manager.test.ts} (98%) rename packages/@aws-cdk/core/test/{test.tokens.ts => tokens.test.ts} (99%) rename packages/@aws-cdk/core/test/{test.util.ts => util.test.ts} (98%) diff --git a/packages/@aws-cdk/core/.gitignore b/packages/@aws-cdk/core/.gitignore index 5960e89add3c9..3bbfa40f65522 100644 --- a/packages/@aws-cdk/core/.gitignore +++ b/packages/@aws-cdk/core/.gitignore @@ -14,4 +14,5 @@ nyc.config.js *.snk !.eslintrc.js -junit.xml \ No newline at end of file +junit.xml +!jest.config.js \ No newline at end of file diff --git a/packages/@aws-cdk/core/.npmignore b/packages/@aws-cdk/core/.npmignore index dfcc4c31f1c8d..90948e3dcecea 100644 --- a/packages/@aws-cdk/core/.npmignore +++ b/packages/@aws-cdk/core/.npmignore @@ -25,4 +25,5 @@ tsconfig.json # exclude cdk artifacts **/cdk.out -junit.xml \ No newline at end of file +junit.xml +jest.config.js \ No newline at end of file diff --git a/packages/@aws-cdk/core/jest.config.js b/packages/@aws-cdk/core/jest.config.js new file mode 100644 index 0000000000000..9dd30a713dd6b --- /dev/null +++ b/packages/@aws-cdk/core/jest.config.js @@ -0,0 +1,10 @@ +const baseConfig = require('cdk-build-tools/config/jest.config'); +module.exports = { + ...baseConfig, + coverageThreshold: { + global: { + branches: 60, + statements: 75, + } + } +}; diff --git a/packages/@aws-cdk/core/lib/tag-manager.ts b/packages/@aws-cdk/core/lib/tag-manager.ts index 2189af4bc4929..cdc224500ef1b 100644 --- a/packages/@aws-cdk/core/lib/tag-manager.ts +++ b/packages/@aws-cdk/core/lib/tag-manager.ts @@ -185,12 +185,22 @@ class NoFormat implements ITagFormatter { } } -const TAG_FORMATTERS: {[key: string]: ITagFormatter} = { - [TagType.AUTOSCALING_GROUP]: new AsgFormatter(), - [TagType.STANDARD]: new StandardFormatter(), - [TagType.MAP]: new MapFormatter(), - [TagType.KEY_VALUE]: new KeyValueFormatter(), - [TagType.NOT_TAGGABLE]: new NoFormat(), + +let _tagFormattersCache: {[key: string]: ITagFormatter} | undefined; + +/** + * Access tag formatters table + * + * In a function because we're in a load cycle with cfn-resource that defines `TagType`. + */ +function TAG_FORMATTERS(): {[key: string]: ITagFormatter} { + return _tagFormattersCache ?? (_tagFormattersCache = { + [TagType.AUTOSCALING_GROUP]: new AsgFormatter(), + [TagType.STANDARD]: new StandardFormatter(), + [TagType.MAP]: new MapFormatter(), + [TagType.KEY_VALUE]: new KeyValueFormatter(), + [TagType.NOT_TAGGABLE]: new NoFormat(), + }); }; /** @@ -245,7 +255,7 @@ export class TagManager { constructor(tagType: TagType, resourceTypeName: string, tagStructure?: any, options: TagManagerOptions = { }) { this.resourceTypeName = resourceTypeName; - this.tagFormatter = TAG_FORMATTERS[tagType]; + this.tagFormatter = TAG_FORMATTERS()[tagType]; if (tagStructure !== undefined) { this._setTag(...this.tagFormatter.parseTags(tagStructure, this.initialTagPriority)); } diff --git a/packages/@aws-cdk/core/package.json b/packages/@aws-cdk/core/package.json index 130dc095e88eb..9731f371c38d6 100644 --- a/packages/@aws-cdk/core/package.json +++ b/packages/@aws-cdk/core/package.json @@ -139,6 +139,7 @@ "cdk-build": { "cloudformation": "AWS::CloudFormation", "cfn2ts-core-import": ".", + "jest": true, "pre": [ "rm -rf test/fs/fixtures && cd test/fs && tar -xzf fixtures.tar.gz" ], @@ -167,13 +168,12 @@ "@types/lodash": "^4.14.161", "@types/minimatch": "^3.0.3", "@types/node": "^10.17.35", - "@types/nodeunit": "^0.0.31", "@types/sinon": "^9.0.7", "cdk-build-tools": "0.0.0", "cfn2ts": "0.0.0", "fast-check": "^2.4.0", "lodash": "^4.17.20", - "nodeunit": "^0.11.3", + "nodeunit-shim": "0.0.0", "pkglint": "0.0.0", "sinon": "^9.1.0", "ts-mock-imports": "^1.3.0" diff --git a/packages/@aws-cdk/core/test/test.annotations.ts b/packages/@aws-cdk/core/test/annotations.test.ts similarity index 98% rename from packages/@aws-cdk/core/test/test.annotations.ts rename to packages/@aws-cdk/core/test/annotations.test.ts index 4a193452a95c2..1b0cbf209c528 100644 --- a/packages/@aws-cdk/core/test/test.annotations.ts +++ b/packages/@aws-cdk/core/test/annotations.test.ts @@ -1,11 +1,11 @@ import { CloudAssembly } from '@aws-cdk/cx-api'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { Construct, App, Stack } from '../lib'; import { Annotations } from '../lib/annotations'; const restore = process.env.CDK_BLOCK_DEPRECATIONS; -export = { +nodeunitShim({ 'tearDown'(cb: any) { process.env.CDK_BLOCK_DEPRECATIONS = restore; // restore to the original value cb(); @@ -78,7 +78,7 @@ export = { test.throws(() => Annotations.of(c1).addDeprecation('foo', 'bar'), /MyStack\/Hello: The API foo is deprecated: bar\. This API will be removed in the next major release/); test.done(); }, -}; +}); function getWarnings(casm: CloudAssembly) { const result = new Array<{ path: string, message: string }>(); diff --git a/packages/@aws-cdk/core/test/test.app.ts b/packages/@aws-cdk/core/test/app.test.ts similarity index 99% rename from packages/@aws-cdk/core/test/test.app.ts rename to packages/@aws-cdk/core/test/app.test.ts index ac14bcff7e620..27b567b0f71be 100644 --- a/packages/@aws-cdk/core/test/test.app.ts +++ b/packages/@aws-cdk/core/test/app.test.ts @@ -1,6 +1,6 @@ import { ContextProvider } from '@aws-cdk/cloud-assembly-schema'; import * as cxapi from '@aws-cdk/cx-api'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { CfnResource, Construct, Stack, StackProps } from '../lib'; import { Annotations } from '../lib/annotations'; import { App, AppProps } from '../lib/app'; @@ -47,7 +47,7 @@ function synthStack(name: string, includeMetadata: boolean = false, context?: an return stack; } -export = { +nodeunitShim({ 'synthesizes all stacks and returns synthesis result'(test: Test) { const response = synth(); delete (response as any).dir; @@ -57,7 +57,7 @@ export = { const stack1 = response.stacks[0]; test.deepEqual(stack1.stackName, 'stack1'); test.deepEqual(stack1.id, 'stack1'); - test.deepEqual(stack1.environment.account, 12345); + test.deepEqual(stack1.environment.account, '12345'); test.deepEqual(stack1.environment.region, 'us-east-1'); test.deepEqual(stack1.environment.name, 'aws://12345/us-east-1'); test.deepEqual(stack1.template, { @@ -408,7 +408,7 @@ export = { test.done(); }, -}; +}); class MyConstruct extends Construct { constructor(scope: Construct, id: string) { @@ -444,4 +444,4 @@ function withCliVersion(block: () => A): A { } finally { delete process.env[cxapi.CLI_VERSION_ENV]; } -} \ No newline at end of file +} diff --git a/packages/@aws-cdk/core/test/test.arn.ts b/packages/@aws-cdk/core/test/arn.test.ts similarity index 99% rename from packages/@aws-cdk/core/test/test.arn.ts rename to packages/@aws-cdk/core/test/arn.test.ts index 820ceeae21f40..5fa7a83d98f7a 100644 --- a/packages/@aws-cdk/core/test/test.arn.ts +++ b/packages/@aws-cdk/core/test/arn.test.ts @@ -1,9 +1,9 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { ArnComponents, Aws, CfnOutput, ScopedAws, Stack } from '../lib'; import { Intrinsic } from '../lib/private/intrinsic'; import { toCloudFormation } from './util'; -export = { +nodeunitShim({ 'create from components with defaults'(test: Test) { const stack = new Stack(); @@ -277,4 +277,4 @@ export = { test.done(); }, -}; +}); diff --git a/packages/@aws-cdk/core/test/test.aspect.ts b/packages/@aws-cdk/core/test/aspect.test.ts similarity index 97% rename from packages/@aws-cdk/core/test/test.aspect.ts rename to packages/@aws-cdk/core/test/aspect.test.ts index 90294a86055a7..5a94e397a91da 100644 --- a/packages/@aws-cdk/core/test/test.aspect.ts +++ b/packages/@aws-cdk/core/test/aspect.test.ts @@ -1,5 +1,5 @@ import * as cxschema from '@aws-cdk/cloud-assembly-schema'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { App } from '../lib'; import { IAspect, Aspects } from '../lib/aspect'; import { Construct, IConstruct } from '../lib/construct-compat'; @@ -25,7 +25,7 @@ class MyAspect implements IAspect { } } -export = { +nodeunitShim({ 'Aspects are invoked only once'(test: Test) { const app = new App(); const root = new MyConstruct(app, 'MyConstruct'); @@ -74,4 +74,4 @@ export = { test.done(); }, -}; +}); diff --git a/packages/@aws-cdk/core/test/test.assets.ts b/packages/@aws-cdk/core/test/assets.test.ts similarity index 98% rename from packages/@aws-cdk/core/test/test.assets.ts rename to packages/@aws-cdk/core/test/assets.test.ts index 5f77e89db470f..fcfae3a9d147f 100644 --- a/packages/@aws-cdk/core/test/test.assets.ts +++ b/packages/@aws-cdk/core/test/assets.test.ts @@ -1,9 +1,9 @@ import * as cxschema from '@aws-cdk/cloud-assembly-schema'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { FileAssetPackaging, Stack } from '../lib'; import { toCloudFormation } from './util'; -export = { +nodeunitShim({ 'addFileAsset correctly sets metadata and creates S3 parameters'(test: Test) { // GIVEN const stack = new Stack(); @@ -156,4 +156,4 @@ export = { test.deepEqual(toCloudFormation(stack), { }); test.done(); }, -}; +}); diff --git a/packages/@aws-cdk/core/test/test.bundling.ts b/packages/@aws-cdk/core/test/bundling.test.ts similarity index 98% rename from packages/@aws-cdk/core/test/test.bundling.ts rename to packages/@aws-cdk/core/test/bundling.test.ts index 566e5c5008c25..411ddc0f1cb92 100644 --- a/packages/@aws-cdk/core/test/test.bundling.ts +++ b/packages/@aws-cdk/core/test/bundling.test.ts @@ -1,9 +1,9 @@ import * as child_process from 'child_process'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import * as sinon from 'sinon'; import { BundlingDockerImage, FileSystem } from '../lib'; -export = { +nodeunitShim({ 'tearDown'(callback: any) { sinon.restore(); callback(); @@ -152,4 +152,4 @@ export = { test.ok(fingerprintStub.calledWith('docker-path', sinon.match({ extraHash: JSON.stringify({}) }))); test.done(); }, -}; +}); diff --git a/packages/@aws-cdk/core/test/test.cfn-json.ts b/packages/@aws-cdk/core/test/cfn-json.test.ts similarity index 97% rename from packages/@aws-cdk/core/test/test.cfn-json.ts rename to packages/@aws-cdk/core/test/cfn-json.test.ts index 73943cb11f4ab..85ee12c822cb8 100644 --- a/packages/@aws-cdk/core/test/test.cfn-json.ts +++ b/packages/@aws-cdk/core/test/cfn-json.test.ts @@ -1,10 +1,10 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { App, CfnResource, Lazy, Stack } from '../lib'; import { CfnJson } from '../lib/cfn-json'; import { CfnUtilsResourceType } from '../lib/private/cfn-utils-provider/consts'; import { handler } from '../lib/private/cfn-utils-provider/index'; -export = { +nodeunitShim({ 'resolves to a fn::getatt'(test: Test) { // GIVEN @@ -89,4 +89,4 @@ export = { test.deepEqual(input, response.Data.Value); test.done(); }, -}; \ No newline at end of file +}); diff --git a/packages/@aws-cdk/core/test/test.cfn-parameter.ts b/packages/@aws-cdk/core/test/cfn-parameter.test.ts similarity index 93% rename from packages/@aws-cdk/core/test/test.cfn-parameter.ts rename to packages/@aws-cdk/core/test/cfn-parameter.test.ts index a370b3948d401..7441e4548cf98 100644 --- a/packages/@aws-cdk/core/test/test.cfn-parameter.ts +++ b/packages/@aws-cdk/core/test/cfn-parameter.test.ts @@ -1,7 +1,7 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { CfnParameter, Stack } from '../lib'; -export = { +nodeunitShim({ 'valueAsString supports both string and number types'(test: Test) { // GIVEN const stack = new Stack(); @@ -29,4 +29,4 @@ export = { test.done(); }, -} \ No newline at end of file +}); diff --git a/packages/@aws-cdk/core/test/test.cfn-resource.ts b/packages/@aws-cdk/core/test/cfn-resource.test.ts similarity index 90% rename from packages/@aws-cdk/core/test/test.cfn-resource.ts rename to packages/@aws-cdk/core/test/cfn-resource.test.ts index 03b615c464171..a36f5ec56e8e1 100644 --- a/packages/@aws-cdk/core/test/test.cfn-resource.ts +++ b/packages/@aws-cdk/core/test/cfn-resource.test.ts @@ -1,9 +1,9 @@ -import * as nodeunit from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import * as core from '../lib'; -export = nodeunit.testCase({ +nodeunitShim({ '._toCloudFormation': { - 'does not call renderProperties with an undefined value'(test: nodeunit.Test) { + 'does not call renderProperties with an undefined value'(test: Test) { const app = new core.App(); const stack = new core.Stack(app, 'TestStack'); const resource = new core.CfnResource(stack, 'DefaultResource', { type: 'Test::Resource::Fake' }); @@ -26,7 +26,7 @@ export = nodeunit.testCase({ test.done(); }, - 'renders "Properties" for a resource that has only properties set to "false"'(test: nodeunit.Test) { + 'renders "Properties" for a resource that has only properties set to "false"'(test: Test) { const app = new core.App(); const stack = new core.Stack(app, 'TestStack'); new core.CfnResource(stack, 'Resource', { @@ -51,7 +51,7 @@ export = nodeunit.testCase({ }, }, - 'applyRemovalPolicy default includes Update policy'(test: nodeunit.Test) { + 'applyRemovalPolicy default includes Update policy'(test: Test) { // GIVEN const app = new core.App(); const stack = new core.Stack(app, 'TestStack'); @@ -74,7 +74,7 @@ export = nodeunit.testCase({ test.done(); }, - 'can switch off updating Update policy'(test: nodeunit.Test) { + 'can switch off updating Update policy'(test: Test) { // GIVEN const app = new core.App(); const stack = new core.Stack(app, 'TestStack'); @@ -98,7 +98,7 @@ export = nodeunit.testCase({ test.done(); }, - 'can add metadata'(test: nodeunit.Test) { + 'can add metadata'(test: Test) { // GIVEN const app = new core.App(); const stack = new core.Stack(app, 'TestStack'); @@ -122,7 +122,7 @@ export = nodeunit.testCase({ test.done(); }, - 'subclasses can override "shouldSynthesize" to lazy-determine if the resource should be included'(test: nodeunit.Test) { + 'subclasses can override "shouldSynthesize" to lazy-determine if the resource should be included'(test: Test) { // GIVEN class HiddenCfnResource extends core.CfnResource { protected shouldSynthesize() { @@ -151,7 +151,7 @@ export = nodeunit.testCase({ test.done(); }, - 'CfnResource cannot be created outside Stack'(test: nodeunit.Test) { + 'CfnResource cannot be created outside Stack'(test: Test) { const app = new core.App(); test.throws(() => { new core.CfnResource(app, 'Resource', { @@ -166,7 +166,7 @@ export = nodeunit.testCase({ /** * Stages start a new scope, which does not count as a Stack anymore */ - 'CfnResource cannot be in Stage in Stack'(test: nodeunit.Test) { + 'CfnResource cannot be in Stage in Stack'(test: Test) { const app = new core.App(); const stack = new core.Stack(app, 'Stack'); const stage = new core.Stage(stack, 'Stage'); diff --git a/packages/@aws-cdk/core/test/test.cloudformation-json.ts b/packages/@aws-cdk/core/test/cloudformation-json.test.ts similarity index 98% rename from packages/@aws-cdk/core/test/test.cloudformation-json.ts rename to packages/@aws-cdk/core/test/cloudformation-json.test.ts index 69ea1b2055a06..8d7e571501462 100644 --- a/packages/@aws-cdk/core/test/test.cloudformation-json.ts +++ b/packages/@aws-cdk/core/test/cloudformation-json.test.ts @@ -1,9 +1,9 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { App, CfnOutput, Fn, Lazy, Stack, Token } from '../lib'; import { Intrinsic } from '../lib/private/intrinsic'; import { evaluateCFN } from './evaluate-cfn'; -export = { +nodeunitShim({ 'string tokens can be JSONified and JSONification can be reversed'(test: Test) { const stack = new Stack(); @@ -235,7 +235,7 @@ export = { test.done(); }, -}; +}); /** * Return two Tokens, one of which evaluates to a Token directly, one which evaluates to it lazily diff --git a/packages/@aws-cdk/core/test/test.condition.ts b/packages/@aws-cdk/core/test/condition.test.ts similarity index 96% rename from packages/@aws-cdk/core/test/test.condition.ts rename to packages/@aws-cdk/core/test/condition.test.ts index c6c0ae8db05a6..8c43f9eb1507c 100644 --- a/packages/@aws-cdk/core/test/test.condition.ts +++ b/packages/@aws-cdk/core/test/condition.test.ts @@ -1,8 +1,8 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import * as cdk from '../lib'; import { toCloudFormation } from './util'; -export = { +nodeunitShim({ 'chain conditions'(test: Test) { // GIVEN const stack = new cdk.Stack(); @@ -63,4 +63,4 @@ export = { }); test.done(); }, -}; +}); diff --git a/packages/@aws-cdk/core/test/test.construct.ts b/packages/@aws-cdk/core/test/construct.test.ts similarity index 99% rename from packages/@aws-cdk/core/test/test.construct.ts rename to packages/@aws-cdk/core/test/construct.test.ts index 06aced4d21fe6..872ba9dceedca 100644 --- a/packages/@aws-cdk/core/test/test.construct.ts +++ b/packages/@aws-cdk/core/test/construct.test.ts @@ -1,12 +1,12 @@ import * as cxschema from '@aws-cdk/cloud-assembly-schema'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { App as Root, Aws, Construct, ConstructNode, ConstructOrder, IConstruct, Lazy, ValidationError } from '../lib'; import { Annotations } from '../lib/annotations'; import { reEnableStackTraceCollection, restoreStackTraceColection } from './util'; /* eslint-disable @typescript-eslint/naming-convention */ -export = { +nodeunitShim({ 'the "Root" construct is a special construct which can be used as the root of the tree'(test: Test) { const root = new Root(); test.equal(root.node.id, '', 'if not specified, name of a root construct is an empty string'); @@ -505,7 +505,7 @@ export = { }, }, -}; +}); function createTree(context?: any) { const root = new Root(); diff --git a/packages/@aws-cdk/core/test/test.context.ts b/packages/@aws-cdk/core/test/context.test.ts similarity index 98% rename from packages/@aws-cdk/core/test/test.context.ts rename to packages/@aws-cdk/core/test/context.test.ts index 3d86dfd2b7d54..89c720e735999 100644 --- a/packages/@aws-cdk/core/test/test.context.ts +++ b/packages/@aws-cdk/core/test/context.test.ts @@ -1,9 +1,9 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { Construct, Stack } from '../lib'; import { ContextProvider } from '../lib/context-provider'; import { synthesize } from '../lib/private/synthesis'; -export = { +nodeunitShim({ 'AvailabilityZoneProvider returns a list with dummy values if the context is not available'(test: Test) { const stack = new Stack(undefined, 'TestStack', { env: { account: '12345', region: 'us-east-1' } }); const azs = stack.availabilityZones; @@ -167,7 +167,7 @@ export = { test.done(); }, -}; +}); /** * Get the expected context key from a stack with missing parameters diff --git a/packages/@aws-cdk/core/test/test.cross-environment-token.ts b/packages/@aws-cdk/core/test/cross-environment-token.test.ts similarity index 98% rename from packages/@aws-cdk/core/test/test.cross-environment-token.ts rename to packages/@aws-cdk/core/test/cross-environment-token.test.ts index cd97e4661162e..4ab55922369e4 100644 --- a/packages/@aws-cdk/core/test/test.cross-environment-token.ts +++ b/packages/@aws-cdk/core/test/cross-environment-token.test.ts @@ -1,10 +1,10 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { App, CfnOutput, CfnResource, Construct, PhysicalName, Resource, Stack } from '../lib'; import { toCloudFormation } from './util'; /* eslint-disable quote-props */ -export = { +nodeunitShim({ 'CrossEnvironmentToken': { 'can reference an ARN with a fixed physical name directly in a different account'(test: Test) { // GIVEN @@ -242,7 +242,7 @@ export = { test.done(); }, -}; +}); class MyResource extends Resource { public readonly arn: string; diff --git a/packages/@aws-cdk/core/test/custom-resource-provider/test.custom-resource-provider.ts b/packages/@aws-cdk/core/test/custom-resource-provider/custom-resource-provider.test.ts similarity index 98% rename from packages/@aws-cdk/core/test/custom-resource-provider/test.custom-resource-provider.ts rename to packages/@aws-cdk/core/test/custom-resource-provider/custom-resource-provider.test.ts index ca3d8e4839241..f3dbff18ed651 100644 --- a/packages/@aws-cdk/core/test/custom-resource-provider/test.custom-resource-provider.ts +++ b/packages/@aws-cdk/core/test/custom-resource-provider/custom-resource-provider.test.ts @@ -1,12 +1,12 @@ import * as fs from 'fs'; import * as path from 'path'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { AssetStaging, CustomResourceProvider, CustomResourceProviderRuntime, Duration, Size, Stack } from '../../lib'; import { toCloudFormation } from '../util'; const TEST_HANDLER = `${__dirname}/mock-provider`; -export = { +nodeunitShim({ 'minimal configuration'(test: Test) { // GIVEN const stack = new Stack(); @@ -169,4 +169,4 @@ export = { test.deepEqual(lambda.Properties.Timeout, 300); test.done(); }, -}; +}); diff --git a/packages/@aws-cdk/core/test/custom-resource-provider/test.nodejs-entrypoint.ts b/packages/@aws-cdk/core/test/custom-resource-provider/nodejs-entrypoint.test.ts similarity index 98% rename from packages/@aws-cdk/core/test/custom-resource-provider/test.nodejs-entrypoint.ts rename to packages/@aws-cdk/core/test/custom-resource-provider/nodejs-entrypoint.test.ts index 40f3fdea54c8e..18e6dfe053ce7 100644 --- a/packages/@aws-cdk/core/test/custom-resource-provider/test.nodejs-entrypoint.ts +++ b/packages/@aws-cdk/core/test/custom-resource-provider/nodejs-entrypoint.test.ts @@ -4,10 +4,10 @@ import * as https from 'https'; import * as os from 'os'; import * as path from 'path'; import * as url from 'url'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import * as entrypoint from '../../lib/custom-resource-provider/nodejs-entrypoint'; -export = { +nodeunitShim({ 'handler return value is sent back to cloudformation as a success response': { async 'physical resource id (ref)'(test: Test) { @@ -147,7 +147,7 @@ export = { test.done(); }, -}; +}); function makeEvent(req: Partial): AWSLambda.CloudFormationCustomResourceEvent { return { @@ -195,4 +195,4 @@ async function invokeHandler(req: AWSLambda.CloudFormationCustomResourceEvent, u } return JSON.parse(actualResponse) as AWSLambda.CloudFormationCustomResourceResponse; -} \ No newline at end of file +} diff --git a/packages/@aws-cdk/core/test/test.custom-resource.ts b/packages/@aws-cdk/core/test/custom-resource.test.ts similarity index 98% rename from packages/@aws-cdk/core/test/test.custom-resource.ts rename to packages/@aws-cdk/core/test/custom-resource.test.ts index a85da1753cd13..619a46c062f6b 100644 --- a/packages/@aws-cdk/core/test/test.custom-resource.ts +++ b/packages/@aws-cdk/core/test/custom-resource.test.ts @@ -1,8 +1,8 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { CustomResource, RemovalPolicy, Stack } from '../lib'; import { toCloudFormation } from './util'; -export = { +nodeunitShim({ 'simple case provider identified by service token'(test: Test) { // GIVEN const stack = new Stack(); @@ -170,4 +170,4 @@ export = { test.done(); }, -}; +}); diff --git a/packages/@aws-cdk/core/test/test.duration.ts b/packages/@aws-cdk/core/test/duration.test.ts similarity index 88% rename from packages/@aws-cdk/core/test/test.duration.ts rename to packages/@aws-cdk/core/test/duration.test.ts index dd3305f7ea945..4d84d80c3eaf7 100644 --- a/packages/@aws-cdk/core/test/test.duration.ts +++ b/packages/@aws-cdk/core/test/duration.test.ts @@ -1,14 +1,14 @@ -import * as nodeunit from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { Duration, Lazy, Stack, Token } from '../lib'; -export = nodeunit.testCase({ - 'negative amount'(test: nodeunit.Test) { +nodeunitShim({ + 'negative amount'(test: Test) { test.throws(() => Duration.seconds(-1), /negative/); test.done(); }, - 'unresolved amount'(test: nodeunit.Test) { + 'unresolved amount'(test: Test) { const stack = new Stack(); const lazyDuration = Duration.seconds(Token.asNumber({ resolve: () => 1337 })); test.equals(stack.resolve(lazyDuration.toSeconds()), 1337); @@ -20,7 +20,7 @@ export = nodeunit.testCase({ test.done(); }, - 'Duration in seconds'(test: nodeunit.Test) { + 'Duration in seconds'(test: Test) { const duration = Duration.seconds(300); test.equal(duration.toSeconds(), 300); @@ -33,7 +33,7 @@ export = nodeunit.testCase({ test.done(); }, - 'Duration in minutes'(test: nodeunit.Test) { + 'Duration in minutes'(test: Test) { const duration = Duration.minutes(5); test.equal(duration.toSeconds(), 300); @@ -46,7 +46,7 @@ export = nodeunit.testCase({ test.done(); }, - 'Duration in hours'(test: nodeunit.Test) { + 'Duration in hours'(test: Test) { const duration = Duration.hours(5); test.equal(duration.toSeconds(), 18_000); @@ -59,7 +59,7 @@ export = nodeunit.testCase({ test.done(); }, - 'seconds to milliseconds'(test: nodeunit.Test) { + 'seconds to milliseconds'(test: Test) { const duration = Duration.seconds(5); test.equal(duration.toMilliseconds(), 5_000); @@ -67,7 +67,7 @@ export = nodeunit.testCase({ test.done(); }, - 'Duration in days'(test: nodeunit.Test) { + 'Duration in days'(test: Test) { const duration = Duration.days(1); test.equal(duration.toSeconds(), 86_400); @@ -77,7 +77,7 @@ export = nodeunit.testCase({ test.done(); }, - 'toISOString'(test: nodeunit.Test) { + 'toISOString'(test: Test) { test.equal(Duration.millis(0).toISOString(), 'PT0S'); test.equal(Duration.seconds(0).toISOString(), 'PT0S'); test.equal(Duration.minutes(0).toISOString(), 'PT0S'); @@ -95,7 +95,7 @@ export = nodeunit.testCase({ test.done(); }, - 'toIsoString'(test: nodeunit.Test) { + 'toIsoString'(test: Test) { test.equal(Duration.millis(0).toIsoString(), 'PT0S'); test.equal(Duration.seconds(0).toIsoString(), 'PT0S'); test.equal(Duration.minutes(0).toIsoString(), 'PT0S'); @@ -114,7 +114,7 @@ export = nodeunit.testCase({ test.done(); }, - 'parse'(test: nodeunit.Test) { + 'parse'(test: Test) { test.equal(Duration.parse('PT0S').toSeconds(), 0); test.equal(Duration.parse('PT0M').toSeconds(), 0); test.equal(Duration.parse('PT0H').toSeconds(), 0); @@ -130,7 +130,7 @@ export = nodeunit.testCase({ test.done(); }, - 'reject illegal parses'(test: nodeunit.Test) { + 'reject illegal parses'(test: Test) { const err = 'Not a valid ISO duration'; test.throws(() => { Duration.parse('PT1D'); @@ -143,7 +143,7 @@ export = nodeunit.testCase({ test.done(); }, - 'to human string'(test: nodeunit.Test) { + 'to human string'(test: Test) { test.equal(Duration.minutes(0).toHumanString(), '0 minutes'); test.equal(Duration.minutes(Lazy.numberValue({ produce: () => 5 })).toHumanString(), ' minutes'); @@ -162,7 +162,7 @@ export = nodeunit.testCase({ test.done(); }, - 'add two durations'(test: nodeunit.Test) { + 'add two durations'(test: Test) { test.equal(Duration.minutes(1).plus(Duration.seconds(30)).toSeconds(), Duration.seconds(90).toSeconds()); test.equal(Duration.minutes(1).plus(Duration.seconds(30)).toMinutes({ integral: false }), Duration.seconds(90).toMinutes({ integral: false })); @@ -170,7 +170,7 @@ export = nodeunit.testCase({ }, }); -function floatEqual(test: nodeunit.Test, actual: number, expected: number) { +function floatEqual(test: Test, actual: number, expected: number) { test.ok( // Floats are subject to rounding errors up to Number.ESPILON actual >= expected - Number.EPSILON && actual <= expected + Number.EPSILON, diff --git a/packages/@aws-cdk/core/test/test.dynamic-reference.ts b/packages/@aws-cdk/core/test/dynamic-reference.test.ts similarity index 84% rename from packages/@aws-cdk/core/test/test.dynamic-reference.ts rename to packages/@aws-cdk/core/test/dynamic-reference.test.ts index 33be26fdab223..e9da4b23b837d 100644 --- a/packages/@aws-cdk/core/test/test.dynamic-reference.ts +++ b/packages/@aws-cdk/core/test/dynamic-reference.test.ts @@ -1,7 +1,7 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { CfnDynamicReference, CfnDynamicReferenceService, Stack } from '../lib'; -export = { +nodeunitShim({ 'can create dynamic references with service and key with colons'(test: Test) { // GIVEN const stack = new Stack(); @@ -14,4 +14,4 @@ export = { test.done(); }, -}; +}); diff --git a/packages/@aws-cdk/core/test/test.environment.ts b/packages/@aws-cdk/core/test/environment.test.ts similarity index 98% rename from packages/@aws-cdk/core/test/test.environment.ts rename to packages/@aws-cdk/core/test/environment.test.ts index ff6cd0881b597..5432fd178f1f8 100644 --- a/packages/@aws-cdk/core/test/test.environment.ts +++ b/packages/@aws-cdk/core/test/environment.test.ts @@ -1,7 +1,7 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { App, Aws, Stack, Token } from '../lib'; -export = { +nodeunitShim({ 'By default, environment region and account are not defined and resolve to intrinsics'(test: Test) { const stack = new Stack(); test.ok(Token.isUnresolved(stack.account)); @@ -137,4 +137,4 @@ export = { test.done(); }, }, -}; +}); diff --git a/packages/@aws-cdk/core/test/test.expiration.ts b/packages/@aws-cdk/core/test/expiration.test.ts similarity index 80% rename from packages/@aws-cdk/core/test/test.expiration.ts rename to packages/@aws-cdk/core/test/expiration.test.ts index 2aa9078f3448c..de17852f4308c 100644 --- a/packages/@aws-cdk/core/test/test.expiration.ts +++ b/packages/@aws-cdk/core/test/expiration.test.ts @@ -1,14 +1,14 @@ -import * as nodeunit from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { Duration, Expiration } from '../lib'; -export = nodeunit.testCase({ - 'from string'(test: nodeunit.Test) { +nodeunitShim({ + 'from string'(test: Test) { const date = new Date('Sun, 26 Jan 2020 00:53:20 GMT'); test.equal(Expiration.fromString('Sun, 26 Jan 2020 00:53:20 GMT').date.getDate(), date.getDate()); test.done(); }, - 'at specified date'(test: nodeunit.Test) { + 'at specified date'(test: Test) { const date = new Date('Sun, 26 Jan 2020 00:53:20 GMT'); test.equal(Expiration.atDate(new Date('Sun, 26 Jan 2020 00:53:20 GMT')).date.toUTCString(), 'Sun, 26 Jan 2020 00:53:20 GMT'); test.equal(Expiration.atDate(new Date(1580000000000)).date.toUTCString(), 'Sun, 26 Jan 2020 00:53:20 GMT'); @@ -16,30 +16,30 @@ export = nodeunit.testCase({ test.done(); }, - 'at time stamp'(test: nodeunit.Test) { + 'at time stamp'(test: Test) { test.equal(Expiration.atDate(new Date(1580000000000)).date.toUTCString(), 'Sun, 26 Jan 2020 00:53:20 GMT'); test.done(); }, - 'after'(test: nodeunit.Test) { + 'after'(test: Test) { test.ok(Math.abs(new Date(Expiration.after(Duration.minutes(10)).date.toUTCString()).getTime() - (Date.now() + 600000)) < 15000); test.done(); }, - 'toEpoch returns correct value'(test: nodeunit.Test) { + 'toEpoch returns correct value'(test: Test) { const date = new Date('Sun, 26 Jan 2020 00:53:20 GMT'); test.equal(Expiration.atDate(date).toEpoch(), 1580000000); test.done(); }, - 'isBefore'(test: nodeunit.Test) { + 'isBefore'(test: Test) { const expire = Expiration.after(Duration.days(2)); test.ok(!expire.isBefore(Duration.days(1))); test.ok(expire.isBefore(Duration.days(3))); test.done(); }, - 'isAfter'(test: nodeunit.Test) { + 'isAfter'(test: Test) { const expire = Expiration.after(Duration.days(2)); test.ok(expire.isAfter(Duration.days(1))); test.ok(!expire.isAfter(Duration.days(3))); diff --git a/packages/@aws-cdk/core/test/test.feature-flags.ts b/packages/@aws-cdk/core/test/feature-flags.test.ts similarity index 92% rename from packages/@aws-cdk/core/test/test.feature-flags.ts rename to packages/@aws-cdk/core/test/feature-flags.test.ts index abb1723e6a3dc..b3ca21c45bea8 100644 --- a/packages/@aws-cdk/core/test/test.feature-flags.ts +++ b/packages/@aws-cdk/core/test/feature-flags.test.ts @@ -1,8 +1,8 @@ import * as cxapi from '@aws-cdk/cx-api'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { FeatureFlags, Stack } from '../lib'; -export = { +nodeunitShim({ isEnabled: { 'returns true when the flag is enabled'(test: Test) { const stack = new Stack(); @@ -28,4 +28,4 @@ export = { test.done(); }, }, -} \ No newline at end of file +}); diff --git a/packages/@aws-cdk/core/test/test.fn.ts b/packages/@aws-cdk/core/test/fn.test.ts similarity index 91% rename from packages/@aws-cdk/core/test/test.fn.ts rename to packages/@aws-cdk/core/test/fn.test.ts index ec3f537ba0945..66828aceba543 100644 --- a/packages/@aws-cdk/core/test/test.fn.ts +++ b/packages/@aws-cdk/core/test/fn.test.ts @@ -1,11 +1,11 @@ import * as fc from 'fast-check'; import * as _ from 'lodash'; -import * as nodeunit from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { App, CfnOutput, Fn, Stack, Token } from '../lib'; import { Intrinsic } from '../lib/private/intrinsic'; -function asyncTest(cb: (test: nodeunit.Test) => Promise): (test: nodeunit.Test) => void { - return async (test: nodeunit.Test) => { +function asyncTest(cb: (test: Test) => Promise): (test: Test) => void { + return async (test: Test) => { let error: Error; try { await cb(test); @@ -24,23 +24,23 @@ const nonEmptyString = fc.string(1, 16); const tokenish = fc.array(nonEmptyString, 2, 2).map(arr => ({ [arr[0]]: arr[1] })); const anyValue = fc.oneof(nonEmptyString, tokenish); -export = nodeunit.testCase({ +nodeunitShim({ 'eager resolution for non-tokens': { - 'Fn.select'(test: nodeunit.Test) { + 'Fn.select'(test: Test) { test.deepEqual(Fn.select(2, ['hello', 'you', 'dude']), 'dude'); test.done(); }, - 'Fn.split'(test: nodeunit.Test) { + 'Fn.split'(test: Test) { test.deepEqual(Fn.split(':', 'hello:world:yeah'), ['hello', 'world', 'yeah']); test.done(); }, }, 'FnParseDomainName': { - 'parse domain name from resolved url'(test: nodeunit.Test) { + 'parse domain name from resolved url'(test: Test) { test.deepEqual(Fn.parseDomainName('https://test.com/'), 'test.com'); test.done(); }, - 'parse domain name on token'(test: nodeunit.Test) { + 'parse domain name on token'(test: Test) { const stack = new Stack(); const url = Fn.join('//', [ 'https:', @@ -54,11 +54,11 @@ export = nodeunit.testCase({ }, }, 'FnJoin': { - 'rejects empty list of arguments to join'(test: nodeunit.Test) { + 'rejects empty list of arguments to join'(test: Test) { test.throws(() => Fn.join('.', [])); test.done(); }, - 'collapse nested FnJoins even if they contain tokens'(test: nodeunit.Test) { + 'collapse nested FnJoins even if they contain tokens'(test: Test) { const stack = new Stack(); const obj = Fn.join('', [ @@ -188,7 +188,7 @@ export = nodeunit.testCase({ }), }, 'Ref': { - 'returns a reference given a logical name'(test: nodeunit.Test) { + 'returns a reference given a logical name'(test: Test) { const stack = new Stack(); test.deepEqual(stack.resolve(Fn.ref('hello')), { Ref: 'hello', @@ -196,7 +196,7 @@ export = nodeunit.testCase({ test.done(); }, }, - 'nested Fn::Join with list token'(test: nodeunit.Test) { + 'nested Fn::Join with list token'(test: Test) { const stack = new Stack(); const inner = Fn.join(',', Token.asList({ NotReallyList: true })); const outer = Fn.join(',', [inner, 'Foo']); diff --git a/packages/@aws-cdk/core/test/fs/test.fs-copy.ts b/packages/@aws-cdk/core/test/fs/fs-copy.test.ts similarity index 98% rename from packages/@aws-cdk/core/test/fs/test.fs-copy.ts rename to packages/@aws-cdk/core/test/fs/fs-copy.test.ts index 840bc94a97087..03ffc770b870c 100644 --- a/packages/@aws-cdk/core/test/fs/test.fs-copy.ts +++ b/packages/@aws-cdk/core/test/fs/fs-copy.test.ts @@ -1,10 +1,10 @@ import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { FileSystem, SymlinkFollowMode } from '../../lib/fs'; -export = { +nodeunitShim({ 'Default: copies all files and subdirectories, with default follow mode is "External"'(test: Test) { // GIVEN const outdir = fs.mkdtempSync(path.join(os.tmpdir(), 'copy-tests')); @@ -124,7 +124,7 @@ export = { ]); test.done(); }, -}; +}); function tree(dir: string, depth = ''): string[] { const lines = new Array(); diff --git a/packages/@aws-cdk/core/test/fs/test.fs-fingerprint.ts b/packages/@aws-cdk/core/test/fs/fs-fingerprint.test.ts similarity index 98% rename from packages/@aws-cdk/core/test/fs/test.fs-fingerprint.ts rename to packages/@aws-cdk/core/test/fs/fs-fingerprint.test.ts index b41ddfffc38c2..ad5bf9cf14160 100644 --- a/packages/@aws-cdk/core/test/fs/test.fs-fingerprint.ts +++ b/packages/@aws-cdk/core/test/fs/fs-fingerprint.test.ts @@ -1,10 +1,10 @@ import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { FileSystem, SymlinkFollowMode } from '../../lib/fs'; -export = { +nodeunitShim({ files: { 'does not change with the file name'(test: Test) { // GIVEN @@ -185,4 +185,4 @@ export = { test.done(); }, }, -}; +}); diff --git a/packages/@aws-cdk/core/test/fs/test.fs.ts b/packages/@aws-cdk/core/test/fs/fs.test.ts similarity index 95% rename from packages/@aws-cdk/core/test/fs/test.fs.ts rename to packages/@aws-cdk/core/test/fs/fs.test.ts index 7616eaef536fc..e1e195daa1005 100644 --- a/packages/@aws-cdk/core/test/fs/test.fs.ts +++ b/packages/@aws-cdk/core/test/fs/fs.test.ts @@ -1,11 +1,11 @@ import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import * as sinon from 'sinon'; import { FileSystem } from '../../lib/fs'; -export = { +nodeunitShim({ 'tearDown'(callback: any) { sinon.restore(); callback(); @@ -47,4 +47,4 @@ export = { test.done(); }, -}; +}); diff --git a/packages/@aws-cdk/core/test/fs/test.utils.ts b/packages/@aws-cdk/core/test/fs/utils.test.ts similarity index 99% rename from packages/@aws-cdk/core/test/fs/test.utils.ts rename to packages/@aws-cdk/core/test/fs/utils.test.ts index 2e43d125d597b..1013095199a03 100644 --- a/packages/@aws-cdk/core/test/fs/test.utils.ts +++ b/packages/@aws-cdk/core/test/fs/utils.test.ts @@ -1,11 +1,11 @@ import * as fs from 'fs'; import * as path from 'path'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { ImportMock } from 'ts-mock-imports'; import { SymlinkFollowMode } from '../../lib/fs'; import * as util from '../../lib/fs/utils'; -export = { +nodeunitShim({ shouldExclude: { 'excludes nothing by default'(test: Test) { test.ok(!util.shouldExclude([], path.join('some', 'file', 'path'))); @@ -192,4 +192,4 @@ export = { }, }, }, -}; +}); diff --git a/packages/@aws-cdk/core/test/test.include.ts b/packages/@aws-cdk/core/test/include.test.ts similarity index 97% rename from packages/@aws-cdk/core/test/test.include.ts rename to packages/@aws-cdk/core/test/include.test.ts index f029506c061e0..d36dbf8739d19 100644 --- a/packages/@aws-cdk/core/test/test.include.ts +++ b/packages/@aws-cdk/core/test/include.test.ts @@ -1,8 +1,8 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { CfnInclude, CfnOutput, CfnParameter, CfnResource, Stack } from '../lib'; import { toCloudFormation } from './util'; -export = { +nodeunitShim({ 'the Include construct can be used to embed an existing template as-is into a stack'(test: Test) { const stack = new Stack(); @@ -78,7 +78,7 @@ export = { test.done(); }, -}; +}); const template = { Parameters: { diff --git a/packages/@aws-cdk/core/test/test.logical-id.ts b/packages/@aws-cdk/core/test/logical-id.test.ts similarity index 99% rename from packages/@aws-cdk/core/test/test.logical-id.ts rename to packages/@aws-cdk/core/test/logical-id.test.ts index d7483b3374397..f4ab0f8eb63d9 100644 --- a/packages/@aws-cdk/core/test/test.logical-id.ts +++ b/packages/@aws-cdk/core/test/logical-id.test.ts @@ -1,11 +1,11 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { CfnElement, CfnResource, Construct, Stack } from '../lib'; import { toCloudFormation } from './util'; /** * These tests are executed once (for specific ID schemes) */ -export = { +nodeunitShim({ 'if the naming scheme uniquifies with a hash we can have the same concatenated identifier'(test: Test) { // GIVEN const stack = new Stack(undefined, 'TestStack'); @@ -270,7 +270,7 @@ export = { test.done(); }, -}; +}); function generateString(chars: number) { let s = ''; diff --git a/packages/@aws-cdk/core/test/test.mappings.ts b/packages/@aws-cdk/core/test/mappings.test.ts similarity index 94% rename from packages/@aws-cdk/core/test/test.mappings.ts rename to packages/@aws-cdk/core/test/mappings.test.ts index f73fe5446b541..7dd67fbcead45 100644 --- a/packages/@aws-cdk/core/test/test.mappings.ts +++ b/packages/@aws-cdk/core/test/mappings.test.ts @@ -1,8 +1,8 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { Aws, CfnMapping, CfnResource, Fn, Stack } from '../lib'; import { toCloudFormation } from './util'; -export = { +nodeunitShim({ 'mappings can be added as another type of entity, and mapping.findInMap can be used to get a token'(test: Test) { const stack = new Stack(); const mapping = new CfnMapping(stack, 'MyMapping', { @@ -24,8 +24,8 @@ export = { RefToValueInMap: mapping.findInMap('TopLevelKey1', 'SecondLevelKey1'), }, }); - test.throws(() => mapping.findInMap('NotFoundTopLevel', 'NotFound'), 'cant take a reference on a non existing key'); - test.throws(() => mapping.findInMap('TopLevelKey1', 'NotFound'), 'cant take a reference on a non existing key'); + test.throws(() => mapping.findInMap('NotFoundTopLevel', 'NotFound'), 'Mapping doesn\'t contain top-level key \'NotFoundTopLevel\''); + test.throws(() => mapping.findInMap('TopLevelKey1', 'NotFound'), 'Mapping doesn\'t contain second-level key \'NotFound\''); // set value can be used to set/modify a specific value mapping.setValue('TopLevelKey2', 'SecondLevelKey2', 'Hi'); @@ -121,4 +121,4 @@ export = { test.deepEqual(stack.resolve(v), { 'Fn::FindInMap': ['mapping', 'size', { Ref: 'AWS::Region' }] }); test.done(); }, -}; +}); diff --git a/packages/@aws-cdk/core/test/test.output.ts b/packages/@aws-cdk/core/test/output.test.ts similarity index 93% rename from packages/@aws-cdk/core/test/test.output.ts rename to packages/@aws-cdk/core/test/output.test.ts index 64024b37570c5..d7b509159a2bb 100644 --- a/packages/@aws-cdk/core/test/test.output.ts +++ b/packages/@aws-cdk/core/test/output.test.ts @@ -1,8 +1,8 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { CfnOutput, CfnResource, Stack } from '../lib'; import { toCloudFormation } from './util'; -export = { +nodeunitShim({ 'outputs can be added to the stack'(test: Test) { const stack = new Stack(); const res = new CfnResource(stack, 'MyResource', { type: 'R' }); @@ -46,4 +46,4 @@ export = { test.done(); }, -}; +}); diff --git a/packages/@aws-cdk/core/test/test.parameter.ts b/packages/@aws-cdk/core/test/parameter.test.ts similarity index 94% rename from packages/@aws-cdk/core/test/test.parameter.ts rename to packages/@aws-cdk/core/test/parameter.test.ts index 92cb128b5bc9e..d13edbffddb0a 100644 --- a/packages/@aws-cdk/core/test/test.parameter.ts +++ b/packages/@aws-cdk/core/test/parameter.test.ts @@ -1,8 +1,8 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { CfnParameter, CfnResource, Construct, Stack } from '../lib'; import { toCloudFormation } from './util'; -export = { +nodeunitShim({ 'parameters can be used and referenced using param.ref'(test: Test) { const stack = new Stack(); @@ -41,4 +41,4 @@ export = { test.deepEqual(stack.resolve(param), { Ref: 'MyParam' }); test.done(); }, -}; +}); diff --git a/packages/@aws-cdk/core/test/private/test.physical-name-generator.ts b/packages/@aws-cdk/core/test/private/physical-name-generator.test.ts similarity index 84% rename from packages/@aws-cdk/core/test/private/test.physical-name-generator.ts rename to packages/@aws-cdk/core/test/private/physical-name-generator.test.ts index 9c77a3eec6dfa..2d6e5e93d8d2a 100644 --- a/packages/@aws-cdk/core/test/private/test.physical-name-generator.ts +++ b/packages/@aws-cdk/core/test/private/physical-name-generator.test.ts @@ -1,10 +1,10 @@ -import * as nodeunit from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { App, Aws, Lazy, Resource, Stack, Token } from '../../lib'; import { GeneratedWhenNeededMarker, generatePhysicalName, isGeneratedWhenNeededMarker } from '../../lib/private/physical-name-generator'; -export = nodeunit.testCase({ +nodeunitShim({ generatePhysicalName: { - 'generates correct physical names'(test: nodeunit.Test) { + 'generates correct physical names'(test: Test) { const app = new App(); const stack = new Stack(app, 'TestStack', { env: { account: '012345678912', region: 'bermuda-triangle-1' } }); @@ -17,7 +17,7 @@ export = nodeunit.testCase({ test.done(); }, - 'generates different names in different accounts'(test: nodeunit.Test) { + 'generates different names in different accounts'(test: Test) { const appA = new App(); const stackA = new Stack(appA, 'TestStack', { env: { account: '012345678912', region: 'bermuda-triangle-1' } }); const resourceA = new TestResource(stackA, 'Resource'); @@ -31,7 +31,7 @@ export = nodeunit.testCase({ test.done(); }, - 'generates different names in different regions'(test: nodeunit.Test) { + 'generates different names in different regions'(test: Test) { const appA = new App(); const stackA = new Stack(appA, 'TestStack', { env: { account: '012345678912', region: 'bermuda-triangle-1' } }); const resourceA = new TestResource(stackA, 'Resource'); @@ -45,7 +45,7 @@ export = nodeunit.testCase({ test.done(); }, - 'fails when the region is an unresolved token'(test: nodeunit.Test) { + 'fails when the region is an unresolved token'(test: Test) { const app = new App(); const stack = new Stack(app, 'TestStack', { env: { account: '012345678912', region: Aws.REGION } }); const testResource = new TestResource(stack, 'A'); @@ -56,7 +56,7 @@ export = nodeunit.testCase({ test.done(); }, - 'fails when the region is not provided'(test: nodeunit.Test) { + 'fails when the region is not provided'(test: Test) { const app = new App(); const stack = new Stack(app, 'TestStack', { env: { account: '012345678912' } }); const testResource = new TestResource(stack, 'A'); @@ -67,7 +67,7 @@ export = nodeunit.testCase({ test.done(); }, - 'fails when the account is an unresolved token'(test: nodeunit.Test) { + 'fails when the account is an unresolved token'(test: Test) { const app = new App(); const stack = new Stack(app, 'TestStack', { env: { account: Aws.ACCOUNT_ID, region: 'bermuda-triangle-1' } }); const testResource = new TestResource(stack, 'A'); @@ -78,7 +78,7 @@ export = nodeunit.testCase({ test.done(); }, - 'fails when the account is not provided'(test: nodeunit.Test) { + 'fails when the account is not provided'(test: Test) { const app = new App(); const stack = new Stack(app, 'TestStack', { env: { region: 'bermuda-triangle-1' } }); const testResource = new TestResource(stack, 'A'); @@ -91,7 +91,7 @@ export = nodeunit.testCase({ }, GeneratedWhenNeededMarker: { - 'is correctly recognized'(test: nodeunit.Test) { + 'is correctly recognized'(test: Test) { const marker = new GeneratedWhenNeededMarker(); const asString = Token.asString(marker); @@ -100,7 +100,7 @@ export = nodeunit.testCase({ test.done(); }, - 'throws when resolved'(test: nodeunit.Test) { + 'throws when resolved'(test: Test) { const marker = new GeneratedWhenNeededMarker(); const asString = Token.asString(marker); @@ -111,7 +111,7 @@ export = nodeunit.testCase({ }, isGeneratedWhenNeededMarker: { - 'correctly response for other tokens'(test: nodeunit.Test) { + 'correctly response for other tokens'(test: Test) { test.ok(!isGeneratedWhenNeededMarker('this is not even a token!')); test.ok(!isGeneratedWhenNeededMarker(Lazy.stringValue({ produce: () => 'Bazinga!' }))); diff --git a/packages/@aws-cdk/core/test/private/test.tree-metadata.ts b/packages/@aws-cdk/core/test/private/tree-metadata.test.ts similarity index 99% rename from packages/@aws-cdk/core/test/private/test.tree-metadata.ts rename to packages/@aws-cdk/core/test/private/tree-metadata.test.ts index 3ef3966b2fd95..ce64cf5991e1a 100644 --- a/packages/@aws-cdk/core/test/private/test.tree-metadata.ts +++ b/packages/@aws-cdk/core/test/private/tree-metadata.test.ts @@ -1,7 +1,7 @@ import * as fs from 'fs'; import * as path from 'path'; import * as cxschema from '@aws-cdk/cloud-assembly-schema'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { App, CfnParameter, CfnResource, Construct, Lazy, Stack, TreeInspector } from '../../lib/index'; abstract class AbstractCfnResource extends CfnResource { @@ -19,7 +19,7 @@ abstract class AbstractCfnResource extends CfnResource { protected abstract get cfnProperties(): { [key: string]: any }; } -export = { +nodeunitShim({ 'tree metadata is generated as expected'(test: Test) { const app = new App(); @@ -309,7 +309,7 @@ export = { test.done(); }, -}; +}); function readJson(outdir: string, file: string) { return JSON.parse(fs.readFileSync(path.join(outdir, file), 'utf-8')); diff --git a/packages/@aws-cdk/core/test/test.resource.ts b/packages/@aws-cdk/core/test/resource.test.ts similarity index 99% rename from packages/@aws-cdk/core/test/test.resource.ts rename to packages/@aws-cdk/core/test/resource.test.ts index 0a4a29f664db8..a559a33658ba2 100644 --- a/packages/@aws-cdk/core/test/test.resource.ts +++ b/packages/@aws-cdk/core/test/resource.test.ts @@ -1,5 +1,5 @@ import * as cxapi from '@aws-cdk/cx-api'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { App, App as Root, CfnCondition, CfnDeletionPolicy, CfnResource, Construct, @@ -8,7 +8,7 @@ import { import { synthesize } from '../lib/private/synthesis'; import { toCloudFormation } from './util'; -export = { +nodeunitShim({ 'all resources derive from Resource, which derives from Entity'(test: Test) { const stack = new Stack(); @@ -783,7 +783,7 @@ export = { test.done(); }, -}; +}); interface CounterProps { Count: number; diff --git a/packages/@aws-cdk/core/test/test.rule.ts b/packages/@aws-cdk/core/test/rule.test.ts similarity index 94% rename from packages/@aws-cdk/core/test/test.rule.ts rename to packages/@aws-cdk/core/test/rule.test.ts index 8385183333855..637f204235f83 100644 --- a/packages/@aws-cdk/core/test/test.rule.ts +++ b/packages/@aws-cdk/core/test/rule.test.ts @@ -1,8 +1,8 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { CfnRule, Fn, Stack } from '../lib'; import { toCloudFormation } from './util'; -export = { +nodeunitShim({ 'Rule can be used to create rules'(test: Test) { const stack = new Stack(); @@ -45,4 +45,4 @@ export = { test.done(); }, -}; +}); diff --git a/packages/@aws-cdk/core/test/test.runtime-info.ts b/packages/@aws-cdk/core/test/runtime-info.test.ts similarity index 97% rename from packages/@aws-cdk/core/test/test.runtime-info.ts rename to packages/@aws-cdk/core/test/runtime-info.test.ts index 46d8e42f85048..67f931bb63ec5 100644 --- a/packages/@aws-cdk/core/test/test.runtime-info.ts +++ b/packages/@aws-cdk/core/test/runtime-info.test.ts @@ -1,10 +1,10 @@ import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { collectRuntimeInformation } from '../lib/private/runtime-info'; -export = { +nodeunitShim({ 'version reporting includes @aws-solutions-konstruk libraries'(test: Test) { const pkgdir = fs.mkdtempSync(path.join(os.tmpdir(), 'runtime-info-konstruk-fixture')); const mockVersion = '1.2.3'; @@ -70,4 +70,4 @@ export = { test.equal(runtimeInfo.libraries['@aws-solutions-konstruk/bar'], undefined); test.done(); }, -}; +}); diff --git a/packages/@aws-cdk/core/test/test.secret-value.ts b/packages/@aws-cdk/core/test/secret-value.test.ts similarity index 97% rename from packages/@aws-cdk/core/test/test.secret-value.ts rename to packages/@aws-cdk/core/test/secret-value.test.ts index 759af3d0d2c27..155a0d371aab0 100644 --- a/packages/@aws-cdk/core/test/test.secret-value.ts +++ b/packages/@aws-cdk/core/test/secret-value.test.ts @@ -1,7 +1,7 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { CfnDynamicReference, CfnDynamicReferenceService, CfnParameter, SecretValue, Stack } from '../lib'; -export = { +nodeunitShim({ 'plainText'(test: Test) { // GIVEN const stack = new Stack(); @@ -99,4 +99,4 @@ export = { test.done(); }, -}; \ No newline at end of file +}); diff --git a/packages/@aws-cdk/core/test/test.size.ts b/packages/@aws-cdk/core/test/size.test.ts similarity index 98% rename from packages/@aws-cdk/core/test/test.size.ts rename to packages/@aws-cdk/core/test/size.test.ts index dcb25ebd95b72..e6e9534039b90 100644 --- a/packages/@aws-cdk/core/test/test.size.ts +++ b/packages/@aws-cdk/core/test/size.test.ts @@ -1,7 +1,7 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { Size, SizeRoundingBehavior, Stack, Token } from '../lib'; -export = { +nodeunitShim({ 'negative amount'(test: Test) { test.throws(() => Size.kibibytes(-1), /negative/); @@ -109,7 +109,7 @@ export = { test.done(); }, -}; +}); function floatEqual(test: Test, actual: number, expected: number) { test.ok( diff --git a/packages/@aws-cdk/core/test/stack-synthesis/test.new-style-synthesis.ts b/packages/@aws-cdk/core/test/stack-synthesis/new-style-synthesis.test.ts similarity index 99% rename from packages/@aws-cdk/core/test/stack-synthesis/test.new-style-synthesis.ts rename to packages/@aws-cdk/core/test/stack-synthesis/new-style-synthesis.test.ts index 8028658b4c7dc..08b48162086a0 100644 --- a/packages/@aws-cdk/core/test/stack-synthesis/test.new-style-synthesis.ts +++ b/packages/@aws-cdk/core/test/stack-synthesis/new-style-synthesis.test.ts @@ -1,7 +1,7 @@ import * as fs from 'fs'; import * as cxschema from '@aws-cdk/cloud-assembly-schema'; import * as cxapi from '@aws-cdk/cx-api'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { App, CfnResource, DefaultStackSynthesizer, FileAssetPackaging, Stack } from '../../lib'; import { evaluateCFN } from '../evaluate-cfn'; @@ -13,7 +13,7 @@ const CFN_CONTEXT = { let app: App; let stack: Stack; -export = { +nodeunitShim({ 'setUp'(cb: () => void) { app = new App({ context: { @@ -218,7 +218,7 @@ export = { test.done(); }, -}; +}); /** * Evaluate a possibly string-containing value the same way CFN would do @@ -242,4 +242,4 @@ function readAssetManifest(asm: cxapi.CloudAssembly): cxschema.AssetManifest { function last(xs?: A[]): A | undefined { return xs ? xs[xs.length - 1] : undefined; -} \ No newline at end of file +} diff --git a/packages/@aws-cdk/core/test/test.stack.ts b/packages/@aws-cdk/core/test/stack.test.ts similarity index 99% rename from packages/@aws-cdk/core/test/test.stack.ts rename to packages/@aws-cdk/core/test/stack.test.ts index 409c096da3610..50a91b7be7827 100644 --- a/packages/@aws-cdk/core/test/test.stack.ts +++ b/packages/@aws-cdk/core/test/stack.test.ts @@ -1,5 +1,5 @@ import * as cxapi from '@aws-cdk/cx-api'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { App, CfnCondition, CfnInclude, CfnOutput, CfnParameter, CfnResource, Construct, Lazy, ScopedAws, Stack, validateString, ISynthesisSession, Tags, LegacyStackSynthesizer, DefaultStackSynthesizer, @@ -9,7 +9,7 @@ import { resolveReferences } from '../lib/private/refs'; import { PostResolveToken } from '../lib/util'; import { toCloudFormation } from './util'; -export = { +nodeunitShim({ 'a stack can be serialized into a CloudFormation template, initially it\'s empty'(test: Test) { const stack = new Stack(); test.deepEqual(toCloudFormation(stack), { }); @@ -581,7 +581,7 @@ export = { test.throws(() => { app.synth(); // eslint-disable-next-line max-len - }, "'Stack2' depends on 'Stack1' (Stack2/SomeParameter -> Stack1.AWS::AccountId). Adding this dependency (Stack1/SomeParameter -> Stack2.AWS::AccountId) would create a cyclic reference."); + }, "'Stack1' depends on 'Stack2' (Stack1 -> Stack2.AWS::AccountId). Adding this dependency (Stack2 -> Stack1.AWS::AccountId) would create a cyclic reference."); test.done(); }, @@ -1011,7 +1011,7 @@ export = { test.ok(new Stack(app, 'Stack', { analyticsReporting: true })._versionReportingEnabled); test.done(); }, -}; +}); class StackWithPostProcessor extends Stack { diff --git a/packages/@aws-cdk/core/test/test.stage.ts b/packages/@aws-cdk/core/test/stage.test.ts similarity index 99% rename from packages/@aws-cdk/core/test/test.stage.ts rename to packages/@aws-cdk/core/test/stage.test.ts index 52fe1c14c4d21..c878c1485d6ce 100644 --- a/packages/@aws-cdk/core/test/test.stage.ts +++ b/packages/@aws-cdk/core/test/stage.test.ts @@ -1,8 +1,8 @@ import * as cxapi from '@aws-cdk/cx-api'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { App, CfnResource, Construct, IAspect, IConstruct, Stack, Stage, Aspects } from '../lib'; -export = { +nodeunitShim({ 'Stack inherits unspecified part of the env from Stage'(test: Test) { // GIVEN const app = new App(); @@ -280,7 +280,7 @@ export = { test.throws(() => new Stage(app, 'mystage', { outdir: '/tmp/foo/bar' }), /"outdir" cannot be specified for nested stages/); test.done(); }, -}; +}); class TouchingAspect implements IAspect { public readonly visits = new Array(); @@ -301,4 +301,4 @@ class BogusStack extends Stack { function acctRegion(s: Stack) { return [s.account, s.region]; -} \ No newline at end of file +} diff --git a/packages/@aws-cdk/core/test/test.staging.ts b/packages/@aws-cdk/core/test/staging.test.ts similarity index 99% rename from packages/@aws-cdk/core/test/test.staging.ts rename to packages/@aws-cdk/core/test/staging.test.ts index 6d649325db94e..0ab19b3f26074 100644 --- a/packages/@aws-cdk/core/test/test.staging.ts +++ b/packages/@aws-cdk/core/test/staging.test.ts @@ -2,7 +2,7 @@ import * as os from 'os'; import * as path from 'path'; import * as cxapi from '@aws-cdk/cx-api'; import * as fs from 'fs-extra'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import * as sinon from 'sinon'; import { App, AssetHashType, AssetStaging, BundlingDockerImage, BundlingOptions, Stack } from '../lib'; @@ -21,7 +21,7 @@ const USER_ARG = `-u ${userInfo.uid}:${userInfo.gid}`; // this is a way to provide a custom "docker" command for staging. process.env.CDK_DOCKER = `${__dirname}/docker-stub.sh`; -export = { +nodeunitShim({ 'tearDown'(cb: any) { if (fs.existsSync(STUB_INPUT_FILE)) { @@ -651,7 +651,7 @@ export = { test.done(); }, -}; +}); // Reads a docker stub and cleans the volume paths out of the stub. function readAndCleanDockerStubInput(file: string) { diff --git a/packages/@aws-cdk/core/test/test.synthesis.ts b/packages/@aws-cdk/core/test/synthesis.test.ts similarity index 98% rename from packages/@aws-cdk/core/test/test.synthesis.ts rename to packages/@aws-cdk/core/test/synthesis.test.ts index 3d8c0fad35cf1..464e544cc562a 100644 --- a/packages/@aws-cdk/core/test/test.synthesis.ts +++ b/packages/@aws-cdk/core/test/synthesis.test.ts @@ -2,14 +2,14 @@ import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; import * as cxschema from '@aws-cdk/cloud-assembly-schema'; -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import * as cdk from '../lib'; function createModernApp() { return new cdk.App(); } -export = { +nodeunitShim({ 'synthesis with an empty app'(test: Test) { // GIVEN const app = createModernApp(); @@ -158,7 +158,7 @@ export = { test.deepEqual(stack.environment, { region: 'us-east-1', account: 'unknown-account', name: 'aws://unknown-account/us-east-1' }); test.done(); }, -}; +}); function list(outdir: string) { return fs.readdirSync(outdir).sort(); diff --git a/packages/@aws-cdk/core/test/test.tag-aspect.ts b/packages/@aws-cdk/core/test/tag-aspect.test.ts similarity index 99% rename from packages/@aws-cdk/core/test/test.tag-aspect.ts rename to packages/@aws-cdk/core/test/tag-aspect.test.ts index a2c90275eb54d..cb2c5363e2153 100644 --- a/packages/@aws-cdk/core/test/test.tag-aspect.ts +++ b/packages/@aws-cdk/core/test/tag-aspect.test.ts @@ -1,4 +1,4 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { CfnResource, CfnResourceProps, Construct, RemoveTag, Stack, Tag, TagManager, TagType, Aspects, Tags } from '../lib'; import { synthesize } from '../lib/private/synthesis'; @@ -38,7 +38,7 @@ class MapTaggableResource extends CfnResource { } } -export = { +nodeunitShim({ 'Tag visit all children of the applied node'(test: Test) { const root = new Stack(); const res = new TaggableResource(root, 'FakeResource', { @@ -276,4 +276,4 @@ export = { test.done(); }, }, -}; +}); diff --git a/packages/@aws-cdk/core/test/test.tag-manager.ts b/packages/@aws-cdk/core/test/tag-manager.test.ts similarity index 98% rename from packages/@aws-cdk/core/test/test.tag-manager.ts rename to packages/@aws-cdk/core/test/tag-manager.test.ts index 235d7b8b0fbe4..7e9e448e97434 100644 --- a/packages/@aws-cdk/core/test/test.tag-manager.ts +++ b/packages/@aws-cdk/core/test/tag-manager.test.ts @@ -1,8 +1,8 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { TagType } from '../lib/cfn-resource'; import { TagManager } from '../lib/tag-manager'; -export = { +nodeunitShim({ 'TagManagerOptions can set tagPropertyName'(test: Test) { const tagPropName = 'specialName'; const mgr = new TagManager(TagType.MAP, 'Foo', undefined, { tagPropertyName: tagPropName }); @@ -146,4 +146,4 @@ export = { test.done(); }, -}; +}); diff --git a/packages/@aws-cdk/core/test/test.tokens.ts b/packages/@aws-cdk/core/test/tokens.test.ts similarity index 99% rename from packages/@aws-cdk/core/test/test.tokens.ts rename to packages/@aws-cdk/core/test/tokens.test.ts index 9356cbad9b49b..28d70be77e53a 100644 --- a/packages/@aws-cdk/core/test/test.tokens.ts +++ b/packages/@aws-cdk/core/test/tokens.test.ts @@ -1,4 +1,4 @@ -import { Test } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { Fn, isResolvableObject, Lazy, Stack, Token, Tokenization } from '../lib'; import { createTokenDouble, extractTokenDouble } from '../lib/private/encoding'; import { Intrinsic } from '../lib/private/intrinsic'; @@ -7,7 +7,7 @@ import { IResolvable } from '../lib/resolvable'; import { evaluateCFN } from './evaluate-cfn'; import { reEnableStackTraceCollection, restoreStackTraceColection } from './util'; -export = { +nodeunitShim({ 'resolve a plain old object should just return the object'(test: Test) { const obj = { PlainOldObject: 123, Array: [1, 2, 3] }; test.deepEqual(resolve(obj), obj); @@ -327,7 +327,7 @@ export = { }; // THEN - test.throws(() => resolve(s), 'The key "${Token[TOKEN.19]}" has been resolved to {"Ref":"Other"} but must be resolvable to a string'); + test.throws(() => resolve(s), 'is used as the key in a map so must resolve to a string, but it resolves to:'); test.done(); }, @@ -653,7 +653,7 @@ export = { test.done(); }, }, -}; +}); class Promise2 implements IResolvable { public readonly creationStack = []; diff --git a/packages/@aws-cdk/core/test/test.util.ts b/packages/@aws-cdk/core/test/util.test.ts similarity index 98% rename from packages/@aws-cdk/core/test/test.util.ts rename to packages/@aws-cdk/core/test/util.test.ts index e573cde4bb1ae..3b9c33f14c9f4 100644 --- a/packages/@aws-cdk/core/test/test.util.ts +++ b/packages/@aws-cdk/core/test/util.test.ts @@ -1,8 +1,8 @@ -import { Test, testCase } from 'nodeunit'; +import { nodeunitShim, Test } from 'nodeunit-shim'; import { CfnResource, Construct, Stack } from '../lib'; import { capitalizePropertyNames, filterUndefined, findLastCommonElement, ignoreEmpty, pathToTopLevelStack } from '../lib/util'; -export = testCase({ +nodeunitShim({ 'capitalizeResourceProperties capitalizes all keys of an object (recursively) from camelCase to PascalCase'(test: Test) { const c = new Stack(); diff --git a/tools/nodeunit-shim/index.ts b/tools/nodeunit-shim/index.ts index e6f0fe91da5a7..8ba50bedefefd 100644 --- a/tools/nodeunit-shim/index.ts +++ b/tools/nodeunit-shim/index.ts @@ -15,6 +15,10 @@ export class Test { expect(a).toEqual(b); } + public notEqual(a: any, b: any, _message?: string) { + expect(a).not.toEqual(b); + } + public equals(a: any, b: any, _message?: string) { expect(a).toEqual(b); } @@ -23,10 +27,14 @@ export class Test { expect(a).toEqual(b); } - public deepEqual(a: any, b: any) { + public deepEqual(a: any, b: any, _message?: string) { expect(a).toEqual(b); } + public notDeepEqual(a: any, b: any, _message?: string) { + expect(a).not.toEqual(b); + } + public ok(a: any, _message?: string) { expect(a).toBeTruthy(); }