<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tomáš Gold</title>
    <description>The latest articles on DEV Community by Tomáš Gold (@tom_gold).</description>
    <link>https://dev.to/tom_gold</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2295038%2F711ba926-f8bb-40d3-87f3-e0e46aeb50f1.png</url>
      <title>DEV Community: Tomáš Gold</title>
      <link>https://dev.to/tom_gold</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tom_gold"/>
    <language>en</language>
    <item>
      <title>Let’s Make Jest Run Much Faster</title>
      <dc:creator>Tomáš Gold</dc:creator>
      <pubDate>Mon, 28 Oct 2024 16:42:21 +0000</pubDate>
      <link>https://dev.to/tom_gold/lets-make-jest-run-much-faster-1hfc</link>
      <guid>https://dev.to/tom_gold/lets-make-jest-run-much-faster-1hfc</guid>
      <description>&lt;p&gt;But first, we need to understand why it is so slow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practical Example
&lt;/h2&gt;

&lt;p&gt;Consider a simple React component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;deepClone&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./utils&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nb"&gt;Object&lt;/span&gt; &lt;span class="nx"&gt;looks&lt;/span&gt; &lt;span class="nx"&gt;like&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;deepClone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;))}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;App component depends only on one utility function - deepClone. The utils file looks like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lodash&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;moment&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;moment&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;mui&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@mui/material&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;deepClone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cloneDeep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getFormattedDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;moment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;YYYY-MM-DD&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;mui&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It exports three one-line helper functions. That's it.&lt;br&gt;
Now, here's a big question: How long do you think it will take to execute this test?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;screen&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@testing-library/react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@testing-library/jest-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;renders the app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The answer? An eternity!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; PASS  src/tests/react-app/react-app.test.js
  √ renders the date and sum correctly (25 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        5.045 s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It took 5 seconds on my machine, to execute a one-liner test case for a one-liner React component.&lt;/p&gt;

&lt;h2&gt;
  
  
  Analyzing Performance
&lt;/h2&gt;

&lt;p&gt;To analyze what is happening behind the scenes, we can use either Chrome's profiler - &lt;a href="https://www.youtube.com/watch?v=RB2g-o39upo&amp;amp;t=153s&amp;amp;pp=ygUPamVzdCBwcm9maWxsaW5n" rel="noopener noreferrer"&gt;I recommend watching this insightful video by Kent C. Dodds&lt;/a&gt;.&lt;br&gt;
Alternatively, you can use a &lt;a href="https://www.npmjs.com/package/jest-neat-runner" rel="noopener noreferrer"&gt;jest-neat-runner&lt;/a&gt; library, which simplifies the profiling process. Set the &lt;strong&gt;NEAT_REPORT_MODULE_LOAD_ABOVE_MS&lt;/strong&gt; option to 150 and enable &lt;strong&gt;NEAT_REPORT_TRANSFORM&lt;/strong&gt;. This configuration will print out the modules that take more than 150ms to load and provide information on how long it took to process (open and transpile) the files.&lt;/p&gt;

&lt;p&gt;Let's use the latter. This is the output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; jest src/tests/react-app/

From src\tests\react-app\utils.js -&amp;gt; @mui/material in 1759ms
From node_modules\@mui\material\node\styles\adaptV4Theme.js -&amp;gt; @mui/system in 509ms
From src\tests\react-app\react-app.test.js -&amp;gt; @testing-library/react in 317ms
From node_modules\@testing-library\react\dist\pure.js -&amp;gt; @testing-library/dom in 266ms
From node_modules\@mui\system\ThemeProvider\ThemeProvider.js -&amp;gt; @mui/private-theming in 166ms
From node_modules\@testing-library\dom\dist\role-helpers.js -&amp;gt; aria-query in 161ms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We're loading "@mui/material" library for almost 2 seconds without even using it!&lt;/p&gt;

&lt;h2&gt;
  
  
  Root Cause In Many Projects?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Messy Dependencies
&lt;/h3&gt;

&lt;p&gt;In my experience, performance problems with jest mainly stem from the large number of transitive dependencies that aren't even used at runtime. As showcased in our example above, if you don't pay enough attention to what files you import into your application, you might end up in the same situation as me.&lt;/p&gt;

&lt;p&gt;In my case, the &lt;em&gt;App&lt;/em&gt; component only depends on the &lt;em&gt;deepClone&lt;/em&gt; utility function. However, since &lt;em&gt;deepClone&lt;/em&gt; is exported from the &lt;em&gt;utils&lt;/em&gt; file, all the dependencies within the &lt;em&gt;utils&lt;/em&gt; file were also loaded along with it.&lt;/p&gt;

&lt;p&gt;Files that contain a lot of loosely related functions and heavy dependencies might significantly slow down your application and tests.&lt;/p&gt;

&lt;h3&gt;
  
  
  Barrel Files
&lt;/h3&gt;

&lt;p&gt;Jest is not a friend with ESM modules, which leads it to fallback to CommonJS. Consequently, tree-shaking doesn't function correctly. This is particularly problematic when relying on modules imported from barrel files (index files).&lt;br&gt;
For instance, when you import a small component or function from a barrel file, Jest will load everything else as well - which obviously causes an unnecessary overhead.&lt;/p&gt;
&lt;h2&gt;
  
  
  What Now?
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Adjusting the Import Strategy Manually
&lt;/h3&gt;

&lt;p&gt;Aside from removing the barrel files and refactoring the entire codebase by breaking up files with numerous dependencies into smaller, more focused modules. We can identify modules that take a long time to load and look for smaller alternative modules or check if the imported module exports individual parts separately (i.e., named imports) instead of using the barrel file.&lt;br&gt;
Meaning, instead of&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;cloneDeep&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lodash&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;do&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;cloneDeep&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lodash/cloneDeep&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we're not using the module at all, we can mock it via &lt;em&gt;jest.mock&lt;/em&gt; to avoid loading it completely.&lt;br&gt;
However, these adjustments can be quite time-consuming.&lt;/p&gt;
&lt;h3&gt;
  
  
  Runtime Cache Approach
&lt;/h3&gt;

&lt;p&gt;A more effective method involves using the &lt;a href="https://www.npmjs.com/package/jest-neat-runner" rel="noopener noreferrer"&gt;jest-neat-runner&lt;/a&gt; library with the &lt;strong&gt;NEAT_RUNTIME_CACHE&lt;/strong&gt; option. When this option is on, the library tracks the real runtime usage of all modules (per test file) and stores dependencies that we do not need for subsequent test runs into a cache. Let me show what it does on the example above&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
&amp;gt; jest src/tests/react-app/

From src\tests\react-app\react-app.test.js -&amp;gt; @testing-library/react in 292ms
From node_modules\@testing-library\react\dist\pure.js -&amp;gt; @testing-library/dom in 241ms
From node_modules\@testing-library\dom\dist\queries\role.js -&amp;gt; aria-query in 176ms

 PASS  src/tests/react-app/react-app.test.js
  √ renders the date and sum correctly (33 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.29 s
Ran all test suites matching /src\\tests\\react-app\\/i.
 📢 Jest run done: 1/1 suites passed on the first run. 
    Used neat cache for 1 file(s).
    Node modules skipped: 26.
    Source modules skipped: 0.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We reduced the execution time from five seconds to two by skipping the loading of 26 unnecessary libraries, including the MUI library.&lt;br&gt;
Be cautious - there are several caveats when using &lt;strong&gt;NEAT_RUNTIME_CACHE&lt;/strong&gt;, so make sure to read the README before using it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Other Optimization Techniques
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Transpilation optimisations&lt;/strong&gt;: Examine how many files need to be transpiled and use the most effective transpiler (like SWC or esbuild). If you want to save time, the &lt;strong&gt;NEAT_REPORT_TRANSFORM&lt;/strong&gt; option in jest-neat-runner will provide detailed information on how much time and how many modules it takes to transpile.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Caching Modules in Memory&lt;/strong&gt;: By default, Jest does not cache modules in memory, meaning every test run must open, parse, and load the module into memory. If you have a vast suite of tests and enough memory, consider using the &lt;strong&gt;NEAT_TRANSFORM_CACHE&lt;/strong&gt; option to speed things up.&lt;/p&gt;
&lt;h2&gt;
  
  
  What About the CI Pipeline?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Parallel Runs:&lt;/strong&gt; CircleCI and GitHub Actions support parallel runs. This means you can spin up more machines and divide the load using the &lt;a href="https://jestjs.io/docs/next/cli#--shard" rel="noopener noreferrer"&gt;shard &lt;/a&gt;parameter in Jest.&lt;br&gt;
&lt;strong&gt;Storing the Jest and Neat Cache&lt;/strong&gt;: This is crucial for taking advantage of Jest and jest-neat-runner in the CI. Be sure to set the &lt;em&gt;cacheDirectory&lt;/em&gt; option in Jest. Then, store the directory after the test run, and restore the cache before running the tests. Caveat: If you're using parallelism, ensure you store unique caches for each node. For instance, CircleCI exposes the &lt;strong&gt;CIRCLE_NODE_INDEX&lt;/strong&gt; environment variable, which you can leverage when storing the cache. This is how it looks in the CircleCI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;restore_cache&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Restore Jest Cache&lt;/span&gt;
      &lt;span class="na"&gt;keys&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;jest-cache-{{ .Branch }}-{{ checksum "package-lock.json" }}-{{ .Environment.CIRCLE_NODE_INDEX }}&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Run Tests with Jest&lt;/span&gt;
      &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
        &lt;span class="s"&gt;mkdir -p ~/repo/cache/jest&lt;/span&gt;
        &lt;span class="s"&gt;npm test -- --cacheDirectory=~/repo/cache/jest&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;save_cache&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Save Jest Cache&lt;/span&gt;
      &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;jest-cache-{{ .Branch }}-{{ checksum "package-lock.json" }}-{{ .Environment.CIRCLE_NODE_INDEX }}&lt;/span&gt;
      &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;~/repo/cache/jest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By following these guidelines, you can significantly enhance Jest's performance in your projects.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>jest</category>
      <category>unittest</category>
    </item>
  </channel>
</rss>
