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

Testing without deploying #1

Closed
knownasilya opened this issue Mar 8, 2018 · 6 comments
Closed

Testing without deploying #1

knownasilya opened this issue Mar 8, 2018 · 6 comments

Comments

@knownasilya
Copy link

Is there a simple way to test this notification without deploying?

@topaxi
Copy link
Owner

topaxi commented Mar 10, 2018

Not that I know of, one way I tested my notifications is to trigger a manual ServiceWorker update in the Google Chrome developer tools in the Application -> ServiceWorkers tab. Not sure if I changed something here as I don't seem to be able to reproduce this in one of my Apps.
It would probably nice to be able to trigger this manually somehow..

@pablogravielseo
Copy link

@topaxi I tried to reproduce just like you said, but not works.

@NullVoxPopuli
Copy link
Collaborator

is there a way we can at least have automated tests for this?
Like, we could mock the behavior of service-worker registration, and then test the affected UI?
I've added ember-concurrency in #3, and that adds enough complexity, where I think tests will be very welcome :)

@jonpitch
Copy link

jonpitch commented Oct 7, 2018

Assuming you use #3 - I test this in a few applications with an acceptance test. Something like:

import { module, test } from 'qunit';
import { visit, currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import { t } from 'ember-intl/test-support';
import page from '../pages/index';
import config from 'ember-get-config';

module('Acceptance | new build notification', function(hooks) {
  setupApplicationTest(hooks);

  hooks.beforeEach(function () {
    config.environment = 'staging';
    window.isUpdateAvailable = new Promise((resolve) => {
      resolve(true);
    });
  });

  hooks.afterEach(function () {
    config.environment = 'test';
    window.isUpdateAvailable = null;
  });

  test('new build renders when update is available', async function(assert) {
    await visit('/');

    assert.equal(currentURL(), '/login');
    assert.ok(page.build.isVisible, 'see new build notification');
    assert.equal(
      page.build.text,
      t('components.new-build-notifier.text'),
      'notification has correct text'
    );
    assert.ok(page.build.action.isVisible, 'see action to reload');
    assert.equal(
      page.build.action.text,
      t('components.new-build-notifier.action'),
      'action button has correct text'
    );
  });
});

Note that I only enable this notification in staging and production environments, hence the config.environment = 'staging';. The assumption is also that the polling interval is configurable. For production usage, I use 20 minutes, but in the test environment I cut that down to 1ms.

@miguelcobain
Copy link
Contributor

What I do for an ad-hoc testing locally is to:

  • start a development server with live-reload disabled with ember s -lr false
  • open app
  • make some change on the app to trigger another build
  • wait for the polling to run

This is easier when you set a smaller polling interval in the component with <ServiceWorkerUpdateNotify @pollingInterval={{1000}}>, for example.

@NullVoxPopuli
Copy link
Collaborator

Resolved via: https://github.com/topaxi/ember-service-worker-update-notify#testing-in-your-app

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

No branches or pull requests

6 participants