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

Conversation

Projects
None yet
2 participants
@alexeykuzmin
Contributor

alexeykuzmin commented May 10, 2018

Rewrite tests with async/await.

@alexeykuzmin alexeykuzmin requested a review from electron/reviewers as a code owner May 10, 2018

@ckerr

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

This comment has been minimized.

Show comment
Hide comment
@alexeykuzmin

alexeykuzmin May 11, 2018

Contributor

@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 =)

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@alexeykuzmin

alexeykuzmin May 14, 2018

Contributor

@ckerr Did I answer you question? Anything else?

Contributor

alexeykuzmin commented May 14, 2018

@ckerr Did I answer you question? Anything else?

@alexeykuzmin

This comment has been minimized.

Show comment
Hide comment
@alexeykuzmin

alexeykuzmin May 14, 2018

Contributor

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')
    })
Contributor

alexeykuzmin commented May 14, 2018

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')
    })
@ckerr

ckerr approved these changes May 14, 2018

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

10 checks passed

WIP ready for review
Details
ci/circleci: electron-linux-arm Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-arm-test Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-arm64 Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-arm64-test Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-ia32 Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-x64 Your tests passed on CircleCI!
Details
ci/circleci: electron-mas-x64 Your tests passed on CircleCI!
Details
ci/circleci: electron-osx-x64 Your tests passed on CircleCI!
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details

@ckerr ckerr deleted the refactor-webview-tests branch May 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment