avajs / ava

Node.js test runner that lets you develop with confidence ๐Ÿš€
MIT License
20.74k stars 1.41k forks source link

Allow custom serialisers #1861

Open OmgImAlexis opened 6 years ago

OmgImAlexis commented 6 years ago

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 commented 6 years ago

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 commented 3 years ago

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 https://github.com/avajs/ava/pull/2428.

aleclarson commented 1 year ago

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

Err.. maybe it wasn't merged? ๐Ÿ˜”

novemberborn commented 1 year ago

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).