Ember acceptance tests fail when ran all at once

187 views Asked by At

I have about 5 acceptance tests which all pass when ran individually. When I want to run all of my tests, the acceptance tests will fail, except for the first one that was ran. All acceptance tests except for the first one will simply not render the application, thus all failing. I've checked to see if there are any pending waiters and if the state is settled and I have not been able to find anything where i can tell it's not. I've also added the waitFor declarator to certain async parts of my code to make sure that everything is resolved. All requests are also mocked with MSW. I start the mock service worker on every test, so that should definitely be running.

These are the current versions of the related dependencies:

"@ember/test-helpers": "^2.8.1", "qunit": "^2.17.2", "qunit-dom": "^1.6.0", "ember-qunit": "^5.1.5", "ember-source": "~3.28.8", "ember-cli": "~3.28.5"

Here is an example from one of my acceptance tests. This file contains three tests. When running all the tests, the first one will act normally and all the following ones will not render, thus failing.

import { visit, waitFor, click, clearRender } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import backstop from 'ember-backstop/test-support/backstop';
import { authenticateSession } from 'ember-simple-auth/test-support';
import { worker } from 'atlas-mocking/browser';
import { getSettledState } from '@ember/test-helpers/settled';
import { getPendingWaiterState } from '@ember/test-waiters';

