@testing-library/svelte 5.2.3 → 5.2.5

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/svelte",
3
- "version": "5.2.3",
3
+ "version": "5.2.5",
4
4
  "description": "Simple and complete Svelte testing utilities that encourage good testing practices.",
5
5
  "main": "src/index.js",
6
6
  "exports": {
@@ -95,7 +95,7 @@
95
95
  },
96
96
  "devDependencies": {
97
97
  "@jest/globals": "^29.7.0",
98
- "@sveltejs/vite-plugin-svelte": "^3.1.1",
98
+ "@sveltejs/vite-plugin-svelte": "^2.0.0 || ^3.0.0 || ^4.0.0",
99
99
  "@testing-library/jest-dom": "^6.3.0",
100
100
  "@testing-library/user-event": "^14.5.2",
101
101
  "@typescript-eslint/eslint-plugin": "^8.0.0",
@@ -111,7 +111,7 @@
111
111
  "eslint-plugin-promise": "^6.4.0",
112
112
  "eslint-plugin-simple-import-sort": "^12.1.1",
113
113
  "eslint-plugin-svelte": "^2.42.0",
114
- "expect-type": "^0.20.0",
114
+ "expect-type": "^1.1.0",
115
115
  "happy-dom": "^15.7.3",
116
116
  "jest": "^29.7.0",
117
117
  "jest-environment-jsdom": "^29.7.0",
@@ -1,7 +1,9 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
1
+ /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-redundant-type-constituents */
2
2
  import type * as Svelte from 'svelte'
3
3
 
4
- type IS_MODERN_SVELTE = any extends Svelte.Component ? false : true
4
+ type IS_MODERN_SVELTE = Svelte.Component extends (...args: any[]) => any
5
+ ? true
6
+ : false
5
7
 
6
8
  /** A compiled, imported Svelte component. */
7
9
  export type Component<
@@ -14,12 +16,12 @@ export type Component<
14
16
  /**
15
17
  * The type of an imported, compiled Svelte component.
16
18
  *
17
- * In Svelte 4, this was the Svelte component class' type.
18
19
  * In Svelte 5, this distinction no longer matters.
20
+ * In Svelte 4, this is the Svelte component class constructor.
19
21
  */
20
- export type ComponentType<C> = C extends Svelte.SvelteComponent
21
- ? Svelte.ComponentType<C>
22
- : C
22
+ export type ComponentType<C> = IS_MODERN_SVELTE extends true
23
+ ? C
24
+ : new (...args: any[]) => C
23
25
 
24
26
  /** The props of a component. */
25
27
  export type Props<C extends Component<any, any>> = Svelte.ComponentProps<C>
@@ -27,8 +29,8 @@ export type Props<C extends Component<any, any>> = Svelte.ComponentProps<C>
27
29
  /**
28
30
  * The exported fields of a component.
29
31
  *
30
- * In Svelte 4, this is simply the instance of the component class.
31
32
  * In Svelte 5, this is the set of variables marked as `export`'d.
33
+ * In Svelte 4, this is simply the instance of the component class.
32
34
  */
33
35
  export type Exports<C> = C extends Svelte.SvelteComponent
34
36
  ? C
package/src/vite.js CHANGED
@@ -7,12 +7,13 @@ import { fileURLToPath } from 'node:url'
7
7
  * Ensures Svelte is imported correctly in tests
8
8
  * and that the DOM is cleaned up after each test.
9
9
  *
10
- * @param {{resolveBrowser?: boolean, autoCleanup?: boolean}} options
10
+ * @param {{resolveBrowser?: boolean, autoCleanup?: boolean, noExternal?: boolean}} options
11
11
  * @returns {import('vite').Plugin}
12
12
  */
13
13
  export const svelteTesting = ({
14
14
  resolveBrowser = true,
15
15
  autoCleanup = true,
16
+ noExternal = true,
16
17
  } = {}) => ({
17
18
  name: 'vite-plugin-svelte-testing-library',
18
19
  config: (config) => {
@@ -27,6 +28,10 @@ export const svelteTesting = ({
27
28
  if (autoCleanup) {
28
29
  addAutoCleanup(config)
29
30
  }
31
+
32
+ if (noExternal) {
33
+ addNoExternal(config)
34
+ }
30
35
  },
31
36
  })
32
37
 
@@ -64,6 +69,10 @@ const addAutoCleanup = (config) => {
64
69
  const test = config.test ?? {}
65
70
  let setupFiles = test.setupFiles ?? []
66
71
 
72
+ if (test.globals) {
73
+ return
74
+ }
75
+
67
76
  if (typeof setupFiles === 'string') {
68
77
  setupFiles = [setupFiles]
69
78
  }
@@ -73,3 +82,40 @@ const addAutoCleanup = (config) => {
73
82
  test.setupFiles = setupFiles
74
83
  config.test = test
75
84
  }
85
+
86
+ /**
87
+ * Add `@testing-library/svelte` to Vite's noExternal rules, if not present.
88
+ *
89
+ * This ensures `@testing-library/svelte` is processed by `@sveltejs/vite-plugin-svelte`
90
+ * in certain monorepo setups.
91
+ */
92
+ const addNoExternal = (config) => {
93
+ const ssr = config.ssr ?? {}
94
+ let noExternal = ssr.noExternal ?? []
95
+
96
+ if (noExternal === true) {
97
+ return
98
+ }
99
+
100
+ if (typeof noExternal === 'string' || noExternal instanceof RegExp) {
101
+ noExternal = [noExternal]
102
+ }
103
+
104
+ if (!Array.isArray(noExternal)) {
105
+ return
106
+ }
107
+
108
+ for (const rule of noExternal) {
109
+ if (typeof rule === 'string' && rule === '@testing-library/svelte') {
110
+ return
111
+ }
112
+
113
+ if (rule instanceof RegExp && rule.test('@testing-library/svelte')) {
114
+ return
115
+ }
116
+ }
117
+
118
+ noExternal.push('@testing-library/svelte')
119
+ ssr.noExternal = noExternal
120
+ config.ssr = ssr
121
+ }
@@ -1,7 +1,9 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
1
+ /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-redundant-type-constituents */
2
2
  import type * as Svelte from 'svelte'
3
3
 
4
- type IS_MODERN_SVELTE = any extends Svelte.Component ? false : true
4
+ type IS_MODERN_SVELTE = Svelte.Component extends (...args: any[]) => any
5
+ ? true
6
+ : false
5
7
 
6
8
  /** A compiled, imported Svelte component. */
7
9
  export type Component<
@@ -14,12 +16,12 @@ export type Component<
14
16
  /**
15
17
  * The type of an imported, compiled Svelte component.
16
18
  *
17
- * In Svelte 4, this was the Svelte component class' type.
18
19
  * In Svelte 5, this distinction no longer matters.
20
+ * In Svelte 4, this is the Svelte component class constructor.
19
21
  */
20
- export type ComponentType<C> = C extends Svelte.SvelteComponent
21
- ? Svelte.ComponentType<C>
22
- : C
22
+ export type ComponentType<C> = IS_MODERN_SVELTE extends true
23
+ ? C
24
+ : new (...args: any[]) => C
23
25
 
24
26
  /** The props of a component. */
25
27
  export type Props<C extends Component<any, any>> = Svelte.ComponentProps<C>
@@ -27,8 +29,8 @@ export type Props<C extends Component<any, any>> = Svelte.ComponentProps<C>
27
29
  /**
28
30
  * The exported fields of a component.
29
31
  *
30
- * In Svelte 4, this is simply the instance of the component class.
31
32
  * In Svelte 5, this is the set of variables marked as `export`'d.
33
+ * In Svelte 4, this is simply the instance of the component class.
32
34
  */
33
35
  export type Exports<C> = C extends Svelte.SvelteComponent
34
36
  ? C
@@ -3,7 +3,7 @@ export const allowedOptions: string[];
3
3
  /** Whether we're using Svelte >= 5. */
4
4
  export const IS_MODERN_SVELTE: boolean;
5
5
  /** Mount the component into the DOM. */
6
- export function mount(Component: any, options: any): any;
6
+ export function mount(Component: any, options: any): Record<string, any>;
7
7
  /** Remove the component from the DOM. */
8
8
  export function unmount(component: any): void;
9
9
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"modern.svelte.d.ts","sourceRoot":"","sources":["../../src/core/modern.svelte.js"],"names":[],"mappings":"AAaA,2CAA2C;AAC3C,sCAOC;AAXD,uCAAuC;AACvC,uCAA2D;AAY3D,wCAAwC;AACxC,yDAQC;AAED,yCAAyC;AACzC,8CAGC;AAED;;;;GAIG;AACH,kEAGC"}
1
+ {"version":3,"file":"modern.svelte.d.ts","sourceRoot":"","sources":["../../src/core/modern.svelte.js"],"names":[],"mappings":"AAaA,2CAA2C;AAC3C,sCAOC;AAXD,uCAAuC;AACvC,uCAA2D;AAY3D,wCAAwC;AACxC,yEAQC;AAED,yCAAyC;AACzC,8CAGC;AAED;;;;GAIG;AACH,kEAGC"}
package/types/vite.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export function svelteTesting({ resolveBrowser, autoCleanup, }?: {
1
+ export function svelteTesting({ resolveBrowser, autoCleanup, noExternal, }?: {
2
2
  resolveBrowser?: boolean;
3
3
  autoCleanup?: boolean;
4
+ noExternal?: boolean;
4
5
  }): import("vite").Plugin;
5
6
  //# sourceMappingURL=vite.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.js"],"names":[],"mappings":"AAYO,iEAHI;IAAC,cAAc,CAAC,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAC,GAC/C,OAAO,MAAM,EAAE,MAAM,CAoBhC"}
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"}