1
- import { TSDocConfiguration } from '@microsoft/tsdoc' ;
1
+ import { Standardization , TSDocConfiguration , TSDocTagDefinition , TSDocTagSyntaxKind } from '@microsoft/tsdoc' ;
2
2
import * as path from 'path' ;
3
3
4
4
import { TSDocConfigFile } from '../TSDocConfigFile' ;
@@ -207,6 +207,8 @@ test('Load p4', () => {
207
207
208
208
test ( 'Re-serialize p3' , ( ) => {
209
209
const configFile : TSDocConfigFile = TSDocConfigFile . loadForFolder ( path . join ( __dirname , 'assets/p3' ) ) ;
210
+ expect ( configFile . hasErrors ) . toBe ( false ) ;
211
+
210
212
// This is the data from p3/tsdoc.json, ignoring its "extends" field.
211
213
expect ( configFile . saveToObject ( ) ) . toMatchInlineSnapshot ( `
212
214
Object {
@@ -229,6 +231,8 @@ test('Re-serialize p3 without defaults', () => {
229
231
parserConfiguration . clear ( true ) ;
230
232
231
233
const defaultsConfigFile : TSDocConfigFile = TSDocConfigFile . loadFromParser ( parserConfiguration ) ;
234
+ expect ( defaultsConfigFile . hasErrors ) . toBe ( false ) ;
235
+
232
236
// This is the default configuration created by the TSDocConfigFile constructor.
233
237
expect ( defaultsConfigFile . saveToObject ( ) ) . toMatchInlineSnapshot ( `
234
238
Object {
@@ -238,6 +242,7 @@ test('Re-serialize p3 without defaults', () => {
238
242
` ) ;
239
243
240
244
const configFile : TSDocConfigFile = TSDocConfigFile . loadForFolder ( path . join ( __dirname , 'assets/p3' ) ) ;
245
+ expect ( configFile . hasErrors ) . toBe ( false ) ;
241
246
configFile . noStandardTags = true ;
242
247
configFile . configureParser ( parserConfiguration ) ;
243
248
@@ -275,6 +280,8 @@ test('Re-serialize p3 with defaults', () => {
275
280
const parserConfiguration : TSDocConfiguration = new TSDocConfiguration ( ) ;
276
281
277
282
const defaultsConfigFile : TSDocConfigFile = TSDocConfigFile . loadFromParser ( parserConfiguration ) ;
283
+ expect ( defaultsConfigFile . hasErrors ) . toBe ( false ) ;
284
+
278
285
// This is the default configuration created by the TSDocConfigFile constructor.
279
286
expect ( defaultsConfigFile . saveToObject ( ) ) . toMatchInlineSnapshot ( `
280
287
Object {
@@ -392,6 +399,7 @@ test('Re-serialize p3 with defaults', () => {
392
399
` ) ;
393
400
394
401
const configFile : TSDocConfigFile = TSDocConfigFile . loadForFolder ( path . join ( __dirname , 'assets/p3' ) ) ;
402
+ expect ( configFile . hasErrors ) . toBe ( false ) ;
395
403
configFile . configureParser ( parserConfiguration ) ;
396
404
397
405
const mergedConfigFile : TSDocConfigFile = TSDocConfigFile . loadFromParser ( parserConfiguration ) ;
@@ -532,6 +540,7 @@ test('Re-serialize p3 with defaults', () => {
532
540
533
541
test ( 'Test noStandardTags for p5' , ( ) => {
534
542
const configFile : TSDocConfigFile = TSDocConfigFile . loadForFolder ( path . join ( __dirname , 'assets/p5' ) ) ;
543
+ expect ( configFile . hasErrors ) . toBe ( false ) ;
535
544
536
545
const configuration : TSDocConfiguration = new TSDocConfiguration ( ) ;
537
546
configFile . configureParser ( configuration ) ;
@@ -542,10 +551,76 @@ test('Test noStandardTags for p5', () => {
542
551
543
552
test ( 'Test noStandardTags for p6' , ( ) => {
544
553
const configFile : TSDocConfigFile = TSDocConfigFile . loadForFolder ( path . join ( __dirname , 'assets/p6' ) ) ;
554
+ expect ( configFile . hasErrors ) . toBe ( false ) ;
545
555
546
556
const configuration : TSDocConfiguration = new TSDocConfiguration ( ) ;
547
557
configFile . configureParser ( configuration ) ;
548
558
549
559
// noStandardTags=false because tsdoc.json overrides tsdoc-base1.json
550
560
expect ( configuration . tagDefinitions . length ) . toBeGreaterThan ( 0 ) ;
551
561
} ) ;
562
+
563
+ test ( 'Test loadFromObject()' , ( ) => {
564
+ const configuration : TSDocConfiguration = new TSDocConfiguration ( ) ;
565
+ configuration . clear ( true ) ;
566
+
567
+ configuration . addTagDefinitions ( [
568
+ new TSDocTagDefinition ( { syntaxKind : TSDocTagSyntaxKind . ModifierTag , tagName : '@tag1' } ) ,
569
+ new TSDocTagDefinition ( { syntaxKind : TSDocTagSyntaxKind . BlockTag , tagName : '@tag2' , allowMultiple : true } ) ,
570
+ new TSDocTagDefinition ( { syntaxKind : TSDocTagSyntaxKind . InlineTag , tagName : '@tag3' , allowMultiple : true } ) ,
571
+ ] ) ;
572
+
573
+ configuration . setSupportForTag ( configuration . tagDefinitions [ 0 ] , true ) ;
574
+
575
+ const configFile : TSDocConfigFile = TSDocConfigFile . loadFromParser ( configuration ) ;
576
+ expect ( configFile . hasErrors ) . toBe ( false ) ;
577
+ const jsonObject : unknown = configFile . saveToObject ( ) ;
578
+
579
+ const configFile2 : TSDocConfigFile = TSDocConfigFile . loadFromObject ( jsonObject ) ;
580
+ expect ( configFile2 . hasErrors ) . toBe ( false ) ;
581
+ const jsonObject2 : unknown = configFile2 . saveToObject ( ) ;
582
+
583
+ expect ( jsonObject2 ) . toMatchInlineSnapshot ( `
584
+ Object {
585
+ "$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
586
+ "noStandardTags": true,
587
+ "supportForTags": Object {
588
+ "@tag1": true,
589
+ },
590
+ "tagDefinitions": Array [
591
+ Object {
592
+ "syntaxKind": "modifier",
593
+ "tagName": "@tag1",
594
+ },
595
+ Object {
596
+ "allowMultiple": true,
597
+ "syntaxKind": "block",
598
+ "tagName": "@tag2",
599
+ },
600
+ Object {
601
+ "allowMultiple": true,
602
+ "syntaxKind": "inline",
603
+ "tagName": "@tag3",
604
+ },
605
+ ],
606
+ }
607
+ ` ) ;
608
+
609
+ expect ( jsonObject2 ) . toStrictEqual ( jsonObject ) ;
610
+ } ) ;
611
+
612
+ test ( 'Test loadFromObject() with extends' , ( ) => {
613
+ const configuration : TSDocConfiguration = new TSDocConfiguration ( ) ;
614
+ configuration . clear ( true ) ;
615
+
616
+ const configFile : TSDocConfigFile = TSDocConfigFile . loadFromParser ( configuration ) ;
617
+ expect ( configFile . hasErrors ) . toBe ( false ) ;
618
+ const jsonObject : unknown = configFile . saveToObject ( ) ;
619
+
620
+ // eslint-disable-next-line
621
+ ( jsonObject as any ) [ 'extends' ] = [ './some-file.json' ] ;
622
+
623
+ expect ( ( ) => {
624
+ TSDocConfigFile . loadFromObject ( jsonObject ) ;
625
+ } ) . toThrowError ( 'The "extends" field cannot be used with TSDocConfigFile.loadFromObject()' ) ;
626
+ } ) ;
0 commit comments