Skip to content

Commit

Permalink
Improve unit test usability (#2463)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kzar authored Mar 8, 2024
1 parent 02deca4 commit 3b02ef5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions unit-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 3b02ef5

Please sign in to comment.