@testing-library/svelte 5.2.10 → 5.3.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ export * from "@testing-library/dom";
2
+ export { act, cleanup, fireEvent, render, setup, UnknownSvelteOptionsError } from "./pure.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -1,8 +1,8 @@
1
- export { cleanup } from "./core/index.js";
1
+ export { UnknownSvelteOptionsError } from "@testing-library/svelte-core";
2
2
  /**
3
3
  * Customize how Svelte renders the component.
4
4
  */
5
- export type SvelteComponentOptions<C extends import("./component-types.js").Component> = import("./component-types.js").Props<C> | Partial<import("./component-types.js").MountOptions<C>>;
5
+ export type SvelteComponentOptions<C extends import("@testing-library/svelte-core/types").Component> = import("@testing-library/svelte-core/types").ComponentOptions<C>;
6
6
  /**
7
7
  * Customize how Testing Library sets up the document and binds queries.
8
8
  */
@@ -13,12 +13,12 @@ export type RenderOptions<Q extends import("@testing-library/dom").Queries = typ
13
13
  /**
14
14
  * The rendered component and bound testing functions.
15
15
  */
16
- export type RenderResult<C extends import("./component-types.js").Component, Q extends import("@testing-library/dom").Queries = typeof import("@testing-library/dom/types/queries.js")> = {
16
+ export type RenderResult<C extends import("@testing-library/svelte-core/types").Component, Q extends import("@testing-library/dom").Queries = typeof import("@testing-library/dom/types/queries.js")> = {
17
17
  container: HTMLElement;
18
18
  baseElement: HTMLElement;
19
- component: import("./component-types.js").Exports<C>;
19
+ component: import("@testing-library/svelte-core/types").Exports<C>;
20
20
  debug: (el?: HTMLElement | DocumentFragment) => void;
21
- rerender: (props: Partial<import("./component-types.js").Props<C>>) => Promise<void>;
21
+ rerender: import("@testing-library/svelte-core/types").Rerender<C>;
22
22
  unmount: () => void;
23
23
  } & { [P in keyof Q]: import("@testing-library/dom").BoundFunction<Q[P]>; };
24
24
  export type FireFunction = (...args: Parameters<import("@testing-library/dom").FireFunction>) => Promise<ReturnType<import("@testing-library/dom").FireFunction>>;
@@ -31,6 +31,8 @@ export type FireObject = { [K in import("@testing-library/dom").EventType]: (...
31
31
  * @returns {Promise<T>}
32
32
  */
33
33
  export function act<T>(fn?: (() => Promise<T>) | (() => T)): Promise<T>;
34
+ /** Unmount components, remove elements added to `<body>`, and reset `@testing-library/dom`. */
35
+ export function cleanup(): void;
34
36
  /**
35
37
  * @typedef {(...args: Parameters<import('@testing-library/dom').FireFunction>) => Promise<ReturnType<import('@testing-library/dom').FireFunction>>} FireFunction
36
38
  */
@@ -51,8 +53,8 @@ export const fireEvent: FireFunction & FireObject;
51
53
  /**
52
54
  * Customize how Svelte renders the component.
53
55
  *
54
- * @template {import('./component-types.js').Component} C
55
- * @typedef {import('./component-types.js').Props<C> | Partial<import('./component-types.js').MountOptions<C>>} SvelteComponentOptions
56
+ * @template {import('@testing-library/svelte-core/types').Component} C
57
+ * @typedef {import('@testing-library/svelte-core/types').ComponentOptions<C>} SvelteComponentOptions
56
58
  */
57
59
  /**
58
60
  * Customize how Testing Library sets up the document and binds queries.
@@ -66,15 +68,15 @@ export const fireEvent: FireFunction & FireObject;
66
68
  /**
67
69
  * The rendered component and bound testing functions.
68
70
  *
69
- * @template {import('./component-types.js').Component} C
71
+ * @template {import('@testing-library/svelte-core/types').Component} C
70
72
  * @template {import('@testing-library/dom').Queries} [Q=typeof import('@testing-library/dom').queries]
71
73
  *
72
74
  * @typedef {{
73
75
  * container: HTMLElement
74
76
  * baseElement: HTMLElement
75
- * component: import('./component-types.js').Exports<C>
77
+ * component: import('@testing-library/svelte-core/types').Exports<C>
76
78
  * debug: (el?: HTMLElement | DocumentFragment) => void
77
- * rerender: (props: Partial<import('./component-types.js').Props<C>>) => Promise<void>
79
+ * rerender: import('@testing-library/svelte-core/types').Rerender<C>
78
80
  * unmount: () => void
79
81
  * } & {
80
82
  * [P in keyof Q]: import('@testing-library/dom').BoundFunction<Q[P]>
@@ -83,15 +85,15 @@ export const fireEvent: FireFunction & FireObject;
83
85
  /**
84
86
  * Render a component into the document.
85
87
  *
86
- * @template {import('./component-types.js').Component} C
88
+ * @template {import('@testing-library/svelte-core/types').Component} C
87
89
  * @template {import('@testing-library/dom').Queries} [Q=typeof import('@testing-library/dom').queries]
88
90
  *
89
- * @param {import('./component-types.js').ComponentType<C>} Component - The component to render.
91
+ * @param {import('@testing-library/svelte-core/types').ComponentImport<C>} Component - The component to render.
90
92
  * @param {SvelteComponentOptions<C>} options - Customize how Svelte renders the component.
91
93
  * @param {RenderOptions<Q>} renderOptions - Customize how Testing Library sets up the document and binds queries.
92
94
  * @returns {RenderResult<C, Q>} The rendered component and bound testing functions.
93
95
  */
94
- export function render<C extends import("./component-types.js").Component, Q extends import("@testing-library/dom").Queries = typeof import("@testing-library/dom/types/queries.js")>(Component: import("./component-types.js").ComponentType<C>, options?: SvelteComponentOptions<C>, renderOptions?: RenderOptions<Q>): RenderResult<C, Q>;
96
+ export function render<C extends import("@testing-library/svelte-core/types").Component, Q extends import("@testing-library/dom").Queries = typeof import("@testing-library/dom/types/queries.js")>(Component: import("@testing-library/svelte-core/types").ComponentImport<C>, options?: SvelteComponentOptions<C>, renderOptions?: RenderOptions<Q>): RenderResult<C, Q>;
95
97
  /**
96
98
  * Configure `@testing-library/dom` for usage with Svelte.
97
99
  *
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pure.d.ts","sourceRoot":"","sources":["../src/pure.js"],"names":[],"mappings":";;;;mCAasE,CAAC,SAA1D,OAAQ,oCAAoC,EAAE,SAAU,IACxD,OAAO,oCAAoC,EAAE,gBAAgB,CAAC,CAAC,CAAC;;;;0BAMtB,CAAC,SAA3C,OAAQ,sBAAsB,EAAE,OAAQ,6DACxC;IACR,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,OAAO,CAAC,EAAE,CAAC,CAAA;CACZ;;;;yBAMkE,CAAC,SAA1D,OAAQ,oCAAoC,EAAE,SAAU,EACd,CAAC,SAA3C,OAAQ,sBAAsB,EAAE,OAAQ,6DAExC;IACR,SAAS,EAAE,WAAW,CAAA;IACtB,WAAW,EAAE,WAAW,CAAA;IACxB,SAAS,EAAE,OAAO,oCAAoC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IAClE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,WAAW,GAAG,gBAAgB,KAAK,IAAI,CAAA;IACpD,QAAQ,EAAE,OAAO,oCAAoC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;IAClE,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB,GAAG,GACD,CAAC,IAAI,MAAM,CAAC,GAAG,OAAO,sBAAsB,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACnE;2BA0ES,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,sBAAsB,EAAE,YAAY,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,OAAO,sBAAsB,EAAE,YAAY,CAAC,CAAC;yBAItI,GACP,CAAC,IAAI,OAAO,sBAAsB,EAAE,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,sBAAsB,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,OAAO,sBAAsB,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GAC1L;AAvBJ;;;;;;GAMG;AACH,oBAJa,CAAC,OACH,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,IAAG,MAAM,CAAC,CAAA,GAC1B,OAAO,CAAC,CAAC,CAAC,CAStB;AAnBD,+FAA+F;AAC/F,gCAEC;AAkBD;;GAEG;AAEH;;;;GAIG;AAEH;;;;;;;GAOG;AACH,wBAFU,YAAY,GAAG,UAAU,CAEmC;AA3HtE;;;;;GAKG;AAEH;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;;;;;GAUG;AACH,uBARsE,CAAC,SAA1D,OAAQ,oCAAoC,EAAE,SAAU,EACd,CAAC,SAA3C,OAAQ,sBAAsB,EAAE,OAAQ,sEAE1C,OAAO,oCAAoC,EAAE,eAAe,CAAC,CAAC,CAAC,YAC/D,sBAAsB,CAAC,CAAC,CAAC,kBACzB,aAAa,CAAC,CAAC,CAAC,GACd,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAkB9B;AAED;;;;;;GAMG;AACH,8BAWC"}
@@ -1 +1 @@
1
- {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.js"],"names":[],"mappings":"AAYO,6EAHI;IAAC,cAAc,CAAC,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAC,GACrE,OAAO,MAAM,EAAE,MAAM,CAyBhC"}
1
+ {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.js"],"names":[],"mappings":"AAcO,6EAHI;IAAC,cAAc,CAAC,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAC,GACrE,OAAO,MAAM,EAAE,MAAM,CAyBhC"}
package/package.json CHANGED
@@ -1,33 +1,34 @@
1
1
  {
2
2
  "name": "@testing-library/svelte",
3
- "version": "5.2.10",
3
+ "version": "5.3.0-next.2",
4
4
  "description": "Simple and complete Svelte testing utilities that encourage good testing practices.",
5
5
  "main": "src/index.js",
6
6
  "exports": {
7
7
  ".": {
8
- "types": "./types/index.d.ts",
8
+ "types": "./dist/index.d.ts",
9
9
  "default": "./src/index.js"
10
10
  },
11
11
  "./svelte5": {
12
- "types": "./types/index.d.ts",
12
+ "types": "./dist/index.d.ts",
13
13
  "default": "./src/index.js"
14
14
  },
15
15
  "./vitest": {
16
- "types": "./types/vitest.d.ts",
16
+ "types": "./dist/vitest.d.ts",
17
17
  "default": "./src/vitest.js"
18
18
  },
19
19
  "./vite": {
20
- "types": "./types/vite.d.ts",
20
+ "types": "./dist/vite.d.ts",
21
21
  "default": "./src/vite.js"
22
22
  }
23
23
  },
24
24
  "type": "module",
25
- "types": "types/index.d.ts",
25
+ "types": "dist/index.d.ts",
26
26
  "license": "MIT",
27
27
  "homepage": "https://github.com/testing-library/svelte-testing-library#readme",
28
28
  "repository": {
29
29
  "type": "git",
30
- "url": "git+https://github.com/testing-library/svelte-testing-library.git"
30
+ "url": "git+https://github.com/testing-library/svelte-testing-library.git",
31
+ "directory": "packages/svelte"
31
32
  },
32
33
  "bugs": {
33
34
  "url": "https://github.com/testing-library/svelte-testing-library/issues"
@@ -49,31 +50,8 @@
49
50
  ],
50
51
  "files": [
51
52
  "src",
52
- "types"
53
+ "dist"
53
54
  ],
54
- "scripts": {
55
- "all": "npm-run-all contributors:generate docs format types build test:vitest:* test:jest test:examples",
56
- "all:legacy": "npm-run-all types:legacy test:vitest:* test:jest",
57
- "docs": "remark --output --use remark-toc --use remark-code-import --use unified-prettier README.md examples",
58
- "lint": "prettier . --check && eslint .",
59
- "format": "prettier . --write && eslint . --fix",
60
- "setup": "npm run install:5 && npm run all",
61
- "test": "vitest run --coverage",
62
- "test:watch": "vitest",
63
- "test:vitest:jsdom": "vitest run tests --coverage --environment jsdom",
64
- "test:vitest:happy-dom": "vitest run tests --coverage --environment happy-dom",
65
- "test:jest": "npx --node-options=\"--experimental-vm-modules --no-warnings\" jest --coverage",
66
- "test:examples": "vitest run examples --coverage",
67
- "types": "svelte-check",
68
- "types:legacy": "svelte-check --tsconfig tsconfig.legacy.json",
69
- "build": "tsc -p tsconfig.build.json && cp src/component-types.d.ts types",
70
- "contributors:add": "all-contributors add",
71
- "contributors:generate": "all-contributors generate",
72
- "preview-release": "./scripts/preview-release",
73
- "install:3": "./scripts/install-dependencies 3",
74
- "install:4": "./scripts/install-dependencies 4",
75
- "install:5": "./scripts/install-dependencies 5"
76
- },
77
55
  "peerDependencies": {
78
56
  "svelte": "^3 || ^4 || ^5 || ^5.0.0-next.0",
79
57
  "vite": "*",
@@ -88,45 +66,11 @@
88
66
  }
89
67
  },
90
68
  "dependencies": {
91
- "@testing-library/dom": "9.x.x || 10.x.x"
69
+ "@testing-library/dom": "9.x.x || 10.x.x",
70
+ "@testing-library/svelte-core": "1.0.0-next.4"
92
71
  },
93
- "devDependencies": {
94
- "@eslint/js": "^9.26.0",
95
- "@jest/globals": "^29.7.0",
96
- "@sveltejs/vite-plugin-svelte": "^5.0.3",
97
- "@testing-library/jest-dom": "^6.6.3",
98
- "@testing-library/user-event": "^14.6.1",
99
- "@vitest/coverage-v8": "^3.1.3",
100
- "@vitest/eslint-plugin": "^1.1.44",
101
- "all-contributors-cli": "^6.26.1",
102
- "eslint": "^9.26.0",
103
- "eslint-config-prettier": "^10.1.5",
104
- "eslint-plugin-jest-dom": "^5.5.0",
105
- "eslint-plugin-promise": "^7.2.1",
106
- "eslint-plugin-simple-import-sort": "^12.1.1",
107
- "eslint-plugin-svelte": "^3.5.1",
108
- "eslint-plugin-testing-library": "^7.1.1",
109
- "eslint-plugin-unicorn": "^59.0.1",
110
- "expect-type": "^1.2.1",
111
- "globals": "^16.1.0",
112
- "happy-dom": "^17.4.6",
113
- "jest": "^29.7.0",
114
- "jest-environment-jsdom": "^29.7.0",
115
- "jsdom": "^26.1.0",
116
- "npm-run-all": "^4.1.5",
117
- "prettier": "^3.5.3",
118
- "prettier-plugin-svelte": "^3.3.3",
119
- "remark-cli": "^12.0.1",
120
- "remark-code-import": "^1.2.0",
121
- "remark-toc": "^9.0.0",
122
- "svelte": "^5.28.2",
123
- "svelte-check": "^4.1.7",
124
- "svelte-jester": "^5.0.0",
125
- "typescript": "^5.8.3",
126
- "typescript-eslint": "^8.32.0",
127
- "typescript-svelte-plugin": "^0.3.46",
128
- "unified-prettier": "^2.0.1",
129
- "vite": "^6.3.5",
130
- "vitest": "^3.1.3"
72
+ "publishConfig": {
73
+ "access": "public",
74
+ "provenance": true
131
75
  }
132
- }
76
+ }
package/src/index.js CHANGED
@@ -23,7 +23,11 @@ if (typeof process !== 'undefined' && !process.env.STL_SKIP_AUTO_CLEANUP) {
23
23
  export * from '@testing-library/dom'
24
24
 
25
25
  // export svelte-specific functions and custom `fireEvent`
26
- export { UnknownSvelteOptionsError } from './core/index.js'
27
- export * from './pure.js'
28
- // `fireEvent` must be named to take priority over wildcard from @testing-library/dom
29
- export { fireEvent } from './pure.js'
26
+ export {
27
+ act,
28
+ cleanup,
29
+ fireEvent,
30
+ render,
31
+ setup,
32
+ UnknownSvelteOptionsError,
33
+ } from './pure.js'
package/src/pure.js CHANGED
@@ -5,15 +5,14 @@ import {
5
5
  getQueriesForElement,
6
6
  prettyDOM,
7
7
  } from '@testing-library/dom'
8
+ import * as Core from '@testing-library/svelte-core'
8
9
  import * as Svelte from 'svelte'
9
10
 
10
- import { addCleanupTask, mount, validateOptions } from './core/index.js'
11
-
12
11
  /**
13
12
  * Customize how Svelte renders the component.
14
13
  *
15
- * @template {import('./component-types.js').Component} C
16
- * @typedef {import('./component-types.js').Props<C> | Partial<import('./component-types.js').MountOptions<C>>} SvelteComponentOptions
14
+ * @template {import('@testing-library/svelte-core/types').Component} C
15
+ * @typedef {import('@testing-library/svelte-core/types').ComponentOptions<C>} SvelteComponentOptions
17
16
  */
18
17
 
19
18
  /**
@@ -29,15 +28,15 @@ import { addCleanupTask, mount, validateOptions } from './core/index.js'
29
28
  /**
30
29
  * The rendered component and bound testing functions.
31
30
  *
32
- * @template {import('./component-types.js').Component} C
31
+ * @template {import('@testing-library/svelte-core/types').Component} C
33
32
  * @template {import('@testing-library/dom').Queries} [Q=typeof import('@testing-library/dom').queries]
34
33
  *
35
34
  * @typedef {{
36
35
  * container: HTMLElement
37
36
  * baseElement: HTMLElement
38
- * component: import('./component-types.js').Exports<C>
37
+ * component: import('@testing-library/svelte-core/types').Exports<C>
39
38
  * debug: (el?: HTMLElement | DocumentFragment) => void
40
- * rerender: (props: Partial<import('./component-types.js').Props<C>>) => Promise<void>
39
+ * rerender: import('@testing-library/svelte-core/types').Rerender<C>
41
40
  * unmount: () => void
42
41
  * } & {
43
42
  * [P in keyof Q]: import('@testing-library/dom').BoundFunction<Q[P]>
@@ -47,56 +46,29 @@ import { addCleanupTask, mount, validateOptions } from './core/index.js'
47
46
  /**
48
47
  * Render a component into the document.
49
48
  *
50
- * @template {import('./component-types.js').Component} C
49
+ * @template {import('@testing-library/svelte-core/types').Component} C
51
50
  * @template {import('@testing-library/dom').Queries} [Q=typeof import('@testing-library/dom').queries]
52
51
  *
53
- * @param {import('./component-types.js').ComponentType<C>} Component - The component to render.
52
+ * @param {import('@testing-library/svelte-core/types').ComponentImport<C>} Component - The component to render.
54
53
  * @param {SvelteComponentOptions<C>} options - Customize how Svelte renders the component.
55
54
  * @param {RenderOptions<Q>} renderOptions - Customize how Testing Library sets up the document and binds queries.
56
55
  * @returns {RenderResult<C, Q>} The rendered component and bound testing functions.
57
56
  */
58
57
  const render = (Component, options = {}, renderOptions = {}) => {
59
- options = validateOptions(options)
60
-
61
- const baseElement =
62
- renderOptions.baseElement ?? options.target ?? document.body
63
-
64
- const queries = getQueriesForElement(baseElement, renderOptions.queries)
65
-
66
- const target =
67
- // eslint-disable-next-line unicorn/prefer-dom-node-append
68
- options.target ?? baseElement.appendChild(document.createElement('div'))
69
-
70
- addCleanupTask(() => {
71
- if (target.parentNode === document.body) {
72
- target.remove()
73
- }
74
- })
75
-
76
- const { component, unmount, rerender } = mount(
77
- Component.default ?? Component,
78
- { ...options, target }
58
+ const { baseElement, container, component, unmount, rerender } = Core.render(
59
+ Component,
60
+ options,
61
+ renderOptions
79
62
  )
80
63
 
81
64
  return {
82
65
  baseElement,
66
+ container,
83
67
  component,
84
- container: target,
85
- debug: (el = baseElement) => {
86
- console.log(prettyDOM(el))
87
- },
88
- rerender: async (props) => {
89
- if (props.props) {
90
- console.warn(
91
- 'rerender({ props: {...} }) deprecated, use rerender({...}) instead'
92
- )
93
- props = props.props
94
- }
95
-
96
- await rerender(props)
97
- },
68
+ rerender,
98
69
  unmount,
99
- ...queries,
70
+ debug: (el = baseElement) => console.log(prettyDOM(el)),
71
+ ...getQueriesForElement(baseElement, renderOptions.queries),
100
72
  }
101
73
  }
102
74
 
@@ -115,11 +87,16 @@ const setup = () => {
115
87
  eventWrapper: Svelte.flushSync ?? ((cb) => cb()),
116
88
  })
117
89
 
118
- addCleanupTask(() => {
90
+ Core.addCleanupTask(() => {
119
91
  configureDTL(originalDTLConfig)
120
92
  })
121
93
  }
122
94
 
95
+ /** Unmount components, remove elements added to `<body>`, and reset `@testing-library/dom`. */
96
+ const cleanup = () => {
97
+ Core.cleanup()
98
+ }
99
+
123
100
  /**
124
101
  * Call a function and wait for Svelte to flush pending changes.
125
102
  *
@@ -160,5 +137,5 @@ for (const [key, baseEvent] of Object.entries(baseFireEvent)) {
160
137
  fireEvent[key] = async (...args) => act(() => baseEvent(...args))
161
138
  }
162
139
 
163
- export { cleanup } from './core/index.js'
164
- export { act, fireEvent, render, setup }
140
+ export { UnknownSvelteOptionsError } from '@testing-library/svelte-core'
141
+ export { act, cleanup, fireEvent, render, setup }
package/src/vite.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import path from 'node:path'
2
2
  import url from 'node:url'
3
3
 
4
+ const STL_PACKAGES = ['@testing-library/svelte', '@testing-library/svelte-core']
5
+
4
6
  /**
5
7
  * Vite plugin to configure @testing-library/svelte.
6
8
  *
@@ -107,17 +109,25 @@ const addNoExternal = (config) => {
107
109
  return
108
110
  }
109
111
 
110
- for (const rule of noExternal) {
111
- if (typeof rule === 'string' && rule === '@testing-library/svelte') {
112
- return
113
- }
112
+ const missingPackages = []
114
113
 
115
- if (rule instanceof RegExp && rule.test('@testing-library/svelte')) {
116
- return
114
+ for (const packageName of STL_PACKAGES) {
115
+ const isIncluded = noExternal.some(
116
+ (rule) =>
117
+ (typeof rule === 'string' && rule === packageName) ||
118
+ (rule instanceof RegExp && rule.test(packageName))
119
+ )
120
+
121
+ if (!isIncluded) {
122
+ missingPackages.push(packageName)
117
123
  }
118
124
  }
119
125
 
120
- noExternal.push('@testing-library/svelte')
126
+ if (missingPackages.length === 0) {
127
+ return
128
+ }
129
+
130
+ noExternal.push(...missingPackages)
121
131
  ssr.noExternal = noExternal
122
132
  config.ssr = ssr
123
133
  }
@@ -1,61 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-deprecated */
2
- import type {
3
- Component as ModernComponent,
4
- ComponentConstructorOptions as LegacyConstructorOptions,
5
- ComponentProps,
6
- EventDispatcher,
7
- mount,
8
- SvelteComponent as LegacyComponent,
9
- SvelteComponentTyped as Svelte3LegacyComponent,
10
- } from 'svelte'
11
-
12
- type IS_MODERN_SVELTE = ModernComponent extends (...args: any[]) => any
13
- ? true
14
- : false
15
-
16
- type IS_LEGACY_SVELTE_4 =
17
- EventDispatcher<any> extends (...args: any[]) => any ? true : false
18
-
19
- /** A compiled, imported Svelte component. */
20
- export type Component<
21
- P extends Record<string, any> = any,
22
- E extends Record<string, any> = any,
23
- > = IS_MODERN_SVELTE extends true
24
- ? ModernComponent<P, E> | LegacyComponent<P>
25
- : IS_LEGACY_SVELTE_4 extends true
26
- ? LegacyComponent<P>
27
- : Svelte3LegacyComponent<P>
28
-
29
- /**
30
- * The type of an imported, compiled Svelte component.
31
- *
32
- * In Svelte 5, this distinction no longer matters.
33
- * In Svelte 4, this is the Svelte component class constructor.
34
- */
35
- export type ComponentType<C> = C extends LegacyComponent
36
- ? new (...args: any[]) => C
37
- : C
38
-
39
- /** The props of a component. */
40
- export type Props<C extends Component> = ComponentProps<C>
41
-
42
- /**
43
- * The exported fields of a component.
44
- *
45
- * In Svelte 5, this is the set of variables marked as `export`'d.
46
- * In Svelte 4, this is simply the instance of the component class.
47
- */
48
- export type Exports<C> = IS_MODERN_SVELTE extends true
49
- ? C extends ModernComponent<any, infer E>
50
- ? E
51
- : C & { $set: never; $on: never; $destroy: never }
52
- : C
53
-
54
- /**
55
- * Options that may be passed to `mount` when rendering the component.
56
- *
57
- * In Svelte 4, these are the options passed to the component constructor.
58
- */
59
- export type MountOptions<C extends Component> = IS_MODERN_SVELTE extends true
60
- ? Parameters<typeof mount<Props<C>, Exports<C>>>[1]
61
- : LegacyConstructorOptions<Props<C>>
@@ -1,32 +0,0 @@
1
- /** @type {Set<() => void>} */
2
- const cleanupTasks = new Set()
3
-
4
- /**
5
- * Register later cleanup task
6
- *
7
- * @param {() => void} onCleanup
8
- */
9
- const addCleanupTask = (onCleanup) => {
10
- cleanupTasks.add(onCleanup)
11
- return onCleanup
12
- }
13
-
14
- /**
15
- * Remove a cleanup task without running it.
16
- *
17
- * @param {() => void} onCleanup
18
- */
19
- const removeCleanupTask = (onCleanup) => {
20
- cleanupTasks.delete(onCleanup)
21
- }
22
-
23
- /** Clean up all components and elements added to the document. */
24
- const cleanup = () => {
25
- for (const handleCleanup of cleanupTasks.values()) {
26
- handleCleanup()
27
- }
28
-
29
- cleanupTasks.clear()
30
- }
31
-
32
- export { addCleanupTask, cleanup, removeCleanupTask }
package/src/core/index.js DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * Rendering core for svelte-testing-library.
3
- *
4
- * Defines how components are added to and removed from the DOM.
5
- * Will switch to legacy, class-based mounting logic
6
- * if it looks like we're in a Svelte <= 4 environment.
7
- */
8
- export { addCleanupTask, cleanup } from './cleanup.js'
9
- export { mount } from './mount.js'
10
- export {
11
- UnknownSvelteOptionsError,
12
- validateOptions,
13
- } from './validate-options.js'
package/src/core/mount.js DELETED
@@ -1,95 +0,0 @@
1
- /**
2
- * Component rendering core, with support for Svelte 3, 4, and 5
3
- */
4
- import * as Svelte from 'svelte'
5
-
6
- import { addCleanupTask, removeCleanupTask } from './cleanup.js'
7
- import { createProps } from './props.svelte.js'
8
-
9
- /** Whether we're using Svelte >= 5. */
10
- const IS_MODERN_SVELTE = typeof Svelte.mount === 'function'
11
-
12
- /** Allowed options to the `mount` call or legacy component constructor. */
13
- const ALLOWED_MOUNT_OPTIONS = IS_MODERN_SVELTE
14
- ? ['target', 'anchor', 'props', 'events', 'context', 'intro']
15
- : ['target', 'accessors', 'anchor', 'props', 'hydrate', 'intro', 'context']
16
-
17
- /** Mount a modern Svelte 5 component into the DOM. */
18
- const mountModern = (Component, options) => {
19
- const [props, updateProps] = createProps(options.props)
20
- const component = Svelte.mount(Component, { ...options, props })
21
-
22
- /** Remove the component from the DOM. */
23
- const unmount = () => {
24
- Svelte.flushSync(() => Svelte.unmount(component))
25
- removeCleanupTask(unmount)
26
- }
27
-
28
- /** Update the component's props. */
29
- const rerender = (nextProps) => {
30
- Svelte.flushSync(() => updateProps(nextProps))
31
- }
32
-
33
- addCleanupTask(unmount)
34
- Svelte.flushSync()
35
-
36
- return { component, unmount, rerender }
37
- }
38
-
39
- /** Mount a legacy Svelte 3 or 4 component into the DOM. */
40
- const mountLegacy = (Component, options) => {
41
- const component = new Component(options)
42
-
43
- /** Remove the component from the DOM. */
44
- const unmount = () => {
45
- component.$destroy()
46
- removeCleanupTask(unmount)
47
- }
48
-
49
- /** Update the component's props. */
50
- const rerender = (nextProps) => {
51
- component.$set(nextProps)
52
- }
53
-
54
- // This `$$.on_destroy` listener is included for strict backwards compatibility
55
- // with previous versions of `@testing-library/svelte`.
56
- // It's unnecessary and will be removed in a future major version.
57
- component.$$.on_destroy.push(() => {
58
- removeCleanupTask(unmount)
59
- })
60
-
61
- addCleanupTask(unmount)
62
-
63
- return { component, unmount, rerender }
64
- }
65
-
66
- /** The mount method in use. */
67
- const mountComponent = IS_MODERN_SVELTE ? mountModern : mountLegacy
68
-
69
- /**
70
- * Render a Svelte component into the document.
71
- *
72
- * @template {import('./types.js').Component} C
73
- * @param {import('./types.js').ComponentType<C>} Component
74
- * @param {import('./types.js').MountOptions<C>} options
75
- * @returns {{
76
- * component: C
77
- * unmount: () => void
78
- * rerender: (props: Partial<import('./types.js').Props<C>>) => Promise<void>
79
- * }}
80
- */
81
- const mount = (Component, options = {}) => {
82
- const { component, unmount, rerender } = mountComponent(Component, options)
83
-
84
- return {
85
- component,
86
- unmount,
87
- rerender: async (props) => {
88
- rerender(props)
89
- // Await the next tick for Svelte 4, which cannot flush changes synchronously
90
- await Svelte.tick()
91
- },
92
- }
93
- }
94
-
95
- export { ALLOWED_MOUNT_OPTIONS, mount }
@@ -1,38 +0,0 @@
1
- /**
2
- * Create a shallowly reactive props object.
3
- *
4
- * This allows us to update props on `rerender`
5
- * without turing `props` into a deep set of Proxy objects
6
- *
7
- * @template {Record<string, unknown>} Props
8
- * @param {Props} initialProps
9
- * @returns {[Props, (nextProps: Partial<Props>) => void]}
10
- */
11
- const createProps = (initialProps) => {
12
- const targetProps = initialProps ?? {}
13
- let currentProps = $state.raw(targetProps)
14
-
15
- const props = new Proxy(targetProps, {
16
- get(_, key) {
17
- return currentProps[key]
18
- },
19
- set(_, key, value) {
20
- currentProps[key] = value
21
- return true
22
- },
23
- has(_, key) {
24
- return Reflect.has(currentProps, key)
25
- },
26
- ownKeys() {
27
- return Reflect.ownKeys(currentProps)
28
- },
29
- })
30
-
31
- const update = (nextProps) => {
32
- currentProps = { ...currentProps, ...nextProps }
33
- }
34
-
35
- return [props, update]
36
- }
37
-
38
- export { createProps }
@@ -1,41 +0,0 @@
1
- import { ALLOWED_MOUNT_OPTIONS } from './mount.js'
2
-
3
- class UnknownSvelteOptionsError extends TypeError {
4
- constructor(unknownOptions, allowedOptions) {
5
- super(`Unknown options.
6
-
7
- Unknown: [ ${unknownOptions.join(', ')} ]
8
- Allowed: [ ${allowedOptions.join(', ')} ]
9
-
10
- To pass both Svelte options and props to a component,
11
- or to use props that share a name with a Svelte option,
12
- you must place all your props under the \`props\` key:
13
-
14
- render(Component, { props: { /** props here **/ } })
15
- `)
16
- this.name = 'UnknownSvelteOptionsError'
17
- }
18
- }
19
-
20
- const validateOptions = (options) => {
21
- const isProps = !Object.keys(options).some((option) =>
22
- ALLOWED_MOUNT_OPTIONS.includes(option)
23
- )
24
-
25
- if (isProps) {
26
- return { props: options }
27
- }
28
-
29
- // Check if any props and Svelte options were accidentally mixed.
30
- const unknownOptions = Object.keys(options).filter(
31
- (option) => !ALLOWED_MOUNT_OPTIONS.includes(option)
32
- )
33
-
34
- if (unknownOptions.length > 0) {
35
- throw new UnknownSvelteOptionsError(unknownOptions, ALLOWED_MOUNT_OPTIONS)
36
- }
37
-
38
- return options
39
- }
40
-
41
- export { UnknownSvelteOptionsError, validateOptions }
@@ -1,61 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-deprecated */
2
- import type {
3
- Component as ModernComponent,
4
- ComponentConstructorOptions as LegacyConstructorOptions,
5
- ComponentProps,
6
- EventDispatcher,
7
- mount,
8
- SvelteComponent as LegacyComponent,
9
- SvelteComponentTyped as Svelte3LegacyComponent,
10
- } from 'svelte'
11
-
12
- type IS_MODERN_SVELTE = ModernComponent extends (...args: any[]) => any
13
- ? true
14
- : false
15
-
16
- type IS_LEGACY_SVELTE_4 =
17
- EventDispatcher<any> extends (...args: any[]) => any ? true : false
18
-
19
- /** A compiled, imported Svelte component. */
20
- export type Component<
21
- P extends Record<string, any> = any,
22
- E extends Record<string, any> = any,
23
- > = IS_MODERN_SVELTE extends true
24
- ? ModernComponent<P, E> | LegacyComponent<P>
25
- : IS_LEGACY_SVELTE_4 extends true
26
- ? LegacyComponent<P>
27
- : Svelte3LegacyComponent<P>
28
-
29
- /**
30
- * The type of an imported, compiled Svelte component.
31
- *
32
- * In Svelte 5, this distinction no longer matters.
33
- * In Svelte 4, this is the Svelte component class constructor.
34
- */
35
- export type ComponentType<C> = C extends LegacyComponent
36
- ? new (...args: any[]) => C
37
- : C
38
-
39
- /** The props of a component. */
40
- export type Props<C extends Component> = ComponentProps<C>
41
-
42
- /**
43
- * The exported fields of a component.
44
- *
45
- * In Svelte 5, this is the set of variables marked as `export`'d.
46
- * In Svelte 4, this is simply the instance of the component class.
47
- */
48
- export type Exports<C> = IS_MODERN_SVELTE extends true
49
- ? C extends ModernComponent<any, infer E>
50
- ? E
51
- : C & { $set: never; $on: never; $destroy: never }
52
- : C
53
-
54
- /**
55
- * Options that may be passed to `mount` when rendering the component.
56
- *
57
- * In Svelte 4, these are the options passed to the component constructor.
58
- */
59
- export type MountOptions<C extends Component> = IS_MODERN_SVELTE extends true
60
- ? Parameters<typeof mount<Props<C>, Exports<C>>>[1]
61
- : LegacyConstructorOptions<Props<C>>
@@ -1,15 +0,0 @@
1
- /**
2
- * Register later cleanup task
3
- *
4
- * @param {() => void} onCleanup
5
- */
6
- export function addCleanupTask(onCleanup: () => void): () => void;
7
- /** Clean up all components and elements added to the document. */
8
- export function cleanup(): void;
9
- /**
10
- * Remove a cleanup task without running it.
11
- *
12
- * @param {() => void} onCleanup
13
- */
14
- export function removeCleanupTask(onCleanup: () => void): void;
15
- //# sourceMappingURL=cleanup.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cleanup.d.ts","sourceRoot":"","sources":["../../src/core/cleanup.js"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,0CAFW,MAAM,IAAI,SAAJ,IAAI,CAKpB;AAWD,kEAAkE;AAClE,gCAMC;AAhBD;;;;GAIG;AACH,6CAFW,MAAM,IAAI,QAIpB"}
@@ -1,4 +0,0 @@
1
- export { mount } from "./mount.js";
2
- export { addCleanupTask, cleanup } from "./cleanup.js";
3
- export { UnknownSvelteOptionsError, validateOptions } from "./validate-options.js";
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.js"],"names":[],"mappings":""}
@@ -1,20 +0,0 @@
1
- /** Allowed options to the `mount` call or legacy component constructor. */
2
- export const ALLOWED_MOUNT_OPTIONS: string[];
3
- /**
4
- * Render a Svelte component into the document.
5
- *
6
- * @template {import('./types.js').Component} C
7
- * @param {import('./types.js').ComponentType<C>} Component
8
- * @param {import('./types.js').MountOptions<C>} options
9
- * @returns {{
10
- * component: C
11
- * unmount: () => void
12
- * rerender: (props: Partial<import('./types.js').Props<C>>) => Promise<void>
13
- * }}
14
- */
15
- export function mount<C extends any>(Component: any, options?: any): {
16
- component: C;
17
- unmount: () => void;
18
- rerender: (props: Partial<any>) => Promise<void>;
19
- };
20
- //# sourceMappingURL=mount.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../src/core/mount.js"],"names":[],"mappings":"AAWA,2EAA2E;AAC3E,6CAE6E;AAsD7E;;;;;;;;;;;GAWG;AACH,sBAT8C,CAAC,SAAlC,GAAgC,kCAGhC;IACR,SAAS,EAAE,CAAC,CAAA;IACZ,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,GAA6B,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3E,CAcH"}
@@ -1,12 +0,0 @@
1
- /**
2
- * Create a shallowly reactive props object.
3
- *
4
- * This allows us to update props on `rerender`
5
- * without turing `props` into a deep set of Proxy objects
6
- *
7
- * @template {Record<string, unknown>} Props
8
- * @param {Props} initialProps
9
- * @returns {[Props, (nextProps: Partial<Props>) => void]}
10
- */
11
- export function createProps<Props extends Record<string, unknown>>(initialProps: Props): [Props, (nextProps: Partial<Props>) => void];
12
- //# sourceMappingURL=props.svelte.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"props.svelte.d.ts","sourceRoot":"","sources":["../../src/core/props.svelte.js"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,4BAJuC,KAAK,SAA9B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAE,gBAC3B,KAAK,GACH,CAAC,KAAK,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CA2BxD"}
@@ -1,5 +0,0 @@
1
- export class UnknownSvelteOptionsError extends TypeError {
2
- constructor(unknownOptions: any, allowedOptions: any);
3
- }
4
- export function validateOptions(options: any): any;
5
- //# sourceMappingURL=validate-options.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validate-options.d.ts","sourceRoot":"","sources":["../../src/core/validate-options.js"],"names":[],"mappings":"AAEA;IACE,sDAaC;CACF;AAED,mDAmBC"}
package/types/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from "@testing-library/dom";
2
- export * from "./pure.js";
3
- export { UnknownSvelteOptionsError } from "./core/index.js";
4
- export { fireEvent } from "./pure.js";
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pure.d.ts","sourceRoot":"","sources":["../src/pure.js"],"names":[],"mappings":";;;;mCAcwD,CAAC,SAA5C,OAAQ,sBAAsB,EAAE,SAAU,IAC1C,OAAO,sBAAsB,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,sBAAsB,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;;;;0BAMvD,CAAC,SAA3C,OAAQ,sBAAsB,EAAE,OAAQ,6DACxC;IACR,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,OAAO,CAAC,EAAE,CAAC,CAAA;CACZ;;;;yBAMoD,CAAC,SAA5C,OAAQ,sBAAsB,EAAE,SAAU,EACA,CAAC,SAA3C,OAAQ,sBAAsB,EAAE,OAAQ,6DAExC;IACR,SAAS,EAAE,WAAW,CAAA;IACtB,WAAW,EAAE,WAAW,CAAA;IACxB,SAAS,EAAE,OAAO,sBAAsB,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IACpD,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,WAAW,GAAG,gBAAgB,KAAK,IAAI,CAAA;IACpD,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,sBAAsB,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACpF,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB,GAAG,GACD,CAAC,IAAI,MAAM,CAAC,GAAG,OAAO,sBAAsB,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACnE;2BAgGS,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,sBAAsB,EAAE,YAAY,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,OAAO,sBAAsB,EAAE,YAAY,CAAC,CAAC;yBAItI,GACP,CAAC,IAAI,OAAO,sBAAsB,EAAE,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,sBAAsB,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,OAAO,sBAAsB,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GAC1L;AAvBJ;;;;;;GAMG;AACH,oBAJa,CAAC,OACH,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,IAAG,MAAM,CAAC,CAAA,GAC1B,OAAO,CAAC,CAAC,CAAC,CAStB;AAED;;GAEG;AAEH;;;;GAIG;AAEH;;;;;;;GAOG;AACH,wBAFU,YAAY,GAAG,UAAU,CAEmC;AAjJtE;;;;;GAKG;AAEH;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;;;;;GAUG;AACH,uBARwD,CAAC,SAA5C,OAAQ,sBAAsB,EAAE,SAAU,EACA,CAAC,SAA3C,OAAQ,sBAAsB,EAAE,OAAQ,sEAE1C,OAAO,sBAAsB,EAAE,aAAa,CAAC,CAAC,CAAC,YAC/C,sBAAsB,CAAC,CAAC,CAAC,kBACzB,aAAa,CAAC,CAAC,CAAC,GACd,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CA6C9B;AAED;;;;;;GAMG;AACH,8BAWC"}
File without changes
File without changes
File without changes
File without changes