From 934b5c82b6046232f4eda6ea28d38cdad414d310 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Fri, 23 Aug 2019 15:30:37 +0200 Subject: [PATCH] fix(jsii-diff): handle violations in Enums (#730) Rendering violations in enums was not considered and so any violation to a full enum type (typically, removing it) would cause the differ to crash. --- packages/jsii-diff/lib/types.ts | 6 +++++- packages/jsii-diff/test/test.enums.ts | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/jsii-diff/lib/types.ts b/packages/jsii-diff/lib/types.ts index 22e0c998e8..14032b98dd 100644 --- a/packages/jsii-diff/lib/types.ts +++ b/packages/jsii-diff/lib/types.ts @@ -73,6 +73,7 @@ function identifier(apiElement: ApiElement) { init(x) { return `${x.parentType.fqn}.${x.name}`; }, property(x) { return `${x.parentType.fqn}.${x.name}`; }, enumMember(x) { return `${x.enumType.fqn}.${x.name}`; }, + enumType(x) { return `${x.fqn}`; }, klass(x) { return `${x.fqn}`; }, iface(x) { return `${x.fqn}`; }, }); @@ -83,7 +84,8 @@ function describeApiElement(apiElement: ApiElement) { method() { return 'METHOD'; }, init() { return 'INITIALIZER'; }, property() { return 'PROP'; }, - enumMember() { return 'ENUM'; }, + enumMember() { return 'ENUM VALUE'; }, + enumType() { return 'ENUM'; }, klass() { return 'CLASS'; }, iface() { return 'IFACE'; }, }); @@ -94,6 +96,7 @@ function dispatch(apiElement: ApiElement, fns: { init(m: reflect.Initializer): T, property(m: reflect.Property): T, enumMember(m: reflect.EnumMember): T, + enumType(m: reflect.EnumType): T, klass(m: reflect.ClassType): T, iface(m: reflect.InterfaceType): T, }) { @@ -104,6 +107,7 @@ function dispatch(apiElement: ApiElement, fns: { if (apiElement instanceof reflect.ClassType) { return fns.klass(apiElement); } if (apiElement instanceof reflect.InterfaceType) { return fns.iface(apiElement); } if (apiElement instanceof reflect.Initializer) { return fns.init(apiElement); } + if (apiElement instanceof reflect.EnumType) { return fns.enumType(apiElement); } throw new Error(`Unrecognized violator: ${apiElement}`); } diff --git a/packages/jsii-diff/test/test.enums.ts b/packages/jsii-diff/test/test.enums.ts index fd9d1e5dcb..16026d9dac 100644 --- a/packages/jsii-diff/test/test.enums.ts +++ b/packages/jsii-diff/test/test.enums.ts @@ -41,4 +41,20 @@ export = { `); test.done(); }, + + // ---------------------------------------------------------------------- + + async 'does not crash when removing enum'(test: Test) { + await expectError(test, + /ENUM testpkg.Foo: has been removed/, + ` + export enum Foo { + BAR, + BAZ, + QUUX + } + `, ` + `); + test.done(); + }, };