How to modify setup config in NodeEnvironment (from jest-environment-node)?

Viewed 718

We're building a NodeJS Framework MidwayJS, and we recommend our users to use Jest to make test cases. We modified Jest Env like this:

'use strict';
const NodeEnvironment = require('jest-environment-node');

/* eslint-disable no-useless-constructor */
class JestEnvironment extends NodeEnvironment {
  constructor(config) {
    super(config);
  }

  async setup() {
    require('ts-node/register');
    this.global.process.env.MIDWAY_TS_MODE = 'true';
    this.global.process.env.MIDWAY_JEST_MODE = 'true';
    this.global.setTimeout(3000)
    await super.setup();
  }

  async teardown() {
    await super.teardown();
  }

  runScript(script) {
    return super.runScript(script);
  }
}

module.exports = JestEnvironment;

With configuration above it goes well, but we got a problem:

Some users create huge project directory and our framework will scan the whole directory before application start, when running test cases it acts also in this way, which makes it in some suitations take more than 3000ms--Jest set default async callback called time to be 3000ms, so if the scanning didn't finished in 3000ms the test would crash.

we solved this easily by use jest.setup.js in one line : jest.setTimeout(30000), but now we want to solve it in the file which showed in the first, and I didn't find a way to modify setup config in it.

I'd appreciate it greatly if you can help me to make it out.

0 Answers
Related