@vitest/browser 4.0.0-beta.1 → 4.0.0-beta.10

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.
Files changed (42) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +3 -15
  3. package/context.d.ts +153 -3
  4. package/dist/client/.vite/manifest.json +6 -6
  5. package/dist/client/__vitest__/assets/index-DFDJV2DF.js +53 -0
  6. package/dist/client/__vitest__/index.html +1 -1
  7. package/dist/client/__vitest_browser__/orchestrator-BXX6oamz.js +296 -0
  8. package/dist/client/__vitest_browser__/{tester-BScMoGFI.js → tester-CMhJ1E1W.js} +294 -570
  9. package/dist/client/__vitest_browser__/{utils-Owv5OOOf.js → utils-CPmDBIKG.js} +3 -3
  10. package/dist/client/error-catcher.js +7 -3
  11. package/dist/client/esm-client-injector.js +1 -0
  12. package/dist/client/orchestrator.html +2 -2
  13. package/dist/client/tester/tester.html +2 -2
  14. package/dist/client.js +24 -8
  15. package/dist/context.js +29 -22
  16. package/dist/expect-element.js +10 -8
  17. package/dist/index-CwoiDq7G.js +6 -0
  18. package/dist/index-DDlvjJVO.js +1 -0
  19. package/dist/index.d.ts +16 -10
  20. package/dist/index.js +550 -98
  21. package/dist/locators/index.d.ts +8 -7
  22. package/dist/locators/index.js +1 -1
  23. package/dist/locators/playwright.js +1 -1
  24. package/dist/locators/preview.js +1 -1
  25. package/dist/locators/webdriverio.js +1 -1
  26. package/dist/providers/playwright.d.ts +103 -0
  27. package/dist/{webdriver-KA1WiV0q.js → providers/playwright.js} +37 -180
  28. package/dist/providers/preview.d.ts +16 -0
  29. package/dist/{providers.js → providers/preview.js} +17 -21
  30. package/dist/providers/webdriverio.d.ts +50 -0
  31. package/dist/providers/webdriverio.js +171 -0
  32. package/dist/shared/screenshotMatcher/types.d.ts +16 -0
  33. package/dist/state.js +4 -2
  34. package/dist/types.d.ts +5 -7
  35. package/jest-dom.d.ts +95 -1
  36. package/package.json +20 -30
  37. package/utils.d.ts +1 -1
  38. package/dist/client/__vitest__/assets/index-BjtzXzAw.js +0 -58
  39. package/dist/client/__vitest_browser__/orchestrator-CQgVbcQq.js +0 -3213
  40. package/dist/index-W1MM53zC.js +0 -1
  41. package/providers/playwright.d.ts +0 -81
  42. package/providers/webdriverio.d.ts +0 -22
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021-Present Vitest Team
3
+ Copyright (c) 2021-Present VoidZero Inc. and Vitest contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,19 +1,7 @@
1
1
  # @vitest/browser
2
2
 
