Skip to content

Commit

Permalink
chore: 🔧 add patch package and jsdom
Browse files Browse the repository at this point in the history
  • Loading branch information
spences10 committed Jan 6, 2024
1 parent 929b6f0 commit e7677c9
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/svead/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"format": "prettier --write .",
"test:integration": "playwright test",
"test:unit": "vitest",
"coverage": "vitest run --coverage"
"coverage": "vitest run --coverage",
"postinstall": "patch-package"
},
"exports": {
".": {
Expand Down Expand Up @@ -65,6 +66,8 @@
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.35.1",
"jsdom": "^23.1.0",
"patch-package": "^8.0.0",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"publint": "^0.2.7",
Expand All @@ -87,4 +90,4 @@
"url": "https://github.com/spences10/svead/issues"
},
"homepage": "https://github.com/spences10/svead#readme"
}
}
57 changes: 57 additions & 0 deletions packages/svead/patches/@testing-library+svelte+4.0.5.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
diff --git a/node_modules/@testing-library/svelte/src/pure.js b/node_modules/@testing-library/svelte/src/pure.js
index 04d3cb0..2f041e0 100644
--- a/node_modules/@testing-library/svelte/src/pure.js
+++ b/node_modules/@testing-library/svelte/src/pure.js
@@ -3,7 +3,7 @@ import {
getQueriesForElement,
prettyDOM
} from '@testing-library/dom'
-import { tick } from 'svelte'
+import { tick, createRoot } from 'svelte'

const containerCache = new Set()
const componentCache = new Set()
@@ -54,18 +54,15 @@ const render = (
return { props: options }
}

- let component = new ComponentConstructor({
+ let component = createRoot(ComponentConstructor, {
target,
- ...checkProps(options)
+ ...checkProps(options),
+ ondestroy: () => componentCache.delete(component)
})

containerCache.add({ container, target, component })
componentCache.add(component)

- component.$$.on_destroy.push(() => {
- componentCache.delete(component)
- })
-
return {
container,
component,
@@ -73,18 +70,14 @@ const render = (
rerender: (options) => {
if (componentCache.has(component)) component.$destroy()

- // eslint-disable-next-line no-new
- component = new ComponentConstructor({
+ component = createRoot(ComponentConstructor, {
target,
- ...checkProps(options)
+ ...checkProps(options),
+ ondestroy: () => componentCache.delete(component)
})

containerCache.add({ container, target, component })
componentCache.add(component)
-
- component.$$.on_destroy.push(() => {
- componentCache.delete(component)
- })
},
unmount: () => {
if (componentCache.has(component)) component.$destroy()
1 change: 1 addition & 0 deletions packages/svead/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { defineConfig } from 'vitest/config';
export default defineConfig({
plugins: [sveltekit()],
test: {
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{js,ts}'],
},
});

0 comments on commit e7677c9

Please sign in to comment.