svelte-declarative-testing 0.3.2 → 0.3.3

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": "svelte-declarative-testing",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "A way to mount your Svelte test components declaratively",
5
5
  "type": "module",
6
6
  "module": "src/index.js",
@@ -1,6 +1,6 @@
1
1
  // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
- exports[`vitest post plugin > produces code that mounts the component and returns a render result 1`] = `"export default function AComponent() {};import { mount } from "svelte"; mount((await import(/* @vite-ignore */import.meta.url)).default, { target: document.body });"`;
3
+ exports[`vitest post plugin > produces code that mounts the component and returns a render result 1`] = `"export default function AComponent() {};import { mount as svelte_declarative_testing_mount } from "svelte";svelte_declarative_testing_mount(AComponent_test, { target: document.body });"`;
4
4
 
5
5
  exports[`vitest pre plugin > produces code with a dummy test suite 1`] = `
6
6
  "
@@ -17,8 +17,8 @@ import { SourceMapGenerator, SourceMapConsumer } from 'source-map';
17
17
  * imported so that the tests run.
18
18
  */
19
19
 
20
- const mountCode =
21
- ';import { mount } from "svelte"; mount((await import(/* @vite-ignore */import.meta.url)).default, { target: document.body });';
20
+ const getMountCode = (/**@type {string}*/ name) =>
21
+ `;import { mount as svelte_declarative_testing_mount } from "svelte";svelte_declarative_testing_mount(${name}, { target: document.body });`;
22
22
 
23
23
  const testFileRegex = /\.(?:test|spec)\.svelte$/;
24
24
  const getNameFromAttr = (node, attr) =>
@@ -123,9 +123,10 @@ const post = () => ({
123
123
 
124
124
  const s = new MagicString(code);
125
125
 
126
- // We mount by reimporting the default export of the Svelte file (the
127
- // component). This is the magic that runs the tests.
128
- s.append(mountCode);
126
+ // TODO: find a more robust way to get the component name
127
+ const name = id.split('/').pop().replace('.svelte', '').replace(/\./g, '_');
128
+
129
+ s.append(getMountCode(name));
129
130
 
130
131
  return { code: s.toString() };
131
132
  },