Skip to content

Commit

Permalink
Update: allow empty string toml config (parcel-bundler#7418)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinyaigeek authored and bhovhannes committed Dec 23, 2021
1 parent 67b94cb commit 7b01ca1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
1 change: 0 additions & 1 deletion packages/core/utils/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export async function loadConfig(
}

let configContent = await fs.readFile(configFile, 'utf8');
if (!configContent) return null;

let config;
if (parse === false) {
Expand Down
50 changes: 50 additions & 0 deletions packages/core/utils/test/config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// @flow strict-local

import assert from 'assert';
import {loadConfig} from '../src/config';
import {inputFS as fs} from '@parcel/test-utils';
import path from 'path';

describe('loadConfig', () => {
it('load config with json', async () => {
assert.deepEqual(
(
await loadConfig(
fs,
path.join(__dirname, './input/config/config.json'),
['config.json'],
path.join(__dirname, './input/config/'),
)
)?.config,
{
hoge: 'fuga',
},
);
});

it('should throw error with empty string json', async () => {
// $FlowFixMe[prop-missing]
await assert.rejects(async () => {
await loadConfig(
fs,
path.join(__dirname, './input/config/empty.json'),
['empty.json'],
path.join(__dirname, './input/config/'),
);
});
});

it('should load with empty string config toml', async () => {
assert.deepEqual(
(
await loadConfig(
fs,
path.join(__dirname, './input/config/empty.toml'),
['empty.toml'],
path.join(__dirname, './input/config/'),
)
)?.config,
{},
);
});
});
3 changes: 3 additions & 0 deletions packages/core/utils/test/input/config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"hoge": "fuga"
}
Empty file.
Empty file.

0 comments on commit 7b01ca1

Please sign in to comment.