0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00
verdaccio/packages/ui-components/vitest/vitestSerializer.ts
Juan Picado 4f6609a072
final migration to vitest remove jest (#4978)
* migrate vitest ui-components

* migrate vitest ui-components

* fix e2e

* cleanup
2024-12-07 21:48:32 +01:00

31 lines
986 B
TypeScript

import { SnapshotSerializer } from 'vitest';
const serializer: SnapshotSerializer = {
serialize(val, config, indentation, depth, refs, printer) {
for (const className of [...val.classList]) {
if (className.startsWith('css-')) {
const hashEnd = className.indexOf('-', 4);
if (hashEnd >= 0) {
val.classList.replace(className, 'makeStyles' + className.substring(hashEnd));
} else {
val.classList.remove(className);
}
}
}
if (!val.classList.length) {
val.removeAttribute('class');
}
return printer(val, config, indentation, depth, refs);
},
test(val) {
return val instanceof Element && [...val.classList].some((name) => name.startsWith('css-'));
},
};
/**
* An object snapshot serializer that removes dynamic CSS classes (generated by makeStyle) from DOM elements.
*
* `css-hash-suffix` is transformed into `makeStyles-suffix`
* `css-hash` is removed
*/
export default serializer;