aboutsummaryrefslogtreecommitdiffstats
path: root/tests/wpt/web-platform-tests/common/subset-tests.js
blob: 1810320e66085660991cff8f83a2a29dc5eb96cc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Only test a subset of tests with, e.g., ?1-10 in the URL.
// Can be used together with <meta name="variant" content="...">
// Sample usage:
// for (const test of tests) {
//   subsetTest(async_test, test.fn, test.name);
// }
(function() {
  var subTestStart = 0;
  var subTestEnd = Infinity;
  var match;
  if (location.search) {
      match = /(?:^\?|&)(\d+)-(\d+|last)(?:&|$)/.exec(location.search);
      if (match) {
        subTestStart = parseInt(match[1], 10);
        if (match[2] !== "last") {
            subTestEnd = parseInt(match[2], 10);
        }
      }
  }
  function shouldRunSubTest(currentSubTest) {
    return currentSubTest >= subTestStart && currentSubTest <= subTestEnd;
  }
  var currentSubTest = 0;
  function subsetTest(testFunc, ...args) {
    currentSubTest++;
    if (shouldRunSubTest(currentSubTest)) {
      return testFunc(...args);
    }
    return null;
  }
  self.shouldRunSubTest = shouldRunSubTest;
  self.subsetTest = subsetTest;
})();