question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ambiguous URL not prioritized with Use

See original GitHub issue

Prerequisites

Environment check

  • I’m using the latest msw version
  • I’m using Node.js version 14 or higher

Browsers

Chromium (Chrome, Brave, etc.)

Reproduction repository

https://github.com/bgantzler/examples/tree/handler-order-with-use

Reproduction steps

cd examples/with-jest yarn yarn test

The test that fails is the one that should succeed, the one the succeeds is the one that should fail.

Current behavior

I am running into the same issue as https://github.com/mswjs/msw/issues/742. I do have the routes in the correct order. The difference is I am using use. Is use acting differently than when the routes are first defined. This is a simple example to get the point across. For me, no routes are being defined when the worker is created. They are defined ad hoc later, so I am using a use for each.

let worker = setupWorker();

worker.use(
   rest.get('/account/referrer/stats', (req, res, ctx) => res(ctx.text('one')))
);

worker.use(
    rest.get('/account/referrer/:code', (req, res, ctx) => res(ctx.text('two')))
);

In this case, if I switch the order, it appears as if the last one defined is the always the one that is used.

Expected behavior

To be able to define routes that overlap, but allow for a prioritization of explicit routes over segmented routes when using use

In the example repo, the test that defines the specific route /login before the segment /:id is the one that fails. Since the specific was defined first (see reference issue https://github.com/mswjs/msw/issues/742), I would have expected it to succeed

The next test that defines the specific route second, I would have expected that to fail, but it succeeds. I am assuming that the one that is defined last is the one that is always being used.

Expected behaviour would be that the defining the handlers with use, the same prioritization would be respected as when defining the handlers with setupWorker.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cah-brian-gantzlercommented, Apr 8, 2022

Will have to land the other stuff first, then see what I can do here.

1reaction
cah-brian-gantzlercommented, Apr 6, 2022

Ok after reading through this I understand the problem. Missed the pre-append part (it is in your docs) which means I need to do the opposite of what was in the referenced issue.

I have gotten farther. Now on to the next issue.

For your FYI, I am converting an large set of tests from pretender to msw. In pretender, then server is created, then all the handlers are created. The code I have does this in different spots, so use makes similar drop in replacement, rather than re-designing the whole test suite to create the handlers first, then create the worker.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ambiguous URLs and their effect on Exchange 2010 to ...
In this scenario where both the MAPI/RPC and HTTP workloads are using the same FQDN you cannot successfully move the FQDN to CAS...
Read more >
.net - Possible to specify a priority namespace when there are ...
Using TheNameSpace for the default, and fully qualified namespace for the other(s). I'd be interested tho if anyone knows a way to prioritize...
Read more >
Ambiguous Anchor Text - Equalize Digital
A link is considered ambiguous if a user has to read the text surrounding the link or see nearby images in order to...
Read more >
Ambiguous rule match · Issue #99 · boostorg/docca - GitHub
In XSLT, I typically only need to use priority="1" (as in the above fix), just to make the priority higher than 0.5.
Read more >
Providing Context for Ambiguous Link Phrases - TPGi
This article demonstrates a technique that allows ambiguous link phrases to be rendered visually in a page, whilst making sense to screen ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found