module('Acceptance | Oportunity test', function (hooks) {
  setupApplicationTest(hooks);

  test('checking if basic values get loaded into detail page', async function (assert) {
    worker.start();
    authenticateSession({
      authToken: '12345',
      otherData: 'some-data',
    });

    await visit('/opportunity/index');
    await waitFor('[data-test="modelRouteTable"]');
    assert.dom('[data-test="modelRouteTable"]').exists();

    await visit('/opportunity/258234/view');
    //check if detailscreen of view page has been rendered
    await waitFor('[data-test="opportunityDetailSection"]');
    await backstop(assert);
    assert.dom('[data-test="name"]').exists();
    assert.dom('[data-test="opportunityStage"]').exists();
    assert.dom('[data-test="opportunityType"]').exists();
    assert.dom('[data-test="closeDate"]').exists();
    assert.dom('[data-test="currency"]').exists();
    assert.dom('[data-test="company"]').exists();
    assert.dom('[data-test="contact"]').exists();
    assert.dom('[data-test="externalReference"]').exists();
    assert.dom('[data-test="owner"]').exists();
    assert.dom('[data-test="organization"]').exists();
    assert.dom('[data-test="salesOrder"]').exists();
    assert.dom('[data-test="campaign"]').exists();

    assert.dom('[data-test="groupRequestDetail"]').exists();
    assert.dom('[data-test="directionType"]').exists();
    assert.dom('[data-test="departureDate"]').exists();
    assert.dom('[data-test="returnDate"]').exists();
    assert.dom('[data-test="directFlightsPreferred"]').exists();
    assert.dom('[data-test="requestNumber"]').exists();
    assert.dom('[data-test="country"]').exists();
    assert.dom('[data-test="extraFlightInformationDetail"]').exists();
    assert.dom('[data-test="passengerNames"]').exists();
    assert.dom('[data-test="budgetPerPerson"]').exists();
    assert.dom('[data-test="luggage"]').exists();
    assert.dom('[data-test="requestedAirline"]').exists();
    assert.dom('[data-test="groupType"]').exists();
    assert.dom('[data-test="commentsDetail"]').exists();
    assert.dom('[data-test="comments"]').exists();
    assert.dom('[data-test="internalComments"]').exists();
    console.log(getSettledState());
    console.log(getPendingWaiterState());
    await clearRender();
  });

  test('checking if correct values get added into edit view', async function (assert) {
    worker.start();
    authenticateSession({
      authToken: '12345',
      otherData: 'some-data',
    });

    await visit('/opportunity/index');
    await waitFor('[data-test="modelRouteTable"]');
    assert.dom('[data-test="modelRouteTable"]').exists();

    await visit('/opportunity/258234/view');
    await waitFor('[data-test="opportunityDetailSection"]');
    await click('[data-test="editButton"]');
    await waitFor('[data-test="opportunityEdit"]');

    //check if editscreen of detail page has been rendered with correct values
    assert.dom('[data-test="nameInput"] input').hasAnyValue();
    assert.dom('[data-test="opportunityStageInput"] select').hasAnyValue();
    assert.dom('[data-test="opportunityTypeInput"] select').hasAnyValue();
    assert.dom('[data-test="closeDateInput"] input').hasAnyValue();
    assert.dom('[data-test="currencyInput"] select').hasAnyValue();
    assert.dom('[data-test="companyInput"] .name').hasAnyText();
    assert.dom('[data-test="contactInput"] .name').hasAnyText();
    assert.dom('[data-test="externalReferenceInput"] input').hasAnyValue();
    assert.dom('[data-test="ownerInput"] .name').hasAnyText();
    assert.dom('[data-test="organizationInput"] select').hasAnyValue();

    assert.dom('[data-test="directionTypeInput"] select').hasAnyValue();
    assert.dom('[data-test="departureDateInput"] input').hasAnyValue();
    assert.dom('[data-test="returnDateInput"] input').hasAnyValue();
    assert.dom('[data-test="directFlightsPreferredInput"] input').hasNoValue();
    assert.dom('[data-test="requestNumberInput"] input').hasNoValue();
    assert.dom('[data-test="countryInput"] .name').doesNotExist();
    assert.dom('[data-test="passengerNamesInput"] select').hasAnyValue();
    assert.dom('[data-test="budgetPerPersonInput"] input').hasNoValue();
    assert.dom('[data-test="luggageInput"] select').hasAnyValue();
    assert.dom('[data-test="requestedAirlineInput"] .name').doesNotExist();
    assert.dom('[data-test="groupTypeInput"] select').hasAnyValue();
    assert.dom('[data-test="commentsInput"] textarea').hasNoValue();
    assert.dom('[data-test="internalCommentsInput"] textarea').hasNoValue();

    await click('[data-test="saveButton"]');
    console.log(getSettledState());
    console.log(getPendingWaiterState());
    await clearRender();
  });

  test('checking if new opportunity renders correctly', async function (assert) {
    worker.start();
    authenticateSession({
      authToken: '12345',
      otherData: 'some-data',
    });

    await visit('/opportunity/index');
    await waitFor('[data-test="modelRouteTable"]');
    assert.dom('[data-test="modelRouteTable"]').exists();

    await click('[data-test="addButton"]');

    assert.dom('[data-test="nameInput"] input').hasNoValue();
    assert.dom('[data-test="opportunityStageInput"] select').hasAnyValue();
    assert.dom('[data-test="opportunityTypeInput"] select').hasNoValue();
    assert.dom('[data-test="closeDateInput"] input').hasAnyValue();
    assert.dom('[data-test="currencyInput"] select').hasAnyValue();
    assert.dom('[data-test="companyInput"] .name').doesNotExist();
    assert.dom('[data-test="contactInput"] .name').doesNotExist();
    assert.dom('[data-test="externalReferenceInput"] input').hasNoValue();
    assert.dom('[data-test="ownerInput"] .name').hasAnyText();
    assert.dom('[data-test="organizationInput"] select').hasNoValue();
    assert.dom('[data-test="salesOrderInput"] .name').doesNotExist();
    assert.dom('[data-test="campaignInput"] .name').doesNotExist();
    console.log(getSettledState());
    console.log(getPendingWaiterState());
    await clearRender();
  });
});```
1

There are 1 answers

0
Michael Vanhoutte On

There was some leaking state caused by a mock websocket. It didn't show any leaking state in getPendingWaiters or getSettledState. By using getDebugInfo, I could see that there were still some unfinished counters though. After this i looked deeper into the code and found that still being the problem by commenting pieces of code.