Repository: depcheck/depcheck
Pull request #682 (2021-11-17 18:47:16)

feat(jest): add support for jest.config.cjs
As per [Jest docs on Configuring Jest](https://jestjs.io/docs/configuration), `jest.config.cjs` is a supported file format of its kind, this PR adds support to it.

codecov[bot]: # [Codecov](https://codecov.io/gh/depcheck/depcheck/pull/682?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=depcheck) Report
> Merging [#682](https://codecov.io/gh/depcheck/depcheck/pull/682?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=depcheck) (9023984) into [main](https://codecov.io/gh/depcheck/depcheck/commit/73c2bec4ae85404c01249b805e7dafe4f8499c65?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=depcheck) (73c2bec) will **decrease** coverage by `0.19%`.
> The diff coverage is `85.72%`.

[![Impacted file tree graph](https://codecov.io/gh/depcheck/depcheck/pull/682/graphs/tree.svg?width=650&height=150&src=pr&token=pgMcKAUD3w&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=depcheck)](https://codecov.io/gh/depcheck/depcheck/pull/682?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=depcheck)

```diff
@@            Coverage Diff             @@
##             main     #682      +/-   ##
==========================================
- Coverage   98.64%   98.45%   -0.18%     
==========================================
  Files          49       49              
  Lines        1023     1031       +8     
==========================================
+ Hits         1009     1015       +6     
- Misses         14       16       +2     
```


| [Impacted Files](https://codecov.io/gh/depcheck/depcheck/pull/682?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=depcheck) | Coverage Δ | |
|---|---|---|
| [src/utils/configuration-reader.js](https://codecov.io/gh/depcheck/depcheck/pull/682/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=depcheck#diff-c3JjL3V0aWxzL2NvbmZpZ3VyYXRpb24tcmVhZGVyLmpz) | `100.00% <ø> (ø)` | |
| [src/cli.js](https://codecov.io/gh/depcheck/depcheck/pull/682/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=depcheck#diff-c3JjL2NsaS5qcw==) | `95.56% <75.00%> (-4.44%)` | :arrow_down: |
| [src/detector/importDeclaration.js](https://codecov.io/gh/depcheck/depcheck/pull/682/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=depcheck#diff-c3JjL2RldGVjdG9yL2ltcG9ydERlY2xhcmF0aW9uLmpz) | `100.00% <100.00%> (ø)` | |
| [src/special/jest.js](https://codecov.io/gh/depcheck/depcheck/pull/682/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=depcheck#diff-c3JjL3NwZWNpYWwvamVzdC5qcw==) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/depcheck/depcheck/pull/682?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=depcheck).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=depcheck)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/depcheck/depcheck/pull/682?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=depcheck). Last update [180e05a...9023984](https://codecov.io/gh/depcheck/depcheck/pull/682?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=depcheck). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=depcheck).


Patch:
diff --git a/src/special/jest.js b/src/special/jest.js
index 249859c..eeaa97b 100644
--- a/src/special/jest.js
+++ b/src/special/jest.js
@@ -4,7 +4,7 @@ import { getContent } from '../utils/file';
 
 const _ = lodash;
 
-const jestConfigRegex = /^jest.([^.]+\.)?conf(ig|).js(on|)$/;
+const jestConfigRegex = /^jest.([^.]+\.)?conf(ig|).(cjs|js(on|))$/;
 const supportedProperties = [
   'dependencyExtractor',
   'preset',


Test patch:
diff --git a/test/special/jest.js b/test/special/jest.js
index 68e0cff..a909362 100644
--- a/test/special/jest.js
+++ b/test/special/jest.js
@@ -8,10 +8,13 @@ const testParser = getTestParserWithTempFile(parser);
 
 const configFileNames = [
   'jest.config.js',
+  'jest.config.cjs',
   'jest.conf.js',
+  'jest.conf.cjs',
   'jest.config.json',
   'jest.conf.json',
   'jest.it.config.js',
+  'jest.it.config.cjs',
 ];
 
 const testCases = [
@@ -195,7 +198,7 @@ describe('jest special parser', () => {
       it(`should ${testCase.name} in config file ${fileName}`, async () => {
         const config = JSON.stringify(testCase.content);
         let content = config;
-        if (fileName.split('.').pop() === 'js') {
+        if (['js', 'cjs'].includes(fileName.split('.').pop())) {
           content = `module.exports = ${config}`;
         }
         return testJest(content, testCase.deps, testCase.deps, fileName);