You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(Note - I'm not totally sure if this is a problem with Fastify itself or with this plugin, but it's only this plugin that appears to be affected by it)
I'm currently using Fastify and have tried to add this plugin in order to generate hypermedia links automatically from the configuration. That works great, until it comes to testing.
I'm testing with Jest, and the test process is:
Build my server
Inject requests into it
Assert the responses
This also works great, and keeps every test isolated. Except that adding this plugin in has broken it. It seems that somehow the routes added to one server instance are remembered in the next one, which means I can only ever run a single test at a time.
This is a minimal reproducing test case: (Using TypeScript but should be trivial to do in JS as well)
import fastify from 'fastify';
import { plugin as reverseRoutesPlugin } from 'fastify-reverse-routes';
async function doTest() {
const server = fastify();
server.register(reverseRoutesPlugin);
server.register(async function (fastify) {
fastify.route({
method: 'GET',
url: '/',
name: 'get_home_document',
handler: async () => {
return 'Hello';
}
});
});
try {
await server.inject({
method: 'GET',
url: '/'
});
} finally {
await server.close();
}
}
describe('Some tests', () => {
test('This is test 1', async () => {
await doTest();
});
test('This is test 2', async () => {
await doTest();
});
});
Running this will produce:
FAIL tests/broken.spec.ts
Some tests
✓ This is test 1 (71 ms)
✕ This is test 2 (2 ms)
● Some tests › This is test 2
Route with name get_home_document already registered
at Object.<anonymous> (node_modules/fastify-reverse-routes/index.js:22:15)
at Object.afterRouteAdded (node_modules/fastify/lib/route.js:223:18)
at node_modules/fastify/lib/route.js:188:25
at Object._encapsulateThreeParam (node_modules/avvio/boot.js:551:7)
at Boot.timeoutCall (node_modules/avvio/boot.js:447:5)
at Boot.callWithCbOrNextTick (node_modules/avvio/boot.js:428:19)
at Boot._after (node_modules/avvio/boot.js:273:26)
at Plugin.Object.<anonymous>.Plugin.exec (node_modules/avvio/plugin.js:132:19)
at Boot.loadPlugin (node_modules/avvio/plugin.js:274:10)
So you can clearly see that the second test fails because the route name is remembered from the first test.
Cheers
The text was updated successfully, but these errors were encountered:
(Note - I'm not totally sure if this is a problem with Fastify itself or with this plugin, but it's only this plugin that appears to be affected by it)
I'm currently using Fastify and have tried to add this plugin in order to generate hypermedia links automatically from the configuration. That works great, until it comes to testing.
I'm testing with Jest, and the test process is:
This also works great, and keeps every test isolated. Except that adding this plugin in has broken it. It seems that somehow the routes added to one server instance are remembered in the next one, which means I can only ever run a single test at a time.
This is a minimal reproducing test case: (Using TypeScript but should be trivial to do in JS as well)
Running this will produce:
So you can clearly see that the second test fails because the route name is remembered from the first test.
Cheers
The text was updated successfully, but these errors were encountered: