emberjs / ember-mocha

Mocha helpers for testing Ember.js applications
Apache License 2.0
130 stars 69 forks source link

Flaky `Cannot assign to read only property 'owner' of object '#<Context>'` #561

Open rreckonerr opened 4 years ago

rreckonerr commented 4 years ago

Cannot assign to read only property 'owner' of object '#<Context>'

I'm upgrading test suit from ember-cli-mocha to ember-mocha 0.15.1 and get randomly failing tests all over again and those tests look fine when I'm running them separately. Is there a way to find out what's causing this error?

rreckonerr commented 4 years ago

Mentioned error appears because of some tests being started before the previous one is finished, which results in tests getting wrong originalContext and not being able to clean it up properly. Is my assumption correct? Any ideas how can I debug this further?

  beforeEach(function () {
    originalContext = _assign({}, this);
    console.group(
      `${originalContext.test.parent.title} => ${originalContext.currentTest.title}`
    );
    return setupContext(this, options)
      .then(() => setupPauseTest(this))
      .then(() => chainHooks(beforeEachHooks, this));
  });

  afterEach(function () {
    return chainHooks(afterEachHooks, this)
      .then(() => teardownContext(this))
      .then(() => {
        // delete any extraneous properties
        for (let key in this) {
          if (!(key in originalContext)) {
            console.log("key to delete :>> ", key);
            delete this[key];
          }
        }

        // copy over the original values
        _assign(this, originalContext);
      })
      .catch((error) => {
        console.log("this :>> ", this);
        console.log("originalContext :>> ", originalContext);
        console.error(error);
      })
      .finally(() => {
        console.groupEnd();
      });
  });

image

Example in the screenshot is failing randomly.

notchris commented 3 years ago

Can confirm this issue occurs