Skip to content

Commit f3ab510

Browse files
committed
Updated unit tests
1 parent 62c2102 commit f3ab510

8 files changed

Lines changed: 50 additions & 38 deletions

File tree

‎libraries/api-extractor/src/test/DocItemLoader.test.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ function testErrorHandler(message: string, fileName: string, lineNumber: number)
1919
capturedErrors.push({ message, fileName, lineNumber });
2020
}
2121

22+
function assertCapturedErrors(expectedMessages: string[]): void {
23+
assert.deepEqual(capturedErrors.map(x => x.message), expectedMessages,
24+
'The captured errors did not match the expected output.');
25+
}
26+
2227
// These warnings would normally be printed at the bottom
2328
// of the source package's '*.api.ts' file.
2429
const warnings: string[] = [];
@@ -61,10 +66,11 @@ describe('DocItemLoader tests', function (): void {
6166
const apiFileGenerator: ApiFileGenerator = new ApiFileGenerator();
6267
apiFileGenerator.writeApiFile(outputApiFile, extractor);
6368

64-
assert.equal(capturedErrors.length, 2);
65-
assert.equal(capturedErrors[0].message, 'circular reference');
66-
assert.equal(capturedErrors[1].message, 'The {@link} tag references an @internal or @alpha API item,'
67-
+ ' which will not appear in the generated documentation');
69+
assertCapturedErrors([
70+
'circular reference',
71+
'The {@link} tag references an @internal or @alpha API item,'
72+
+ ' which will not appear in the generated documentation'
73+
]);
6874
TestFileComparer.assertFileMatchesExpected(outputJsonFile, expectedJsonFile);
6975
TestFileComparer.assertFileMatchesExpected(outputApiFile, expectedApiFile);
7076
});

‎libraries/api-extractor/testInputs/example1/example1-output.api.ts‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ class ___proto__ {
33
public propertyIsEnumerable: string;
44
}
55

