|
| 1 | +// NOTE: THIS SOURCE FILE IS FOR DEBUGGING PURPOSES ONLY. |
| 2 | +// IT IS INVOKED BY THE "Run.cmd" AND "Debug.cmd" BATCH FILES. |
| 3 | + |
| 4 | +import * as ts from 'typescript'; |
| 5 | +import Analyzer from './Analyzer'; |
| 6 | +import ApiFileGenerator from './generators/ApiFileGenerator'; |
| 7 | +import TypeDocGenerator from './generators/TypeDocGenerator'; |
| 8 | +import ApiJsonGenerator from './generators/ApiJsonGenerator'; |
| 9 | +import { IDocItem } from './IDocItem'; |
| 10 | +import { IApiDefinitionReference } from './IApiDefinitionReference'; |
| 11 | +import DocItemLoader from './DocItemLoader'; |
| 12 | +import TestFileComparer from './TestFileComparer'; |
| 13 | +import JsonFile from './JsonFile'; |
| 14 | +import ApiStructuredType from './definitions/ApiStructuredType'; |
| 15 | +import ApiDocumentation from './definitions/ApiDocumentation'; |
| 16 | + |
| 17 | +const analyzer: Analyzer = new Analyzer(); |
| 18 | + |
| 19 | +/** |
| 20 | + * Dummy class wrapping ApiDocumentation to test its protected methods |
| 21 | + */ |
| 22 | +let myDocumentedClass: ApiStructuredType; |
| 23 | +class TestApiDocumentation extends ApiDocumentation { |
| 24 | + constructor() { |
| 25 | + super(myDocumentedClass, analyzer.docItemLoader, (msg: string) => { return; }); |
| 26 | + } |
| 27 | + |
| 28 | + public tokenizeDocs(docs: string): string[] { |
| 29 | + return this._tokenizeDocs(docs); |
| 30 | + } |
| 31 | + |
| 32 | + public parseDocsBlock(tokens: string[], startingIndex: number, tagName?: string): string { |
| 33 | + return this._parseDocsBlock(tokens, startingIndex, tagName); |
| 34 | + } |
| 35 | + |
| 36 | + public parseDocsInline(token: string): string { |
| 37 | + return this._parseDocsInline(token); |
| 38 | + } |
| 39 | + |
| 40 | + public parseApiReferenceExpression(apiDefinitionRef: string): IApiDefinitionReference { |
| 41 | + return this._parseApiReferenceExpression(apiDefinitionRef); |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +analyzer.analyze({ |
| 46 | + compilerOptions: { |
| 47 | + target: ts.ScriptTarget.ES5, |
| 48 | + module: ts.ModuleKind.CommonJS, |
| 49 | + moduleResolution: ts.ModuleResolutionKind.NodeJs, |
| 50 | + experimentalDecorators: true, |
| 51 | + jsx: ts.JsxEmit.React, |
| 52 | + rootDir: '../../spfx-core/sp-loader' |
| 53 | + }, |
| 54 | + entryPointFile: '../../spfx-core/sp-loader/src/index.ts', // local/bundles/platform-exports.ts', |
| 55 | + otherFiles: ['../../spfx-core/sp-loader/typings/tsd.d.ts'] |
| 56 | +}); |
| 57 | + |
| 58 | +const apiFileGenerator: ApiFileGenerator = new ApiFileGenerator(); |
| 59 | +apiFileGenerator.writeApiFile('./lib/DebugRun.api.ts', analyzer); |
| 60 | + |
| 61 | +const typeDocGenerator: TypeDocGenerator = new TypeDocGenerator(); |
| 62 | +typeDocGenerator.writeApiFile('./lib/DebugRun.typedoc.ts', analyzer); |
| 63 | + |
| 64 | +const apiJsonGenerator: ApiJsonGenerator = new ApiJsonGenerator(); |
| 65 | +apiJsonGenerator.writeJsonFile('./lib/DebugRun.json', analyzer); |
| 66 | + |
| 67 | +/** |
| 68 | + * Debugging inheritdoc expression parser. |
| 69 | + * Analyzer on example2 is needed for testing the parser. |
| 70 | + */ |
| 71 | +analyzer.analyze({ |
| 72 | + compilerOptions: { |
| 73 | + target: ts.ScriptTarget.ES5, |
| 74 | + module: ts.ModuleKind.CommonJS, |
| 75 | + moduleResolution: ts.ModuleResolutionKind.NodeJs, |
| 76 | + experimentalDecorators: true, |
| 77 | + jsx: ts.JsxEmit.React, |
| 78 | + rootDir: './testInputs/example2' |
| 79 | + }, |
| 80 | + entryPointFile: './testInputs/example2/index.ts', // local/bundles/platform-exports.ts', |
| 81 | + otherFiles: [] |
| 82 | +}); |
| 83 | + |
| 84 | +myDocumentedClass = analyzer.package.getSortedMemberItems() |
| 85 | + .filter(apiItem => apiItem.name === 'MyDocumentedClass')[0] as ApiStructuredType; |
| 86 | +const apiDoc: TestApiDocumentation = new TestApiDocumentation(); |
| 87 | + |
| 88 | +/** |
| 89 | + * Put test cases here |
| 90 | + */ |
| 91 | +let apiReferenceExpr: string = '@microsoft/sp-core-library:Guid.equals'; |
| 92 | +let actual: IApiDefinitionReference; |
| 93 | +actual = apiDoc.parseApiReferenceExpression(apiReferenceExpr); |
| 94 | + |
| 95 | +apiReferenceExpr = '@microsoft/sp-core-library:Guid'; |
| 96 | +actual = apiDoc.parseApiReferenceExpression(apiReferenceExpr); |
| 97 | + |
| 98 | +apiReferenceExpr = 'sp-core-library:Guid'; |
| 99 | +actual = apiDoc.parseApiReferenceExpression(apiReferenceExpr); |
| 100 | + |
| 101 | +apiReferenceExpr = 'Guid.equals'; |
| 102 | +actual = apiDoc.parseApiReferenceExpression(apiReferenceExpr); |
| 103 | + |
| 104 | +apiReferenceExpr = 'Guid'; |
| 105 | +actual = apiDoc.parseApiReferenceExpression(apiReferenceExpr); |
| 106 | + |
| 107 | +// Should report error |
| 108 | +apiReferenceExpr = 'sp-core-library:Guid:equals'; |
| 109 | +try { |
| 110 | + actual = apiDoc.parseApiReferenceExpression(apiReferenceExpr); |
| 111 | +} catch (error) { |
| 112 | + console.log(error); |
| 113 | +} |
| 114 | + |
| 115 | +/** |
| 116 | + * Debugging DocItemLoader |
| 117 | + */ |
| 118 | +const apiDefinitionRef: IApiDefinitionReference = { |
| 119 | + scopeName: '@microsoft', |
| 120 | + packageName: 'sp-core-library', |
| 121 | + exportName: 'DisplayMode', |
| 122 | + memberName: '' |
| 123 | +}; |
| 124 | + |
| 125 | +const docItemLoader: DocItemLoader = new DocItemLoader('./testInputs/example2'); |
| 126 | +/* tslint:disable:no-unused-variable */ |
| 127 | +const apiDocItemNotInCache: IDocItem = docItemLoader.getItem(apiDefinitionRef); |
| 128 | +JsonFile.saveJsonFile('./lib/inheritedDoc-output.json', JSON.stringify(apiDocItemNotInCache)); |
| 129 | +TestFileComparer.assertFileMatchesExpected('./lib/inheritedDoc-output.json', './testInputs/inheritedDoc-output.json'); |
| 130 | +/* tslint:disable:no-unused-variable */ |
| 131 | +const apiDocItemInCache: IDocItem = docItemLoader.getItem(apiDefinitionRef); |
0 commit comments