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

Allow custom serialisers #1861

Open
OmgImAlexis opened this issue Jul 13, 2018 · 4 comments
Open

Allow custom serialisers #1861

OmgImAlexis opened this issue Jul 13, 2018 · 4 comments
Milestone

Comments

@OmgImAlexis
Copy link

Description

Currently if a HTML element is passed to t.snapshot it copies the code as is to the .md file.

I was hoping to pass a function to the serialiser so I could pretty print the content before it's saved to the .md file.

Relevant Links

Example: app-header.spec.js.md

Example: html serialiser for Jest


It’s designed to do that, but it’s not exposed in AVA. Happy to work out details if you open an issue.

Ref: https://twitter.com/novemberborn/status/1017718535274065920

@novemberborn
Copy link
Member

The library underlying t.snapshot() and t.deepEqual() is concordance. It was designed to be extensible (see @concordance/react, but we've never exposed an interface to do so within AVA.

Writing such extensions is a fair bit more difficult than for Jest's snapshot mechanism, but I guess it won't get easier until we start encouraging people to write their own 😄

Question though, how do we want to configure these extensions? Programmatically?

import {registerConcordancePlugin} from 'ava/extend'

Or in the configuration file, with a factory method pattern?

export default {
  plugins: [
    ({registerConcordance}) => registerConcordance()
  ]
}

We'll also need some metadata regarding the plugin that's been registered, so that if AVA encounters a snapshot without the corresponding plugin being available, it can give a useful error message.

It's been a while since I've looked at the underlying code but these are the main questions I think.

@novemberborn
Copy link
Member

I'm tentatively adding this to the 4.0 milestone, but I reckon it won't make it. We're removing our built-in React support in AVA 4 so we'd want something like this to continue supporting React projects.

See a stalled attempt in #2428.

novemberborn added a commit that referenced this issue Jan 8, 2022
Basic API for augmenting the themes and appending plugins. Fixes #1861.
@novemberborn novemberborn removed their assignment Jul 3, 2023
@aleclarson
Copy link

aleclarson commented Aug 13, 2023

I see a fix got merged, but this issue wasn't closed. Is it documented anywhere?

Err.. maybe it wasn't merged? 😔

@novemberborn
Copy link
Member

I see a fix got merged, but this issue wasn't closed. Is it documented anywhere?

Err.. maybe it wasn't merged? 😔

Concordance needs a hefty dose of maintenance, though the extensibility APIs may not change much. So yea the issue is still open and this could be picked up by anybody but it's not currently a priority for me (insofar as a side-project can have priorities).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants