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

[TECH] Mise à jour de ember-mocha dans Pix App. #638

Merged
merged 5 commits into from
Aug 12, 2019

Conversation

lisequesnel
Copy link
Contributor

@lisequesnel lisequesnel commented Aug 7, 2019

🦄 Problème

Pix avait quelques versions de retard sur ember-mocha, avec des changements importants notamment sur l'utilisation d'une nouvelle API : https://github.com/emberjs/ember-mocha.

🤖 Solution

Cette PR est la troisième et dernière partie pour utiliser la nouvelle API d'ember-mocha. Elle :

  • supprime les usages dépréciés
  • met à jour ember-mocha et ses dépendances : ember-cli-mirage

Plus techniquement, on avait avant pour les tests d'acceptance :

import { describe, it, beforeEach, afterEach } from 'mocha';
import { expect } from 'chai';
import startApp from 'app/tests/helpers/start-app';
import destroyApp from 'app/tests/helpers/destroy-app';

describe('basic acceptance test', function() {
  let application;

  beforeEach(function() {
    application = startApp();
  });

  afterEach(function() {
    destroyApp(application);
  });

  it('can visit /', function() {
    visit('/');

    return andThen(() => {
      expect(currentURL()).to.equal('/');
    });
  });
});

Maintenant :

import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupApplicationTest } from 'ember-mocha';
import { visit, currentURL } from '@ember/test-helpers';

describe('basic acceptance test', function() {
  setupApplicationTest();

  it('can visit /', async function() {
    await visit('/');
    expect(currentURL()).to.equal('/');
  });
});

🌈 Remarques

  • Avant, ember-auto-import n'existait pas, faker a donc été inclus dans ember-mocha. Avec l'apparition de ember-auto-import, plus de problème, donc faker a été sorti de ember-mocha. Ces deux packages nous sont donc nécessaires maintenant.
  • visit() lève une erreur Transition Aborted qui fait échouer les tests : c'est une issue connue visit() throws TransitionAborted error emberjs/ember-test-helpers#332. Pour contourner le problème une méthode visitWithAbortedTransition a été introduite.

user: { organizations: [{ id: 1 }, { id: 2 }] }
}));
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Je ne comprends pas très bien l'écriture de ces stubs. Est-ce que

currentUserStub = {
  user: { organizations: [{ id: 1 }, { id: 2 }] }
};

ne suffit pas ? A quoi sert la notion de Service ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Il me semble qu'on a besoin de Service pour avoir toutes les méthodes "cachées" comme les listeners d'events, etc

@lisequesnel lisequesnel force-pushed the ember-mocha-acceptance-tests-deprecation branch from 99e30aa to a9ea237 Compare August 8, 2019 11:41
@pix-service
Copy link
Contributor

@lisequesnel lisequesnel force-pushed the ember-mocha-acceptance-tests-deprecation branch from a9ea237 to 3a2d95b Compare August 9, 2019 08:53
in version 1.0.0, faker is removed from ember-cli-mirage.
We need to import it independently thanks to ember-auto-import.

It was included in ember-cli-mirage because ember-auto-import did not
exist in the first place.
@lisequesnel lisequesnel force-pushed the ember-mocha-acceptance-tests-deprecation branch from 3a2d95b to e07634d Compare August 12, 2019 08:24
@lisequesnel lisequesnel merged commit 407c6d0 into dev Aug 12, 2019
@lisequesnel lisequesnel deleted the ember-mocha-acceptance-tests-deprecation branch August 12, 2019 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants