summaryrefslogtreecommitdiff
path: root/test/script_loader.py
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2021-12-27 16:55:28 +0100
committerWojtek Kosior <koszko@koszko.org>2021-12-27 16:55:28 +0100
commit01e977f922ea29cd2994f96c18e4b3f033b1802d (patch)
tree0c5b3ceb13bf364c209ef097644d81e6e04ea91d /test/script_loader.py
parentb590eaa2f64ead3384eadc6fe58f6358aa1a0478 (diff)
downloadbrowser-extension-01e977f922ea29cd2994f96c18e4b3f033b1802d.tar.gz
browser-extension-01e977f922ea29cd2994f96c18e4b3f033b1802d.zip
facilitate egistering dynamic content scripts with mappings data
Diffstat (limited to 'test/script_loader.py')
-rw-r--r--test/script_loader.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/test/script_loader.py b/test/script_loader.py
index edf8143..f66f9ae 100644
--- a/test/script_loader.py
+++ b/test/script_loader.py
@@ -43,10 +43,12 @@ def make_relative_path(path):
script_cache = {}
-def load_script(path):
+def load_script(path, code_to_add=None):
"""
`path` is a .js file path in Haketilo sources. It may be absolute or
- specified relative to Haketilo's project directory.
+ specified relative to Haketilo's project directory. `code_to_add` is
+ optional code to be appended to the end of the main file being imported.
+ it can contain directives like `#IMPORT`.
Return a string containing script from `path` together with all other
scripts it depends on. Dependencies are wrapped in the same way Haketilo's
@@ -57,13 +59,15 @@ def load_script(path):
a dependency to be substituted by a mocked value.
"""
path = make_relative_path(path)
- if str(path) in script_cache:
- return script_cache[str(path)]
+ key = f'{str(path)}:{code_to_add}' if code_to_add is not None else str(path)
+ if key in script_cache:
+ return script_cache[key]
awk = subprocess.run(['awk', '-f', str(awk_script), '--', '-D', 'MOZILLA',
- '-D', 'MV2', '--output=amalgamate-js:' + str(path)],
+ '-D', 'MV2', '-D', 'TEST', '-D', 'UNIT_TEST',
+ '--output=amalgamate-js:' + key],
stdout=subprocess.PIPE, cwd=script_root, check=True)
script = awk.stdout.decode()
- script_cache[str(path)] = script
+ script_cache[key] = script
return script