Skip to content

Tests

The test framework is Vitest. The tests are in tests/, and vitest.config.ts configures them.

  • vitest.config.ts uses the plugin WxtVitest from WXT. The plugin gives each test the same environment as the extension code: the automatic imports, and browser bound to @webext-core/fake-browser. Thus a test can import lib/throttle.ts directly.
  • No test opens a browser, and no test sends a request to patreon.com.
  • tests/throttle.test.ts waits for real time, because a delay is the subject of the test. It needs approximately 20 seconds. The timeout in vitest.config.ts is 60 seconds.
  • tests/normalize.test.ts reads .api-dumps/. Git ignores that directory, thus a new copy of the repository has no recorded answer. The tests then report as skipped and give the command that records one. They do not fail.
  • The tests print nothing that comes out of a dump. A test name has no campaign ID, and each assertion becomes a count or a boolean before Vitest sees it. Vitest prints the value that an assertion received when the assertion fails, and that value can be account data (see rules for account data).
  • npm run normalize:check, npm run throttle:check, and npm run docs:check each run one test file. Use them when you change one area.

Write each new test in tests/, with the name <area>.test.ts.