3
- [Browser runner](https://vitest.dev/guide/browser/) for Vitest.
3
+ [![NPM version](https://img.shields.io/npm/v/@vitest/browser?color=a1b858&label=)](https://www.npmjs.com/package/@vitest/browser)
4
4
 
5
- > ⚠️ This package is **experimental**. While this package will be released along with other packages, it will not follow SemVer for breaking changes until we mark it as ready.
5
+ Running Vitest tests in the real browser.
6
6
 
7
- ## Development Setup
8
-
9
- At project root:
10
-
11
- ```bash
12
- cd test/browser
13
- # runs relevant tests for the browser mode
14
- # useful to confirm everything works fine
15
- pnpm test
16
- # runs tests as the browser mode
17
- # useful during development
18
- pnpm test-fixtures
19
- ```
7
+ [GitHub](https://github.com/vitest-dev/vitest) | [Documentation](https://vitest.dev/guide/browser/)
package/context.d.ts CHANGED
@@ -44,6 +44,129 @@ export interface ScreenshotOptions {
44
44
  save?: boolean
45
45
  }
46
46
 
47
+ export interface ScreenshotComparatorRegistry {
48
+ pixelmatch: {
49
+ /**
50
+ * The maximum number of pixels that are allowed to differ between the captured
51
+ * screenshot and the stored reference image.
52
+ *
53
+ * If set to `undefined`, any non-zero difference will cause the test to fail.
54
+ *
55
+ * For example, `allowedMismatchedPixels: 10` means the test will pass if 10
56
+ * or fewer pixels differ, but fail if 11 or more differ.
57
+ *
58
+ * If both this and `allowedMismatchedPixelRatio` are set, the more restrictive
59
+ * value (i.e., fewer allowed mismatches) will be used.
60
+ *
61
+ * @default undefined
62
+ */
63
+ allowedMismatchedPixels?: number | undefined
64
+ /**
65
+ * The maximum allowed ratio of differing pixels between the captured screenshot
66
+ * and the reference image.
67
+ *
68
+ * Must be a value between `0` and `1`.
69
+ *
70
+ * For example, `allowedMismatchedPixelRatio: 0.02` means the test will pass
71
+ * if up to 2% of pixels differ, but fail if more than 2% differ.
72
+ *
73
+ * If both this and `allowedMismatchedPixels` are set, the more restrictive
74
+ * value (i.e., fewer allowed mismatches) will be used.
75
+ *
76
+ * @default undefined
77
+ */
78
+ allowedMismatchedPixelRatio?: number | undefined
79
+ /**
80
+ * Acceptable perceived color difference between the same pixel in two images.
81
+ *
82
+ * Value ranges from `0` (strict) to `1` (very lenient). Lower values mean
83
+ * small differences will be detected.
84
+ *
85
+ * The comparison uses the {@link https://en.wikipedia.org/wiki/YIQ | YIQ color space}.
86
+ *
87
+ * @default 0.1
88
+ */
89
+ threshold?: number | undefined
90
+ /**
91
+ * If `true`, disables detection and ignoring of anti-aliased pixels.
92
+ *
93
+ * @default false
94
+ */
95
+ includeAA?: boolean | undefined
96
+ /**
97
+ * Blending level of unchanged pixels in the diff image.
98
+ *
99
+ * Ranges from `0` (white) to `1` (original brightness).
100
+ *
101
+ * @default 0.1
102
+ */
103
+ alpha?: number | undefined
104
+ /**
105
+ * Color used for anti-aliased pixels in the diff image.
106
+ *
107
+ * Format: `[R, G, B]`
108
+ *
109
+ * @default [255, 255, 0]
110
+ */
111
+ aaColor?: [r: number, g: number, b: number] | undefined
112
+ /**
113
+ * Color used for differing pixels in the diff image.
114
+ *
115
+ * Format: `[R, G, B]`
116
+ *
117
+ * @default [255, 0, 0]
118
+ */
119
+ diffColor?: [r: number, g: number, b: number] | undefined
120
+ /**
121
+ * Optional alternative color for dark-on-light differences, to help show
122
+ * what's added vs. removed.
123
+ *
124
+ * If not set, `diffColor` is used for all differences.
125
+ *
126
+ * Format: `[R, G, B]`
127
+ *
128
+ * @default undefined
129
+ */
130
+ diffColorAlt?: [r: number, g: number, b: number] | undefined
131
+ /**
132
+ * If `true`, shows only the diff as a mask on a transparent background,
133
+ * instead of overlaying it on the original image.
134
+ *
135
+ * Anti-aliased pixels won't be shown (if detected).
136
+ *
137
+ * @default false
138
+ */
139
+ diffMask?: boolean | undefined
140
+ }
141
+ }
142
+
143
+ export interface ScreenshotMatcherOptions<
144
+ ComparatorName extends keyof ScreenshotComparatorRegistry = keyof ScreenshotComparatorRegistry
145
+ > {
146
+ /**
147
+ * The name of the comparator to use for visual diffing.
148
+ *
149
+ * Must be one of the keys from {@linkcode ScreenshotComparatorRegistry}.
150
+ *
151
+ * @defaultValue `'pixelmatch'`
152
+ */
153
+ comparatorName?: ComparatorName
154
+ comparatorOptions?: ScreenshotComparatorRegistry[ComparatorName]
155
+ screenshotOptions?: Omit<
156
+ ScreenshotOptions,
157
+ 'element' | 'base64' | 'path' | 'save' | 'type'
158
+ >
159
+ /**
160
+ * Time to wait until a stable screenshot is found.
161
+ *
162
+ * Setting this value to `0` disables the timeout, but if a stable screenshot
163
+ * can't be determined the process will not end.
164
+ *
165
+ * @default 5000
166
+ */
167
+ timeout?: number
168
+ }
169
+
47
170
  export interface BrowserCommands {
48
171
  readFile: (
49
172
  path: string,
@@ -332,6 +455,8 @@ interface LocatorSelectors {
332
455
  getByTestId: (text: string | RegExp) => Locator
333
456
  }
334
457
 
458
+ export interface FrameLocator extends LocatorSelectors {}
459
+
335
460
  export interface Locator extends LocatorSelectors {
336
461
  /**
337
462
  * Selector string that will be used to locate the element by the browser provider.
@@ -350,6 +475,12 @@ export interface Locator extends LocatorSelectors {
350
475
  */
351
476
  readonly selector: string
352
477
 
478
+ /**
479
+ * The number of elements that this locator is matching.
480
+ * @see {@link https://vitest.dev/guide/browser/locators#length}
481
+ */
482
+ readonly length: number
483
+
353
484
  /**
354
485
  * Click on an element. You can use the options to set the cursor position.
355
486
  * @see {@link https://vitest.dev/guide/browser/interactivity-api#userevent-click}
@@ -421,7 +552,7 @@ export interface Locator extends LocatorSelectors {
421
552
  *
422
553
  * @see {@link https://vitest.dev/guide/browser/locators#element}
423
554
  */
424
- element(): Element
555
+ element(): HTMLElement | SVGElement
425
556
  /**
426
557
  * Returns an array of elements matching the selector.
427
558
  *
@@ -429,7 +560,7 @@ export interface Locator extends LocatorSelectors {
429
560
  *
430
561
  * @see {@link https://vitest.dev/guide/browser/locators#elements}
431
562
  */
432
- elements(): Element[]
563
+ elements(): (HTMLElement | SVGElement)[]
433
564
  /**
434
565
  * Returns an element matching the selector.
435
566
  *
@@ -438,7 +569,7 @@ export interface Locator extends LocatorSelectors {
438
569
  *
439
570
  * @see {@link https://vitest.dev/guide/browser/locators#query}
440
571
  */
441
- query(): Element | null
572
+ query(): HTMLElement | SVGElement | null
442
573
  /**
443
574
  * Wraps an array of `.elements()` matching the selector in a new `Locator`.
444
575
  *
@@ -578,6 +709,25 @@ export interface BrowserPage extends LocatorSelectors {
578
709
  * @see {@link https://vitest.dev/guide/browser/locators}
579
710
  */
580
711
  elementLocator(element: Element): Locator
712
+ /**
713
+ * The iframe locator. This is a document locator that enters the iframe body
714
+ * and works similarly to the `page` object.
715
+ *
716
+ * As the first argument, pass down the locator to the `<iframe>` element itself.
717
+ *
718
+ * **Warning:** At the moment, this is supported only by the `playwright` provider.
719
+ * @example
720
+ * ```ts
721
+ * const frame = page.frameLocator(
722
+ * page.getByTestId('iframe')
723
+ * )
724
+ *
725
+ * await frame.getByText('Hello World').click()
726
+ * ```
727
+ * @param locator The locator object.
728
+ * @see {@link https://vitest.dev/guide/browser/locators}
729
+ */
730
+ frameLocator(locator: Locator): FrameLocator
581
731
  }
582
732
 
583
733
  export interface BrowserLocators {
@@ -1,24 +1,24 @@
1
1
  {
2
- "_utils-Owv5OOOf.js": {
3
- "file": "__vitest_browser__/utils-Owv5OOOf.js",
2
+ "_utils-CPmDBIKG.js": {
3
+ "file": "__vitest_browser__/utils-CPmDBIKG.js",
4
4
  "name": "utils"
5
5
  },
6
6
  "orchestrator.html": {
7
- "file": "__vitest_browser__/orchestrator-CQgVbcQq.js",
7
+ "file": "__vitest_browser__/orchestrator-BXX6oamz.js",
8
8
  "name": "orchestrator",
9
9
  "src": "orchestrator.html",
10
10
  "isEntry": true,
11
11
  "imports": [
12
- "_utils-Owv5OOOf.js"
12
+ "_utils-CPmDBIKG.js"
13
13
  ]
14
14
  },
15
15
  "tester/tester.html": {
16
- "file": "__vitest_browser__/tester-BScMoGFI.js",
16
+ "file": "__vitest_browser__/tester-CMhJ1E1W.js",
17
17
  "name": "tester",
18
18
  "src": "tester/tester.html",
19
19
  "isEntry": true,
20
20
  "imports": [
21
- "_utils-Owv5OOOf.js"
21
+ "_utils-CPmDBIKG.js"
22
22
  ]
23
23
  }
24
24
  }