Skip to content

Commit

Permalink
Drop JSON5 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain STEPHANT committed Feb 22, 2019
1 parent cfa94e7 commit e847424
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 47 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -79,7 +79,6 @@ Session.vim
out/
.idea_modules/
atlassian-ide-plugin.xml
mocha.iml

# SourceTree
*_BACKUP_*
Expand Down
4 changes: 1 addition & 3 deletions docs/index.md
Expand Up @@ -1627,8 +1627,7 @@ In addition to supporting the legacy [`mocha.opts`](#mochaopts) run-control form

- **JavaScript**: Create a `.mocharc.js` in your project's root directory, and export an object (`module.exports = {/* ... */}`) containing your configuration.
- **YAML**: Create a `.mocharc.yaml` (or `.mocharc.yml`) in your project's root directory.
- **JSON**: Create a `.mocharc.json` in your project's root directory. Comments — while not valid JSON — are allowed in this file, and will be ignored by Mocha.
- **[JSON5](https://json5.org/)**: Create a `.mocharc.jsonc` (or `.mocharc.json5`) in your project's root directory.
- **JSON**: Create a `.mocharc.json` (or `.mocharc.jsonc`) in your project's root directory. Comments — while not valid JSON — are allowed in this file, and will be ignored by Mocha.
- **`package.json`**: Create a `mocha` property in your project's `package.json`.

Mocha suggests using one of the above strategies for configuration instead of the legacy `mocha.opts` format.
Expand All @@ -1651,7 +1650,6 @@ If no custom path was given, and if there are multiple configuration files in th
1. `.mocharc.yaml`
1. `.mocharc.yml`
1. `.mocharc.jsonc`
1. `.mocharc.json5`
1. `.mocharc.json`

### Merging
Expand Down
4 changes: 0 additions & 4 deletions lib/cli/config.js
Expand Up @@ -25,7 +25,6 @@ exports.CONFIG_FILES = [
'.mocharc.yaml',
'.mocharc.yml',
'.mocharc.jsonc',
'.mocharc.json5',
'.mocharc.json'
];

Expand All @@ -37,7 +36,6 @@ const parsers = (exports.parsers = {
yaml: filepath =>
require('js-yaml').safeLoad(fs.readFileSync(filepath, 'utf8')),
js: filepath => require(filepath),
json5: filepath => require('json5').parse(fs.readFileSync(filepath, 'utf8')),
json: filepath =>
JSON.parse(
require('strip-json-comments')(fs.readFileSync(filepath, 'utf8'))
Expand All @@ -59,8 +57,6 @@ exports.loadConfig = filepath => {
config = parsers.yaml(filepath);
} else if (ext === '.js') {
config = parsers.js(filepath);
} else if (/\.json[5c]/.test(ext)) {
config = parsers.json5(filepath);
} else {
config = parsers.json(filepath);
}
Expand Down
15 changes: 0 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -502,7 +502,6 @@
"growl": "1.10.5",
"he": "1.2.0",
"js-yaml": "3.12.0",
"json5": "2.1.0",
"log-symbols": "2.2.0",
"minimatch": "3.0.4",
"mkdirp": "0.5.1",
Expand Down
2 changes: 0 additions & 2 deletions test/integration/config.spec.js
Expand Up @@ -11,10 +11,8 @@ describe('config', function() {
var configDir = path.join(__dirname, 'fixtures', 'config');
var js = loadConfig(path.join(configDir, 'mocharc.js'));
var json = loadConfig(path.join(configDir, 'mocharc.json'));
var jsonc = loadConfig(path.join(configDir, 'mocharc.jsonc'));
var yaml = loadConfig(path.join(configDir, 'mocharc.yaml'));
expect(js, 'to equal', json);
expect(json, 'to equal', yaml);
expect(yaml, 'to equal', jsonc);
});
});
7 changes: 0 additions & 7 deletions test/integration/fixtures/config/mocharc.jsonc

This file was deleted.

16 changes: 2 additions & 14 deletions test/node-unit/cli/config.spec.js
Expand Up @@ -21,7 +21,6 @@ describe('cli/config', function() {
beforeEach(function() {
sandbox.stub(parsers, 'yaml').returns(config);
sandbox.stub(parsers, 'json').returns(config);
sandbox.stub(parsers, 'json5').returns(config);
sandbox.stub(parsers, 'js').returns(config);
});

Expand Down Expand Up @@ -61,20 +60,9 @@ describe('cli/config', function() {
describe('when supplied a filepath with .jsonc extension', function() {
const filepath = 'foo.jsonc';

it('should use the JSON5 parser', function() {
it('should use the JSON parser', function() {
loadConfig('foo.jsonc');
expect(parsers.json5, 'to have calls satisfying', [
{args: [filepath], returned: config}
]).and('was called times', 1);
});
});

describe('when supplied a filepath with .json5 extension', function() {
const filepath = 'foo.json5';

it('should use the JSON5 parser', function() {
loadConfig('foo.json5');
expect(parsers.json5, 'to have calls satisfying', [
expect(parsers.json, 'to have calls satisfying', [
{args: [filepath], returned: config}
]).and('was called times', 1);
});
Expand Down

0 comments on commit e847424

Please sign in to comment.