aboutsummaryrefslogtreecommitdiff
path: root/compute_scripts.awk
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2021-11-24 15:53:00 +0100
committerWojtek Kosior <koszko@koszko.org>2021-12-01 21:06:28 +0100
commit93dd73600e91eb19e11f5ca57f9429a85cf0150f (patch)
tree1e90890a39798f6cd9a1c0886d1234ccc187f5b3 /compute_scripts.awk
parent463e6830faf5bb81474ac55cf95eed6ae68cc684 (diff)
downloadbrowser-extension-93dd73600e91eb19e11f5ca57f9429a85cf0150f.tar.gz
browser-extension-93dd73600e91eb19e11f5ca57f9429a85cf0150f.zip
improve unit testing approach
Unit tests were moved to their own subdirectory. Fixtures common to many unit tests were moved to test/unit/conftest.py. A facility to execute scripts in page's global scope was added. A workaround was employed to present information about errors in injected scripts. Sample unit tests for regexes in common/patterns.js were added.
Diffstat (limited to 'compute_scripts.awk')
-rw-r--r--compute_scripts.awk14
1 files changed, 11 insertions, 3 deletions
diff --git a/compute_scripts.awk b/compute_scripts.awk
index 2bad3c5..1f3b11e 100644
--- a/compute_scripts.awk
+++ b/compute_scripts.awk
@@ -105,8 +105,7 @@ function print_exports_code(filename, i, count, export_name) {
}
}
-function wrap_file(filename) {
- print "\"use strict\";\n\n({fun: (function() {\n"
+function partially_wrap_file(filename) {
print_imports_code(filename)
printf "\n\n"
@@ -114,6 +113,13 @@ function wrap_file(filename) {
printf "\n\n"
print_exports_code(filename)
+}
+
+function wrap_file(filename) {
+ print "\"use strict\";\n\n({fun: (function() {\n"
+
+ partially_wrap_file(filename)
+
print "\n})}).fun();"
}
@@ -151,7 +157,7 @@ function compute_dependencies(filename, i, count, import_name, next_file) {
}
function print_usage() {
- printf "usage: %2 compute_scripts.awk script_dependencies|wrapped_code FILENAME[...]\n",
+ printf "usage: %2 compute_scripts.awk script_dependencies|wrapped_code|partially_wrapped_code FILENAME[...]\n",
ARGV[0] > "/dev/stderr"
exit 1
}
@@ -189,6 +195,8 @@ BEGIN {
print("exports_init.js")
if (compute_dependencies(root_filename) > 0)
exit 1
+ } else if (operation == "partially_wrapped_code") {
+ partially_wrap_file(root_filename)
} else if (operation == "wrapped_code") {
wrap_file(root_filename)
} else {