Yoast / YoastSEO.js

Analyze content on a page and give SEO feedback as well as render a snippet preview.
GNU General Public License v3.0
403 stars 170 forks source link

Rewrite tree unit tests to use the YAML-string to tree parser. #2112

Open hansjovis opened 5 years ago

hansjovis commented 5 years ago

In #2110 a way to parse YAML-strings to a structured tree is introduced. We should rewrite the unit tests that build and compare trees to use this new functionality.

Example:

    it( "can build a tree from HTML source code", () => {
        const html = "<section>This? is a section.</section>";

        const paragraph = new Paragraph();
        paragraph.sourceStartIndex = 9;
        paragraph.sourceEndIndex = 28;
        paragraph.text = "This? is a section.";

        const section = new StructuredNode( "section" );
        section.sourceStartIndex = 0;
        section.sourceEndIndex = 38;
        section.children = [ paragraph ];

        const expected = new StructuredNode( "root" );
        expected.sourceStartIndex = 0;
        expected.sourceEndIndex = 38;
        expected.children = [ section ];

        const tree = buildTree( html );

        expect( tree.toString() ).toEqual( expected.toString() );
    } );

Should be transformed to:

    it( "can build a tree from HTML source code", () => {
        const html = "<section>This? is a section.</section>";
                cons expected = buildTreeFromYaml`
Structured:
  tag: root
  sourceStartIndex: 9
  sourceEndIndex: 38
  children:
    - Structured:
         tag: section
         sourceStartIndex: 0
         sourceEndIndex: 38
         children:
           - Paragraph:
                sourceStartIndex: 9
                sourceEndIndex: 28
                text: This? is a section.
`;
        const tree = buildTree( html );
        expect( tree.toString() ).toEqual( expected.toString() );
    } );

requires #2081