6+
// WARNING: propertyWithNoType has incomplete type information
7+
// @internal
8+
class _InternalClass {
9+
// (undocumented)
10+
public test(): void;
11+
}
12+
13+
// @internal (preapproved)
14+
class _PreapprovedInternalClass {
15+
}
16+
17+
618
// (undocumented)
719
class A extends __proto__, implements hasOwnProperty {
820
// (undocumented)
@@ -13,10 +25,10 @@ class A extends __proto__, implements hasOwnProperty {
1325

1426
// @public
1527
class AliasClass4 {
28+
// @internal
29+
public _aliasFunc(): void;
1630
// (undocumented)
1731
public aliasField: number;
18-
// @internal
19-
public aliasFunc(): void;
2032
// (undocumented)
2133
public readonly shouldBeReadOnly: number;
2234
}
@@ -43,13 +55,6 @@ interface hasOwnProperty {
4355
___lookupSetter__: __proto__;
4456
}
4557

46-
// WARNING: propertyWithNoType has incomplete type information
47-
// @internal
48-
class InternalClass {
49-
// (undocumented)
50-
public test(): void;
51-
}
52-
5358
// (undocumented)
5459
class MyClass {
5560
// (undocumented)
@@ -60,11 +65,6 @@ class MyClass {
6065
public test(): void;
6166
}
6267

63-
// @internal (preapproved)
64-
class PreapprovedInternalClass {
65-
}
66-
67-
6868
// (undocumented)
6969
export function publicFunction(param: number): string;
7070

‎libraries/api-extractor/testInputs/example1/folder/AliasClass.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ export class AliasClass {
1010
* AEDoc for aliasFunc()
1111
* @internal
1212
*/
13-
public aliasFunc(): void {
14-
console.log('this is a public API');
13+
public _aliasFunc(): void {
14+
console.log('this is an internal API');
1515
}
16-
public aliasField: number;
17-
1816

17+
public aliasField: number;
1918

2019
public get shouldBeReadOnly(): number {
2120
return this.readOnlyNumber;

‎libraries/api-extractor/testInputs/example1/index.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import OtherName from './folder/AliasClass2';
22

3-
export { default as MyClass, InternalClass, PreapprovedInternalClass, __proto__, hasOwnProperty, A } from './folder/MyClass';
3+
export {
4+
default as MyClass, InternalClass as _InternalClass,
5+
PreapprovedInternalClass as _PreapprovedInternalClass,
6+
__proto__,
7+
hasOwnProperty,
8+
A
9+
} from './folder/MyClass';
10+
411
export { AliasClass3 as AliasClass4 } from './folder/AliasClass3';
512

613
function privateFunction(): number {

‎libraries/api-extractor/testInputs/example3/example3-output.api.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// @internal
2+
enum _internalEnum {
3+
}
4+
15
enum inheritEnumValues {
26
index_one = 1,
37
index_zero = 0
@@ -17,10 +21,6 @@ enum inheritLocalOptionOne {
1721
// WARNING: Unable to find referenced member "MyClass.methodWithTwoParams"
1822
export function inheritLocalOptionTwoFunction(): void;
1923

20-
// @internal
21-
enum internalEnum {
22-
}
23-
2424
interface IStructuredTypeInherit {
2525
thisIsTypeLiteral: [{name: string, age: number}];
2626
}

‎libraries/api-extractor/testInputs/example3/example3-output.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@
351351
"referenceType": "code",
352352
"scopeName": "",
353353
"packageName": "",
354-
"exportName": "internalEnum",
354+
"exportName": "_internalEnum",
355355
"memberName": ""
356356
}
357357
],

‎libraries/api-extractor/testInputs/example3/src/MyClass.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
export enum inheritLocalOptionOne {
55
}
66

7-
/**
7+
/**
88
* {@inheritdoc MyClass.methodWithTwoParams }
99
*/
1010
// (Error #1) methodWithTwoParams not a member of MyClass
@@ -27,7 +27,7 @@ export enum inheritEnumValues {
2727
}
2828

2929
/**
30-
* We will try to inheritdoc the documentation for
30+
* We will try to inheritdoc the documentation for
3131
* one of the enum value's documentation.
3232
*/
3333
export enum sourceEnumValuesDoc{
@@ -36,7 +36,7 @@ export enum sourceEnumValuesDoc{
3636
*/
3737
zero = 0,
3838
/**
39-
* We will also try to inherit this.
39+
* We will also try to inherit this.
4040
*/
4141
one = 1
4242
}
@@ -114,27 +114,27 @@ export interface IStructuredTypeSource {
114114
}
115115

116116
/**
117-
* Here we test that an error is reported when attempting to link to an
117+
* Here we test that an error is reported when attempting to link to an
118118
* internal API item.
119119
* {@link publicEnum}
120-
* {@link internalEnum}
120+
* {@link _internalEnum}
121121
*/
122122
export enum testingLinks {
123123
}
124124

125125
/**
126126
* This enum is public and any API items can safely inherit documentation
127127
* or link to this item.
128-
*
128+
*
129129
* @public
130130
*/
131131
export enum publicEnum {
132132
}
133133

134134
/**
135-
* This enum is internal and an error should be reported
135+
* This enum is internal and an error should be reported
136136
* if any API items inherit or link to this item.
137-
*
137+
*
138138
* @internal
139139
*/
140140
export enum internalEnum {

‎libraries/api-extractor/testInputs/example3/src/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* This example folder is used to test the functionality of DocItemLoader and API reference resolution.
2+
* This example folder is used to test the functionality of DocItemLoader and API reference resolution.
33
*/
44
declare const packageDescription: void;
55

@@ -16,6 +16,6 @@ export {
1616
IStructuredTypeSource,
1717
testingLinks,
1818
publicEnum,
19-
internalEnum
19+
internalEnum as _internalEnum
2020
} from './MyClass';
2121
export { default as MyClass } from './MyClass';

0 commit comments

Comments
 (0)