Closed weyert closed 2 years ago
I have tested these changes by run the build
-command and copy the contents of the generated lib
-directory to the lib
-directory in my project that uses this package and then wrote the following Jest unit test:
import { fromTraffic } from '@mswjs/source'
import { default as json } from './__data__/health-check.json'
it.only('should throw exception when all services are unavailable', async () => {
server.use(
...fromTraffic(json),
// rest.get('https://localhost:30001/-/health', (_req, res, _ctx) => {
// res.networkError('Network Error')
// }),
// rest.get('https://localhost:30002/-/health', (_req, res, _ctx) => {
// res.networkError('Network Error')
// }),
)
await expect(controller.check()).rejects.toThrow('Service Unavailable Exception')
})
For me, after these changes, the above unit test was passing without errors. The project is a Nest.js project using Typescript.
Note I currently don't have a ESM only project ready to test if the ESM module part of the package works as expected. I will try to do make one tomorrow.
It'd be great to have automated tests in different formats (CJS/ESM) that help us catch regressions regarding module format incompatibilities.
@weyert, I'm sorry, I think I've just messed up the commit authorship after rewording the commit. Could you please git commit --amend --author=X
with your proper name + GitHub email? Thanks.
@weyert, I'm sorry, I think I've just messed up the commit authorship after rewording the commit. Could you please
git commit --amend --author=X
with your proper name + GitHub email? Thanks.
I think I did now but not 100% sure
It'd be great to have automated tests in different formats (CJS/ESM) that help us catch regressions regarding module format incompatibilities.
Yeah, good idea, I am not sure what the best approach is. Maybe a simple script that .mjs
(for ESM) and .js
(for CJS) then tries to load the package?
@weyert, you've set the commit author to @tapico-weyert. If it's the expected result then everything is okay!
This has been released in v0.1.0!
Make sure to always update to the latest version (npm i @mswjs/source@latest
) to get the newest features and bug fixes.
Predictable release automation by @ossjs/release.
Added the package
tsup
to assist in bundling@mswjs/source
-package so it both supports CommonJS and ESM modules. Thepackage.json
file has been modified so the appropriate properties for the modernexports
-approach of exporting, and the oldermain
-module
combination.During building and running the tests the
fromOpenApi
had issues to pass the tests or build due to the way theSwaggerParser
utility class was exporter. The code has been updated so it refers to thedeferences
-function viaSwaggerParser.deferences()
instead of trying to instantiate the class.For this reason the
tsconfig.json
has been updated so that it enablesesModuleInterop
andallowSyntheticDefaultImports
after this change the package build and bundled successfully withtsup
and passed the unit tests, before errors like below were shown: