Code Monkey home page Code Monkey logo

Comments (10)

Turbo87 avatar Turbo87 commented on June 16, 2024 2

This has been solved with the new testing API released in v0.14.0

from ember-mocha.

alexlafroscia avatar alexlafroscia commented on June 16, 2024 1

I've been playing around with this some, and have had trouble overriding the existing pauseTest helper to set the timeout. However, introducing a new helper works.

What I did to override the existing helper was adding this to the test-helper.js for a demo app:

import { before } from 'mocha';

before(function() {
  const originalPauseTestHelper = Ember.Test._helpers.pauseTest.method;

  Ember.Test.registerAsyncHelper('pauseTest', () => {
    this.timeout(0);

    return originalPauseTestHelper();
  });
});

My hope was that setting the timeout in here would override the default value of 2000 and cause the test now to fail. However, this doesn't work; I'm guessing that's the case because the context (this) of the before hook needs to be set up before the it callback is called, but in this case we're setting it after the test has already started.

What did work was setting up a new helper, like this:

import { before } from 'mocha';

before(function() {
  const originalPauseTestHelper = Ember.Test._helpers.pauseTest.method;

  Ember.Test.registerAsyncHelper('pauseMochaTest', (app, context) => {
    context.timeout(0);

    return originalPauseTestHelper();
  });
});

In this case, the tests passes the context into the helper, like:

pauseMochaTest(this);

So now it can set the timeout correctly, because it's accessing the context of the it callback instead of the context of the before.

I've tried to see if there's some way to access the it context from the before but it doesn't seem possible. How do you feel about "solving" this with a new helper?

from ember-mocha.

rwjblue avatar rwjblue commented on June 16, 2024

Yeah, we should be able to do that.

from ember-mocha.

alexlafroscia avatar alexlafroscia commented on June 16, 2024

On the other hand, it seems like if you return a promise from the it callback, Mocha just waits for it to resolve. In this cause, pauseTest returns a promise that doesn't ever resolve, so as long as you do

return pauseTest();

it seems like the test doesn't time out.

from ember-mocha.

Turbo87 avatar Turbo87 commented on June 16, 2024

I'd be very surprised by that. The default behavior in Mocha is to timeout after 2 sec when either the done callback is used or a Promise is returned. Not sure if the ember-mocha-adapter mucks around with that though...

from ember-mocha.

alexlafroscia avatar alexlafroscia commented on June 16, 2024

@Turbo87 what do you find surprising? I'm happy to throw together a demo repo.

from ember-mocha.

Turbo87 avatar Turbo87 commented on June 16, 2024

I find it surprising that it doesn't time out when returning a Promise, because that is definitely not the default behavior of Mocha itself.

from ember-mocha.

alexlafroscia avatar alexlafroscia commented on June 16, 2024

Hmm, you're right. I guess I was mistaken about what I was seeing earlier when returning pauseTest().

from ember-mocha.

caseywatts avatar caseywatts commented on June 16, 2024

this feels silly to have to do this, but I just added a snippet to atom for this and I thought I'd share :)

  'timeout then pauseTest()':
    'prefix': 'pau',
    'body': 'this.timeout(0); return pauseTest();'

from ember-mocha.

caseywatts avatar caseywatts commented on June 16, 2024

I'm updating the docs for this here:
emberjs/ember.js#16740

from ember-mocha.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.