Skip to content

Commit 7b3ec3c

Browse files
committed
fix(test-utils): Support re-export declarations
1 parent 26a251e commit 7b3ec3c

File tree

11 files changed

+56
-4
lines changed

11 files changed

+56
-4
lines changed

fixtures/test-utils/errors-no-wrapper-classes/errors-no-wrapper-classes.ts renamed to fixtures/test-utils/errors-no-wrapper-classes/index.ts

File renamed without changes.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"extends": "../tsconfig.json",
3-
"include": ["errors-no-wrapper-classes.ts"]
2+
"extends": "../tsconfig.json"
43
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { ElementWrapper } from './core';
5+
6+
export class AlertWrapper extends ElementWrapper {
7+
findContent() {
8+
return new ElementWrapper();
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { ElementWrapper } from './core';
5+
6+
export class ButtonWrapper extends ElementWrapper {
7+
findText() {
8+
return new ElementWrapper();
9+
}
10+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
export class ElementWrapper {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
export { AlertWrapper } from './alert';
4+
export { ButtonWrapper } from './button';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../tsconfig.json"
3+
}

src/components/type-utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,11 @@ export function extractDeclaration(symbol: ts.Symbol) {
107107
}
108108
return declarations[0];
109109
}
110+
111+
export function printFlags(flags: number, mapping: Record<number, string>) {
112+
/* v8 ignore next */
113+
return Object.entries(mapping)
114+
.filter(([key, value]) => Number(key) & flags)
115+
.map(([key, value]) => value)
116+
.join(' | ');
117+
}

src/test-utils-new/extractor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ export default function extractDocumentation(
4343
if (extraExports.includes(className)) {
4444
continue;
4545
}
46-
if (!(symbol.flags & ts.SymbolFlags.Class)) {
46+
const classType = checker.getDeclaredTypeOfSymbol(symbol);
47+
if (!classType.isClass()) {
4748
throw new Error(`Exported symbol is not a class, got ${checker.symbolToString(symbol)}`);
4849
}
4950

50-
const classType = checker.getTypeAtLocation(extractDeclaration(symbol));
5151
const classDefinition: TestUtilsDoc = { name: className, methods: [] };
5252
for (const property of classType.getProperties()) {
5353
const declaration = property.valueDeclaration;

test/test-utils/doc-generation.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ describe('Generate documentation', () => {
8383
expect(childClassMethod?.inheritedFrom).toBeUndefined();
8484
});
8585

86+
test('deal with re-exports', () => {
87+
const results = buildTestUtilsProject('exports');
88+
expect(results.map(classDoc => classDoc.name)).toEqual(['AlertWrapper', 'ButtonWrapper']);
89+
const alertWrapper = results.find(classDoc => classDoc.name === 'AlertWrapper')!;
90+
expect(alertWrapper.methods.map(method => method.name)).toEqual(['findContent']);
91+
const buttonWrapper = results.find(classDoc => classDoc.name === 'ButtonWrapper')!;
92+
expect(buttonWrapper.methods.map(method => method.name)).toEqual(['findText']);
93+
});
94+
8695
test('default value rendering', () => {
8796
const results = buildTestUtilsProject('default-values');
8897
expect(results.length).toBe(1);

0 commit comments

Comments
 (0)