3
3
import os
4
4
import re
5
5
import subprocess
6
- import tempfile
6
+ import typing
7
7
from collections import namedtuple
8
8
9
+ from playwright .path_utils import get_file_dirname
10
+
11
+ _dirname = get_file_dirname ()
12
+
9
13
TestCase = namedtuple ("TestCase" , ["api" , "file" , "test" ])
10
14
11
15
12
- def pytest_test_cases ():
16
+ def pytest_test_cases () -> typing . Generator [ TestCase , None , None ] :
13
17
p = subprocess .run (
14
18
["pytest" , "--browser" , "chromium" , "--collect-only" , "-q" ],
19
+ cwd = _dirname / ".." / "tests" ,
15
20
stdout = subprocess .PIPE ,
21
+ check = True ,
16
22
)
17
23
regex = (
18
24
r"tests/(?P<api>a?sync)/test_(?P<file>.*)\.py::test_(?P<test>.*)\[chromium\]"
@@ -24,32 +30,44 @@ def pytest_test_cases():
24
30
)
25
31
26
32
27
- def jest_test_cases (playwright_js_path ):
28
- env = os .environ .copy ()
29
- env ["REPORT_ONLY" ] = "true"
30
- with tempfile .NamedTemporaryFile () as results :
31
- subprocess .run (
32
- ["npx" , "jest" , "--json" , "--outputFile" , results .name ],
33
- env = env ,
34
- cwd = playwright_js_path ,
35
- stderr = subprocess .DEVNULL ,
36
- )
33
+ def jest_test_cases (playwright_js_path : str ) -> typing .Generator [TestCase , None , None ]:
34
+ p = subprocess .run (
35
+ [
36
+ "node" ,
37
+ os .path .join ("test" , "runner" ),
38
+ "test" ,
39
+ "--trial-run" ,
40
+ "--reporter" ,
41
+ "json" ,
42
+ ],
43
+ cwd = playwright_js_path ,
44
+ stdout = subprocess .PIPE ,
45
+ stderr = subprocess .DEVNULL ,
46
+ check = True ,
47
+ )
48
+
49
+ tests = json .loads (p .stdout .decode ())
50
+ for test in [* tests ["pending" ], * tests ["passes" ], * tests ["failures" ]]:
51
+ regex = r"(.*/)?(?P<file>[^/]+)\.spec\.[jt]s$"
52
+
53
+ match = re .match (regex , test ["file" ])
54
+ if not match :
55
+ continue
56
+
57
+ file = match .group ("file" )
37
58
38
- for test_suite in json .load (results )["testResults" ]:
39
- regex = r"(.*/)?(?P<file>[^/]+)\.spec\.[jt]s$"
40
- file = re .match (regex , test_suite ["name" ]).group ("file" )
41
- for assertion in test_suite ["assertionResults" ]:
42
- yield TestCase ("sync" , normalized (file ), normalized (assertion ["title" ]))
43
- yield TestCase (
44
- "async" , normalized (file ), normalized (assertion ["title" ])
45
- )
59
+ yield TestCase ("sync" , normalized (file ), normalized (test ["title" ]))
60
+ yield TestCase ("async" , normalized (file ), normalized (test ["title" ]))
46
61
47
62
48
- def normalized (original ):
49
- return re .sub (r"[^a-z_]" , "_" , original , flags = re .IGNORECASE )
63
+ def normalized (original : str ) -> str :
64
+ cleaned = re .sub (r"[^a-z0-9_]" , "_" , original , flags = re .IGNORECASE )
65
+ cleaned = re .sub (r"[_]+" , "_" , cleaned )
66
+ cleaned = cleaned .strip ("_" )
67
+ return cleaned
50
68
51
69
52
- def main ():
70
+ def main () -> None :
53
71
parser = argparse .ArgumentParser ()
54
72
parser .add_argument (
55
73
"--playwright-js-path" ,
@@ -69,12 +87,13 @@ def main():
69
87
javascript_tests = set (jest_test_cases (args .playwright_js_path ))
70
88
71
89
if args .api :
72
- javascript_tests = set ([x for x in javascript_tests if x [ 0 ] == args .api ])
90
+ javascript_tests = set ([x for x in javascript_tests if x . api == args .api ])
73
91
74
92
missing = javascript_tests .difference (python_tests )
75
93
found = javascript_tests .intersection (python_tests )
76
94
77
95
print ("MISSING, MISPELLED, OR MISNAMED:" )
96
+ print ("=" * 80 )
78
97
for (api , file , test ) in sorted (missing ):
79
98
print (f"{ api } /test_{ file } .py::test_{ test } " )
80
99
0 commit comments