How can I solve the Jest message "Jest did not exit one second after the test run has completed."?

1.3k views Asked by At

We are using frisby.js for our automated API tests and frisby.js uses Jest as test runner. Now in our case we do a global setup before executing all API tests and after the test execution we do a global teardown.

This global setup and teardown I've set in jest.conf.js:

globalSetup: './jest.globalSetup.js',
globalTeardown: './jest.globalTeardown.js',

So, the global teardown exports an async function that is triggered once after all test suites. In our global teardown we are generating a test coverage and test reports with an external report engine:

const coverage = require('./test-coverage-generator');
const XunitViewerCli = require('xunit-viewer/cli');

module.exports = async function() {
  await coverage.generateTestCoverage();
  await XunitViewerCli({
      results: './api/reporting/test-reports/jest-junit-report-' + process.env.API_TEST_FOLDER + '.xml',
      ignore: [],
      output: './api/reporting/test-reports/jest-junit-report-' + process.env.API_TEST_FOLDER + '.html',
      title: 'Test Report API Tests for ' + process.env.API_TEST_FOLDER,
      port: false,
      watch: false,
      color: true,
      filter: {}
  });
}

And the report generation is the problem why Jest generates the message Jest did not exit one second after the test run has completed. at the end of the tests, because the report generation takes more than one second.

So, I don't want to see this message anymore, because this message is confused. Maybe is it possible to increase the default Jest timeout of one second globally or are there any other possible solutions to prevent this message?

1

There are 1 answers

0
Divyanshu Maithani On

I faced something similar, the solution was to return a promise from the function exported from globalTeardown module. Something like this should resolve the issue:

module.exports = async function() {
  await coverage.generateTestCoverage();
  // returns a promise
  return XunitViewerCli({
      results: './api/reporting/test-reports/jest-junit-report-' + process.env.API_TEST_FOLDER + '.xml',
      ignore: [],
      output: './api/reporting/test-reports/jest-junit-report-' + process.env.API_TEST_FOLDER + '.html',
      title: 'Test Report API Tests for ' + process.env.API_TEST_FOLDER,
      port: false,
      watch: false,
      color: true,
      filter: {}
  });
}