From 3b02ef537dbff2b48d55966eefbb976fa8e9abb1 Mon Sep 17 00:00:00 2001 From: Dave Vandyke Date: Fri, 8 Mar 2024 12:40:59 +0000 Subject: [PATCH] Improve unit test usability (#2463) The unit tests were a little tricky to work with, for failures the wrong line numbers were given and console.log() didn't work. Let's try to improve the situation: 1. Have the unit tests bundled with inline sourcemaps, that can then be used to report the line numbers correctly. 2. Add a note to the unit test's README to mention to use console.warn() or console.error() instead of console.log(). Note: Unfortunately adding inline sourcemaps seems to slow down Karma/Jasmine quite a bit. In the future, we might consider using a faster test runner, or one that supports external sourcemaps. --- Makefile | 2 +- unit-test/README.md | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 52bce17987..b4a04ed220 100755 --- a/Makefile +++ b/Makefile @@ -67,7 +67,7 @@ watch: ## unit-test: Run the unit tests. ESBUILD_TESTS = unit-test/background/*.js unit-test/background/**/*.js unit-test/ui/**/*.js unit-test/shared-utils/*.js unit-test: - $(ESBUILD) --outdir=build/test --inject:./unit-test/inject-chrome-shim.js $(ESBUILD_TESTS) + $(ESBUILD) --sourcemap=inline --outdir=build/test --inject:./unit-test/inject-chrome-shim.js $(ESBUILD_TESTS) node_modules/.bin/karma start karma.conf.js .PHONY: unit-test diff --git a/unit-test/README.md b/unit-test/README.md index 248d195667..f455e97666 100644 --- a/unit-test/README.md +++ b/unit-test/README.md @@ -12,3 +12,10 @@ Tests can be run as follows: - `npm test`: Run all tests (both node and browser). - `npm run test.unit`: Run only browser-based unit tests. - `npm run test.node`: Run only node-based unit tests. + +## Notes + +- To reduce the amount of noise when running the tests, `console.log()` and + `console.debug()` output is suppressed. If you need to log something to the + console while working on the tests use `console.warn()` or `console.error()` + instead.