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

Jasmine timeout somehow used in Jest tests? #896

Closed
yedidyak opened this issue Dec 8, 2016 · 4 comments
Closed

Jasmine timeout somehow used in Jest tests? #896

yedidyak opened this issue Dec 8, 2016 · 4 comments

Comments

@yedidyak
Copy link

yedidyak commented Dec 8, 2016

I have two Wallaby configs, one for Jasmine and one for Jest.

wallabyJest.js:

const babelOptions = {
  "presets": [
    "es2015",
    "stage-0",
    "react"
  ]
};

module.exports = function(wallaby) {
  return {
    env: {
      type: 'node',
      runner: 'node'
    },

    testFramework: 'jest',

    files: [
      'src/**/*.js',
      '!src/**/*.test.js'
    ],

    tests: [
      'src/**/*.test.js'
    ],

    compilers: {
      '**/*.js': wallaby.compilers.babel(babelOptions)
    },

    setup: function (w) {
      require('babel-polyfill');
    }
  };
};

When I run a test using that config, if it fails by a timeout I get the following message in the console:

Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

I can't see where to change the default timeout, nor why it's taking a jasmine environment var.

If I change that var in the test itself, for example bu putting jasmine.DEFAULT_TIMEOUT_INTERVAL = 10 in beforeEach(), it uses the changed value, but I can't find a way t set it globally.

Am I missing something?

@ArtemGovorov
Copy link
Member

Jest is using jasmine behind the scenes so yes, it does use Jasmine timeout. You may configure jest to increase the timeout globally as described in the jest repo, for example by creating a jestSetup.js file with the increased timeout:

jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;

and making it jest setupTestFrameworkScriptFile:

module.exports = function(wallaby) {
  return {
    ...
    setup: function (w) {
      ...
      w.testFramework.configure({
         setupTestFrameworkScriptFile: '<rootDir>/jestSetup.js'
      });
    }
  };
};

@sudhanshuraheja
Copy link

5000 works well as a global config, if you want to change the timeout for a specific test, please do this

test("test an API which takes time", () => {

    doYourThing()

}, 10000)

@kachkaev
Copy link

kachkaev commented Feb 1, 2018

@sudhanshuraheja does this work for both sync and async tests? I could not use timeout for potentially long-running sync jobs – these tests never caused a timeout:

test("sync test", () => {
    const result = slowSyncFunction();
    expect(result).toEqual(42);
}, 10)

This works though:

test("async test", async () => {
    const result = await slowAsyncFunction();
    expect(result).toEqual(42);
}, 10)

If timeouts for sync stuff are not supported by design, how could the efficiency of sync code tested in jest then?

@ArtemGovorov
Copy link
Member

@kachkaev I don't think Jest (or any test runners, except for Wallaby.js) can detect timeouts in long-running sync tests.

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

4 participants