diff --git a/test/test_jsinterp_external.py b/test/test_jsinterp_external.py
index 7f66c032a..9cc4c970f 100644
--- a/test/test_jsinterp_external.py
+++ b/test/test_jsinterp_external.py
@@ -1,9 +1,14 @@
#!/usr/bin/env python3
-# Allow direct execution
+from __future__ import annotations
import os
+import dataclasses
+import datetime
+import time
import sys
import unittest
+import http.cookiejar
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -11,14 +16,43 @@
from test.helper import (
FakeYDL,
)
+from yt_dlp.cookies import YoutubeDLCookieJar
from yt_dlp.jsinterp.common import ExternalJSI
from yt_dlp.jsinterp._deno import DenoJSI, DenoJITlessJSI, DenoJSDomJSI
from yt_dlp.jsinterp._phantomjs import PhantomJSJSI
+@dataclasses.dataclass
+class NetscapeFields:
+ name: str
+ value: str
+ domain: str
+ path: str
+ secure: bool
+ expires: int | None
+
+ def to_cookie(self):
+ return http.cookiejar.Cookie(
+ 0, self.name, self.value,
+ None, False,
+ self.domain, True, self.domain.startswith('.'),
+ self.path, True,
+ self.secure, self.expires, False,
+ None, None, {},
+ )
+
+ def expire_str(self):
+ return datetime.datetime.fromtimestamp(
+ self.expires, datetime.timezone.utc).strftime('%a, %d %b %Y %H:%M:%S GMT')
+
+ def __eq__(self, other: NetscapeFields | http.cookiejar.Cookie):
+ return all(getattr(self, attr) == getattr(other, attr) for attr in ['name', 'value', 'domain', 'path', 'secure', 'expires'])
+
+
class Base:
class TestExternalJSI(unittest.TestCase):
_JSI_CLASS: type[ExternalJSI] = None
+ maxDiff = 2000
def setUp(self):
self.ydl = FakeYDL()
@@ -52,6 +86,7 @@ def test_execute_dom_script(self):