diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
commit | 0b6210cd37b68b94252cb798598b12974a20e1c1 (patch) | |
tree | e371686554a877842d95aa94f100bee552ff2a8e /test/wpt/tests/common/subset-tests-by-key.js | |
parent | Initial commit. (diff) | |
download | node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.tar.xz node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.zip |
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | test/wpt/tests/common/subset-tests-by-key.js | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/test/wpt/tests/common/subset-tests-by-key.js b/test/wpt/tests/common/subset-tests-by-key.js new file mode 100644 index 0000000..483017a --- /dev/null +++ b/test/wpt/tests/common/subset-tests-by-key.js @@ -0,0 +1,83 @@ +(function() { + var subTestKeyPattern = null; + var match; + var collectKeys = false; + var collectCounts = false; + var keys = {}; + var exclude = false; + if (location.search) { + match = /(?:^\?|&)(include|exclude)=([^&]+)?/.exec(location.search); + if (match) { + subTestKeyPattern = new RegExp(`^${match[2]}$`); + if (match[1] === 'exclude') { + exclude = true; + } + } + // Below is utility code to generate <meta> for copy/paste into tests. + // Sample usage: + // test.html?get-keys + match = /(?:^\?|&)get-keys(&get-counts)?(?:&|$)/.exec(location.search); + if (match) { + collectKeys = true; + if (match[1]) { + collectCounts = true; + } + add_completion_callback(() => { + var metas = []; + var template = '<meta name="variant" content="?include=%s">'; + if (collectCounts) { + template += ' <!--%s-->'; + } + for (var key in keys) { + var meta = template.replace("%s", key); + if (collectCounts) { + meta = meta.replace("%s", keys[key]); + } + metas.push(meta); + } + var pre = document.createElement('pre'); + pre.textContent = metas.join('\n') + '\n'; + document.body.insertBefore(pre, document.body.firstChild); + document.getSelection().selectAllChildren(pre); + }); + } + } + /** + * Check if `key` is in the subset specified in the URL. + * @param {string} key + * @returns {boolean} + */ + function shouldRunSubTest(key) { + if (key && subTestKeyPattern) { + var found = subTestKeyPattern.test(key); + if (exclude) { + return !found; + } + return found; + } + return true; + } + /** + * Only test a subset of tests with `?include=Foo` or `?exclude=Foo` in the URL. + * Can be used together with `<meta name="variant" content="...">` + * Sample usage: + * for (const test of tests) { + * subsetTestByKey("Foo", async_test, test.fn, test.name); + * } + */ + function subsetTestByKey(key, testFunc, ...args) { + if (collectKeys) { + if (collectCounts && key in keys) { + keys[key]++; + } else { + keys[key] = 1; + } + } + if (shouldRunSubTest(key)) { + return testFunc(...args); + } + return null; + } + self.shouldRunSubTest = shouldRunSubTest; + self.subsetTestByKey = subsetTestByKey; +})(); |