Mailspring/spec_integration
Ben Gotow c6354feb41 feat(pro): New Nylas identity provider, onboarding and auth
commit 50d0cfb87c
Author: Ben Gotow <bengotow@gmail.com>
Date:   Fri May 27 14:01:49 2016 -0700

    IdentityStore conveniene methods for subscription state

commit 80c3c7b956
Author: Ben Gotow <bengotow@gmail.com>
Date:   Fri May 27 12:03:53 2016 -0700

    Periodically refresh identity, show expired notice in top bar

commit 5dc39efe98
Merge: 4c4f463 906ea74
Author: Juan Tejada <juans.tejada@gmail.com>
Date:   Thu May 26 15:17:46 2016 -0700

    Merge branch 'bengotow/n1-pro' of github.com:nylas/N1 into bengotow/n1-pro

commit 4c4f463f4b
Author: Juan Tejada <juans.tejada@gmail.com>
Date:   Thu May 26 15:16:48 2016 -0700

    Hijack links inside email that go to billing site and add SSO to them

commit 906ea74807
Author: Ben Gotow <bengotow@gmail.com>
Date:   Thu May 26 12:02:29 2016 -0700

    Add custom welcome page for upgrading users

commit 2ba9aedfe9
Author: Juan Tejada <juans.tejada@gmail.com>
Date:   Wed May 25 17:27:12 2016 -0700

    Add styling to Subscription tab in prefs

commit 384433a338
Author: Ben Gotow <bengotow@gmail.com>
Date:   Wed May 25 16:21:18 2016 -0700

    Add better style reset, more IdentityStore changes

commit c4f9dfb4e4
Author: Ben Gotow <bengotow@gmail.com>
Date:   Wed May 25 15:29:41 2016 -0700

    Add subscription tab

commit bd4c25405a
Author: Ben Gotow <bengotow@gmail.com>
Date:   Wed May 25 14:18:40 2016 -0700

    Point to billing-staging for now

commit 578e808bfc
Author: Ben Gotow <bengotow@gmail.com>
Date:   Wed May 25 13:30:13 2016 -0700

    Rename account helpers > onboarding helpers

commit dfea0a9861
Author: Ben Gotow <bengotow@gmail.com>
Date:   Wed May 25 13:26:46 2016 -0700

    A few minor fixes

commit 7110217fd4
Author: Ben Gotow <bengotow@gmail.com>
Date:   Wed May 25 12:58:21 2016 -0700

    feat(onboarding): Nylas Pro onboarding overhaul

    Summary:
    Rip out all invite-related code

    Enable Templates and Translate by default

    Scrub packages page, unused code in onboarding pkg

    Remove resizing

    New onboarding screens

    IMAP provider list, validation

    Call success with response object as well

    Renaming and tweaks

    Test Plan: No tests yet

    Reviewers: evan, juan, jackie

    Differential Revision: https://phab.nylas.com/D2985

commit dc9ea45ca9
Author: Ben Gotow <bengotow@gmail.com>
Date:   Wed May 25 12:52:39 2016 -0700

    Renaming and tweaks

commit 5ca4cd31ce
Author: Ben Gotow <bengotow@gmail.com>
Date:   Wed May 25 11:03:57 2016 -0700

    Call success with response object as well

commit 45f14f9b00
Author: Ben Gotow <bengotow@gmail.com>
Date:   Tue May 24 18:26:38 2016 -0700

    IMAP provider list, validation

commit c6ca124e6e
Author: Ben Gotow <bengotow@gmail.com>
Date:   Sat May 21 11:14:44 2016 -0700

    New onboarding screens

commit dad918d926
Author: Ben Gotow <bengotow@gmail.com>
Date:   Thu May 19 16:37:31 2016 -0700

    Remove resizing

commit ecb1a569e2
Author: Ben Gotow <bengotow@gmail.com>
Date:   Thu May 19 16:36:04 2016 -0700

    Scrub packages page, unused code in onboarding pkg

