@vitest/browser-playwright 4.1.5 → 5.0.0-beta.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/dist/index.js +31 -12
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parseKeyDef, resolveScreenshotPath, defineBrowserProvider } from '@vitest/browser';
|
|
2
2
|
export { defineBrowserCommand } from '@vitest/browser';
|
|
3
3
|
import { createManualModuleSource } from '@vitest/mocker/node';
|
|
4
4
|
import c from 'tinyrainbow';
|
|
@@ -173,9 +173,9 @@ const basename = function(p, extension) {
|
|
|
173
173
|
// - locator('[data-vitest="true"]').contentFrame().getByRole('button')
|
|
174
174
|
// ⇓
|
|
175
175
|
// - getByRole('button')
|
|
176
|
-
function getDescribedLocator(context, selector) {
|
|
177
|
-
const
|
|
178
|
-
return typeof
|
|
176
|
+
function getDescribedLocator(context, { locator, selector }) {
|
|
177
|
+
const iframeLocator = context.iframe.locator(selector);
|
|
178
|
+
return typeof iframeLocator.describe === "function" ? iframeLocator.describe(locator) : iframeLocator;
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
const clear = async (context, selector) => {
|
|
@@ -198,7 +198,7 @@ const tripleClick = async (context, selector, options = {}) => {
|
|
|
198
198
|
|
|
199
199
|
const dragAndDrop = async (context, source, target, options_) => {
|
|
200
200
|
const frame = await context.frame();
|
|
201
|
-
await frame.dragAndDrop(source, target, options_);
|
|
201
|
+
await frame.dragAndDrop(source.selector, target.selector, options_);
|
|
202
202
|
};
|
|
203
203
|
|
|
204
204
|
const fill = async (context, selector, text, options = {}) => {
|
|
@@ -497,6 +497,14 @@ function selectAll() {
|
|
|
497
497
|
}
|
|
498
498
|
}
|
|
499
499
|
|
|
500
|
+
const SCREENSHOT_STYLES = `
|
|
501
|
+
iframe[data-vitest="true"] {
|
|
502
|
+
position: absolute !important;
|
|
503
|
+
inset: 0 !important;
|
|
504
|
+
z-index: ${Number.MAX_SAFE_INTEGER} !important;
|
|
505
|
+
transform: none !important;
|
|
506
|
+
}
|
|
507
|
+
`;
|
|
500
508
|
/**
|
|
501
509
|
* Takes a screenshot using the provided browser context and returns a buffer and the expected screenshot path.
|
|
502
510
|
*
|
|
@@ -517,23 +525,29 @@ async function takeScreenshot(context, name, options) {
|
|
|
517
525
|
await mkdir(dirname(savePath), { recursive: true });
|
|
518
526
|
}
|
|
519
527
|
const mask = options.mask?.map((selector) => getDescribedLocator(context, selector));
|
|
528
|
+
const style = context.project.config.browser.ui ? options.style === undefined ? SCREENSHOT_STYLES : SCREENSHOT_STYLES + options.style : options.style;
|
|
520
529
|
if (options.element) {
|
|
521
530
|
const { element: selector, ...config } = options;
|
|
522
531
|
const element = getDescribedLocator(context, selector);
|
|
523
532
|
const buffer = await element.screenshot({
|
|
524
533
|
...config,
|
|
525
534
|
mask,
|
|
526
|
-
path: savePath
|
|
535
|
+
path: savePath,
|
|
536
|
+
style
|
|
527
537
|
});
|
|
528
538
|
return {
|
|
529
539
|
buffer,
|
|
530
540
|
path
|
|
531
541
|
};
|
|
532
542
|
}
|
|
533
|
-
const buffer = await getDescribedLocator(context,
|
|
543
|
+
const buffer = await getDescribedLocator(context, {
|
|
544
|
+
selector: "body",
|
|
545
|
+
locator: "locator('body')"
|
|
546
|
+
}).screenshot({
|
|
534
547
|
...options,
|
|
535
548
|
mask,
|
|
536
|
-
path: savePath
|
|
549
|
+
path: savePath,
|
|
550
|
+
style
|
|
537
551
|
});
|
|
538
552
|
return {
|
|
539
553
|
buffer,
|
|
@@ -616,14 +630,14 @@ const markTrace = async (context, payload) => {
|
|
|
616
630
|
if (!context.provider.tracingContexts.has(context.sessionId)) {
|
|
617
631
|
return;
|
|
618
632
|
}
|
|
619
|
-
const { name,
|
|
633
|
+
const { name, element, stack } = payload;
|
|
620
634
|
const location = parseLocation(context, stack);
|
|
621
635
|
// mark trace via group/groupEnd with dummy calls to force snapshot.
|
|
622
636
|
// https://github.com/microsoft/playwright/issues/39308
|
|
623
637
|
await context.context.tracing.group(name, { location });
|
|
624
638
|
try {
|
|
625
|
-
if (
|
|
626
|
-
const locator = getDescribedLocator(context,
|
|
639
|
+
if (element) {
|
|
640
|
+
const locator = getDescribedLocator(context, element);
|
|
627
641
|
if (typeof locator._expect === "function") {
|
|
628
642
|
await locator._expect("to.be.attached", {
|
|
629
643
|
isNot: false,
|
|
@@ -757,6 +771,10 @@ const upload = async (context, selector, files, options) => {
|
|
|
757
771
|
await getDescribedLocator(context, selector).setInputFiles(playwrightFiles, options);
|
|
758
772
|
};
|
|
759
773
|
|
|
774
|
+
const viewport = async (context, options) => {
|
|
775
|
+
await context.page.setViewportSize(options);
|
|
776
|
+
};
|
|
777
|
+
|
|
760
778
|
const wheel = async (context, selector, options) => {
|
|
761
779
|
await hover(context, selector);
|
|
762
780
|
const times = options.times ?? 1;
|
|
@@ -790,7 +808,8 @@ var commands = {
|
|
|
790
808
|
__vitest_annotateTraces: annotateTraces,
|
|
791
809
|
__vitest_markTrace: markTrace,
|
|
792
810
|
__vitest_groupTraceStart: groupTraceStart,
|
|
793
|
-
__vitest_groupTraceEnd: groupTraceEnd
|
|
811
|
+
__vitest_groupTraceEnd: groupTraceEnd,
|
|
812
|
+
__vitest_viewport: viewport
|
|
794
813
|
};
|
|
795
814
|
|
|
796
815
|
const pkgRoot = resolve(fileURLToPath(import.meta.url), "../..");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/browser-playwright",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "5.0.0-beta.2",
|
|
5
5
|
"description": "Browser running for Vitest using playwright",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
],
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"playwright": "*",
|
|
45
|
-
"vitest": "
|
|
45
|
+
"vitest": "5.0.0-beta.2"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|
|
48
48
|
"playwright": {
|
|
@@ -51,12 +51,12 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"tinyrainbow": "^3.1.0",
|
|
54
|
-
"@vitest/
|
|
55
|
-
"@vitest/
|
|
54
|
+
"@vitest/browser": "5.0.0-beta.2",
|
|
55
|
+
"@vitest/mocker": "5.0.0-beta.2"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"playwright": "^1.59.0",
|
|
59
|
-
"vitest": "
|
|
59
|
+
"vitest": "5.0.0-beta.2"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "premove dist && pnpm rollup -c",
|