test: unit tests for the profile, the registry and the update check - #9
Merged
Merged
Conversation
This repo had no unit test. What it had was one end-to-end run that needs Docker and a Foundry licence, so CI never ran a line of it. Forty tests now cover the three parts that decide what a GM gets: reading the settings registry, writing and reading a profile, and the update check with the request budget around it. The rules that would be expensive to get wrong are each pinned by one test. A value whose name looks like a credential stays out of the file. A setting that changed scope is skipped rather than written somewhere else. An import carries on past a value the setting refuses. A refusal from GitHub stops the loop and caches nothing for the modules it never reached. Proven by breaking two of those guards on purpose: the scope check and the stop after a rate limit. Two tests failed, and passed again when the guards came back. `pnpm run test` runs in CI, after lint. Needs @vttforge/testing 0.12.0, whose mock fills the settings registry.
`restore()` replaces the whole `game` object, so a patch written over `game.settings.get` or `set` goes with it. That makes the two tests that patch one depend on `beforeEach` rebuilding the mock. They put it back themselves now.
Contributor
Author
|
Re-ran the end-to-end check against the published Two tests patch On the mutation check: it proves those two tests bite, and nothing wider. The secret filter, the day-long cache and the version comparison are covered by tests that have not been mutated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This repo had no unit test. What it had was one end-to-end run that needs Docker and a Foundry licence, so CI never ran a line of it.
What is covered
Forty tests over the three parts that decide what a GM gets.
The settings registry (
settings-registry.ts). Each entry narrowed to what the vault needs, core left out, registration order kept, and a package that throws from its own getter handed back asundefinedinstead of stopping an export.The profile (
profile.ts). A value whose name looks like a credential stays out of the file unless asked for. A setting that changed scope is skipped rather than written somewhere else. A setting whose package is not installed here is skipped with a reason. An import carries on past a value the setting refuses, because a profile older than the world is the ordinary case.The update check (
updates/check.ts,updates/github.ts). A player is refused before a single request is spent. An answer younger than a day costs nothing, the button asks again, and so does an answer older than a day. A refusal from GitHub stops the loop and caches nothing for the modules it never reached. A tag that is not a version is reported as unreadable rather than shown as the version to upgrade to. A 403 is told apart from the hourly budget by its header.Proof they catch something
Two guards were broken on purpose: the scope check in
applyProfile, and thebreakafter a rate limit incheckUpdates.Both passed again when the guards came back.
CI
pnpm run testruns after lint.pnpm run buildstill produces a zip with no test file in it.Needs
@vttforge/testing0.12.0, whose mock fillsgame.settings.settingsand answersregisterMenuandgame.keybindings.@vttforge/typesmoves to^0.8.0with it.