-
Notifications
You must be signed in to change notification settings - Fork 4
fix(test-utils): Support re-export declarations #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| { | ||
| "extends": "../tsconfig.json", | ||
| "include": ["errors-no-wrapper-classes.ts"] | ||
| "extends": "../tsconfig.json" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { ElementWrapper } from './core'; | ||
|
|
||
| export class AlertWrapper extends ElementWrapper { | ||
| findContent() { | ||
| return new ElementWrapper(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { ElementWrapper } from './core'; | ||
|
|
||
| export class ButtonWrapper extends ElementWrapper { | ||
| findText() { | ||
| return new ElementWrapper(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| export class ElementWrapper {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| export { AlertWrapper } from './alert'; | ||
| export { ButtonWrapper } from './button'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "extends": "../tsconfig.json" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,11 +43,11 @@ export default function extractDocumentation( | |
| if (extraExports.includes(className)) { | ||
| continue; | ||
| } | ||
| if (!(symbol.flags & ts.SymbolFlags.Class)) { | ||
| const classType = checker.getDeclaredTypeOfSymbol(symbol); | ||
| if (!classType.isClass()) { | ||
| throw new Error(`Exported symbol is not a class, got ${checker.symbolToString(symbol)}`); | ||
| } | ||
|
|
||
| const classType = checker.getTypeAtLocation(extractDeclaration(symbol)); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The actual fix. Replace |
||
| const classDefinition: TestUtilsDoc = { name: className, methods: [] }; | ||
| for (const property of classType.getProperties()) { | ||
| const declaration = property.valueDeclaration; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import ts from 'typescript'; | ||
| import { test, expect } from 'vitest'; | ||
| import { printFlags } from '../../lib/components/type-utils'; | ||
|
|
||
| test('serialises node flags', () => { | ||
| expect( | ||
| printFlags( | ||
| ts.NodeFlags.HasAsyncFunctions + ts.NodeFlags.HasImplicitReturn + ts.NodeFlags.ContainsThis, | ||
| ts.NodeFlags | ||
| ) | ||
| ).toEqual('ContainsThis | HasImplicitReturn | ReachabilityCheckFlags | HasAsyncFunctions | ReachabilityAndEmitFlags'); | ||
| }); | ||
|
|
||
| test('serialises type flags', () => { | ||
| expect(printFlags(ts.TypeFlags.Number + ts.TypeFlags.Enum, ts.TypeFlags)).toEqual( | ||
| 'Number | Enum | NumberLike | EnumLike | PossiblyFalsy | Primitive | NotPrimitiveUnion | Singleton | Intrinsic | IncludesMask | DisjointDomains | DefinitelyNonNullable | Narrowable' | ||
| ); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,12 @@ describe('documentTestUtils throws error for ', () => { | |
| expect(() => buildTestUtilsProject('errors-empty')).toThrow('Failed to parse tsconfig.json'); | ||
| }); | ||
|
|
||
| test('throws error on unknown export', () => { | ||
| expect(() => buildTestUtilsProject('errors-no-wrapper-classes')).toThrow( | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixture existed, but was never used 🤦 |
||
| 'Exported symbol is not a class, got speakTruth' | ||
| ); | ||
| }); | ||
|
|
||
| test('having no input files because of a non-matching glob', () => { | ||
| expect(() => | ||
| buildTestUtilsProject('simple', { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not used in the final version of the code, but it was useful in local debugging to convert binary flags into readable strings
Let's keep it in the code so I will not have to remember how it is done every time