title: Why won't Jest create a coverage folder?
body: <p>I have <code>&quot;test&quot;: &quot;jest --coverage --color --detectOpenHandles&quot;</code> set up in my <code>package.json</code>. In order to make this work, I have to run <code>npx jest --coverage</code> first (to create the <code>coverage</code> folder. Otherwise I will get the following error.</p>
  <p>I was under the impression that if I run  <code>jest --coverage</code> then it would create the <code>coverage</code> folder. Is that the wrong assumption?</p>
  <p>I have a <code>TypeScript\Node</code> application.</p>
  <p>The error is:</p>
  <pre><code> Failed to write coverage reports:
          ERROR: Error: ENOENT: no such file or directory, open '/Users/MY-PATH/coverage/coverage-final.json'
          STACK: Error: ENOENT: no such file or directory, open '/Users/MY-PATH/coverage/coverage-final.json'
      at Object.openSync (node:fs:585:3)
      at FileWriter.writeFile (/Users/MY-PATH/node_modules/istanbul-lib-report/lib/file-writer.js:185:41)
      at JsonReport.onStart (/Users/MY-PATH/node_modules/istanbul-reports/lib/json/index.js:17:45)
      at Visitor.value (/Users/MY-PATH/node_modules/istanbul-lib-report/lib/tree.js:38:38)
      at ReportTree.visit (/Users/MY-PATH/node_modules/istanbul-lib-report/lib/tree.js:126:17)
      at JsonReport.execute (/Users/MY-PATH/node_modules/istanbul-lib-report/lib/report-base.js:12:44)
      at /Users/MY-PATH/node_modules/@jest/reporters/build/CoverageReporter.js:253:12
      at Array.forEach (&lt;anonymous&gt;)
      at CoverageReporter.onRunComplete (/Users/MY-PATH/node_modules/@jest/reporters/build/CoverageReporter.js:241:25)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
  </code></pre>
  <p>The contents of <code>package.json</code> are:</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;scripts&quot;: {
      &quot;lint&quot;: &quot;eslint --ext .ts .&quot;,
      &quot;lint:fix&quot;: &quot;eslint --fix --ext .ts .&quot;,
      &quot;start&quot;: &quot;npm run lint &amp;&amp; ts-node-dev --respawn --pretty --transpile-only src/server.ts&quot;,
      &quot;test&quot;: &quot;jest --coverage --color --detectOpenHandles&quot;
    },
    &quot;dependencies&quot;: {
      &quot;axios&quot;: &quot;^0.24.0&quot;,
      &quot;cors&quot;: &quot;^2.8.5&quot;,
      &quot;dotenv&quot;: &quot;^10.0.0&quot;,
      &quot;eslint-config-airbnb&quot;: &quot;^19.0.4&quot;,
      &quot;eslint-config-airbnb-typescript&quot;: &quot;^16.1.0&quot;,
      &quot;express&quot;: &quot;^4.17.2&quot;,
      &quot;express-jwt&quot;: &quot;^6.1.0&quot;,
      &quot;helmet&quot;: &quot;^5.0.1&quot;,
      &quot;inversify&quot;: &quot;^6.0.1&quot;,
      &quot;jwks-rsa&quot;: &quot;^2.0.5&quot;,
      &quot;reflect-metadata&quot;: &quot;^0.1.13&quot;,
      &quot;winston&quot;: &quot;^3.4.0&quot;,
      &quot;winston-daily-rotate-file&quot;: &quot;^4.6.0&quot;
    },
    &quot;devDependencies&quot;: {
      &quot;@types/cors&quot;: &quot;^2.8.12&quot;,
      &quot;@types/dotenv&quot;: &quot;^8.2.0&quot;,
      &quot;@types/express&quot;: &quot;^4.17.13&quot;,
      &quot;@types/express-jwt&quot;: &quot;^6.0.4&quot;,
      &quot;@types/helmet&quot;: &quot;^4.0.0&quot;,
      &quot;@types/jest&quot;: &quot;^27.4.0&quot;,
      &quot;@types/node&quot;: &quot;^17.0.7&quot;,
      &quot;@types/supertest&quot;: &quot;^2.0.11&quot;,
      &quot;@typescript-eslint/eslint-plugin&quot;: &quot;^5.10.1&quot;,
      &quot;@typescript-eslint/parser&quot;: &quot;^5.10.1&quot;,
      &quot;eslint&quot;: &quot;^8.7.0&quot;,
      &quot;eslint-config-airbnb-base&quot;: &quot;^15.0.0&quot;,
      &quot;eslint-plugin-import&quot;: &quot;^2.25.4&quot;,
      &quot;jest&quot;: &quot;^27.4.7&quot;,
      &quot;supertest&quot;: &quot;^6.2.2&quot;,
      &quot;ts-jest&quot;: &quot;^27.1.3&quot;,
      &quot;ts-node-dev&quot;: &quot;^1.1.8&quot;,
      &quot;typescript&quot;: &quot;^4.5.4&quot;
    }
  }
  
  </code></pre>
  <p><code>jest.config.ts</code> looks like:</p>
  <pre><code>import { Config } from '@jest/types';
  
  
  export default {
    transform: {
      '^.+\\.ts?$': 'ts-jest',
    },
    testEnvironment: 'node',
    testMatch: [
      '**/?(*.)+(spec|test).ts',
    ],
    testPathIgnorePatterns: [
      '/lib/',
      '/node_modules/',
    ],
    moduleFileExtensions: [
      'ts',
      'tsx',
      'js',
      'jsx',
      'json',
      'node',
    ],
    collectCoverage: true,
    collectCoverageFrom: [
      '**/*.ts',
      '!**/*container.(t|j)s',
    ],
    roots: [
      '&lt;rootDir&gt;/src',
    ],
    coverageThreshold: {
      global: {
        branches: 80,
        functions: 80,
        lines: 80,
        statements: 80,
      },
    },
  } as Config.InitialOptions;
  </code></pre>