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

Option for enhanced debugging output during testing #561

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

olofd
Copy link

@olofd olofd commented Sep 18, 2024

Hello fellow maintainers and old friends (@klippx @tulios), hope all is well!

This PR is a joint effort between me, @J3MPA and @vaibhavar

One thing that we have struggled with a lot with in mappersmith is to know why your installed mock does not match
an outgoing request. This PR aims to change that by giving the developer much more detailed information on why their mock does not match the request. (See attached screenshot).
It should only affect test-code.

We have put the behaviour behind a new flag that you can pass to install({ enhancedDebugging: true })
My thinking is that we might want to dog food it a bit before it would replace the existing behaviour.

Unfortunately the PR includes two dependencies that you might object to, but let's have a discussion on how we can solve that. Should we add them as optionalDependencies and give instructions if enhancedDebugging is enabled?

Let us know what you think.

Olof Dahlbom

Screenshot 2024-09-18 at 21 37 58

Copy link

changeset-bot bot commented Sep 18, 2024

⚠️ No Changeset found

Latest commit: 6bd36c7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@olofd olofd changed the title [WIP] Test improvements [WIP] Option for enhanced debugging output durign testing Sep 19, 2024
@olofd olofd changed the title [WIP] Option for enhanced debugging output durign testing [WIP] Option for enhanced debugging output during testing Sep 19, 2024
@klippx klippx self-requested a review November 5, 2024 10:47
Copy link
Collaborator

@klippx klippx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for late review, I am excited to try this out. It is a very cool PR, and I realize that it needs dependencies added for it to work, since mappersmith/test is not a separate package, it's all part of a single published package. So testing suffers from productions requirement of being zero dependency, and adding deps would make production build "look bad" since it is technically not zero dep any more...

But about optionalDependencies, idk how that would work. It would install them anyway unless you did --no-optional so it doesn't help much, even if we update install instructions. But even though, I still do not think this option helps a user to A) having it during development but B) not having it in a production build (as it is today) since they only have one lockfile.

If we really want to keep things zero dependency we have to go for a monorepo and publish a separate package for @mappersmith/test for instance, which is a large effort and beyond the scope here. But in that future state we can have @mappersmith/forge as the production part without dependencies. For now, I think we have to bite the bullet and just allow dependencies.

Comment on lines +272 to +275
"dependencies": {
"diff": "^7.0.0",
"tty-table": "^4.2.3"
}
Copy link
Collaborator

@klippx klippx Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would this work?

https://docs.npmjs.com/cli/v7/configuring-npm/package-json#peerdependenciesmeta

Suggested change
"dependencies": {
"diff": "^7.0.0",
"tty-table": "^4.2.3"
}
"peerDependencies": {
"diff": "^7.0.0",
"tty-table": "^4.2.3"
},
"peerDependenciesMeta": {
"diff": {
"optional": true
},
"tty-table": {
"optional": true
}
}

I guess since this PR aims to be in "experimentation" mode we could consider have it like this for now even though it is a wonkier install experience for the user.

I am not proposing this change, just asking if you have considered it and how you feel about it.

function MockRequest(id, props) {
this.id = id

this.mockName = props.mockName ? props.mockName : this.id
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe interpolate a name from the id, something like:

Suggested change
this.mockName = props.mockName ? props.mockName : this.id
this.mockName = props.mockName ? props.mockName : `Mock#${this.id}`

enhancedDebugging: false,
}
) => {
options.enhancedDebugging = enhancedDebugging
originalGateway = configs.gateway
Copy link
Collaborator

@klippx klippx Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you think if there is a way to "globally" enable enhancedDebugging via configs (GlobalConfigs) object? Would be very nice if a user could do perhaps something like

export const configs: GlobalConfigs = {
  test: {
    experimentalEnhancedMockResponseOutputFormat: true
  }
}

@klippx klippx changed the title [WIP] Option for enhanced debugging output during testing Option for enhanced debugging output during testing Nov 5, 2024
@@ -11,3 +11,4 @@ tsconfig.tsbuildinfo
tmp/
dist/
.vscode/
.yarn/cache
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, we are weird, but revert this. And check in the changes of yarn/cache folder :)

Otherwise CI breaks, it wants the cached entries (faster CI).

@@ -0,0 +1,285 @@
import { sortedUrl, toSortedQueryString } from '../mocks/mock-utils'
import { Request } from '../request'
import colors from '@colors/colors'
Copy link
Collaborator

@klippx klippx Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dependency is missing, and the test suite fails without it on CI. For you it might work due to a transitive dependency from Karma.

UPDATE:

Actually, this is not working for TSUP which wants to emit ESM output. You can reproduce with yarn tsup.

I think that due to these packages are not ESM, it will be quite hard (dare I say impossible?) to get it to work... 😭

Are there any alternative ESM packages we can use instead?

@olofd
Copy link
Author

olofd commented Nov 5, 2024

Sorry for late review, I am excited to try this out. It is a very cool PR, and I realize that it needs dependencies added for it to work, since mappersmith/test is not a separate package, it's all part of a single published package. So testing suffers from productions requirement of being zero dependency, and adding deps would make production build "look bad" since it is technically not zero dep any more...

But about optionalDependencies, idk how that would work. It would install them anyway unless you did --no-optional so it doesn't help much, even if we update install instructions. But even though, I still do not think this option helps a user to A) having it during development but B) not having it in a production build (as it is today) since they only have one lockfile.

If we really want to keep things zero dependency we have to go for a monorepo and publish a separate package for @mappersmith/test for instance, which is a large effort and beyond the scope here. But in that future state we can have @mappersmith/forge as the production part without dependencies. For now, I think we have to bite the bullet and just allow dependencies.

No problem with later review. Been equally busy on my end tbh.

It was mostly this dependency discussion I wanted to raise before moving forward with the PR.

Another alternative would ofc. to internalize all the dependent code in a neat place under /test while we are evaluating this?

I could try doing that if you think it’s a good idea.

There is a great cleanliness of having zero deps and I really do not want to ruin that either.

@klippx
Copy link
Collaborator

klippx commented Nov 5, 2024

As you can see, I tried my best to get this branch working in #563

But even if the mappersmith PR looks green, the smoke test fails when trying to use mappersmith/test from an ESM project. I have tested this in our ESM monorepo and it is exactly the same error.

This means we have to solve this problem before merging. I can try to get it working in it's current state, but it might be best if you find ESM compatible options and relieve me from the stress and pain of trying to cover up of the anti pattern of using non-ESM modules in a library whose goal it is to emit ESM.

@klippx
Copy link
Collaborator

klippx commented Nov 5, 2024

@olofd and Jens and Vaibav, Feel free to join mappersmith discord server to get quicker discussion and a way to ping each other https://discord.gg/TfAk625Z

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