trurl-master / accessibility-testing-toolkit

Accessibility Testing Toolkit
MIT License
4 stars 0 forks source link

`getAccessibleTree` as standalone package/export #2

Open nolanlawson opened 2 months ago

nolanlawson commented 2 months ago

First off, thank you for making this package – it is truly excellent! :slightly_smiling_face:

This is a small feature request. I'm looking for a way to compute the accessibility tree from a given DOM element, especially for environments without programmatic access to a browser's DevTools. (In other words: something akin to Puppeteer's accessibility.snapshot, but for environments like JSDOM or even a standalone web page.)

This library seems absolutely ideal for that, since it exports the getAccessibleTree function here:

https://github.com/trurl-master/accessibility-testing-toolkit/blob/c731954f7a42c496a20134c1f4570834c2758c3d/src/index.ts#L12

However, if I try to use this function (e.g. via esm.sh), I get an error:

ReferenceError: expect is not defined

Of course, this is because of this line:

https://github.com/trurl-master/accessibility-testing-toolkit/blob/c731954f7a42c496a20134c1f4570834c2758c3d/src/matchers.ts#L10

In other words, there is a side effect where the library expects a global expect.extend function.

This is fine for environments like Vite/Vitest, and I can trivially work around it using:

globalThis.expect = { extend: () => {} }

However, it would be great if I could just grab the getAccessibleTree function alone, without any side effects. Would you consider exposing it as a standalone package, or maybe a standalone export from this package?

trurl-master commented 2 months ago

Hey @nolanlawson!

First off, thank you for making this package – it is truly excellent! 🙂

Thank you! :) I hoped it would help somebody 🥳

Would you consider exposing it as a standalone package, or maybe a standalone export from this package?

It absolutely makes sense, but I think I would rather put matchers as a separate import. So the package doesn't depend on it by default. I'll take a look this week-end!

PS. I must warn you though, It's still very much experimental. I learn as I go, and the output may change in the future

PPS. Thank you for creating this issue! It motivates me to work on it

trurl-master commented 2 months ago

Hey @nolanlawson !

I just published 1.1.0 as beta release, could you verify if it's working for you?

nolanlawson commented 2 months ago

Yep that works perfectly! Thank you!! :bow: