Skip to content

Commit

Permalink
fix(jsii-diff): handle violations in Enums (#730)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rix0rrr authored and mergify[bot] committed Aug 23, 2019
1 parent 51c69bc commit 934b5c8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/jsii-diff/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`; },
});
Expand All @@ -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'; },
});
Expand All @@ -94,6 +96,7 @@ function dispatch<T>(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,
}) {
Expand All @@ -104,6 +107,7 @@ function dispatch<T>(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}`);
}
Expand Down
16 changes: 16 additions & 0 deletions packages/jsii-diff/test/test.enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
};

0 comments on commit 934b5c8

Please sign in to comment.