|
| 1 | +import { readFileSync } from 'fs'; |
| 2 | + |
1 | 3 | import { ClassDeclaration } from '../src/declarations/ClassDeclaration';
|
2 | 4 | import { DeclarationVisibility } from '../src/declarations/DeclarationVisibility';
|
3 | 5 | import { DefaultDeclaration } from '../src/declarations/DefaultDeclaration';
|
@@ -560,6 +562,106 @@ describe('TypescriptParser', () => {
|
560 | 562 | expect(usages).toContain('complexComp');
|
561 | 563 | expect(usages).toContain('SingleComp');
|
562 | 564 | });
|
| 565 | + |
| 566 | + it('should parse functions inside {}', () => { |
| 567 | + const usages = parsed.usages; |
| 568 | + |
| 569 | + expect(usages).toContain('myFunc'); |
| 570 | + }); |
| 571 | + |
| 572 | + it('should parse component functions inside {}', () => { |
| 573 | + const usages = parsed.usages; |
| 574 | + |
| 575 | + expect(usages).toContain('MyFunc'); |
| 576 | + }); |
| 577 | + |
| 578 | + it('should parse a component inside a map', () => { |
| 579 | + const usages = parsed.usages; |
| 580 | + |
| 581 | + expect(usages).toContain('AnotherComp'); |
| 582 | + expect(usages).toContain('foobarVariable'); |
| 583 | + }); |
| 584 | + |
| 585 | + it('should parse a function inside a map', () => { |
| 586 | + const usages = parsed.usages; |
| 587 | + |
| 588 | + expect(usages).toContain('valFunc'); |
| 589 | + }); |
| 590 | + |
| 591 | + it('should parseSource correctly', async () => { |
| 592 | + const parsedSource = await parser.parseSource(readFileSync(file).toString()); |
| 593 | + |
| 594 | + expect(parsedSource.usages).toMatchSnapshot(); |
| 595 | + }); |
| 596 | + }); |
| 597 | + |
| 598 | + describe('TSX: Specific cases', () => { |
| 599 | + |
| 600 | + const testFiles = [ |
| 601 | + { |
| 602 | + filename: '1.tsx', |
| 603 | + requiredUsages: [ |
| 604 | + 'sortBy', |
| 605 | + 'Divider', |
| 606 | + 'Checkbox', |
| 607 | + ], |
| 608 | + }, |
| 609 | + { |
| 610 | + filename: '2.tsx', |
| 611 | + requiredUsages: [ |
| 612 | + 'ActionDelete', |
| 613 | + 'Divider', |
| 614 | + 'cloneDeep', |
| 615 | + ], |
| 616 | + }, |
| 617 | + { |
| 618 | + filename: '3.tsx', |
| 619 | + requiredUsages: [ |
| 620 | + 'ImageEdit', |
| 621 | + 'IconButton', |
| 622 | + 'TableHeaderColumn', |
| 623 | + ], |
| 624 | + }, |
| 625 | + ]; |
| 626 | + |
| 627 | + for (const testFile of testFiles) { |
| 628 | + |
| 629 | + it('should parse the correct usages with "parseFile"', async () => { |
| 630 | + const file = getWorkspaceFile(`typescript-parser/specific-cases/${testFile.filename}`); |
| 631 | + const parsed = await parser.parseFile(file, rootPath); |
| 632 | + |
| 633 | + for (const usage of testFile.requiredUsages) { |
| 634 | + expect(parsed.usages).toContain(usage); |
| 635 | + } |
| 636 | + |
| 637 | + expect(parsed.usages).toMatchSnapshot(); |
| 638 | + }); |
| 639 | + |
| 640 | + it('should parse the correct usages with "parseFiles"', async () => { |
| 641 | + const file = getWorkspaceFile(`typescript-parser/specific-cases/${testFile.filename}`); |
| 642 | + const parsed = (await parser.parseFiles([file], rootPath))[0]; |
| 643 | + |
| 644 | + for (const usage of testFile.requiredUsages) { |
| 645 | + expect(parsed.usages).toContain(usage); |
| 646 | + } |
| 647 | + |
| 648 | + expect(parsed.usages).toMatchSnapshot(); |
| 649 | + }); |
| 650 | + |
| 651 | + it('should parse the correct usages with "parseSource"', async () => { |
| 652 | + const file = getWorkspaceFile(`typescript-parser/specific-cases/${testFile.filename}`); |
| 653 | + const fileSource = readFileSync(file).toString(); |
| 654 | + const parsed = await parser.parseSource(fileSource); |
| 655 | + |
| 656 | + for (const usage of testFile.requiredUsages) { |
| 657 | + expect(parsed.usages).toContain(usage); |
| 658 | + } |
| 659 | + |
| 660 | + expect(parsed.usages).toMatchSnapshot(); |
| 661 | + }); |
| 662 | + |
| 663 | + } |
| 664 | + |
563 | 665 | });
|
564 | 666 |
|
565 | 667 | });
|
0 commit comments