From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- testing/web-platform/tests/common/subset-tests.js | 60 +++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 testing/web-platform/tests/common/subset-tests.js (limited to 'testing/web-platform/tests/common/subset-tests.js') diff --git a/testing/web-platform/tests/common/subset-tests.js b/testing/web-platform/tests/common/subset-tests.js new file mode 100644 index 0000000000..58e93413de --- /dev/null +++ b/testing/web-platform/tests/common/subset-tests.js @@ -0,0 +1,60 @@ +(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); + } + } + // Below is utility code to generate for copy/paste into tests. + // Sample usage: + // test.html?split=1000 + match = /(?:^\?|&)split=(\d+)(?:&|$)/.exec(location.search); + if (match) { + var testsPerVariant = parseInt(match[1], 10); + add_completion_callback(tests => { + var total = tests.length; + var template = ''; + var metas = []; + for (var i = 1; i < total - testsPerVariant; i = i + testsPerVariant) { + metas.push(template.replace("%s", i).replace("%s", i + testsPerVariant - 1)); + } + metas.push(template.replace("%s", i).replace("%s", "last")); + var pre = document.createElement('pre'); + pre.textContent = metas.join('\n'); + document.body.insertBefore(pre, document.body.firstChild); + document.getSelection().selectAllChildren(pre); + }); + } + } + /** + * Check if `currentSubTest` is in the subset specified in the URL. + * @param {number} currentSubTest + * @returns {boolean} + */ + function shouldRunSubTest(currentSubTest) { + return currentSubTest >= subTestStart && currentSubTest <= subTestEnd; + } + var currentSubTest = 0; + /** + * Only test a subset of tests with, e.g., `?1-10` in the URL. + * Can be used together with `` + * Sample usage: + * for (const test of tests) { + * subsetTest(async_test, test.fn, test.name); + * } + */ + function subsetTest(testFunc, ...args) { + currentSubTest++; + if (shouldRunSubTest(currentSubTest)) { + return testFunc(...args); + } + return null; + } + self.shouldRunSubTest = shouldRunSubTest; + self.subsetTest = subsetTest; +})(); -- cgit v1.2.3