@testing-library/svelte 5.2.3 → 5.2.4

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.4",
4
4
  "description": "Simple and complete Svelte testing utilities that encourage good testing practices.",
5
5
  "main": "src/index.js",
6
6
  "exports": {
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
+ }
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"}