Skip to content

Commit

Permalink
also support comments in json file
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Feb 7, 2022
1 parent 9d7a27b commit 739ec0d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Features

- `[jest-config]` Support comments in JSON config file ([#12316](https://github.com/facebook/jest/pull/12316))
- `[pretty-format]` Expose `ConvertAnsi` plugin ([#12308](https://github.com/facebook/jest/pull/12308))

### Fixes
Expand Down
1 change: 1 addition & 0 deletions e2e/multiple-configs/jest.config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
// this is a comment in a JSON file
"displayName": "Config from json file"
}
3 changes: 2 additions & 1 deletion packages/jest-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"micromatch": "^4.0.4",
"parse-json": "^5.2.0",
"pretty-format": "^27.5.0",
"slash": "^3.0.0"
"slash": "^3.0.0",
"strip-json-comments": "^3.1.1"
},
"devDependencies": {
"@types/glob": "^7.1.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-config/src/readConfigFileAndSetRootDir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import * as path from 'path';
import * as fs from 'graceful-fs';
import parseJson = require('parse-json');
import stripJsonComments = require('strip-json-comments');
import type {Service} from 'ts-node';
import type {Config} from '@jest/types';
import {interopRequireDefault, requireOrImportModule} from 'jest-util';
Expand All @@ -34,7 +35,7 @@ export default async function readConfigFileAndSetRootDir(
configObject = await loadTSConfigFile(configPath);
} else if (isJSON) {
const fileContent = fs.readFileSync(configPath, 'utf8');
configObject = parseJson(fileContent, configPath);
configObject = parseJson(stripJsonComments(fileContent), configPath);
} else {
configObject = await requireOrImportModule<any>(configPath);
}
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12624,6 +12624,7 @@ __metadata:
semver: ^7.3.5
slash: ^3.0.0
strip-ansi: ^6.0.0
strip-json-comments: ^3.1.1
ts-node: ^9.0.0
typescript: ^4.0.3
peerDependencies:
Expand Down

0 comments on commit 739ec0d

Please sign in to comment.