pactflow / pact-msw-adapter

Create MSW (mock-service-worker) mocks, and generate pact contracts from the recorded interactions.
MIT License
45 stars 15 forks source link

Support for running in the browser #213

Open ruud opened 4 months ago

ruud commented 4 months ago

Checklist

Before making a feature request, I have:

Feature description

We would like to integrate pact-msw-adapter into the mock server of our test framework, which is open source and available at https://github.com/modernweb-dev/web/tree/master/packages/mocks. The mock server is based on MSW and the test-runner runs in the browser.

Use case

We would like to integrate the pact-msw-adapter to make it easy for our users to create Pact contracts. We expect that by integrating it into the mock server of the web test runner, the way of working of users, does not need to change, if they want to start creating contracts.

When adding the pact-msw-adapter we run into the following problems:

It would be helpful if your very useful adapter were available as an esmodule, so that we could properly integrate it into our web test-runner.

ruud commented 4 months ago

MSW uses strict-event-emitter instead of the EventEmitter of Node. That could be a suggestion to stay compatable with MSW.

ruud commented 4 months ago

Also utils/utils.ts uses var path = require("path");.

It may be possible to separate the exports that target a node environment from the browser specific exports. Then they can be imported into the Web Test Runner separately.

For example, the creation of the contracts in the browser can be done by the web test-runner and the writing to files can be done by the node process.

YOU54F commented 3 months ago

Hey @ruud,

We would like to integrate pact-msw-adapter into the mock server of our test framework, which is open source and available at https://github.com/modernweb-dev/web/tree/master/packages/mocks. The mock server is based on MSW and the test-runner runs in the browser.

This sounds awesome, we'd love to see if we can support it.

If you can provide a pull request along with relevant tests, I'd definitely look to add that into the package.

with regards to lodash, I remember previously looking at removing it as a dep, there was a commit on the following branch but for whatever reason I never finished it off 😅

https://github.com/pactflow/pact-msw-adapter/tree/deps/rm/lodash

rcollette commented 1 month ago

To provide some context about how this would drive traffic to Pact/Pactflow @YOU54F - The Angular team is supposed to be replacing Karma with the Modern Web Test Runner in a future release.

YOU54F commented 1 month ago

interesting!

There is already an open issue for support for CDC on the project

https://github.com/modernweb-dev/web/issues/2766

edit: ahh it was created by the OP

ruud commented 1 month ago

Modern web is setting standards for testing web components (using Lit) with the web test runner. For me Angular is out of scope.