question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unit test runs very slow (6 sec per a test)

See original GitHub issue
  • Issue

After config ts-jest to create-react app successfully, I saw a test case run 6s. That’s very slow. My jest config following the document: (ts|tsx)": “<rootDir>/node_modules/ts-jest/preprocessor.js”

My code

describe("App", () => {
    it("renders only 1 App component", () => {
        const component = shallow(<App />);
        console.log(component.html())
        expect(component).toHaveLength(1);
    });
});

Result: PASS src/containers/test/App.spec.tsx (6.119s)

  • Expected behavior

I searched some tutorials on the internet, there is a preprocessor.js file:

const tsc = require("typescript");
const tsConfig = require("./tsconfig.json");

module.exports = {
  process(src, path) {
    if (path.endsWith(".ts") || path.endsWith(".tsx")) {
      return tsc.transpile(src, tsConfig.compilerOptions, path, []);
    } else if (path.endsWith(".js") ) {
      return tsc.transpile(src, tsConfig.compilerOptions, path, []);
    }
    return src;
  }
};

If I use this file, the test case runs on 3 -4s. Can you explain me this problem? Does preprocessor.js of TS-Jest have more functionalities than that file as well?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:63
  • Comments:78 (6 by maintainers)

github_iconTop GitHub Comments

86reactions
bbughcommented, Jun 20, 2019

If you’re having trouble with this, you could try running jest with --maxWorkers=1 or --runInBand. We were having very slow tests too, but running it with only one worker (which is what both of those commands do) reduced our run time by 95% in a local dev test. Seems counter-intuitive, but it’s working. runInBand says it’s intended for debugging purposes, so I’d stick to the maxWorkers flag if it works for you.

58reactions
Loremastercommented, Jan 24, 2019

@EvanDarwin I am experiencing issues with slow tests too. It can take around 30-50 seconds for a single test. Were you able to resolve it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Jest - Simple tests are slow - Stack Overflow
Run the tests syncronously.. allows jest to optimize? ... but per your reports, it looks like the actual test is running in 6...
Read more >
Are Slow Tests Killing Your Feedback Loop? - Quality Coding
A unit test that takes 1/10th of a second to run is a slow unit test. As Michael says: “Yes, I'm serious.” Because...
Read more >
(some) JUnit test execution super slow
Typically, a test class passes in 1, 2 seconds. But for me, since a few weeks, sometimes, a single test method needs 5+...
Read more >
Very slow PHPUnit tests using PHP7.2 or PHP7.1. - Laracasts
If I run my tests using PHP7.2 or PHP7.1 they are about 3x slower than if I run them using PHP7.0. Is there...
Read more >
Diagnosing slow tests (again) - Jon Skeet's coding blog
Looking at the test runs, I saw that the tests for .NET Core 1.0 were completing in about 15 seconds on AppVeyor (Windows),...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found