github.com/web-platform-tests/wpt.fyi@v0.0.0-20240530210107-70cf978996f1/webapp/components/test/test-file-results.html (about)

     1  <!doctype html>
     2  <html>
     3  <head>
     4    <meta charset="utf-8">
     5    <script src="../../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
     6    <script src="../../node_modules/wct-browser-legacy/browser.js"></script>
     7  
     8    <script type="module" src="../test-runs.js"></script>
     9    <script type="module" src="../test-file-results.js"></script>
    10  </head>
    11  <body>
    12    <test-fixture id="test-file-results-fixture">
    13      <template>
    14        <test-file-results
    15          path="/2dcontext/the-canvas-state/2d.state.saverestore.bitmap.html">
    16        </test-file-results>
    17      </template>
    18    </test-fixture>
    19    <script type="module">
    20  import { TestFileResults } from '../test-file-results.js';
    21  import { TEST_RUNS_DATA } from './util/helpers.js';
    22  import { PolymerElement } from '../../node_modules/@polymer/polymer/polymer-element.js';
    23  
    24  suite('TestFileResults', () => {
    25    let tfr;
    26  
    27    setup(() => {
    28      const id = 'test-file-results-fixture';
    29      document.getElementById(id)
    30        .setAttribute('test-runs', JSON.stringify(TEST_RUNS_DATA));
    31      tfr = fixture(id);
    32    });
    33  
    34    test('instanceof Polymer.Element', () => {
    35      assert.isTrue(new TestFileResults() instanceof PolymerElement);
    36      assert.isTrue(document.createElement('test-file-results') instanceof PolymerElement);
    37    });
    38  
    39    suite('static get is()', () => {
    40      test('test-file-results', () => {
    41        assert.equal(TestFileResults.is, 'test-file-results');
    42      });
    43    });
    44  
    45    suite('resultsURL', () => {
    46      test('v1 url', () => {
    47        expect(
    48          tfr.resultsURL(
    49            TEST_RUNS_DATA[1],
    50            '/example/test/path'
    51          )).to.equal('https://storage.googleapis.com/wptd/03d67ae5d9/edge-15-windows-10/example/test/path');
    52      });
    53      test('v2 url', () => {
    54        expect(
    55          tfr.resultsURL(
    56            TEST_RUNS_DATA[0],
    57            '/example/test/path'
    58          )).to.equal('https://storage.googleapis.com/wptd/53c5bf648c/chrome-63.0-linux/example/test/path');
    59      });
    60    });
    61  
    62    suite('TestFileResults.prototype.*', () => {
    63      suite('statusName', () => {
    64        test('no subtests', () => {
    65          assert.equal(tfr.statusName(0), 'Test status');
    66        });
    67        test('> 0 subtests', () => {
    68          assert.equal(tfr.statusName(1), 'Harness status');
    69          assert.equal(tfr.statusName(99), 'Harness status');
    70        });
    71      });
    72  
    73      suite('resultsTableHeaders', () => {
    74        test('empty array', () => {
    75          expect(tfr.resultsTableHeaders([])).to.deep.equal([
    76            {name: '', results: []},
    77            {name: 'Duration', results: []},
    78          ]);
    79        });
    80  
    81        test('null', () => {
    82          expect(tfr.resultsTableHeaders([null])).to.deep.equal([
    83            {name: '', results: [{status: null, message: null}]},
    84            {name: 'Duration', results: [{status: null, message: null}]},
    85          ]);
    86        });
    87  
    88        test('missing fields', () => {
    89          const resultsPerTestRun = [
    90            {status: 'PASS', duration: '1000'},
    91            {status: 'PASS', message: 'OK'},
    92          ];
    93          expect(tfr.resultsTableHeaders(resultsPerTestRun)).to.deep.equal([
    94            {
    95              name: '',
    96              results: [
    97                {status: 'PASS', message: undefined},
    98                {status: 'PASS', message: 'OK'}
    99              ]
   100            },
   101            {
   102              name: 'Duration',
   103              results: [
   104                {status: '1 seconds', message: null},
   105                {status: 'N/A', message: null}
   106              ]
   107            },
   108          ]);
   109        });
   110      });
   111  
   112      suite('filterResultsTableBySearch', () => {
   113        const resultsTable = [
   114          {
   115            name: 'Harness status',
   116            results: [
   117              {status: 'OK', message: null},
   118              {status: 'OK', message: null}
   119            ]
   120          },
   121          {
   122            name: 'Duration',
   123            results: [
   124              {status: '0.5 seconds', message: null},
   125              {status: '0.6 seconds', message: null}
   126            ]
   127          },
   128          {
   129            name: 'subtest foo',
   130            results: [
   131              {status: 'PASS', message: null},
   132              {status: 'PASS', message: null}
   133            ]
   134          },
   135          {
   136            name: 'subtest bar',
   137            results: [
   138              {status: 'PASS', message: null},
   139              {status: 'PASS', message: null}
   140            ]
   141          }
   142        ];
   143        const searchResults = {results: [
   144          {
   145            test: '/foo/bar.html',
   146            subtests: ['subtest foo']
   147          }
   148        ]};
   149  
   150        test('smoke test', () => {
   151          expect(
   152            tfr.filterResultsTableBySearch('/foo/bar.html', resultsTable, searchResults)
   153          ).to.deep.equal([
   154            {
   155              name: 'Harness status',
   156              results: [
   157                {status: 'OK', message: null},
   158                {status: 'OK', message: null}
   159              ]
   160            },
   161            {
   162              name: 'Duration',
   163              results: [
   164                {status: '0.5 seconds', message: null},
   165                {status: '0.6 seconds', message: null}
   166              ]
   167            },
   168            {
   169              name: 'subtest foo',
   170              results: [
   171                {status: 'PASS', message: null},
   172                {status: 'PASS', message: null}
   173              ]
   174            },
   175          ]);
   176        });
   177  
   178        test('empty values', () => {
   179          expect(tfr.filterResultsTableBySearch('', null, searchResults)).to.equal(null);
   180          expect(tfr.filterResultsTableBySearch('', resultsTable, null)).to.deep.equal(resultsTable);
   181        });
   182  
   183        test('unmatching paths', () => {
   184          expect(
   185            tfr.filterResultsTableBySearch('/foo/notbar.html', resultsTable, searchResults)
   186          ).to.deep.equal(resultsTable);
   187        });
   188      });
   189  
   190      suite('mergeNamesInto', () => {
   191        test('empty', () => {
   192          const names = ['a', 'b'];
   193          const allNames = [];
   194          tfr.mergeNamesInto(names, allNames);
   195          expect(allNames).to.deep.equal(names);
   196        });
   197  
   198        test('missing before', () => {
   199          const names = ['a', 'aa', 'ab', 'b', 'c'];
   200          const allNames = ['a', 'b'];
   201          tfr.mergeNamesInto(names, allNames);
   202          expect(allNames).to.deep.equal(names);
   203        });
   204  
   205        test('missing after', () => {
   206          const before = ['a', 'x', 'b'];
   207          const after = ['a', 'b', 'y', 'z'];
   208          let result = [...before];
   209          tfr.mergeNamesInto(after, result);
   210          expect(result).to.deep.equal(['a', 'x', 'b', 'y', 'z']);
   211  
   212          result = [...after];
   213          tfr.mergeNamesInto(before, result);
   214          expect(result).to.deep.equal(['a', 'x', 'b', 'y', 'z']);
   215        });
   216      });
   217  
   218      suite('shuffleScreenshots', () => {
   219        test('path in screenshots - first', () => {
   220          const rawScreenshots = {
   221            '/foo/bar/baz.html': 'sha1:060311f9cd4c5b09202a034c4961ca42a3f83ce2',
   222            '/foo/bar/baz-ref.html': 'sha1:cf459fa6f04d2c0a18bc30762941289d700224bd',
   223          };
   224          const screenshots = tfr.shuffleScreenshots('/foo/bar/baz.html', rawScreenshots);
   225          assert.lengthOf(Object.keys(rawScreenshots), 2);
   226          assert.deepEqual(Array.from(screenshots.entries()), [
   227            ['/foo/bar/baz.html', 'sha1:060311f9cd4c5b09202a034c4961ca42a3f83ce2'],
   228            ['/foo/bar/baz-ref.html', 'sha1:cf459fa6f04d2c0a18bc30762941289d700224bd'],
   229          ]);
   230        });
   231  
   232        test('path in screenshots - not first', () => {
   233          const rawScreenshots = {
   234            '/foo/bar/baz-ref.html': 'sha1:cf459fa6f04d2c0a18bc30762941289d700224bd',
   235            '/foo/bar/baz.html': 'sha1:060311f9cd4c5b09202a034c4961ca42a3f83ce2',
   236          };
   237          const screenshots = tfr.shuffleScreenshots('/foo/bar/baz.html', rawScreenshots);
   238          assert.lengthOf(Object.keys(rawScreenshots), 2);
   239          assert.deepEqual(Array.from(screenshots.entries()), [
   240            ['/foo/bar/baz.html', 'sha1:060311f9cd4c5b09202a034c4961ca42a3f83ce2'],
   241            ['/foo/bar/baz-ref.html', 'sha1:cf459fa6f04d2c0a18bc30762941289d700224bd'],
   242          ]);
   243        });
   244  
   245        test('path not in screenshots', () => {
   246          const rawScreenshots = {
   247            '/foo/bar/baz.html': 'sha1:060311f9cd4c5b09202a034c4961ca42a3f83ce2',
   248            '/foo/bar/baz-ref.html': 'sha1:cf459fa6f04d2c0a18bc30762941289d700224bd',
   249            '/foo/bar/baz-ref2.html': 'sha1:cf459fa6f04d2c0a18bc30762941289d700224bd',
   250          };
   251          const screenshots = tfr.shuffleScreenshots('/not-foo/bar.html', rawScreenshots);
   252          assert.lengthOf(Object.keys(rawScreenshots), 3);
   253          assert.lengthOf(Array.from(screenshots.entries()), 3);
   254        });
   255      });
   256    });
   257  });
   258  </script>
   259  </body>
   260  </html>