mirror of
https://github.com/cockpit-project/cockpit.git
synced 2026-11-03 21:49:50 -09:00
test_browser: collect coverage for qunit tests
This will collect coverage data from the test runs and write .lcov files into `lcov/` with names like `qunit-base1-test-fsinfo-html.info.gz`. Nothing is done with these files yet, but you can manually inspect them using `lcov`.
This commit is contained in:
parent
db449c8df3
commit
50bb15f521
3 changed files with 16 additions and 0 deletions
1
build.js
1
build.js
|
|
@ -37,6 +37,7 @@ const pkgOptions = {
|
|||
|
||||
// context options for qunit tests in qunit/
|
||||
const qunitOptions = {
|
||||
...!production ? { sourcemap: "linked" } : {},
|
||||
bundle: true,
|
||||
minify: false,
|
||||
nodePaths,
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import re
|
|||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import urllib.parse
|
||||
from bisect import bisect_left
|
||||
from typing import Any, Mapping, Sequence
|
||||
|
||||
|
|
@ -159,6 +160,12 @@ def get_dist_map(package):
|
|||
|
||||
|
||||
def get_distfile(url, dist_map):
|
||||
path = urllib.parse.urlparse(url).path
|
||||
if path.startswith('/qunit/'):
|
||||
relpath = path[1:]
|
||||
if os.path.exists(relpath) and os.path.exists(f'{relpath}.map'):
|
||||
return DistFile(path[1:])
|
||||
|
||||
parts = url.split("/")
|
||||
if len(parts) < 3 or "cockpit" not in parts:
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
import contextlib
|
||||
import glob
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
from typing import AsyncIterator
|
||||
|
||||
import lcov
|
||||
import pytest
|
||||
from webdriver_bidi import ChromiumBidi
|
||||
from yarl import URL
|
||||
|
|
@ -60,6 +62,9 @@ async def test_browser(html: str) -> None:
|
|||
spawn_test_server() as base_url,
|
||||
ChromiumBidi(headless=os.environ.get('TEST_SHOW_BROWSER', '0') == '0') as browser
|
||||
):
|
||||
await browser.cdp("Profiler.enable")
|
||||
await browser.cdp("Profiler.startPreciseCoverage", callCount=False, detailed=True)
|
||||
|
||||
await browser.bidi(
|
||||
'browsingContext.navigate',
|
||||
context=browser.context,
|
||||
|
|
@ -101,6 +106,9 @@ async def test_browser(html: str) -> None:
|
|||
if error_message is not None:
|
||||
pytest.fail(f'Test failed: {error_message}')
|
||||
|
||||
coverage = await browser.cdp("Profiler.takePreciseCoverage")
|
||||
lcov.write_lcov(coverage['result']['result'], outlabel=re.sub(r'[^A-Za-z0-9]+', '-', html))
|
||||
|
||||
|
||||
# run test-timeformat.ts in different time zones: west/UTC/east
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
Loading…
Reference in a new issue