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

Refactor <webview> tag tests #12886

Merged
merged 1 commit into from
May 14, 2018
Merged

Refactor <webview> tag tests #12886

merged 1 commit into from
May 14, 2018

Conversation

alexeykuzmin
Copy link
Contributor

@alexeykuzmin alexeykuzmin commented May 10, 2018

Rewrite tests with async/await.

@alexeykuzmin alexeykuzmin requested a review from a team May 10, 2018 21:43
@alexeykuzmin alexeykuzmin force-pushed the refactor-webview-tests branch 5 times, most recently from 4f4136f to 7fdc029 Compare May 10, 2018 23:58
Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

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

LGTM, but before I Approve -- If I'm reading correctly, this is not about a functional change, but about making the log output more readable. Is that correct?

@alexeykuzmin
Copy link
Contributor Author

alexeykuzmin commented May 11, 2018

@ckerr In several case it does make output more readable. And that was initial reason for some refactoring.

But mostly the changes here are about making code simpler, and easier to read and change. (Tests have to be super simple.)
Promises and async/await is the best thing happened to JS ever =)

@alexeykuzmin
Copy link
Contributor Author

@ckerr Did I answer you question? Anything else?

@alexeykuzmin
Copy link
Contributor Author

A good example would be a test with two event listeners:

    it('loads native modules when navigation happens', (done) => {
      <...>

      const listener = () => {
        webview.removeEventListener('did-finish-load', listener)
        const listener2 = (e) => {
          assert.equal(e.message, 'function')
          done()
        }
        webview.addEventListener('console-message', listener2)
        webview.reload()
      }
      webview.addEventListener('did-finish-load', listener)
      webview.setAttribute('nodeintegration', 'on')
      webview.src = `file://${fixtures}/pages/native-module.html`
      document.body.appendChild(webview)
    })

changed to
(non-essential part is omitted <...>)

    it('loads native modules when navigation happens', async function () {
      <...>

      await loadWebView(webview, {
        nodeintegration: 'on',
        src: `file://${fixtures}/pages/native-module.html`
      })

      webview.reload()

      const {message} = await waitForEvent(webview, 'console-message')
      assert.equal(message, 'function')
    })

Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

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

Yes that answers my question, I was just making sure that I wasn't misunderstanding the scope of the PR.

As for the PR itself, these changed tests are a lot more straightforward / readable. Thanks for these improvements!

@ckerr ckerr merged commit fc34076 into master May 14, 2018
@ckerr ckerr deleted the refactor-webview-tests branch May 14, 2018 22:00
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