svelte-declarative-testing 0.3.1 → 0.3.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.
- package/README.md +31 -31
- package/package.json +1 -2
- package/src/components/core/Expect.svelte +0 -0
- package/src/components/core/index.d.ts +26 -11
- package/src/plugins/__snapshots__/vitest.test.ts.snap +1 -1
- package/src/plugins/index.d.ts +3 -0
- package/src/plugins/vitest.js +1 -1
- package/.vscode/extensions.json +0 -8
- package/ast.json +0 -1670
- package/eslint.config.js +0 -40
- package/examples/basic/Basic.test.svelte +0 -46
- package/src/plugins/vitest.test.ts +0 -229
- package/tsconfig.json +0 -35
- package/vitest.config.ts +0 -36
package/README.md
CHANGED
|
@@ -45,25 +45,25 @@ Your tests can look like this:
|
|
|
45
45
|
</script>
|
|
46
46
|
|
|
47
47
|
<Test it="opens the menu when the trigger is clicked">
|
|
48
|
-
<!--
|
|
49
|
-
|
|
50
|
-
<
|
|
51
|
-
|
|
52
|
-
<
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
<!-- Anything passed via the mount() snippet is rendered for each test -->
|
|
49
|
+
{#snippet mount()}
|
|
50
|
+
<Popover>
|
|
51
|
+
<PopoverTrigger>Open Menu</PopoverTrigger>
|
|
52
|
+
<PopoverMenu>
|
|
53
|
+
<PopoverMenuItem href="/account">Account</PopoverMenuItem>
|
|
54
|
+
<PopoverMenuItem href="/logout">Log out</PopoverMenuItem>
|
|
55
|
+
</PopoverMenu>
|
|
56
|
+
</Popover>
|
|
57
|
+
{/snippet}
|
|
56
58
|
|
|
57
59
|
<!-- one or more test functions can be provided as checks -->
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
/>
|
|
66
|
-
{/snippet}
|
|
60
|
+
<Check
|
|
61
|
+
fn={async (screen) => {
|
|
62
|
+
expect(screen.getByRole('menu', { includeHidden: true })).not.toBeVisible();
|
|
63
|
+
await screen.getByRole('button', { name: 'Open Menu' }).click();
|
|
64
|
+
expect(screen.getByRole('menu')).toBeVisible();
|
|
65
|
+
}}
|
|
66
|
+
/>
|
|
67
67
|
</Test>
|
|
68
68
|
```
|
|
69
69
|
|
|
@@ -173,8 +173,8 @@ rendered for each test.
|
|
|
173
173
|
| Properties | Type | Description |
|
|
174
174
|
| ---------- | ---------- | ------------------------------------------------------------------------------------- |
|
|
175
175
|
| `label` | `string` | The descriptive label for the test suite |
|
|
176
|
-
| `
|
|
177
|
-
| `
|
|
176
|
+
| `mount` | `Snippet` | Any component(s) that you wish to render for the tests |
|
|
177
|
+
| `children` | `Snippet` | A snippet block containing one or more `<Test>` elements |
|
|
178
178
|
| `skip` | `any` | Skips the suite if truthy, just like `describe.skip()` |
|
|
179
179
|
| `only` | `any` | Only run this suite if truthy, just like `describe.only()` |
|
|
180
180
|
| `todo` | `any` | Mark the suite as todo if truthy, just like `describe.todo()` |
|
|
@@ -184,17 +184,17 @@ rendered for each test.
|
|
|
184
184
|
|
|
185
185
|
```svelte
|
|
186
186
|
<Describe label="My Integration Tests">
|
|
187
|
-
|
|
187
|
+
{#snippet mount()}
|
|
188
|
+
<Button>My button</Button>
|
|
189
|
+
{/snippet}
|
|
188
190
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
</Test>
|
|
191
|
+
<Test it="renders an accessible button">
|
|
192
|
+
<!-- Test body goes here -->
|
|
193
|
+
</Test>
|
|
193
194
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
{/snippet}
|
|
195
|
+
<Test it="does something when I click the button">
|
|
196
|
+
<!-- Test body goes here -->
|
|
197
|
+
</Test>
|
|
198
198
|
</Describe>
|
|
199
199
|
```
|
|
200
200
|
|
|
@@ -213,8 +213,8 @@ parent `<Describe>` are rendered.
|
|
|
213
213
|
| Properties | Type | Description |
|
|
214
214
|
| ---------- | ---------- | -------------------------------------------------------------------------------- |
|
|
215
215
|
| `it` | `string` | The description of the test |
|
|
216
|
-
| `
|
|
217
|
-
| `
|
|
216
|
+
| `mount` | `Snippet` | Any component(s) that you wish to render for the test |
|
|
217
|
+
| `children` | `Snippet` | A snippet block containing one or more `<Check>` elements |
|
|
218
218
|
| `skip` | `any` | Skips the test if truthy, just like `test.skip()` |
|
|
219
219
|
| `only` | `any` | Only run this test if truthy, just like `test.only()` |
|
|
220
220
|
| `todo` | `any` | Mark the test as todo if truthy, just like `test.todo()` |
|
|
@@ -255,7 +255,7 @@ You can provide as many checks as you like and they will run sequentially.
|
|
|
255
255
|
{#snippet checks()}
|
|
256
256
|
<Check fn={({queryByRole}) => {
|
|
257
257
|
expect(queryByRole("button")).toBeIntheDocument();
|
|
258
|
-
}/>
|
|
258
|
+
}}/>
|
|
259
259
|
{/snippet}
|
|
260
260
|
</Describe>
|
|
261
261
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-declarative-testing",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "A way to mount your Svelte test components declaratively",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -37,7 +37,6 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"magic-string": "^0.30.21",
|
|
39
39
|
"source-map": "^0.7.6",
|
|
40
|
-
"ts-essentials": "^10.1.1",
|
|
41
40
|
"zimmerframe": "^1.1.4"
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
File without changes
|
|
@@ -1,26 +1,41 @@
|
|
|
1
1
|
import type { Snippet, Component } from 'svelte';
|
|
2
|
-
import { XOR } from 'ts-essentials';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
type KeysAsExclusiveUnion<T> = {
|
|
4
|
+
[K in keyof T]: { [P in K]: T[P] } & { [P in Exclude<keyof T, K>]?: never };
|
|
5
|
+
}[keyof T];
|
|
6
|
+
|
|
7
|
+
export type ModifierProps = {
|
|
8
|
+
/* These are all mutually exclusive on Describe and Test */
|
|
9
|
+
only?: boolean;
|
|
10
|
+
todo?: boolean;
|
|
11
|
+
skip?: boolean;
|
|
12
|
+
skipIf?: () => boolean;
|
|
13
|
+
runIf?: () => boolean;
|
|
14
|
+
fails?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type ModifiersWithoutFails = Omit<ModifierProps, 'fails'>;
|
|
18
|
+
|
|
19
|
+
type DescribeModifierProps =
|
|
20
|
+
| KeysAsExclusiveUnion<ModifiersWithoutFails>
|
|
21
|
+
| { [K in keyof ModifiersWithoutFails]?: never };
|
|
22
|
+
|
|
23
|
+
type TestModifierProps =
|
|
24
|
+
| KeysAsExclusiveUnion<ModifierProps>
|
|
25
|
+
| { [K in keyof ModifierProps]?: never };
|
|
12
26
|
|
|
13
27
|
export type DescribeProps = {
|
|
14
28
|
label: string;
|
|
15
29
|
children: Snippet;
|
|
16
30
|
mount?: Snippet;
|
|
17
|
-
|
|
31
|
+
fails?: never;
|
|
32
|
+
} & DescribeModifierProps;
|
|
18
33
|
|
|
19
34
|
export type BaseTestProps = {
|
|
20
35
|
it: string;
|
|
21
36
|
children: Snippet;
|
|
22
37
|
mount?: Snippet;
|
|
23
|
-
} &
|
|
38
|
+
} & TestModifierProps;
|
|
24
39
|
|
|
25
40
|
type RenderResult = {
|
|
26
41
|
unmount: () => void | Promise<void>;
|
|
@@ -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(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 } from "svelte"; mount((await import(/* @vite-ignore */import.meta.url)).default, { target: document.body });"`;
|
|
4
4
|
|
|
5
5
|
exports[`vitest pre plugin > produces code with a dummy test suite 1`] = `
|
|
6
6
|
"
|
package/src/plugins/vitest.js
CHANGED
|
@@ -18,7 +18,7 @@ import { SourceMapGenerator, SourceMapConsumer } from 'source-map';
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
const mountCode =
|
|
21
|
-
';import { mount } from "svelte"; mount((await import(import.meta.url)).default, { target: document.body });';
|
|
21
|
+
';import { mount } from "svelte"; mount((await import(/* @vite-ignore */import.meta.url)).default, { target: document.body });';
|
|
22
22
|
|
|
23
23
|
const testFileRegex = /\.(?:test|spec)\.svelte$/;
|
|
24
24
|
const getNameFromAttr = (node, attr) =>
|