commit 3e0a44156c
Author: Ben Gotow <bengotow@gmail.com>
Date:   Thu May 19 16:33:12 2016 -0700

    Enable Templates and Translate by default

commit 0d218bc86f
Author: Ben Gotow <bengotow@gmail.com>
Date:   Thu May 19 16:30:47 2016 -0700

    Rip out all invite-related code
2016-05-27 14:21:19 -07:00
..
fixtures
helpers cleanup(config): Additional notes about config.cson => json 2016-04-26 13:17:29 -07:00
jasmine feat(babel6): Initial babel conversion 2016-05-06 11:54:38 -07:00
clean-app-boot-spec.es6 feat(pro): New Nylas identity provider, onboarding and auth 2016-05-27 14:21:19 -07:00
contenteditable-integration-spec.es6
logged-in-app-boot-spec.es6 fix(require): Move more requires to new electron format 2016-04-13 15:35:01 -07:00
package.json feat(babel6): Initial babel conversion 2016-05-06 11:54:38 -07:00
README.md

Integration Testing

In addition to unit tests, we run integration tests using ChromeDriver and WebdriverIO through the Spectron library.

Running Tests

script/grunt run-integration-tests

This command will, in order:

  1. Run npm test in the /spec_integration directory and pass in the NYLAS_ROOT_PATH
  2. Boot jasmine and load all files ending in -spec
  3. Most tests in beforeAll will boot N1 via the N1Launcher. See spec_integration/helpers/n1-launcher.es6
  4. This instantiates a new spectron Application which will spawn a ChromeDriver process with the appropriate N1 launch args.
  5. ChromeDriver will then boot a Selenium server at http://localhost:9515
  6. The ChromeDriver / Selenium server will boot N1 with testing hooks and expose an controlling API.
  7. The API is made easily available through the Spectron API
  8. The N1Launcher's mainWindowReady or popoutComposerWindowReady or onboardingWindowReady methods poll the app until the designated window is available and loaded. Then will resolve a Promise once everything has booted.

Writing Tests

The Spectron API is a pure extension over the Webdriver API. Reference both to write tests.

Most of the methods on app.client object apply to the "currently focused" window only. Since N1 has several windows (many of which are hidden) the N1Launcher extension will cycle through windows automatically until it finds the one you want, and then select it.

Furthermore, "loaded" in the pure Spectron sense is only once the window is booted. N1 windows take much longer to full finish loading packages and rendering the UI. The N1Launcher::windowReady method and its derivatives take this into account.

You will almost always need the minimal boilerplate for each integration test:

describe('My test', () => {
  beforeAll((done)=>{
    // Boot in dev mode with no arguments
    this.app = new N1Launcher(["--dev"]);
    this.app.mainWindowReady().finally(done);
  });

  afterAll((done)=> {
    if (this.app && this.app.isRunning()) {
      this.app.stop().finally(done);
    } else {
      done()
    }
  });

  it("is a test you'll write", () => {
  });

  it("is an async test you'll write", (done) => {
    doSomething.finally(done)
  });
});

Executing Code in N1's environment

The app.client.execute and app.client.executeAsync methods are extremely helpful when running code in N1. Those are documented slightly more on the WebdriveIO API docs page here

it("is a test you'll write", () => {
  this.app.client.execute((arg1)=>{
    // NOTE: `arg1` just got passed in over a JSON api. It can only be a
    // primitive data type

    // I'M RUNNING IN N1
    return someValue

  }, arg1).then(({value})=>{
    // NOTE: the return is stuffed in an attribute called `value`. Also it
    // passed back of a JSON API and can only be a primitive value.
  })
});

Debugging tests.

Debugging is through lots of console.loging.

There is code is spec_integration/jasmine/bootstrap.js that attempts to catch unhandled Promises and color them accordingly.

If you want to access logs from within N1 via the app.client.execute blocks, you'll have to either package it up yourself and return it, or use the new app.client.getMainProcessLogs() just added into Spectron.