Skip to content

Commit 7798bb5

Browse files
committed
{feature} use screen path to check if the screen is already open
1 parent f50d9bb commit 7798bb5

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

packages/test/src/screen.js

+18-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,24 @@ export async function openScreen(baseURL, page, harnessEnvironment, screen) {
3232
);
3333
}
3434

35-
if (
36-
typeof screen.isOpen !== "function" ||
37-
!(await screen.isOpen(page, baseURL))
38-
) {
35+
let isOpen;
36+
if (typeof screen.isOpen === "function") {
37+
isOpen = await screen.isOpen(page, baseURL);
38+
}
39+
40+
if (isOpen == null && "path" in screen && typeof screen.path === "string") {
41+
const url = new URL(screen.path, baseURL);
42+
const currentUrl = new URL(page.url());
43+
44+
// Should this be more intelligent? e.g. if the page to open is example.com/lorem
45+
// and the currently open page is example.com/lorem?ipsum, then the page is actually
46+
// already open
47+
// Then again, that sounds like it could be a problem if you want to use the open
48+
// function to clear the URL's search and hash?
49+
isOpen = url.href === currentUrl.href;
50+
}
51+
52+
if (!isOpen) {
3953
if (hasOpenFunction(screen)) {
4054
await screen.open(page, baseURL, (screen) =>
4155
openScreen(baseURL, page, harnessEnvironment, screen),

0 commit comments

Comments
 (0)