1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-12-19 14:38:53 +00:00

test script tag

This commit is contained in:
c-basalt
2024-12-30 17:54:45 -05:00
parent fb474064ee
commit b87a0582c5
4 changed files with 64 additions and 13 deletions

View File

@@ -32,6 +32,48 @@ class Base:
def test_execute(self):
self.assertEqual(self.jsi.execute('console.log("Hello, world!");'), 'Hello, world!')
def test_execute_dom_parse(self):
if 'dom' not in self.jsi._SUPPORTED_FEATURES:
self.skipTest('DOM not supported')
self.assertEqual(self.jsi.execute(
'console.log(document.getElementById("test-div").innerHTML);',
location='https://example.com',
html='<html><body><div id="test-div">Hello, world!</div></body></html>'),
'Hello, world!')
def test_execute_dom_script(self):
if 'dom' not in self.jsi._SUPPORTED_FEATURES:
self.skipTest('DOM not supported')
self.assertEqual(self.jsi.execute(
'console.log(document.getElementById("test-div").innerHTML);',
location='https://example.com',
html='''<html><body>
<div id="test-div"></div>
<script src="https://example.com/script.js"></script>
<script type="text/javascript">
document.getElementById("test-div").innerHTML = "Hello, world!"
</script>
</body></html>'''),
'Hello, world!')
def test_execute_dom_script_with_error(self):
if 'dom' not in self.jsi._SUPPORTED_FEATURES:
self.skipTest('DOM not supported')
if self.jsi.JSI_KEY == 'PhantomJS':
self.skipTest('PhantomJS does not catch errors')
self.assertEqual(self.jsi.execute(
'console.log(document.getElementById("test-div").innerHTML);',
location='https://example.com',
html='''<html><body>
<div id="test-div"></div>
<script src="https://example.com/script.js"></script>
<script type="text/javascript">
document.getElementById("test-div").innerHTML = "Hello, world!"
a = b; // Undefined variable assignment
</script>
</body></html>'''),
'Hello, world!')
class TestDeno(Base.TestExternalJSI):
_JSI_CLASS = DenoJSI