Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hold on to reference to MSW worker start promise #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mrloop
Copy link
Contributor

@mrloop mrloop commented Jan 10, 2024

At the moment you can't await MSW worker setup. Pretenderjs setup was not asynchronous, but MSW is. This commit allows you to await MSW setup before running tests

import setupMirageOriginal from 'ember-cli-mirage/test-support/setup-mirage';

export default function setupMirage(hooks) {
  setupMirageOriginal(hooks);

  hooks.beforeEach(function () {
    let msw = this.server.interceptor.msw;
    if (msw) return msw._startPromise;
  });
}

Ideally mirage-js would be updated to await interceptor setup but as noted in the README this is a breaking change. This commit allows you to await MSW worker setup without changing the miragejs API

@mrloop
Copy link
Contributor Author

mrloop commented Jan 10, 2024

One of my test suites regularly stalls due to not awaiting MSW setup. A lot of tests will pass but eventually hit timing issue between MSW setup and tests running.

@IanVS
Copy link
Contributor

IanVS commented May 23, 2024

@mrloop I'm very sorry, I haven't seen your activity in this repo, as I wasn't properly subscribed to all notifications. I am going to try to dust this project back off and see what I can do with it. Have you been using it, perhaps with this change patched in? If so, how has it been working for you?

@mrloop
Copy link
Contributor Author

mrloop commented Jun 12, 2024

👋🏻 @IanVS I am subscribed to notifications but this one got lost in all the noise from other notifications 😞 . Yeah using mirage-msw, and this commit, across all ember apps at work, apart from 1 which I having issues with module resolution at build time. Its the only typescript app we have, and I haven't figure out yet how to get it to build yet. When I've got that latest one working I was going to take a look at upgrading to msw 2 across all the apps. mirage-msw has been working great in general, to give you an idea of scale we've a repo just for the mirage setup routes, serializers etc, with is around 140K lines of JS this is shared between all our other repos. All our other apps will have a little bit of additional mirage configuration but the majority is in the single dedicated mirage repo. Our largest ember app has around 515K of Javascript in test files, around half of this is acceptance tests so mirage-msw is being exercised well. I was writting some tests using mirage today, and just so much nicer being able to use the network tab to look at requests, instead of printing them to console.

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.

2 participants