Hold on to reference to MSW worker start promise#16
Hold on to reference to MSW worker start promise#16mrloop wants to merge 1 commit intomiragejs:mainfrom
Conversation
|
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. |
|
@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? |
|
👋🏻 @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. |
|
I think this problem goes away a bit when no longer relying on With that baseline, once msw is applied, the only change really needed is to await that startMirage call since's its now async import { settled, type TestContext } from '@ember/test-helpers'
import type { Server } from 'miragejs'
import startMirage from 'my-app/mirage/servers/default'
interface Context extends TestContext {
server?: Server
}
export function setupMirage(hooks: NestedHooks) {
- hooks.beforeEach(function (this: Context) {
- this.server = startMirage({ environment: 'test' })
+ hooks.beforeEach(async function (this: Context) {
+ this.server = await startMirage({ environment: 'test' })
})That being said, merging this seems harmless and might help those who haven't yet made the leap from ember-cli-mirage |
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
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