Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for async waitForTarget #7885

Merged
merged 3 commits into from Feb 18, 2022
Merged

feat: add support for async waitForTarget #7885

merged 3 commits into from Feb 18, 2022

Conversation

tmkx
Copy link
Contributor

@tmkx tmkx commented Jan 1, 2022

What kind of change does this PR introduce?

feature

Did you add tests for your changes?
yes
If relevant, did you update the documentation?
yes
Summary
sometimes we need to call waitForTarget in async:

const target = await browser.waitForTarget((target) =>
  target
    .page()
    .then((page) => page.title())
    .then((title) => title === 'expected')
);

Does this PR introduce a breaking change?
no

Other information

@OrKoN
Copy link
Collaborator

OrKoN commented Feb 11, 2022

Does it make sense to use debugError instead of console.error?

@tmkx
Copy link
Contributor Author

tmkx commented Feb 11, 2022

@OrKoN Hello, I do not understand, what does this have to do with debugError and console.error?

@OrKoN
Copy link
Collaborator

OrKoN commented Feb 11, 2022

Apologies, ignore that, I intended to leave that comment on #7883

@OrKoN
Copy link
Collaborator

OrKoN commented Feb 15, 2022

The timeout setting is not respected if the callback never resolves or takes a long time to resolve. Could you address that? also, the firefox-related failures probably require itFailsFirefox instead of it.

@tmkx
Copy link
Contributor Author

tmkx commented Feb 15, 2022

Sorry, the test was copied from this one, so it should use itFailsFirefox also. Updated.

itFailsFirefox(
'should report when a new page is created and closed',
async () => {
const { page, server, context } = getTestState();
const [otherPage] = await Promise.all([
context
.waitForTarget(
(target) =>
target.url() === server.CROSS_PROCESS_PREFIX + '/empty.html'
)
.then((target) => target.page()),
page.evaluate(
(url: string) => window.open(url),
server.CROSS_PROCESS_PREFIX + '/empty.html'
),
]);

@OrKoN OrKoN self-requested a review February 18, 2022 06:00
src/common/Browser.ts Outdated Show resolved Hide resolved
src/common/Browser.ts Outdated Show resolved Hide resolved
test/target.spec.ts Outdated Show resolved Hide resolved
Promise.race([
targetPromise,
(async () => {
for (const target of this.targets()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh, additional edge cases come to mind. WDYT about the following: we start waiting for a target and start checking existing targets one by one (and say there is a hundred of targets), then a matching target gets created and we resolve the waitForTarget with it. Although we resolved the inner promise continues executing and keeps checking the remaining targets one by one. I think that should be addressed by checking if the waitWithTimeout has been resolved and returning earlier.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think let's leave this for a follow-up (seems to be rather an edge case)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants