From 01e977f922ea29cd2994f96c18e4b3f033b1802d Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Mon, 27 Dec 2021 16:55:28 +0100 Subject: facilitate egistering dynamic content scripts with mappings data --- test/script_loader.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'test/script_loader.py') 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 -- cgit v1.2.3