1 #! /usr/bin/env python3
6 assert len(sys
.argv
) == 2
7 MOCHI_PATH
= pathlib
.Path(sys
.argv
[1])
8 assert MOCHI_PATH
.suffix
== ".html"
10 TEST_PATH
= MOCHI_PATH
.with_suffix(".solo.html")
13 def read_local_file(include
):
14 inc_path
= MOCHI_PATH
.parent
15 file_path
= inc_path
/ include
18 return file_path
.read_bytes()
23 SIMPLETEST_REPLACEMENT
= b
"""
26 // SimpleTest.js replacement
28 function debug(text) {
29 var elem = document.getElementById('mochi-to-testcase-output');
30 elem.innerHTML += '\\n<br/>\\n' + text;
33 function ok(val, text) {
34 var status = val ? 'Test <font color=\\'green\\'>passed</font>: '
35 : 'Test <font color=\\'red\\' >FAILED</font>: ';
39 function todo(val, text) {
40 var status = val ? 'Test <font color=\\'orange\\'>UNEXPECTED PASS</font>: '
41 : 'Test <font color=\\'blue\\' >todo</font>: ';
45 function addLoadEvent(func) {
46 window.addEventListener('load', func);
50 waitForExplicitFinish: () => {},
52 requestFlakyTimeout: () => {},
56 pushPrefEnv: async (env, callback = null) => {
57 console.log(`SpecialPowers.pushPrefEnv(${JSON.stringify(env)})`);
58 await new Promise(res => {
65 popPrefEnv: async (callback = null) => {
66 console.log('SpecialPowers.popPrefEnv()');
67 await new Promise(res => {
76 <div id='mochi-to-testcase-output'></div>
80 INCLUDE_PATTERN
= re
.compile(b
"<script\\s*src=['\"](.*)\\.js['\"]>\\s*</script>")
81 CSS_PATTERN
= re
.compile(
82 b
"<link\\s*rel=['\"]stylesheet['\"]\\s*href=['\"]([^=>]*)['\"]>"
85 with
open(TEST_PATH
, "wb") as fout
:
86 with
open(MOCHI_PATH
, "rb") as fin
:
89 for css
in CSS_PATTERN
.findall(line
):
91 print("Ignoring stylesheet: " + css
.decode())
93 for inc
in INCLUDE_PATTERN
.findall(line
):
95 if inc
== b
"/MochiKit/MochiKit":
98 if inc
== b
"/tests/SimpleTest/SimpleTest":
99 print("Injecting SimpleTest replacement")
100 fout
.write(SIMPLETEST_REPLACEMENT
)
103 inc_js
= inc
.decode() + ".js"
104 inc_data
= read_local_file(inc_js
)
106 print("Warning: Unknown JS file ignored: " + inc_js
)
109 print("Injecting include: " + inc_js
)
110 fout
.write(b
"\n<script>\n// Imported from: " + inc_js
.encode() + b
"\n")
112 fout
.write(b
"\n</script>\n")