From dd79cc0e465a7e1bab60010bdcc0d6e17ca3c1de Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 6 Feb 2026 23:53:00 -0500 Subject: [PATCH 1/3] test: run vitest in browser mode https://vitest.dev/guide/browser/ --- __tests__/__snapshots__/index.test.tsx.snap | 19 - .../index.test.ts} | 26 +- .../preserve-custom-attributes.test.ts | 15 + .../custom-attributes.test.ts.snap | 13 + .../__snapshots__/index.test.tsx.snap | 125 + .../dom-to-react/custom-attributes.test.ts | 18 + .../index.test.tsx} | 57 +- __tests__/index.test.tsx | 37 +- __tests__/integration/index.test.ts | 4 +- .../options/__snapshots__/trim.test.ts.snap | 20 + __tests__/options/trim.test.ts | 27 + package-lock.json | 3059 +++++++++++++---- package.json | 5 +- vitest.config.browser.mts | 19 + 14 files changed, 2629 insertions(+), 815 deletions(-) rename __tests__/{attributes-to-props.test.ts => attributes-to-props/index.test.ts} (94%) create mode 100644 __tests__/attributes-to-props/preserve-custom-attributes.test.ts create mode 100644 __tests__/dom-to-react/__snapshots__/custom-attributes.test.ts.snap create mode 100644 __tests__/dom-to-react/__snapshots__/index.test.tsx.snap create mode 100644 __tests__/dom-to-react/custom-attributes.test.ts rename __tests__/{dom-to-react.test.tsx => dom-to-react/index.test.tsx} (82%) create mode 100644 __tests__/options/__snapshots__/trim.test.ts.snap create mode 100644 __tests__/options/trim.test.ts create mode 100644 vitest.config.browser.mts diff --git a/__tests__/__snapshots__/index.test.tsx.snap b/__tests__/__snapshots__/index.test.tsx.snap index 8c56d99e..df4ceb03 100644 --- a/__tests__/__snapshots__/index.test.tsx.snap +++ b/__tests__/__snapshots__/index.test.tsx.snap @@ -340,22 +340,3 @@ exports[`replace option > replaces the element if a valid React element is retur `; - -exports[`trim option > preserves whitespace text nodes when disabled if valid in parent (default) 1`] = ` - - - - - - - - -
- hello - - - - -   -
-`; diff --git a/__tests__/attributes-to-props.test.ts b/__tests__/attributes-to-props/index.test.ts similarity index 94% rename from __tests__/attributes-to-props.test.ts rename to __tests__/attributes-to-props/index.test.ts index 46839025..47f4b30e 100644 --- a/__tests__/attributes-to-props.test.ts +++ b/__tests__/attributes-to-props/index.test.ts @@ -1,5 +1,6 @@ -import attributesToProps, { type Attributes } from '../src/attributes-to-props'; -import * as utilities from '../src/utilities'; +import attributesToProps, { + type Attributes, +} from '../../src/attributes-to-props'; it('returns empty object is argument is undefined', () => { expect(attributesToProps()).toEqual({}); @@ -353,24 +354,3 @@ describe('attributesToProps with custom attribute', () => { `); }); }); - -describe('utilities.PRESERVE_CUSTOM_ATTRIBUTES=false', () => { - const emptyProps = {}; - - beforeAll(() => { - vi.spyOn(utilities, 'PRESERVE_CUSTOM_ATTRIBUTES', 'get').mockReturnValue( - false, - ); - }); - - afterAll(() => { - vi.restoreAllMocks(); - }); - - it('omits unknown attributes', () => { - const attributes = { - unknownAttribute: 'someValue', - }; - expect(attributesToProps(attributes)).toEqual(emptyProps); - }); -}); diff --git a/__tests__/attributes-to-props/preserve-custom-attributes.test.ts b/__tests__/attributes-to-props/preserve-custom-attributes.test.ts new file mode 100644 index 00000000..4085429c --- /dev/null +++ b/__tests__/attributes-to-props/preserve-custom-attributes.test.ts @@ -0,0 +1,15 @@ +import attributesToProps from '../../src/attributes-to-props'; + +vi.mock('../../src/utilities', async (importOriginal) => ({ + ...(await importOriginal()), + PRESERVE_CUSTOM_ATTRIBUTES: false, +})); + +describe('utilities.PRESERVE_CUSTOM_ATTRIBUTES=false', () => { + const emptyProps = {}; + + it('omits unknown attributes', () => { + const attributes = { unknownAttribute: 'someValue' }; + expect(attributesToProps(attributes)).toEqual(emptyProps); + }); +}); diff --git a/__tests__/dom-to-react/__snapshots__/custom-attributes.test.ts.snap b/__tests__/dom-to-react/__snapshots__/custom-attributes.test.ts.snap new file mode 100644 index 00000000..a8bbb95c --- /dev/null +++ b/__tests__/dom-to-react/__snapshots__/custom-attributes.test.ts.snap @@ -0,0 +1,13 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`domToReact > when React version is 15 > removes unknown attributes 1`] = ` + +`; diff --git a/__tests__/dom-to-react/__snapshots__/index.test.tsx.snap b/__tests__/dom-to-react/__snapshots__/index.test.tsx.snap new file mode 100644 index 00000000..09f726b7 --- /dev/null +++ b/__tests__/dom-to-react/__snapshots__/index.test.tsx.snap @@ -0,0 +1,125 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`domToReact > converts