Skip to content

test: assert the fastify 5 plugin dependency error - #136

Open
mikaelkaron wants to merge 1 commit into
mercurius-js:mainfrom
mikaelkaron:fix/fastify-5-dependency-error
Open

test: assert the fastify 5 plugin dependency error#136
mikaelkaron wants to merge 1 commit into
mercurius-js:mainfrom
mikaelkaron:fix/fastify-5-dependency-error

Conversation

@mikaelkaron

Copy link
Copy Markdown

npm test does not pass on main: registration - should error if mercurius is not loaded still expects the AssertionError that fastify 4 raised for an unmet plugin dependency.

✖ registration - should error if mercurius is not loaded
  + [FastifyError: The dependency 'mercurius' of plugin 'mercurius-auth' is not registered] {
  +   code: 'FST_ERR_PLUGIN_DEPENDENCY_NOT_REGISTERED',
  - [AssertionError: The dependency 'mercurius' of plugin 'mercurius-auth' is not registered] {
  -   code: 'ERR_ASSERTION',

Fastify 5 raises a FastifyError coded FST_ERR_PLUGIN_DEPENDENCY_NOT_REGISTERED, so the test asserts that code and the message instead.

It also gets a t.plan. Without one, the assertion inside the catch is skipped — and the test passes — whenever registration does not throw at all, which is precisely the regression this test exists to catch.

Verification

  • npm test passes: lint, 123 tests with 2 skipped, tstyche 47 assertions.
  • No source change, test only.

`registration - should error if mercurius is not loaded` expected the
`AssertionError` fastify 4 raised for an unmet plugin dependency. Fastify 5
raises a `FastifyError` coded `FST_ERR_PLUGIN_DEPENDENCY_NOT_REGISTERED`
instead, so the assertion has failed since the move to fastify 5 and `npm test`
does not pass on main.

The test now asserts that code and the message. It also gets a `t.plan`, without
which the assertion in the `catch` is skipped entirely — and the test passes —
whenever registration does not throw, which is the failure mode this test exists
to catch.

Signed-off-by: Mikael Karon <mikael@karon.se>
@mikaelkaron

Copy link
Copy Markdown
Author

@mcollina bump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant